Closed arhag closed 6 months ago
Simpler version:
An index should be maintained in the new fork database to allow the best head to be quickly selected.
Computed fields for index (in order):
In this case, the core
is the immutable one. There would be no next_core_metadata
anymore.
Also, we need to vote on blocks that are not yet validated. The rule for now is:
core.final_on_strong_qc_block_num
for the block you are considering to vote on and use that to find the actual block ID of the ancestor block that has that block number.Keeping open until the following is done:
Also, we need to vote on blocks that are not yet validated. The rule for now is:
- Get the
core.final_on_strong_qc_block_num
for the block you are considering to vote on and use that to find the actual block ID of the ancestor block that has that block number.- If that block ID is not an ancestor of the current head block, then do not vote for that block.
- Otherwise, consider voting for that block according to the decide_vote rules.
This needs to search the branch of bsp->id()
which is not necessarily the head branch. Then it should verify the found block state is validated.
Depends on https://github.com/AntelopeIO/leap/issues/2244.
Update index for picking the best branch (rename
by_lib_block_num
toby_best_branch
) to order based on the computed fields derived from data inblock_state
.This issue assumes the following structures exist:
And that there is a member function
next_metadata
in the block header state core with the following function signature:The idea is to keep a cache of a
qc_claim
calledmost_recent_ancestor_with_qc
within eachblock_state
in the fork database which makes a QC claim on its most recent ancestor that has a valid QC. And in addition to keep a cache of thenext_core_metadata
that is derived from thecore
of thatblock_state
by callingcore.next_metadata(most_recent_ancestor_with_qc)
. Any timemost_recent_ancestor_with_qc
is mutated for ablock_state
, the correspondingnext_core_metadata
should also be recomputed.If a new QC (weak of strong) is achieved on a
block_state
, Leap must not only update themost_recent_ancestor_with_qc
of thatblock_state
but it must also traverse to the descendant blocks to determine whether their correspondingmost_recent_ancestor_with_qc
s should also be updated. If ablock_state
has a betterqc_claim
(as determined byoperator<
) then itsmost_recent_ancestor_with_qc
should not be updated nor should those of any of its descendant blocks.An index should be maintained in the new fork database to allow the best head to be quickly selected.
Computed fields for index (in order):
next_core_metadata.last_final_block_num
next_core_metadata.latest_qc_claim_block_num
Between blocks, the best head (as determined by the index) can be checked to determine if a fork switch is necessary.