avalanchego icon indicating copy to clipboard operation
avalanchego copied to clipboard

Add GetPreference to support VM persisting preference across restart

Open aaronbuchwald opened this issue 1 year ago • 2 comments

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 Verify in the ProposerVM under its own DB prefix
  • [x] Persist the preference to disk in the ProposerVM
  • [x] Implement cleanup mechanism within ProposerVM Initialize to wipe any verified blocks that are no longer preferred
  • [x] Update ProposerVM Initialize function to correctly garbage collect no longer preferred verified blocks and initialize the preference correctly
  • [x] Update the consensus engine to utilize GetPreference instead of setting the preference to the last accepted block during startup

aaronbuchwald avatar Jan 19 '24 20:01 aaronbuchwald

Aaron cannot approve because he is the author and I took over later to approving on his behalf for now

joshua-kim avatar Apr 05 '24 22:04 joshua-kim