Commit 63b4af70 authored by protolambda's avatar protolambda Committed by GitHub

op-supervisor: do not return zeroed included-in block (#12842)

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

* op-supervisor: fix tests, implement review suggestion
parent 5c54f884
......@@ -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)
}
......
......@@ -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
......@@ -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()
......
......@@ -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)
......@@ -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))
......@@ -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))
......@@ -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))
......@@ -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))
......@@ -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))
})
})
......@@ -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))
})
})
......@@ -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))
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment