Skip to content

Commit

Permalink
refactor Pointer method on iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
axelKingsley committed Sep 27, 2024
1 parent 858b085 commit c5af298
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
7 changes: 4 additions & 3 deletions op-supervisor/supervisor/backend/db/logs/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
13 changes: 9 additions & 4 deletions op-supervisor/supervisor/backend/db/logs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 1 addition & 11 deletions op-supervisor/supervisor/backend/safety/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down

0 comments on commit c5af298

Please sign in to comment.