Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always verify blocks before justifications #1618

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions lib/src/sync/all_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,13 +1003,30 @@ impl<TBl, TRq, TSrc> AllForksSync<TBl, TRq, TSrc> {
/// This method takes ownership of the [`AllForksSync`] and starts a verification
/// process. The [`AllForksSync`] is yielded back at the end of this process.
pub fn process_one(mut self) -> ProcessOne<TBl, TRq, TSrc> {
// Try to find a block to verify.
// All blocks are always verified before verifying justifications, in order to guarantee
// that the block that a justification targets has already been verified.
// TODO: revisit that ^ as advancing finality should have priority over advancing the chain
let block_to_verify = self.inner.blocks.unverified_leaves().find(|block| {
block.parent_block_hash == self.chain.finalized_block_hash()
|| self
.chain
.contains_non_finalized_block(&block.parent_block_hash)
});
if let Some(block) = block_to_verify {
return ProcessOne::BlockVerify(BlockVerify {
parent: self,
block_to_verify: block,
});
}

// Try to find a justification to verify.
// TODO: O(n)
let source_id_with_finality_proof = self
.inner
.blocks
.sources()
.find(|id| !self.inner.blocks[*id].unverified_finality_proofs.is_none());

if let Some(source_id_with_finality_proof) = source_id_with_finality_proof {
let finality_proof_to_verify = self.inner.blocks[source_id_with_finality_proof]
.unverified_finality_proofs
Expand All @@ -1022,21 +1039,7 @@ impl<TBl, TRq, TSrc> AllForksSync<TBl, TRq, TSrc> {
});
}

let block = self.inner.blocks.unverified_leaves().find(|block| {
block.parent_block_hash == self.chain.finalized_block_hash()
|| self
.chain
.contains_non_finalized_block(&block.parent_block_hash)
});

if let Some(block) = block {
ProcessOne::BlockVerify(BlockVerify {
parent: self,
block_to_verify: block,
})
} else {
ProcessOne::AllSync { sync: self }
}
ProcessOne::AllSync { sync: self }
}
}

Expand Down
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix "Justification targets block not in the chain" errors, leading to peers being erroneously banned. ([#1618](https://github.com/smol-dot/smoldot/pull/1618))

## 2.0.19 - 2024-01-26

### Fixed
Expand Down
Loading