Disallow Duplicate Best Headers (#653)

* Add test proving bug

* Add checks for duplicate headers

* Fix Clippy error
This commit is contained in:
Hernando Castano
2021-01-19 11:03:26 -05:00
committed by Bastian Köcher
parent 507edb950c
commit 6cd4f5edf1
2 changed files with 57 additions and 6 deletions
+6 -1
View File
@@ -521,7 +521,12 @@ impl<T: Config> BridgeStorage for PalletStorage<T> {
match current_height.cmp(&best_height) {
Ordering::Equal => {
<BestHeaders<T>>::append(hash);
// Want to avoid duplicates in the case where we're writing a finalized header to
// storage which also happens to be at the best height the best height
let not_duplicate = !<ImportedHeaders<T>>::contains_key(hash);
if not_duplicate {
<BestHeaders<T>>::append(hash);
}
}
Ordering::Greater => {
<BestHeaders<T>>::kill();