From c5af298bc2f3a62cc7794e16ab4084e17c8259da Mon Sep 17 00:00:00 2001 From: axelKingsley Date: Thu, 26 Sep 2024 14:41:36 -0500 Subject: [PATCH] refactor Pointer method on iterator --- .../supervisor/backend/db/logs/iterator.go | 7 ++++--- op-supervisor/supervisor/backend/db/logs/state.go | 13 +++++++++---- op-supervisor/supervisor/backend/safety/views.go | 12 +----------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/op-supervisor/supervisor/backend/db/logs/iterator.go b/op-supervisor/supervisor/backend/db/logs/iterator.go index 8cac703df217..f9e65c41e890 100644 --- a/op-supervisor/supervisor/backend/db/logs/iterator.go +++ b/op-supervisor/supervisor/backend/db/logs/iterator.go @@ -8,12 +8,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/db/entrydb" + "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/db/heads" "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types" ) type IteratorState interface { NextIndex() entrydb.EntryIdx - Pointer() (hash common.Hash, num uint64, timestamp uint64, logsSince uint32, ok bool) + HeadPointer() (heads.HeadPointer, error) SealedBlock() (hash common.Hash, num uint64, ok bool) InitMessage() (hash common.Hash, logIndex uint32, ok bool) ExecMessage() *types.ExecutingMessage @@ -166,6 +167,6 @@ func (i *iterator) ExecMessage() *types.ExecutingMessage { return i.current.ExecMessage() } -func (i *iterator) Pointer() (hash common.Hash, num uint64, timestamp uint64, logsSince uint32, ok bool) { - return i.current.Pointer() +func (i *iterator) HeadPointer() (heads.HeadPointer, error) { + return i.current.HeadPointer() } diff --git a/op-supervisor/supervisor/backend/db/logs/state.go b/op-supervisor/supervisor/backend/db/logs/state.go index 8937ca683851..df63f96e3599 100644 --- a/op-supervisor/supervisor/backend/db/logs/state.go +++ b/op-supervisor/supervisor/backend/db/logs/state.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/db/entrydb" + "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/db/heads" "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types" ) @@ -126,12 +127,16 @@ func (l *logContext) ExecMessage() *types.ExecutingMessage { return nil } -func (l *logContext) Pointer() (hash common.Hash, num uint64, timestamp uint64, logsSince uint32, ok bool) { +func (l *logContext) HeadPointer() (heads.HeadPointer, error) { if l.need != 0 { - ok = false - return + return heads.HeadPointer{}, errors.New("cannot provide head pointer while state is incomplete") } - return l.blockHash, l.blockNum, l.timestamp, l.logsSince, true + return heads.HeadPointer{ + LastSealedBlockHash: l.blockHash, + LastSealedBlockNum: l.blockNum, + LastSealedTimestamp: l.timestamp, + LogsSince: l.logsSince, + }, nil } // ApplyEntry applies an entry on top of the current state. diff --git a/op-supervisor/supervisor/backend/safety/views.go b/op-supervisor/supervisor/backend/safety/views.go index 6f14da84afeb..cdaabf614602 100644 --- a/op-supervisor/supervisor/backend/safety/views.go +++ b/op-supervisor/supervisor/backend/safety/views.go @@ -2,7 +2,6 @@ package safety import ( "errors" - "fmt" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/db/heads" @@ -22,16 +21,7 @@ type View struct { } func (vi *View) Cross() (heads.HeadPointer, error) { - parentHash, parentNum, timestamp, logsSince, ok := vi.iter.Pointer() - if !ok { - return heads.HeadPointer{}, fmt.Errorf("no db content yet: %w", logs.ErrFuture) - } - return heads.HeadPointer{ - LastSealedBlockHash: parentHash, - LastSealedBlockNum: parentNum, - LastSealedTimestamp: timestamp, - LogsSince: logsSince, - }, nil + return vi.iter.HeadPointer() } func (vi *View) Local() (heads.HeadPointer, error) {