Skip to content

Commit

Permalink
Remove an externally reachable unwrap (#285)
Browse files Browse the repository at this point in the history
If some peer sent us a block without proof to our `RunningNode` we would
try to unwrap the `udata` and panic. This commit actually handles the
case and remove the panic
  • Loading branch information
Davidson-Souza authored Nov 21, 2024
1 parent 2ead823 commit 3a2ce7a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/floresta-wire/src/p2p_wire/running_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,19 @@ where
self.blocks.insert(block.block.block_hash(), (peer, block));
while let Some((peer, block)) = self.blocks.remove(&next_block) {
debug!("processing block {}", block.block.block_hash(),);
let (proof, del_hashes, inputs) = floresta_chain::proof_util::process_proof(
&block.udata.unwrap(),
&block.block.txdata,
&self.chain,
)?;
let Some(udata) = &block.udata else {
warn!("peer {peer} sent us a block without udata");
self.increase_banscore(peer, 5).await?;
self.send_to_random_peer(
NodeRequest::GetBlock((vec![block.block.block_hash()], true)),
service_flags::UTREEXO.into(),
)
.await?;
return Ok(());
};

let (proof, del_hashes, inputs) =
floresta_chain::proof_util::process_proof(udata, &block.block.txdata, &self.chain)?;
if let Err(e) = self
.chain
.connect_block(&block.block, proof, inputs, del_hashes)
Expand Down

0 comments on commit 3a2ce7a

Please sign in to comment.