op-supervisor: Add IDs to database entries
Description
Adds a single byte ID to each entry written to the database so that it is possible to detect if chain heads were not updated correctly after the log db was truncated and new entries written. ie
We might have a write sequence like:
- Write logs a,b,c
- Update cross-unsafe to point to c (idx 2)
- Rewind database to b (removing c)
- Update cross-unsafe to point to b (ie idx 1)
- Append x to the log db (so we now have a,b,x)
If we crash at that point it's possible that we come back and have cross-unsafe at idx 2 because the head rollback didn't get flushed, but log db with a,b,x because the log db writes did get flushed. This can now be detected because while x is at the same index as the previous c it will have a different ID.
Not yet implemented is recovering from such a situation - for the unsafe head, it should just point to the last entry in the log db. For other heads it's not possible to know exactly how far to roll them back, so they will need to drop back to the earliest head that still has a valid index and ID. If the cross-finalised head is also invalidated, it needs to be set to the final entry for the current finalized block (which will need to be loaded via RPC) because while the finalized head tracked by op-node may decrease on pipeline reset or restarts, the block data and thus the logs never actually change. For devnet 1 we may just consider that case unrecoverable.
Tests
Added unit tests.
Metadata
- https://github.com/ethereum-optimism/optimism/issues/11028