fix(rollup-verifier): delete committed batch meta when reverting a batch (#1000)

* fix(rollup-verifier): delete committed batch metadata when reverting a batch

* chore: auto version bump [bot]

* remove a comment

---------

Co-authored-by: colinlyguo <colinlyguo@users.noreply.github.com>
This commit is contained in:
colin 2024-08-26 17:15:29 +08:00 committed by GitHub
parent 233a6adc15
commit 03f3b2b60d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 2 deletions

View file

@ -208,3 +208,11 @@ func ReadCommittedBatchMeta(db ethdb.Reader, batchIndex uint64) *CommittedBatchM
}
return cbm
}
// DeleteCommittedBatchMeta removes the block ranges of all chunks associated with a specific batch from the database.
// Note: Only non-finalized batches can be reverted.
func DeleteCommittedBatchMeta(db ethdb.KeyValueWriter, batchIndex uint64) {
if err := db.Delete(committedBatchMetaKey(batchIndex)); err != nil {
log.Crit("failed to delete committed batch metadata", "batch index", batchIndex, "err", err)
}
}

View file

@ -211,7 +211,7 @@ func TestBatchChunkRanges(t *testing.T) {
DeleteBatchChunkRanges(db, uint64(len(chunks)+1))
}
func TestWriteReadCommittedBatchMeta(t *testing.T) {
func TestWriteReadDeleteCommittedBatchMeta(t *testing.T) {
db := NewMemoryDatabase()
testCases := []struct {
@ -261,6 +261,19 @@ func TestWriteReadCommittedBatchMeta(t *testing.T) {
if got := ReadCommittedBatchMeta(db, 256); got != nil {
t.Fatalf("Expected nil for non-existing value, got %+v", got)
}
// delete: revert batch
for _, tc := range testCases {
DeleteCommittedBatchMeta(db, tc.batchIndex)
readChunkRange := ReadCommittedBatchMeta(db, tc.batchIndex)
if readChunkRange != nil {
t.Fatal("Committed batch metadata was not deleted", "batch index", tc.batchIndex)
}
}
// delete non-existing value: ensure the delete operation handles non-existing values without errors.
DeleteCommittedBatchMeta(db, 256)
}
func TestOverwriteCommittedBatchMeta(t *testing.T) {

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 6 // Minor version component of the current release
VersionPatch = 4 // Patch version component of the current release
VersionPatch = 5 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

View file

@ -219,6 +219,7 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
batchIndex := event.BatchIndex.Uint64()
log.Trace("found new RevertBatch event", "batch index", batchIndex)
rawdb.DeleteCommittedBatchMeta(s.db, batchIndex)
rawdb.DeleteBatchChunkRanges(s.db, batchIndex)
case s.l1FinalizeBatchEventSignature: