avalanchego
avalanchego copied to clipboard
Add GetPreference to support VM persisting preference across restart
Addresses https://github.com/ava-labs/avalanchego/issues/2577
This PR adds GetPreference to the VM interface in order to persist the preference after a restart. This ensures that if the node/VM shuts down while a block is already in consensus, the VM will persist that preference after a restart.
As described in https://github.com/ava-labs/avalanchego/issues/2577, in order to make this change as minimal as possible, this is implemented inside of the ProposerVM which already stores wrapped blocks of all the underlying VMs. As a result, we only need to implement it in the ProposerVM once and the ProposerVM's roll forward mechanism ensures that inner VMs are brought up to date with the last preference of the consensus engine.
- [x] Add GetPreference to the VM interface
- [x] Implement ProposerVM "roll forward" mechanism to bring the inner VM up to date with the ProposerVM
- [x] Persist blocks to disk during
Verifyin the ProposerVM under its own DB prefix - [x] Persist the preference to disk in the ProposerVM
- [x] Implement cleanup mechanism within ProposerVM
Initializeto wipe any verified blocks that are no longer preferred - [x] Update ProposerVM
Initializefunction to correctly garbage collect no longer preferred verified blocks and initialize the preference correctly - [x] Update the consensus engine to utilize
GetPreferenceinstead of setting the preference to the last accepted block during startup
Aaron cannot approve because he is the author and I took over later to approving on his behalf for now