Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-dodos-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/l2geth": patch
---

Add `VerifiedIndex` to db and api
25 changes: 25 additions & 0 deletions l2geth/core/rawdb/rollup_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/log"
)

// ReadHeadIndex will read the known tip of the CTC
func ReadHeadIndex(db ethdb.KeyValueReader) *uint64 {
data, _ := db.Get(headIndexKey)
if len(data) == 0 {
Expand All @@ -16,6 +17,7 @@ func ReadHeadIndex(db ethdb.KeyValueReader) *uint64 {
return &ret
}

// WriteHeadIndex will write the known tip of the CTC
func WriteHeadIndex(db ethdb.KeyValueWriter, index uint64) {
value := new(big.Int).SetUint64(index).Bytes()
if index == 0 {
Expand All @@ -26,6 +28,7 @@ func WriteHeadIndex(db ethdb.KeyValueWriter, index uint64) {
}
}

// ReadHeadQueueIndex will read the known tip of the queue
func ReadHeadQueueIndex(db ethdb.KeyValueReader) *uint64 {
data, _ := db.Get(headQueueIndexKey)
if len(data) == 0 {
Expand All @@ -35,6 +38,7 @@ func ReadHeadQueueIndex(db ethdb.KeyValueReader) *uint64 {
return &ret
}

// WriteHeadQueueIndex will write the known tip of the queue
func WriteHeadQueueIndex(db ethdb.KeyValueWriter, index uint64) {
value := new(big.Int).SetUint64(index).Bytes()
if index == 0 {
Expand All @@ -44,3 +48,24 @@ func WriteHeadQueueIndex(db ethdb.KeyValueWriter, index uint64) {
log.Crit("Failed to store queue index", "err", err)
}
}

// ReadHeadVerifiedIndex will read the known tip of the batched transactions
func ReadHeadVerifiedIndex(db ethdb.KeyValueReader) *uint64 {
data, _ := db.Get(headVerifiedIndexKey)
if len(data) == 0 {
return nil
}
ret := new(big.Int).SetBytes(data).Uint64()
return &ret
}

// WriteHeadVerifiedIndex will write the known tip of the batched transactions
func WriteHeadVerifiedIndex(db ethdb.KeyValueWriter, index uint64) {
value := new(big.Int).SetUint64(index).Bytes()
if index == 0 {
value = []byte{0}
}
if err := db.Put(headVerifiedIndexKey, value); err != nil {
log.Crit("Failed to store verifier index", "err", err)
}
}
2 changes: 2 additions & 0 deletions l2geth/core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var (
headIndexKey = []byte("LastIndex")
// headQueueIndexKey tracks th last processed queue index
headQueueIndexKey = []byte("LastQueueIndex")
// headVerifiedIndexKey tracks the latest verified index
headVerifiedIndexKey = []byte("LastVerifiedIndex")

preimagePrefix = []byte("secure-key-") // preimagePrefix + hash -> preimage
configPrefix = []byte("ethereum-config-") // config prefix for the db
Expand Down
23 changes: 13 additions & 10 deletions l2geth/eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ func (b *EthAPIBackend) GetEthContext() (uint64, uint64) {
return bn, ts
}

func (b *EthAPIBackend) GetRollupContext() (uint64, uint64) {
i := uint64(0)
q := uint64(0)
index := b.eth.syncService.GetLatestIndex()
if index != nil {
i = *index
func (b *EthAPIBackend) GetRollupContext() (uint64, uint64, uint64) {
index := uint64(0)
queueIndex := uint64(0)
verifiedIndex := uint64(0)

if latest := b.eth.syncService.GetLatestIndex(); latest != nil {
index = *latest
}
if latest := b.eth.syncService.GetLatestEnqueueIndex(); latest != nil {
queueIndex = *latest
}
queueIndex := b.eth.syncService.GetLatestEnqueueIndex()
if queueIndex != nil {
q = *queueIndex
if latest := b.eth.syncService.GetLatestVerifiedIndex(); latest != nil {
verifiedIndex = *latest
}
return i, q
return index, queueIndex, verifiedIndex
}

// ChainConfig returns the active chain configuration.
Expand Down
17 changes: 12 additions & 5 deletions l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1913,9 +1913,15 @@ type EthContext struct {
BlockNumber uint64 `json:"blockNumber"`
Timestamp uint64 `json:"timestamp"`
}

// RollupContext represents the height of the rollup.
// Index is the last processed CanonicalTransactionChain index
// QueueIndex is the last processed `enqueue` index
// VerifiedIndex is the last processed CTC index that was batched
type RollupContext struct {
Index uint64 `json:"index"`
QueueIndex uint64 `json:"queueIndex"`
Index uint64 `json:"index"`
QueueIndex uint64 `json:"queueIndex"`
VerifiedIndex uint64 `json:"verifiedIndex"`
}

type rollupInfo struct {
Expand All @@ -1932,7 +1938,7 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo {
}
syncing := api.b.IsSyncing()
bn, ts := api.b.GetEthContext()
index, queueIndex := api.b.GetRollupContext()
index, queueIndex, verifiedIndex := api.b.GetRollupContext()

return rollupInfo{
Mode: mode,
Expand All @@ -1942,8 +1948,9 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo {
Timestamp: ts,
},
RollupContext: RollupContext{
Index: index,
QueueIndex: queueIndex,
Index: index,
QueueIndex: queueIndex,
VerifiedIndex: verifiedIndex,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion l2geth/internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Backend interface {
IsVerifier() bool
IsSyncing() bool
GetEthContext() (uint64, uint64)
GetRollupContext() (uint64, uint64)
GetRollupContext() (uint64, uint64, uint64)
GasLimit() uint64
GetDiff(*big.Int) (diffdb.Diff, error)
SuggestDataPrice(ctx context.Context) (*big.Int, error)
Expand Down
4 changes: 2 additions & 2 deletions l2geth/les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (b *LesApiBackend) GetEthContext() (uint64, uint64) {
return 0, 0
}

func (b *LesApiBackend) GetRollupContext() (uint64, uint64) {
return 0, 0
func (b *LesApiBackend) GetRollupContext() (uint64, uint64, uint64) {
return 0, 0, 0
}

func (b *LesApiBackend) IsSyncing() bool {
Expand Down
54 changes: 52 additions & 2 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,40 +537,90 @@ func (s *SyncService) syncTransactionsToTip() error {

// Methods for safely accessing and storing the latest
// L1 blocknumber and timestamp. These are held in memory.

// GetLatestL1Timestamp returns the OVMContext timestamp
func (s *SyncService) GetLatestL1Timestamp() uint64 {
return atomic.LoadUint64(&s.OVMContext.timestamp)
}

// GetLatestL1BlockNumber returns the OVMContext blocknumber
func (s *SyncService) GetLatestL1BlockNumber() uint64 {
return atomic.LoadUint64(&s.OVMContext.blockNumber)
}

// SetLatestL1Timestamp will set the OVMContext timestamp
func (s *SyncService) SetLatestL1Timestamp(ts uint64) {
atomic.StoreUint64(&s.OVMContext.timestamp, ts)
}

// SetLatestL1BlockNumber will set the OVMContext blocknumber
func (s *SyncService) SetLatestL1BlockNumber(bn uint64) {
atomic.StoreUint64(&s.OVMContext.blockNumber, bn)
}

// GetLatestEnqueueIndex reads the last queue index processed
func (s *SyncService) GetLatestEnqueueIndex() *uint64 {
return rawdb.ReadHeadQueueIndex(s.db)
}

// GetNextEnqueueIndex returns the next queue index to process
func (s *SyncService) GetNextEnqueueIndex() uint64 {
latest := s.GetLatestEnqueueIndex()
if latest == nil {
return 0
}
return *latest + 1
}

// SetLatestEnqueueIndex writes the last queue index that was processed
func (s *SyncService) SetLatestEnqueueIndex(index *uint64) {
if index != nil {
rawdb.WriteHeadQueueIndex(s.db, *index)
}
}

// GetLatestIndex reads the last CTC index that was processed
func (s *SyncService) GetLatestIndex() *uint64 {
return rawdb.ReadHeadIndex(s.db)
}

// GetNextIndex reads the next CTC index to process
func (s *SyncService) GetNextIndex() uint64 {
latest := s.GetLatestIndex()
if latest == nil {
return 0
}
return *latest + 1
}

// SetLatestIndex writes the last CTC index that was processed
func (s *SyncService) SetLatestIndex(index *uint64) {
if index != nil {
rawdb.WriteHeadIndex(s.db, *index)
}
}

func (s *SyncService) GetLatestIndex() *uint64 {
return rawdb.ReadHeadIndex(s.db)
// GetLatestVerifiedIndex reads the last verified CTC index that was processed
// These are set by processing batches of transactions that were submitted to
// the Canonical Transaction Chain.
func (s *SyncService) GetLatestVerifiedIndex() *uint64 {
return rawdb.ReadHeadVerifiedIndex(s.db)
}

// GetNextVerifiedIndex reads the next verified index
func (s *SyncService) GetNextVerifiedIndex() uint64 {
index := s.GetLatestVerifiedIndex()
if index == nil {
return 0
}
return *index + 1
}

// SetLatestVerifiedIndex writes the last verified index that was processed
func (s *SyncService) SetLatestVerifiedIndex(index *uint64) {
if index != nil {
rawdb.WriteHeadVerifiedIndex(s.db, *index)
}
}

// reorganize will reorganize to directly to the index passed in.
Expand Down