Currently the controllerhead (fork_database::chain_head in hotstuff_integration) is set on startup from the fork_databasehead on normal startup. It is created to be genesis when starting a fresh chain or --replay-blockchain option. It is created from the block_header_state stored in snapshot when starting from a snapshot.
Because head is only stored in fork database on shutdown, a replay that is interrupted (e.g. ctrl-c) wipes out reversible blocks in the fork database when it stores the current head information into the fork database. Ideally, loss of reversible blocks should not happen when a replay is interrupted.
Proposal: Store controller headblock_header_state needed for re-start in a separate file along side shared_memory.bin in the state directory. Use this file to store current head during shutdown of replay as well as normal shutdown outside of replay. On startup, verify the head matches the chainbase revision and TAPOS block_summary_object; if not exit with error.
Bonus: Investigate storing only the block_id of head in controller and pulling block_state out of fork database only when needed. If this doesn't result in loss of performance, it provides a cleaner implementation for instant finality as block id works for both block_state and block_state_legacy. If this doesn't work out, then moving to using block_handle instead of fork_database::chain_head is preferred.
Depends on https://github.com/AntelopeIO/leap/issues/2141.
Currently the
controller
head
(fork_database::chain_head
inhotstuff_integration
) is set on startup from thefork_database
head
on normal startup. It is created to begenesis
when starting a fresh chain or--replay-blockchain
option. It is created from theblock_header_state
stored in snapshot when starting from a snapshot.Because
head
is only stored in fork database on shutdown, a replay that is interrupted (e.g. ctrl-c) wipes out reversible blocks in the fork database when it stores the current head information into the fork database. Ideally, loss of reversible blocks should not happen when a replay is interrupted.Proposal: Store controller
head
block_header_state
needed for re-start in a separate file along sideshared_memory.bin
in thestate
directory. Use this file to store current head during shutdown of replay as well as normal shutdown outside of replay. On startup, verify thehead
matches the chainbase revision and TAPOSblock_summary_object
; if not exit with error.Bonus: Investigate storing only the
block_id
ofhead
in controller and pullingblock_state
out of fork database only when needed. If this doesn't result in loss of performance, it provides a cleaner implementation for instant finality as block id works for bothblock_state
andblock_state_legacy
. If this doesn't work out, then moving to usingblock_handle
instead offork_database::chain_head
is preferred.