Skip to content

Commit

Permalink
add init latest executed height
Browse files Browse the repository at this point in the history
  • Loading branch information
sideninja committed Sep 19, 2024
1 parent 015f11a commit 35f011a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
19 changes: 13 additions & 6 deletions storage/pebble/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (b *Blocks) Store(
)
}

if err := b.store.set(latestEVMHeightKey, nil, evmHeightBytes, batch); err != nil {
if err := b.store.set(latestIndexedHeight, nil, evmHeightBytes, batch); err != nil {
return fmt.Errorf(
"failed to store latest EVM height: %d, with: %w",
block.Height,
Expand Down Expand Up @@ -178,7 +178,7 @@ func (b *Blocks) LatestIndexedHeight() (uint64, error) {
}

func (b *Blocks) latestEVMHeight() (uint64, error) {
val, err := b.store.get(latestEVMHeightKey)
val, err := b.store.get(latestIndexedHeight)
if err != nil {
if errors.Is(err, errs.ErrEntityNotFound) {
return 0, errs.ErrStorageNotInitialized
Expand Down Expand Up @@ -227,8 +227,12 @@ func (b *Blocks) InitHeights(cadenceHeight uint64, cadenceID flow.Identifier) er
return fmt.Errorf("failed to init latest Cadence height at: %d, with: %w", cadenceHeight, err)
}

if err := b.store.set(latestEVMHeightKey, nil, uint64Bytes(0), nil); err != nil {
return fmt.Errorf("failed to init latest EVM height at: %d, with: %w", 0, err)
if err := b.store.set(latestIndexedHeight, nil, uint64Bytes(0), nil); err != nil {
return fmt.Errorf("failed to init latest indexed EVM height at: %d, with: %w", 0, err)
}

if err := b.store.set(latestExecutedHeight, nil, uint64Bytes(0), nil); err != nil {
return fmt.Errorf("failed to init latest executed EVM height at: %d, with: %w", 0, err)
}

// we store genesis block because it isn't emitted over the network
Expand Down Expand Up @@ -268,15 +272,18 @@ func (b *Blocks) SetExecutedHeight(evmHeight uint64) error {
b.mux.Lock()
defer b.mux.Unlock()

return b.store.set(evmHeightIndex, nil, uint64Bytes(evmHeight), nil)
return b.store.set(latestExecutedHeight, nil, uint64Bytes(evmHeight), nil)
}

func (b *Blocks) LatestExecutedHeight() (uint64, error) {
b.mux.RLock()
defer b.mux.RUnlock()

val, err := b.store.get(evmHeightIndex)
val, err := b.store.get(latestExecutedHeight)
if err != nil {
if errors.Is(err, errs.ErrEntityNotFound) {
return 0, errs.ErrStorageNotInitialized
}
return 0, err
}

Expand Down
4 changes: 2 additions & 2 deletions storage/pebble/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
blockIDToHeightKey = byte(2)
evmHeightToCadenceHeightKey = byte(3)
evmHeightToCadenceIDKey = byte(4)
evmHeightIndex = byte(5)
latestExecutedHeight = byte(5)

// transaction keys
txIDKey = byte(10)
Expand All @@ -30,7 +30,7 @@ const (
ledgerSlabIndex = byte(51)

// special keys
latestEVMHeightKey = byte(100)
latestIndexedHeight = byte(100)
latestCadenceHeightKey = byte(102)
)

Expand Down
2 changes: 1 addition & 1 deletion storage/pebble/receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (r *Receipts) BloomsForBlockRange(start, end uint64) ([]*models.BloomsHeigh
}

func (r *Receipts) getLast() (uint64, error) {
l, err := r.store.get(latestEVMHeightKey)
l, err := r.store.get(latestIndexedHeight)
if err != nil {
return 0, fmt.Errorf("failed getting latest EVM height: %w", err)
}
Expand Down

0 comments on commit 35f011a

Please sign in to comment.