AntelopeIO / spring

C++ implementation of the Antelope protocol with Savanna consensus
Other
5 stars 2 forks source link

Refactor head block state management #7

Closed heifner closed 2 months ago

heifner commented 7 months ago

Depends on https://github.com/AntelopeIO/leap/issues/2141.

Currently the controller head (fork_database::chain_head in hotstuff_integration) is set on startup from the fork_database head 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 head block_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.

linh2931 commented 2 months ago

https://github.com/AntelopeIO/spring/pull/133 is too old. It can be closed and try a fix on the latest code base.