mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 12:11:09 +00:00
Do not run forced_canonicalization for archive nodes (#13051)
We don't canonicalize on archive nodes and thus `best_canonical` always returned `None`. So, the moment such a node tried to force canonicalize, it was trapped in some endless loop. This pr solves this by renaming `best_canonical` to `last_canonicalized` and also making the return value more clear by introducing a custom enum `LastCanonicalized`.
This commit is contained in:
@@ -283,6 +283,17 @@ fn to_meta_key<S: Codec>(suffix: &[u8], data: &S) -> Vec<u8> {
|
||||
buffer
|
||||
}
|
||||
|
||||
/// Status information about the last canonicalized block.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum LastCanonicalized {
|
||||
/// Not yet have canonicalized any block.
|
||||
None,
|
||||
/// The given block number is the last canonicalized block.
|
||||
Block(u64),
|
||||
/// No canonicalization is happening (pruning mode is archive all).
|
||||
NotCanonicalizing,
|
||||
}
|
||||
|
||||
pub struct StateDbSync<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
mode: PruningMode,
|
||||
non_canonical: NonCanonicalOverlay<BlockHash, Key>,
|
||||
@@ -349,15 +360,28 @@ impl<BlockHash: Hash, Key: Hash, D: MetaDb> StateDbSync<BlockHash, Key, D> {
|
||||
Ok(commit)
|
||||
}
|
||||
|
||||
fn best_canonical(&self) -> Option<u64> {
|
||||
self.non_canonical.last_canonicalized_block_number()
|
||||
/// Returns the block number of the last canonicalized block.
|
||||
fn last_canonicalized(&self) -> LastCanonicalized {
|
||||
if self.mode == PruningMode::ArchiveAll {
|
||||
LastCanonicalized::NotCanonicalizing
|
||||
} else {
|
||||
self.non_canonical
|
||||
.last_canonicalized_block_number()
|
||||
.map(LastCanonicalized::Block)
|
||||
.unwrap_or_else(|| LastCanonicalized::None)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_pruned(&self, hash: &BlockHash, number: u64) -> IsPruned {
|
||||
match self.mode {
|
||||
PruningMode::ArchiveAll => IsPruned::NotPruned,
|
||||
PruningMode::ArchiveCanonical | PruningMode::Constrained(_) => {
|
||||
if self.best_canonical().map(|c| number > c).unwrap_or(true) {
|
||||
if self
|
||||
.non_canonical
|
||||
.last_canonicalized_block_number()
|
||||
.map(|c| number > c)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
if self.non_canonical.have_block(hash) {
|
||||
IsPruned::NotPruned
|
||||
} else {
|
||||
@@ -611,9 +635,9 @@ impl<BlockHash: Hash, Key: Hash, D: MetaDb> StateDb<BlockHash, Key, D> {
|
||||
self.db.write().remove(hash)
|
||||
}
|
||||
|
||||
/// Returns last finalized block number.
|
||||
pub fn best_canonical(&self) -> Option<u64> {
|
||||
return self.db.read().best_canonical()
|
||||
/// Returns last canonicalized block.
|
||||
pub fn last_canonicalized(&self) -> LastCanonicalized {
|
||||
self.db.read().last_canonicalized()
|
||||
}
|
||||
|
||||
/// Check if block is pruned away.
|
||||
|
||||
Reference in New Issue
Block a user