Adds support for the step
parameter in BlocksByRange request (#737)
* Add duplication prevention to gossipsub * Clean up topic logs * Add content addressed messages for gossip * Support BlocksByRange step parameter
This commit is contained in:
parent
45271abc16
commit
41d6d5fafd
@ -310,12 +310,22 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
"peer" => format!("{:?}", peer_id),
|
"peer" => format!("{:?}", peer_id),
|
||||||
"count" => req.count,
|
"count" => req.count,
|
||||||
"start_slot" => req.start_slot,
|
"start_slot" => req.start_slot,
|
||||||
|
"step" => req.step,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if req.step == 0 {
|
||||||
|
warn!(self.log,
|
||||||
|
"Peer sent invalid range request";
|
||||||
|
"error" => "Step sent was 0");
|
||||||
|
self.network.disconnect(peer_id, GoodbyeReason::Fault);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut block_roots = self
|
let mut block_roots = self
|
||||||
.chain
|
.chain
|
||||||
.forwards_iter_block_roots(Slot::from(req.start_slot))
|
.forwards_iter_block_roots(Slot::from(req.start_slot))
|
||||||
.take_while(|(_root, slot)| slot.as_u64() < req.start_slot + req.count)
|
.take_while(|(_root, slot)| slot.as_u64() < req.start_slot + req.count * req.step)
|
||||||
|
.step_by(req.step as usize)
|
||||||
.map(|(root, _slot)| root)
|
.map(|(root, _slot)| root)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -326,7 +336,9 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
if let Ok(Some(block)) = self.chain.store.get::<BeaconBlock<T::EthSpec>>(&root) {
|
if let Ok(Some(block)) = self.chain.store.get::<BeaconBlock<T::EthSpec>>(&root) {
|
||||||
// Due to skip slots, blocks could be out of the range, we ensure they are in the
|
// Due to skip slots, blocks could be out of the range, we ensure they are in the
|
||||||
// range before sending
|
// range before sending
|
||||||
if block.slot >= req.start_slot && block.slot < req.start_slot + req.count {
|
if block.slot >= req.start_slot
|
||||||
|
&& block.slot < req.start_slot + req.count * req.step
|
||||||
|
{
|
||||||
blocks_sent += 1;
|
blocks_sent += 1;
|
||||||
self.network.send_rpc_response(
|
self.network.send_rpc_response(
|
||||||
peer_id.clone(),
|
peer_id.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user