Conversation
|
I am not quite sure how to handle the finality case where we finalize a block that the "best" chain doesn't contain. One solution I had was to prevent indexing by number for non-finalized blocks, but that would probably hamstring the UX a little too much. |
|
I've noticed this changes DB keys for block data to use hashes instead of numbers. Using numbers is quite beneficial for DB performance. Blocks tend to be requested in groups by number when syncing and it helps a lot when they are located close in the DB. Geth did that optimization a while a go and the improvement was significant. I'd prefer to keep the current design. Additional blocks sharing the same number could be suffixed with an extra index and the suffix would be removed on finalization. |
|
I'd rather have correctness than optimization for the moment, so let's re-optimize the DB once this is merged and the new consensus is integrated. Could you make a proposal for a new database schema that is efficient and handles reorgs/non-instant finality and file it? |
svyatonik
left a comment
There was a problem hiding this comment.
Looked mostly at light + db-related changes (haven't touched state-db changes at all) to resolve #765 later - seems good. The only important thing I haven't understood - why not to fail when trying to revert finalized block (left a comment) - could you please elaborate?
| // TODO: ensure this doesn't conflict with old finalized block. | ||
| let meta = self.blockchain.meta.read(); | ||
| let f_num = f_header.number().clone(); | ||
| let number_u64: u64 = f_num.as_().into(); |
There was a problem hiding this comment.
Looks like .into() here is redundant.
| } | ||
|
|
||
| let mut canonicalize_state = |canonical_hash| { | ||
| trace!(target: "db", "Canonicalize block #{} ({:?})", number_u64 - self.pruning_window, canonical_hash); |
There was a problem hiding this comment.
Isn't the number_u64 - self.pruning_window expression is constant? I mean this will print the same number, but different hashes
| for retracted in tree_route.retracted() { | ||
| if retracted.hash == meta.finalized_hash { | ||
| // TODO: can we recover here? | ||
| warn!("Safety failure: reverting finalized block {:?}", |
There was a problem hiding this comment.
Why don't we return an error here? I thought that retracting finalized blocks should be impossible.
There was a problem hiding this comment.
in general yes, but after having one experience with authorities signing a bad block I thought this would leave things easier to recover from in the future.
| /// ``` | ||
| /// | ||
| /// ```ignore | ||
| /// Tree route from C to E. Retracted empty. Common is C, enacted [E1, E2] |
There was a problem hiding this comment.
"Tree route from C to E" -> "Tree route from C to E2"?
The way I see it only the best chain can be finalized. If there's a need to finalize some other chain the best chain should be reorganized to that chain first. I.e. it should become the new best |
|
"best" here just means longest? |
Currently yes, although the blockchain backend does not enforce this. The "is_new_best" flag is provided by the client. |
|
If the finalised leaf is on the non-best-chain, then we'll need to reorg first. |
|
|
|
I'll add tree-route tests in the follow-up PR |
* Update referral_or_council_of accordingly * Nit * Fix rls warnings in tokens/src/lib.rs * Fix tokens/src/mock.rs * Keep original asset_power and add internal_asset_power * Fix staking/src/mock.rs * Build wasm * Nits * Finish cross_chain_assets threshold test * Build wasm
…paritytech#760) * begin porting over traits; remove Config use of Hash * port over the Header bits that we need * sp_core_hashing where possible, move Verify to PairSigner, remove unused errors * tidy up Config things and move related bits into one place * fix codegen * copy Era over * move AccountId, Address, Signer to Signer trait and a pass over fixing examples * impl MultiAddress, MultiSignature, AccountId32 and add back to Config (for decoding later) * Copy over StorageKey, StorageData, StorageChangeSet * subxt core compiling with no sp_core or sp_runtime * Get examples compiling * pass over fixing tests * cargo fmt * clippy tweaks and update polkadot.rs * fix codegen docs * port over special DigestItem encoding/decoding * clippy and doc fixes * cargo fmt and example fix * more cargo fmt-ing... * substrate-extra to substrate-compat * cargo.toml comments * simplify PairSigner trait bounds * move RPC types to a separate file * fix docs * Add some tests for things and other PR feedback * bump to latest sp deps * avoid needing substrate-compat feature in a test
Partially addresses #746
This rewrites the blockchain DB to handle non-instant finality and chain reorganizations.
Pruning and CHT generation is done after finality now.