Skip to content

Commit

Permalink
Merge pull request #77 from EspressoSystems/ma/fix-preconf-hotshot-ge…
Browse files Browse the repository at this point in the history
…nesis

Preconfirmations: skip pre-rollup hotshot blocks
  • Loading branch information
jbearer authored Sep 25, 2023
2 parents 444f8da + ba12129 commit 4f96bb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 7 additions & 5 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,22 @@ func (etherMan *Client) getMaxPreconfirmation() (uint64, error) {
return blockHeight, nil
}

func (etherMan *Client) GetPreconfirmations(ctx context.Context, fromL2Block uint64) ([]Block, map[common.Hash][]Order, error) {
l2BlockHeight, err := etherMan.getMaxPreconfirmation()
func (etherMan *Client) GetPreconfirmations(ctx context.Context, fromL2Batch uint64) ([]Block, map[common.Hash][]Order, error) {
hotShotBlockHeight, err := etherMan.getMaxPreconfirmation()
if err != nil {
return nil, nil, err
}

var blocks []Block
order := make(map[common.Hash][]Order)

log.Infof("Getting L2 blocks in range ", fromL2Block, "-", l2BlockHeight)
for l2BlockNum := fromL2Block; l2BlockNum < l2BlockHeight; l2BlockNum++ {
fromHotShotBlock := fromL2Batch + etherMan.cfg.GenesisHotShotBlockNumber
log.Infof("Getting HotShot blocks in range %d - %d", fromHotShotBlock, hotShotBlockHeight)
for hotShotBlockNum := fromHotShotBlock; hotShotBlockNum < hotShotBlockHeight; hotShotBlockNum++ {
var batch SequencedBatch
var l1BlockNum uint64
err = etherMan.fetchL2Block(ctx, l2BlockNum, &batch, &l1BlockNum)

err = etherMan.fetchL2Block(ctx, hotShotBlockNum, &batch, &l1BlockNum)
if err != nil {
return nil, nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,15 @@ func (s *ClientSynchronizer) syncBlocks(lastEthBlockSynced *state.Block) (*state
func (s *ClientSynchronizer) syncPreconfirmations() error {
for {
// Figure out where to start from: what is the first L2 block we haven't synchronized yet?
// This is the same as the last synchronized batch number, since L2 block numbers and batch
// numbers are offset by 1.
// This is the first batch after the last synchronized batch number.
latestSyncedBatch, err := s.state.GetLastBatchNumber(s.ctx, nil)
if err != nil {
log.Warn("error getting latest batch synced. Error: ", err)
return err
}

// Fetch new preconfirmed blocks from the sequencer.
blocks, order, err := s.etherMan.GetPreconfirmations(s.ctx, latestSyncedBatch)
blocks, order, err := s.etherMan.GetPreconfirmations(s.ctx, latestSyncedBatch+1)
if err != nil {
log.Warn("error getting preconfirmations. Error: ", err)
return err
Expand Down

0 comments on commit 4f96bb4

Please sign in to comment.