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

Make set_parent_hash mark entire chain as bad #2121

Merged
merged 4 commits into from
Mar 7, 2022
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
1 change: 1 addition & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
- Implement the `ext_crypto_ecdsa_verify_version_1` host function ([#2120](https://github.com/paritytech/smoldot/pull/2120)).
- Implement the `ext_crypto_ecdsa_sign_prehashed_version_1` host function ([#2120](https://github.com/paritytech/smoldot/pull/2120)).
- Implement the `ext_crypto_ecdsa_verify_prehashed_version_1` host function ([#2120](https://github.com/paritytech/smoldot/pull/2120)).
- Properly mark all descendants as bad when a block is determined to be bad ([#2121](https://github.com/paritytech/smoldot/pull/2121)).
17 changes: 14 additions & 3 deletions src/sync/all_forks/disjoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<TBl> DisjointBlocks<TBl> {
}

if parent_is_bad {
block.bad = true;
self.set_block_bad(height, hash);
}
}

Expand Down Expand Up @@ -432,8 +432,8 @@ mod tests {

#[test]
fn set_parent_hash_updates_bad() {
// Calling `set_parent_hash` where the parent is a known a bad block marks the block as
// bad as well.
// Calling `set_parent_hash` where the parent is a known a bad block marks the block and
// its children as bad as well.

let mut collection = super::DisjointBlocks::new();

Expand All @@ -443,10 +443,21 @@ mod tests {
assert_eq!(collection.unknown_blocks().count(), 0);

collection.insert(2, [2; 32], None, ());
assert!(!collection.is_bad(2, &[2; 32]).unwrap());
collection.insert(3, [3; 32], Some([2; 32]), ());
assert!(!collection.is_bad(3, &[3; 32]).unwrap());
collection.insert(3, [31; 32], Some([2; 32]), ());
assert!(!collection.is_bad(3, &[31; 32]).unwrap());
collection.insert(4, [4; 32], Some([3; 32]), ());
assert!(!collection.is_bad(4, &[4; 32]).unwrap());
assert_eq!(collection.unknown_blocks().count(), 1);

collection.set_parent_hash(2, &[2; 32], [1; 32]);
assert_eq!(collection.unknown_blocks().count(), 0);
assert!(collection.is_bad(2, &[2; 32]).unwrap());
assert!(collection.is_bad(3, &[3; 32]).unwrap());
assert!(collection.is_bad(3, &[31; 32]).unwrap());
assert!(collection.is_bad(4, &[4; 32]).unwrap());
}

#[test]
Expand Down