Skip to content

Commit

Permalink
moved all etherman types to types folder because was not able to test…
Browse files Browse the repository at this point in the history
… due import cycles
  • Loading branch information
joanestebanr committed Aug 27, 2024
1 parent 30ab325 commit 3acd277
Show file tree
Hide file tree
Showing 54 changed files with 2,072 additions and 610 deletions.
10 changes: 5 additions & 5 deletions actions/processor_manager/processor_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman"
ethtypes "github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman/types"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/synchronizer/actions"
)
Expand All @@ -26,18 +26,18 @@ var (
// To build the object use L1EventProcessorsBuilder
type L1EventProcessors struct {
// forkId -> event -> processor
processors map[actions.ForkIdType]map[etherman.EventOrder]actions.L1EventProcessor
processors map[actions.ForkIdType]map[ethtypes.EventOrder]actions.L1EventProcessor
}

// NewL1EventProcessors returns a empty new L1EventProcessors
func NewL1EventProcessors() *L1EventProcessors {
return &L1EventProcessors{
processors: make(map[actions.ForkIdType]map[etherman.EventOrder]actions.L1EventProcessor),
processors: make(map[actions.ForkIdType]map[ethtypes.EventOrder]actions.L1EventProcessor),
}
}

// Get returns the processor, first try specific, if not wildcard and if not found returns nil
func (p *L1EventProcessors) Get(forkId actions.ForkIdType, event etherman.EventOrder) actions.L1EventProcessor {
func (p *L1EventProcessors) Get(forkId actions.ForkIdType, event ethtypes.EventOrder) actions.L1EventProcessor {
if _, ok := p.processors[forkId]; !ok {
if forkId == actions.WildcardForkId {
return nil
Expand All @@ -54,7 +54,7 @@ func (p *L1EventProcessors) Get(forkId actions.ForkIdType, event etherman.EventO
}

// Process execute the event for the forkId and event
func (p *L1EventProcessors) Process(ctx context.Context, forkId actions.ForkIdType, order etherman.Order, block *etherman.Block, dbTx dbTxType) error {
func (p *L1EventProcessors) Process(ctx context.Context, forkId actions.ForkIdType, order ethtypes.Order, block *ethtypes.Block, dbTx dbTxType) error {
processor := p.Get(forkId, order.Name)
if processor == nil {
var strBlockNumber string
Expand Down
23 changes: 12 additions & 11 deletions etherman/banana_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package etherman
import (
"context"

ethtypes "github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman/types"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

func (etherMan *Client) processBananaEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) (bool, error) {
func (etherMan *Client) processBananaEvent(ctx context.Context, vLog types.Log, blocks *[]ethtypes.Block, blocksOrder *map[common.Hash][]ethtypes.Order) (bool, error) {
if len(vLog.Topics) == 0 {
return false, nil
}
Expand All @@ -21,7 +22,7 @@ func (etherMan *Client) processBananaEvent(ctx context.Context, vLog types.Log,
return false, nil
}

func (etherMan *Client) rollbackBatchesManagerEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
func (etherMan *Client) rollbackBatchesManagerEvent(ctx context.Context, vLog types.Log, blocks *[]ethtypes.Block, blocksOrder *map[common.Hash][]ethtypes.Order) error {
/*
event RollbackBatches(
uint64 indexed targetBatch,
Expand All @@ -36,23 +37,23 @@ func (etherMan *Client) rollbackBatchesManagerEvent(ctx context.Context, vLog ty

block, err := addNewBlockToResult(ctx, etherMan, vLog, blocks, blocksOrder)
if err != nil {
log.Warnf("error addNewBlockToResult RollbackBatches event: %v", err)
log.Warnf("error addNewethtypes.BlockToResult RollbackBatches event: %v", err)
return err
}
rollbackBatchesData := RollbackBatchesData{
rollbackBatchesData := ethtypes.RollbackBatchesData{
TargetBatch: eventData.TargetBatch,
AccInputHashToRollback: eventData.AccInputHashToRollback,
}
block.RollbackBatches = append(block.RollbackBatches, rollbackBatchesData)
order := Order{
Name: RollbackBatchesOrder,
order := ethtypes.Order{
Name: ethtypes.RollbackBatchesOrder,
Pos: len(block.RollbackBatches) - 1,
}
addNewOrder(&order, block.BlockHash, blocksOrder)
return nil
}

func (etherMan *Client) updateL1InfoTreeV2Event(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error {
func (etherMan *Client) updateL1InfoTreeV2Event(ctx context.Context, vLog types.Log, blocks *[]ethtypes.Block, blocksOrder *map[common.Hash][]ethtypes.Order) error {

/* https://github.com/0xPolygonHermez/zkevm-contracts/blob/949b0b96c10056fa7be9632bcc2f26202a9c3a9c/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol#L39C1-L44C7
Expand All @@ -71,16 +72,16 @@ func (etherMan *Client) updateL1InfoTreeV2Event(ctx context.Context, vLog types.
if err != nil {
return err
}
L1InfoTreeV2Data := L1InfoTreeV2Data{
L1InfoTreeV2Data := ethtypes.L1InfoTreeV2Data{
CurrentL1InfoRoot: eventData.CurrentL1InfoRoot,
LeafCount: eventData.LeafCount,
// TODO: Fix this type
//BlockHash: eventData.Blockhash,
//ethtypes.BlockHash: eventData.ethtypes.Blockhash,
MinTimestamp: eventData.MinTimestamp,
}
block.L1InfoTreeV2 = append(block.L1InfoTreeV2, L1InfoTreeV2Data)
order := Order{
Name: UpdateL1InfoTreeV2Order,
order := ethtypes.Order{
Name: ethtypes.UpdateL1InfoTreeV2Order,
Pos: len(block.L1InfoTreeV2) - 1,
}
addNewOrder(&order, block.BlockHash, blocksOrder)
Expand Down
10 changes: 6 additions & 4 deletions etherman/banana_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"testing"

ethtypes "github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
Expand All @@ -13,8 +15,8 @@ func TestBananaEventsNoTopics(t *testing.T) {
sut := Client{}
ctx := context.TODO()
vLog := types.Log{}
blocks := &[]Block{}
blocksOrder := &map[common.Hash][]Order{}
blocks := &[]ethtypes.Block{}
blocksOrder := &map[common.Hash][]ethtypes.Order{}

processed, err := sut.processBananaEvent(ctx, vLog, blocks, blocksOrder)
require.NoError(t, err)
Expand All @@ -27,8 +29,8 @@ func TestBananaEventsUnknownTopics(t *testing.T) {
vLog := types.Log{
Topics: []common.Hash{common.HexToHash("0x12345678")},
}
blocks := &[]Block{}
blocksOrder := &map[common.Hash][]Order{}
blocks := &[]ethtypes.Block{}
blocksOrder := &map[common.Hash][]ethtypes.Order{}

processed, err := sut.processBananaEvent(ctx, vLog, blocks, blocksOrder)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 3acd277

Please sign in to comment.