Skip to content

Commit

Permalink
implements #49
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed May 16, 2024
1 parent 1e73256 commit 9067d02
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 1 deletion.
1 change: 1 addition & 0 deletions synchronizer/common/syncinterfaces/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type StorageBlockReaderInterface interface {
AddBlock(ctx context.Context, block *entities.L1Block, dbTx stateTxType) error
GetPreviousBlock(ctx context.Context, offset uint64, fromBlockNumber *uint64, dbTx stateTxType) (*entities.L1Block, error)
GetFirstUncheckedBlock(ctx context.Context, fromBlockNumber uint64, dbTx stateTxType) (*entities.L1Block, error)
GetBlockByNumber(ctx context.Context, blockNumber uint64, dbTx stateTxType) (*entities.L1Block, error)
}

type StorageForkIDInterface interface {
Expand Down
60 changes: 60 additions & 0 deletions synchronizer/mocks/storage_block_reader_interface.go

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

60 changes: 60 additions & 0 deletions synchronizer/mocks/storage_interface.go

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

60 changes: 60 additions & 0 deletions synchronizer/mocks/storage_sync_queries.go

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

96 changes: 96 additions & 0 deletions synchronizer/mocks/synchronizer_block_querier.go

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

14 changes: 14 additions & 0 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ type SynchronizerL1InfoTreeQuerier interface {
GetLeafsByL1InfoRoot(ctx context.Context, l1InfoRoot common.Hash) ([]L1InfoTreeLeaf, error)
}

type L1Block struct {
BlockNumber uint64
BlockHash common.Hash
ParentHash common.Hash
ReceivedAt time.Time
Checked bool // The block is safe (have past the safe point, e.g. Finalized in L1)
HasEvents bool // This block have events from the rollup
SyncVersion string
}

type SynchronizerBlockQuerier interface {
GetL1BlockByNumber(ctx context.Context, blockNumber uint64) (*L1Block, error)
}

type SequencedBatches struct {
FromBatchNumber uint64
ToBatchNumber uint64
Expand Down
10 changes: 10 additions & 0 deletions synchronizer/synchronizer_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type storageSyncQueries interface {
syncinterfaces.StorageBlockReaderInterface
syncinterfaces.StorageSequenceBatchesInterface
syncinterfaces.StorageVirtualBatchInterface
syncinterfaces.StorageBlockReaderInterface
}

type SyncrhronizerQueries struct {
Expand Down Expand Up @@ -97,3 +98,12 @@ func (s *SyncrhronizerQueries) GetLastestVirtualBatchNumber(ctx context.Context)
}
return lastBatchNumber, nil
}

func (s *SyncrhronizerQueries) GetL1BlockByBlock(ctx context.Context, blockNumber uint64) (*L1Block, error) {
block, err := s.storage.GetBlockByNumber(ctx, blockNumber, nil)
if block == nil {
return nil, err
}
res := L1Block(*block)
return &res, err
}
1 change: 0 additions & 1 deletion synchronizer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import (
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities"
)

type L1Block = entities.L1Block
type stateTxType = entities.Tx

0 comments on commit 9067d02

Please sign in to comment.