Skip to content

Commit

Permalink
keep track of the latest verified block during batches stage for rpc …
Browse files Browse the repository at this point in the history
…calls (ledgerwatch#21)
  • Loading branch information
hexoscott committed Dec 15, 2023
1 parent 737410d commit 5e226bc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions zk/stages/stage_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ledgerwatch/erigon/zk/hermez_db"
txtype "github.com/ledgerwatch/erigon/zk/tx"

"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/log/v3"
)

Expand Down Expand Up @@ -91,6 +92,11 @@ func SpawnStageBatches(
return fmt.Errorf("save stage progress error: %v", err)
}

highestVerifiedBatch, err := sync_stages.GetStageProgress(tx, sync_stages.L1VerificationsBatchNo)
if err != nil {
return fmt.Errorf("could not retrieve l1 verifications batch no progress")
}

startSyncTime := time.Now()
errChan := make(chan error)

Expand Down Expand Up @@ -191,6 +197,11 @@ func SpawnStageBatches(
}
highestSeenBatchNo = l2Block.BatchNumber

// store our finalized state if this batch matches the highest verified batch number on the L1
if l2Block.BatchNumber == highestVerifiedBatch {
rawdb.WriteForkchoiceFinalized(tx, l2Block.L2Blockhash)
}

if lastHash != emptyHash {
l2Block.ParentHash = lastHash
} else {
Expand Down

0 comments on commit 5e226bc

Please sign in to comment.