Skip to content

Commit

Permalink
Avoid updating the block gap when it's unchanged
Browse files Browse the repository at this point in the history
Previously, the block gap storage could be updated even when the gap is
the same as before. This patch fixes it by only updating the storage
when the gap is changed.
  • Loading branch information
liuchengxu committed Sep 1, 2024
1 parent b7d5f15 commit bde7609
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions substrate/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,19 +1693,19 @@ impl<Block: BlockT> Backend<Block> {
number,
hash,
)?;
}
if start > end {
transaction.remove(columns::META, meta_keys::BLOCK_GAP);
block_gap = None;
debug!(target: "db", "Removed block gap.");
} else {
block_gap = Some((start, end));
debug!(target: "db", "Update block gap. {:?}", block_gap);
transaction.set(
columns::META,
meta_keys::BLOCK_GAP,
&(start, end).encode(),
);
if start > end {
transaction.remove(columns::META, meta_keys::BLOCK_GAP);
block_gap = None;
debug!(target: "db", "Removed block gap.");
} else {
block_gap = Some((start, end));
debug!(target: "db", "Update block gap. {:?}", block_gap);
transaction.set(
columns::META,
meta_keys::BLOCK_GAP,
&(start, end).encode(),
);
}
}
} else if number > best_num + One::one() &&
number > One::one() && self.blockchain.header(parent_hash)?.is_none()
Expand Down

0 comments on commit bde7609

Please sign in to comment.