Skip to content

Commit

Permalink
Make set_parent_hash mark entire chain as bad (#2121)
Browse files Browse the repository at this point in the history
* Make set_parent_hash mark entire chain as bad

* Test with an actual chain

* Update CHANGELOG
  • Loading branch information
tomaka authored Mar 7, 2022
1 parent 40a24f8 commit b8b7a1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit b8b7a1f

Please sign in to comment.