diff --git a/op-service/eth/id.go b/op-service/eth/id.go index 7beeabfe329ca..c323d1e69b9a4 100644 --- a/op-service/eth/id.go +++ b/op-service/eth/id.go @@ -85,6 +85,10 @@ func (id L1BlockRef) ParentID() BlockID { } } +// BlockRef is a Block Ref indepdendent of L1 or L2 +// Because L1BlockRefs are strict subsets of L2BlockRefs, BlockRef is a direct alias of L1BlockRef +type BlockRef = L1BlockRef + func (id L2BlockRef) ID() BlockID { return BlockID{ Hash: id.Hash, diff --git a/op-supervisor/supervisor/backend/db/db.go b/op-supervisor/supervisor/backend/db/db.go index 8459266c0704d..c4f8296d1ce01 100644 --- a/op-supervisor/supervisor/backend/db/db.go +++ b/op-supervisor/supervisor/backend/db/db.go @@ -167,7 +167,7 @@ func (db *ChainsDB) AddLog( func (db *ChainsDB) SealBlock( chain types.ChainID, - block eth.L2BlockRef) error { + block eth.BlockRef) error { logDB, ok := db.logDBs[chain] if !ok { return fmt.Errorf("%w: %v", ErrUnknownChain, chain) diff --git a/op-supervisor/supervisor/backend/safety/safety.go b/op-supervisor/supervisor/backend/safety/safety.go index c7828336ba57e..326c72755e35c 100644 --- a/op-supervisor/supervisor/backend/safety/safety.go +++ b/op-supervisor/supervisor/backend/safety/safety.go @@ -14,9 +14,9 @@ import ( type SafetyIndex interface { // Updaters for the latest local safety status of each chain - UpdateLocalUnsafe(chainID types.ChainID, ref eth.L2BlockRef) error - UpdateLocalSafe(chainID types.ChainID, at eth.L1BlockRef, ref eth.L2BlockRef) error - UpdateFinalizeL1(ref eth.L1BlockRef) error + UpdateLocalUnsafe(chainID types.ChainID, ref eth.BlockRef) error + UpdateLocalSafe(chainID types.ChainID, at eth.BlockRef, ref eth.BlockRef) error + UpdateFinalizeL1(ref eth.BlockRef) error // Getters for the latest safety status of each chain UnsafeL2(chainID types.ChainID) (heads.HeadPointer, error) @@ -42,10 +42,10 @@ type safetyIndex struct { finalized map[types.ChainID]eth.BlockID // remember what each non-finalized L2 block is derived from - derivedFrom map[types.ChainID]map[common.Hash]eth.L1BlockRef + derivedFrom map[types.ChainID]map[common.Hash]eth.BlockRef // the last received L1 finality signal. - finalizedL1 eth.L1BlockRef + finalizedL1 eth.BlockRef } func NewSafetyIndex(log log.Logger, chains ChainsDBClient) *safetyIndex { @@ -55,12 +55,12 @@ func NewSafetyIndex(log log.Logger, chains ChainsDBClient) *safetyIndex { unsafe: make(map[types.ChainID]*View), safe: make(map[types.ChainID]*View), finalized: make(map[types.ChainID]eth.BlockID), - derivedFrom: make(map[types.ChainID]map[common.Hash]eth.L1BlockRef), + derivedFrom: make(map[types.ChainID]map[common.Hash]eth.BlockRef), } } // UpdateLocalUnsafe updates the local-unsafe view for the given chain, and advances the cross-unsafe status. -func (r *safetyIndex) UpdateLocalUnsafe(chainID types.ChainID, ref eth.L2BlockRef) error { +func (r *safetyIndex) UpdateLocalUnsafe(chainID types.ChainID, ref eth.BlockRef) error { view, ok := r.safe[chainID] if !ok { iter, err := r.chains.IteratorStartingAt(chainID, ref.Number, 0) @@ -76,11 +76,11 @@ func (r *safetyIndex) UpdateLocalUnsafe(chainID types.ChainID, ref eth.L2BlockRe LastSealedTimestamp: ref.Time, LogsSince: 0, }, - localDerivedFrom: eth.L1BlockRef{}, + localDerivedFrom: eth.BlockRef{}, validWithinView: r.ValidWithinUnsafeView, } r.unsafe[chainID] = view - } else if err := view.UpdateLocal(eth.L1BlockRef{}, ref); err != nil { + } else if err := view.UpdateLocal(eth.BlockRef{}, ref); err != nil { return fmt.Errorf("failed to update local-unsafe: %w", err) } local, _ := r.unsafe[chainID].Local() @@ -102,7 +102,7 @@ func (r *safetyIndex) advanceCrossUnsafe() { // UpdateLocalSafe updates the local-safe view for the given chain, and advances the cross-safe status. func (r *safetyIndex) UpdateLocalSafe( - chainID types.ChainID, at eth.L1BlockRef, ref eth.L2BlockRef) error { + chainID types.ChainID, at eth.BlockRef, ref eth.BlockRef) error { view, ok := r.safe[chainID] if !ok { iter, err := r.chains.IteratorStartingAt(chainID, ref.Number, 0) @@ -129,7 +129,7 @@ func (r *safetyIndex) UpdateLocalSafe( // register what this L2 block is derived from m, ok := r.derivedFrom[chainID] if !ok { - m = make(map[common.Hash]eth.L1BlockRef) + m = make(map[common.Hash]eth.BlockRef) r.derivedFrom[chainID] = m } m[ref.Hash] = at @@ -152,7 +152,7 @@ func (r *safetyIndex) advanceCrossSafe() { } // UpdateFinalizeL1 updates the finalized L1 block, and advances the finalized safety status. -func (r *safetyIndex) UpdateFinalizeL1(ref eth.L1BlockRef) error { +func (r *safetyIndex) UpdateFinalizeL1(ref eth.BlockRef) error { if ref.Number <= r.finalizedL1.Number { return fmt.Errorf("ignoring old L1 finality signal of %s, already have %s", ref, r.finalizedL1) } diff --git a/op-supervisor/supervisor/backend/safety/views.go b/op-supervisor/supervisor/backend/safety/views.go index c9393758fad5c..f99c31b484165 100644 --- a/op-supervisor/supervisor/backend/safety/views.go +++ b/op-supervisor/supervisor/backend/safety/views.go @@ -15,7 +15,7 @@ type View struct { iter logs.Iterator localView heads.HeadPointer - localDerivedFrom eth.L1BlockRef + localDerivedFrom eth.BlockRef validWithinView func(l1View uint64, execMsg *types.ExecutingMessage) error } @@ -31,7 +31,7 @@ func (vi *View) Local() (heads.HeadPointer, error) { return vi.localView, nil } -func (vi *View) UpdateLocal(at eth.L1BlockRef, ref eth.L2BlockRef) error { +func (vi *View) UpdateLocal(at eth.BlockRef, ref eth.BlockRef) error { vi.localView = heads.HeadPointer{ LastSealedBlockHash: ref.Hash, LastSealedBlockNum: ref.Number, diff --git a/op-supervisor/supervisor/backend/source/chain_processor.go b/op-supervisor/supervisor/backend/source/chain_processor.go index 60568fe296fb4..9c63950a1629b 100644 --- a/op-supervisor/supervisor/backend/source/chain_processor.go +++ b/op-supervisor/supervisor/backend/source/chain_processor.go @@ -21,7 +21,7 @@ type Source interface { } type LogProcessor interface { - ProcessLogs(ctx context.Context, block eth.L2BlockRef, receipts gethtypes.Receipts) error + ProcessLogs(ctx context.Context, block eth.BlockRef, receipts gethtypes.Receipts) error } type DatabaseRewinder interface { @@ -29,9 +29,9 @@ type DatabaseRewinder interface { LatestBlockNum(chain types.ChainID) (num uint64, ok bool) } -type BlockProcessorFn func(ctx context.Context, block eth.L1BlockRef) error +type BlockProcessorFn func(ctx context.Context, block eth.BlockRef) error -func (fn BlockProcessorFn) ProcessBlock(ctx context.Context, block eth.L1BlockRef) error { +func (fn BlockProcessorFn) ProcessBlock(ctx context.Context, block eth.BlockRef) error { return fn(ctx, block) } @@ -131,7 +131,7 @@ func (s *ChainProcessor) worker() { func (s *ChainProcessor) update(nextNum uint64) error { ctx, cancel := context.WithTimeout(s.ctx, time.Second*10) nextL1, err := s.client.L1BlockRefByNumber(ctx, nextNum) - next := eth.L2BlockRef{ + next := eth.BlockRef{ Hash: nextL1.Hash, ParentHash: nextL1.ParentHash, Number: nextL1.Number, @@ -166,7 +166,7 @@ func (s *ChainProcessor) update(nextNum uint64) error { return nil } -func (s *ChainProcessor) OnNewHead(ctx context.Context, head eth.L1BlockRef) error { +func (s *ChainProcessor) OnNewHead(ctx context.Context, head eth.BlockRef) error { // update the latest target s.lastHead.Store(head.Number) // signal that we have something to process diff --git a/op-supervisor/supervisor/backend/source/log_processor.go b/op-supervisor/supervisor/backend/source/log_processor.go index 8a815f7ca9e98..d7f7e1fbeae0b 100644 --- a/op-supervisor/supervisor/backend/source/log_processor.go +++ b/op-supervisor/supervisor/backend/source/log_processor.go @@ -15,12 +15,12 @@ import ( ) type LogStorage interface { - SealBlock(chain types.ChainID, block eth.L2BlockRef) error + SealBlock(chain types.ChainID, block eth.BlockRef) error AddLog(chain types.ChainID, logHash common.Hash, parentBlock eth.BlockID, logIdx uint32, execMsg *types.ExecutingMessage) error } type ChainsDBClientForLogProcessor interface { - SealBlock(chain types.ChainID, block eth.L2BlockRef) error + SealBlock(chain types.ChainID, block eth.BlockRef) error AddLog(chain types.ChainID, logHash common.Hash, parentBlock eth.BlockID, logIdx uint32, execMsg *types.ExecutingMessage) error } @@ -44,7 +44,7 @@ func newLogProcessor(chain types.ChainID, logStore LogStorage) *logProcessor { // ProcessLogs processes logs from a block and stores them in the log storage // for any logs that are related to executing messages, they are decoded and stored -func (p *logProcessor) ProcessLogs(_ context.Context, block eth.L2BlockRef, rcpts ethTypes.Receipts) error { +func (p *logProcessor) ProcessLogs(_ context.Context, block eth.BlockRef, rcpts ethTypes.Receipts) error { for _, rcpt := range rcpts { for _, l := range rcpt.Logs { // log hash represents the hash of *this* log as a potentially initiating message diff --git a/op-supervisor/supervisor/backend/source/log_processor_test.go b/op-supervisor/supervisor/backend/source/log_processor_test.go index 6e96d731fcfff..2e1322f55aed1 100644 --- a/op-supervisor/supervisor/backend/source/log_processor_test.go +++ b/op-supervisor/supervisor/backend/source/log_processor_test.go @@ -17,7 +17,7 @@ var logProcessorChainID = types.ChainIDFromUInt64(4) func TestLogProcessor(t *testing.T) { ctx := context.Background() - block1 := eth.L2BlockRef{ + block1 := eth.BlockRef{ ParentHash: common.Hash{0x42}, Number: 100, Hash: common.Hash{0x11}, @@ -205,7 +205,7 @@ type stubLogStorage struct { seals []storedSeal } -func (s *stubLogStorage) SealBlock(chainID types.ChainID, block eth.L2BlockRef) error { +func (s *stubLogStorage) SealBlock(chainID types.ChainID, block eth.BlockRef) error { if logProcessorChainID != chainID { return fmt.Errorf("chain id mismatch, expected %v but got %v", logProcessorChainID, chainID) }