Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preconfirmations: skip pre-rollup hotshot blocks #77

Merged
merged 4 commits into from
Sep 25, 2023
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
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