Currently in substrate there is a possibility to set state pruning to "archive-canonical" or "number". In docs it states, that these values will cause to:
- archive-canonical - Keep only the state of finalized blocks.
- number - Keep the state of the last number of finalized blocks.
That said, when digging deeper there is a fundamental difference between canonical and finalized. It is described in https://github.com/paritytech/substrate/blob/master/client/db/src/lib.rs
//! # Canonicality vs. Finality
//!
//! Finality indicates that a block will not be reverted, according to the consensus algorithm,
//! while canonicality indicates that the block may be reverted, but we will be unable to do so,
//! having discarded heavy state that will allow a chain reorganization.
//!
//! Finality implies canonicality but not vice-versa.
And this functionality works in such a way, that if best block is over 4096 (constant value named CANONICALIZATION_DELAY
) blocks on top of best finalized block, state of yet unfinalized blocks will be pruned by function force_delayed_canonicalize
(https://github.com/paritytech/substrate/blob/129fee774a6d185d117a57fd1e81b3d0d05ad747/client/db/src/lib.rs#L1399).
This has proven problematic for me, when using pruning. I could not call runtime_api for the state of best finalized block (it was already pruned because of finalization stall).
Because of that I have three questions:
- Are there any plans to add something like
archive-finalized
? So in this setting unfinalized blocks would not be prunned. - Why is
force_delayed_canonicalize
function needed? Are there any dangers of it not being called? - Why is
CANONICALIZATION_DELAY
set to 4096 blocks? Can it be bigger?