Correct parent lookup (#1027)

* Correct parent-lookup with block gossip verification

* Further update port conflicts in tests
This commit is contained in:
Age Manning
2020-04-20 16:54:37 +10:00
committed by GitHub
parent 2d3acadfb5
commit 7acb136974
5 changed files with 154 additions and 153 deletions

View File

@@ -60,7 +60,7 @@ impl<T: BeaconChainTypes> Router<T> {
executor: &tokio::runtime::TaskExecutor,
log: slog::Logger,
) -> error::Result<mpsc::UnboundedSender<RouterMessage<T::EthSpec>>> {
let message_handler_log = log.new(o!("service"=> "msg_handler"));
let message_handler_log = log.new(o!("service"=> "router"));
trace!(message_handler_log, "Service starting");
let (handler_send, handler_recv) = mpsc::unbounded_channel();
@@ -262,16 +262,18 @@ impl<T: BeaconChainTypes> Router<T> {
AttestationType::Unaggregated { should_store: true },
);
}
PubsubMessage::BeaconBlock(block) => match self.processor.should_forward_block(block) {
Ok(verified_block) => {
self.propagate_message(id, peer_id.clone());
self.processor.on_block_gossip(peer_id, verified_block);
}
Err(e) => {
warn!(self.log, "Could not verify block for gossip";
PubsubMessage::BeaconBlock(block) => {
match self.processor.should_forward_block(&peer_id, block) {
Ok(verified_block) => {
self.propagate_message(id, peer_id.clone());
self.processor.on_block_gossip(peer_id, verified_block);
}
Err(e) => {
warn!(self.log, "Could not verify block for gossip";
"error" => format!("{:?}", e));
}
}
},
}
PubsubMessage::VoluntaryExit(_exit) => {
// TODO: Apply more sophisticated validation
self.propagate_message(id, peer_id.clone());

View File

@@ -490,9 +490,17 @@ impl<T: BeaconChainTypes> Processor<T> {
/// across the network.
pub fn should_forward_block(
&mut self,
peer_id: &PeerId,
block: Box<SignedBeaconBlock<T::EthSpec>>,
) -> Result<GossipVerifiedBlock<T>, BlockError> {
self.chain.verify_block_for_gossip(*block)
let result = self.chain.verify_block_for_gossip(*block.clone());
if let Err(BlockError::ParentUnknown(_)) = result {
// if we don't know the parent, start a parent lookup
// TODO: Modify the return to avoid the block clone.
self.send_to_sync(SyncMessage::UnknownBlock(peer_id.clone(), block));
}
result
}
/// Process a gossip message declaring a new block.
@@ -534,7 +542,8 @@ impl<T: BeaconChainTypes> Processor<T> {
}
BlockProcessingOutcome::ParentUnknown { .. } => {
// Inform the sync manager to find parents for this block
debug!(self.log, "Block with unknown parent received";
// This should not occur. It should be checked by `should_forward_block`
error!(self.log, "Block with unknown parent attempted to be processed";
"peer_id" => format!("{:?}",peer_id));
self.send_to_sync(SyncMessage::UnknownBlock(peer_id, block));
}