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
Changes from 1 commit
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
11 changes: 8 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,15 @@ 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());
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());
}

#[test]
Expand Down