Skip to content

Commit

Permalink
op-supervisor: do not return zeroed included-in block (ethereum-optim…
Browse files Browse the repository at this point in the history
…ism#12842)

* op-supervisor: do not return zeroed included-in block

* op-supervisor: fix tests, implement review suggestion
  • Loading branch information
protolambda authored Nov 7, 2024
1 parent 5c54f88 commit 63b4af7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion op-supervisor/supervisor/backend/cross/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *Worker) worker() {
return
}
if errors.Is(err, types.ErrFuture) {
s.log.Debug("Worker awaits more data", "err", err)
s.log.Debug("Worker awaits additional blocks", "err", err)
} else {
s.log.Warn("Failed to process work", "err", err)
}
Expand Down
9 changes: 5 additions & 4 deletions op-supervisor/supervisor/backend/db/logs/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ func (db *DB) Contains(blockNum uint64, logIdx uint32, logHash common.Hash) (typ
defer db.rwLock.RUnlock()
db.log.Trace("Checking for log", "blockNum", blockNum, "logIdx", logIdx, "hash", logHash)

// Hot-path: check if we have the block
if db.lastEntryContext.hasCompleteBlock() && db.lastEntryContext.blockNum < blockNum {
return types.BlockSeal{}, types.ErrFuture
}

evtHash, iter, err := db.findLogInfo(blockNum, logIdx)
if err != nil {
return types.BlockSeal{}, err // may be ErrConflict if the block does not have as many logs
Expand All @@ -306,10 +311,6 @@ func (db *DB) Contains(blockNum uint64, logIdx uint32, logHash common.Hash) (typ
if err == nil {
panic("expected iterator to stop with error")
}
if errors.Is(err, types.ErrFuture) {
// Log is known, but as part of an unsealed block.
return types.BlockSeal{}, nil
}
if errors.Is(err, types.ErrStop) {
h, n, _ := iter.SealedBlock()
timestamp, _ := iter.SealedTimestamp()
Expand Down
22 changes: 16 additions & 6 deletions op-supervisor/supervisor/backend/db/logs/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ func TestAddDependentLog(t *testing.T) {
require.NoError(t, db.lastEntryContext.forceBlock(bl15, 5000))
err := db.AddLog(createHash(1), bl15, 0, &execMsg)
require.NoError(t, err)
bl16 := eth.BlockID{Hash: createHash(16), Number: 16}
require.NoError(t, db.SealBlock(bl15.Hash, bl16, 5002))
},
func(t *testing.T, db *DB, m *stubMetrics) {
requireContains(t, db, 16, 0, createHash(1), execMsg)
Expand All @@ -602,6 +604,8 @@ func TestAddDependentLog(t *testing.T) {
require.Equal(t, m.entryCount, int64(searchCheckpointFrequency+2))
err := db.AddLog(createHash(1), bl16, 0, &execMsg)
require.NoError(t, err)
bl17 := eth.BlockID{Hash: createHash(17), Number: 17}
require.NoError(t, db.SealBlock(bl16.Hash, bl17, 5002))
},
func(t *testing.T, db *DB, m *stubMetrics) {
requireContains(t, db, 16, 0, createHash(9))
Expand Down Expand Up @@ -632,6 +636,8 @@ func TestAddDependentLog(t *testing.T) {
// 260 = executing message check
require.Equal(t, int64(261), m.entryCount)
db.debugTip()
bl16 := eth.BlockID{Hash: createHash(16), Number: 16}
require.NoError(t, db.SealBlock(bl15.Hash, bl16, 5001))
},
func(t *testing.T, db *DB, m *stubMetrics) {
requireContains(t, db, 16, 251, createHash(9))
Expand Down Expand Up @@ -661,6 +667,8 @@ func TestAddDependentLog(t *testing.T) {
// 260 = executing message check
db.debugTip()
require.Equal(t, int64(261), m.entryCount)
bl16 := eth.BlockID{Hash: createHash(16), Number: 16}
require.NoError(t, db.SealBlock(bl15.Hash, bl16, 5001))
},
func(t *testing.T, db *DB, m *stubMetrics) {
requireContains(t, db, 16, 252, createHash(9))
Expand Down Expand Up @@ -689,8 +697,8 @@ func TestContains(t *testing.T) {
requireContains(t, db, 51, 0, createHash(1))
requireContains(t, db, 51, 1, createHash(3))
requireContains(t, db, 51, 2, createHash(2))
requireContains(t, db, 53, 0, createHash(1))
requireContains(t, db, 53, 1, createHash(3))
requireFuture(t, db, 53, 0, createHash(1))
requireFuture(t, db, 53, 1, createHash(3))

// 52 was sealed as empty
requireConflicts(t, db, 52, 0, createHash(1))
Expand Down Expand Up @@ -1039,7 +1047,7 @@ func TestRewind(t *testing.T) {
requireContains(t, db, 51, 1, createHash(2))
requireContains(t, db, 52, 0, createHash(3))
// Still have the pending log of unsealed block if the rewind to unknown sealed block fails
requireContains(t, db, 53, 0, createHash(4))
requireFuture(t, db, 53, 0, createHash(4))
})
})

Expand All @@ -1055,8 +1063,9 @@ func TestRewind(t *testing.T) {
require.ErrorIs(t, db.Rewind(25), types.ErrSkipped)
},
func(t *testing.T, db *DB, m *stubMetrics) {
requireContains(t, db, 51, 0, createHash(1))
requireContains(t, db, 51, 0, createHash(1))
// block 51 is not sealed yet
requireFuture(t, db, 51, 0, createHash(1))
requireFuture(t, db, 51, 0, createHash(1))
})
})

Expand Down Expand Up @@ -1189,7 +1198,8 @@ func TestRewind(t *testing.T) {
// try to add a log to 17, on top of 16
err = db.AddLog(createHash(42), bl16, 0, nil)
require.NoError(t, err)
requireContains(t, db, 17, 0, createHash(42))
// not sealed yet
requireFuture(t, db, 17, 0, createHash(42))
})
})
}
Expand Down

0 comments on commit 63b4af7

Please sign in to comment.