Skip to content

Commit

Permalink
return last L1InfoRoot in function GetL1InfoTreeDataFromBatchL2Data (0…
Browse files Browse the repository at this point in the history
  • Loading branch information
agnusmor authored Dec 20, 2023
1 parent f44dd2d commit 57d5b47
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
4 changes: 2 additions & 2 deletions sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (f *finalizer) reprocessFullBatch(ctx context.Context, batchNum uint64, ini

executorBatchRequest := state.ProcessRequest{
BatchNumber: batch.BatchNumber,
L1InfoRoot_V2: mockL1InfoRoot, //TODO: Carlos
L1InfoRoot_V2: mockL1InfoRoot,
OldStateRoot: initialStateRoot,
OldAccInputHash: initialAccInputHash,
Transactions: batch.BatchL2Data,
Expand All @@ -427,7 +427,7 @@ func (f *finalizer) reprocessFullBatch(ctx context.Context, batchNum uint64, ini
SkipVerifyL1InfoRoot_V2: true,
Caller: caller,
}
executorBatchRequest.L1InfoTreeData_V2, err = f.state.GetL1InfoTreeDataFromBatchL2Data(ctx, batch.BatchL2Data, nil)
executorBatchRequest.L1InfoTreeData_V2, _, err = f.state.GetL1InfoTreeDataFromBatchL2Data(ctx, batch.BatchL2Data, nil)
if err != nil {
log.Errorf("[reprocessFullBatch] failed to get L1InfoTreeData for batch %d. Error: %w", batch.BatchNumber, err)
reprocessError(nil)
Expand Down
2 changes: 1 addition & 1 deletion sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type stateInterface interface {
GetStorageAt(ctx context.Context, address common.Address, position *big.Int, root common.Hash) (*big.Int, error)
StoreL2Block(ctx context.Context, batchNumber uint64, l2Block *state.ProcessBlockResponse, txsEGPLog []*state.EffectiveGasPriceLog, dbTx pgx.Tx) error
BuildChangeL2Block(deltaTimestamp uint32, l1InfoTreeIndex uint32) []byte
GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]state.L1DataV2, error)
GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]state.L1DataV2, common.Hash, error)
GetBlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.Block, error)
}

Expand Down
21 changes: 15 additions & 6 deletions sequencer/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions state/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,36 @@ func (s *State) GetBatchTimestamp(ctx context.Context, batchNumber uint64, force
}
return batchTimestamp, nil
}

// GetL1InfoTreeDataFromBatchL2Data returns a map with the L1InfoTreeData used in the L2 blocks included in the batchL2Data and the last L1InfoRoot used
func (s *State) GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]L1DataV2, common.Hash, error) {
batchRaw, err := DecodeBatchV2(batchL2Data)
if err != nil {
return nil, ZeroHash, err
}

l1InfoTreeData := map[uint32]L1DataV2{}
lastL1InfoRoot := ZeroHash

for _, l2blockRaw := range batchRaw.Blocks {
_, found := l1InfoTreeData[l2blockRaw.IndexL1InfoTree]
if !found {
l1InfoTreeExitRootStorageEntry, err := s.GetL1InfoRootLeafByIndex(ctx, l2blockRaw.IndexL1InfoTree, dbTx)
if err != nil {
return nil, ZeroHash, err
}

l1Data := L1DataV2{
GlobalExitRoot: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.GlobalExitRoot,
BlockHashL1: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.PreviousBlockHash,
MinTimestamp: uint64(l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.Timestamp.Unix()),
}

l1InfoTreeData[l2blockRaw.IndexL1InfoTree] = l1Data

lastL1InfoRoot = l1InfoTreeExitRootStorageEntry.L1InfoTreeRoot
}
}

return l1InfoTreeData, lastL1InfoRoot, nil
}
1 change: 0 additions & 1 deletion state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,5 @@ type storage interface {
GetL1InfoRootLeafByL1InfoRoot(ctx context.Context, l1InfoRoot common.Hash, dbTx pgx.Tx) (L1InfoTreeExitRootStorageEntry, error)
GetL1InfoRootLeafByIndex(ctx context.Context, l1InfoTreeIndex uint32, dbTx pgx.Tx) (L1InfoTreeExitRootStorageEntry, error)
GetLeafsByL1InfoRoot(ctx context.Context, l1InfoRoot common.Hash, dbTx pgx.Tx) ([]L1InfoTreeExitRootStorageEntry, error)
GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]L1DataV2, error)
GetBlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*Block, error)
}
27 changes: 0 additions & 27 deletions state/pgstatestorage/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,30 +956,3 @@ func (p *PostgresStorage) GetRawBatchTimestamps(ctx context.Context, batchNumber
}
return batchTimestamp, virtualBatchTimestamp, err
}

// GetL1InfoTreeDataFromBatchL2Data returns a map with the L1InfoTreeData used in the L2 blocks included in the batchL2Data
func (p *PostgresStorage) GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]state.L1DataV2, error) {
batchRaw, err := state.DecodeBatchV2(batchL2Data)
if err != nil {
return nil, err
}

l1InfoTreeData := map[uint32]state.L1DataV2{}

for _, l2blockRaw := range batchRaw.Blocks {
_, found := l1InfoTreeData[l2blockRaw.IndexL1InfoTree]
if !found {
l1InfoTreeExitRootStorageEntry, err := p.GetL1InfoRootLeafByIndex(ctx, l2blockRaw.IndexL1InfoTree, dbTx)
if err != nil {
return nil, err
}
l1InfoTreeData[l2blockRaw.IndexL1InfoTree] = state.L1DataV2{
GlobalExitRoot: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.GlobalExitRoot,
BlockHashL1: l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.PreviousBlockHash,
MinTimestamp: uint64(l1InfoTreeExitRootStorageEntry.L1InfoTreeLeaf.GlobalExitRoot.Timestamp.Unix()),
}
}
}

return l1InfoTreeData, nil
}

0 comments on commit 57d5b47

Please sign in to comment.