From 70c772e7161607b629024338e1694bd5d9440715 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:00:27 +0200 Subject: [PATCH 1/6] #3518 compatibility with ethereum-API L2 node --- cmd/run.go | 17 +++- synchronizer/actions/check_l2block.go | 13 ++- synchronizer/actions/check_l2block_test.go | 37 ++++--- ...vm_client_ethereum_compatible_interface.go | 98 +++++++++++++++++++ .../zkevm_ethereum_compatible_client.go | 21 ++++ synchronizer/synchronizer.go | 61 ++++++------ 6 files changed, 196 insertions(+), 51 deletions(-) create mode 100644 synchronizer/common/syncinterfaces/mocks/zkevm_client_ethereum_compatible_interface.go create mode 100644 synchronizer/common/syncinterfaces/zkevm_ethereum_compatible_client.go diff --git a/cmd/run.go b/cmd/run.go index 233b4453a6..301b5ba954 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -37,6 +37,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/synchronizer" "github.com/0xPolygonHermez/zkevm-node/synchronizer/common/syncinterfaces" + "github.com/ethereum/go-ethereum/ethclient" "github.com/jackc/pgx/v4/pgxpool" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/urfave/cli/v2" @@ -280,6 +281,15 @@ func newEtherman(c config.Config) (*etherman.Client, error) { return etherman.NewClient(c.Etherman, c.NetworkConfig.L1Config) } +func newL2EthClient(url string) (*ethclient.Client, error) { + ethClient, err := ethclient.Dial(url) + if err != nil { + log.Errorf("error connecting L1 to %s: %+v", url, err) + return nil, err + } + return ethClient, nil +} + func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerStorage *ethtxmanager.PostgresStorage, st *state.State, pool *pool.Pool, eventLog *event.EventLog) { var trustedSequencerURL string var err error @@ -295,6 +305,11 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS } log.Info("trustedSequencerURL ", trustedSequencerURL) } + ethClientForL2, err := newL2EthClient(trustedSequencerURL) + if err != nil { + log.Fatal(err) + } + ethClientForL2.BlockByNumber(context.Background(), nil) zkEVMClient := client.NewClient(trustedSequencerURL) etherManForL1 := []syncinterfaces.EthermanFullInterface{} // If synchronizer are using sequential mode, we only need one etherman client @@ -310,7 +325,7 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS etm := ethtxmanager.New(cfg.EthTxManager, etherman, ethTxManagerStorage, st) sy, err := synchronizer.NewSynchronizer( cfg.IsTrustedSequencer, etherman, etherManForL1, st, pool, etm, - zkEVMClient, eventLog, cfg.NetworkConfig.Genesis, cfg.Synchronizer, cfg.Log.Environment == "development", + zkEVMClient, ethClientForL2, eventLog, cfg.NetworkConfig.Genesis, cfg.Synchronizer, cfg.Log.Environment == "development", ) if err != nil { log.Fatal(err) diff --git a/synchronizer/actions/check_l2block.go b/synchronizer/actions/check_l2block.go index d2d546d6a4..14c9e5cb19 100644 --- a/synchronizer/actions/check_l2block.go +++ b/synchronizer/actions/check_l2block.go @@ -6,9 +6,9 @@ import ( "fmt" "math/big" - "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/state" + "github.com/ethereum/go-ethereum/core/types" "github.com/jackc/pgx/v4" ) @@ -129,11 +129,14 @@ func (p *CheckL2BlockHash) iterationCheckL2Block(ctx context.Context, l2BlockNum } func compareL2Blocks(prefixLogs string, localL2Block *state.L2Block, trustedL2Block *types.Block) error { - if localL2Block == nil || trustedL2Block == nil || trustedL2Block.Hash == nil { - return fmt.Errorf("%s localL2Block or trustedL2Block or trustedHash are nil", prefixLogs) + if localL2Block == nil || trustedL2Block == nil { + return fmt.Errorf("%s localL2Block or trustedL2Block are nil", prefixLogs) + } + if localL2Block.Hash() != trustedL2Block.Hash() { + return fmt.Errorf("%s localL2Block.Hash %s and trustedL2Block.Hash %s are different", prefixLogs, localL2Block.Hash().String(), trustedL2Block.Hash().String()) } - if localL2Block.Hash() != *trustedL2Block.Hash { - return fmt.Errorf("%s localL2Block.Hash %s and trustedL2Block.Hash %s are different", prefixLogs, localL2Block.Hash().String(), (*trustedL2Block.Hash).String()) + if localL2Block.ParentHash() != trustedL2Block.ParentHash() { + return fmt.Errorf("%s localL2Block.ParentHash %s and trustedL2Block.ParentHash %s are different", prefixLogs, localL2Block.ParentHash().String(), trustedL2Block.ParentHash().String()) } return nil } diff --git a/synchronizer/actions/check_l2block_test.go b/synchronizer/actions/check_l2block_test.go index da4510fd66..28a8a503b7 100644 --- a/synchronizer/actions/check_l2block_test.go +++ b/synchronizer/actions/check_l2block_test.go @@ -5,7 +5,6 @@ import ( "math/big" "testing" - rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/synchronizer/actions" mock_syncinterfaces "github.com/0xPolygonHermez/zkevm-node/synchronizer/common/syncinterfaces/mocks" @@ -19,7 +18,7 @@ import ( type CheckL2BlocksTestData struct { sut *actions.CheckL2BlockHash mockState *mock_syncinterfaces.StateFullInterface - zKEVMClient *mock_syncinterfaces.ZKEVMClientInterface + zKEVMClient *mock_syncinterfaces.ZKEVMClientEthereumCompatibleInterface } func TestCheckL2BlockHash_GetMinimumL2BlockToCheck(t *testing.T) { @@ -57,7 +56,7 @@ func TestCheckL2BlockHashNotEnoughBlocksToCheck(t *testing.T) { func newCheckL2BlocksTestData(t *testing.T, initialL2Block, modulus uint64) CheckL2BlocksTestData { res := CheckL2BlocksTestData{ mockState: mock_syncinterfaces.NewStateFullInterface(t), - zKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), + zKEVMClient: mock_syncinterfaces.NewZKEVMClientEthereumCompatibleInterface(t), } res.sut = actions.NewCheckL2BlockHash(res.mockState, res.zKEVMClient, initialL2Block, modulus) return res @@ -97,18 +96,23 @@ func TestCheckL2BlockHashMatch(t *testing.T) { data.mockState.EXPECT().GetLastL2BlockNumber(mock.Anything, mock.Anything).Return(lastL2Block, nil) data.mockState.EXPECT().GetL2BlockByNumber(mock.Anything, lastL2Block, mock.Anything).Return(stateBlock, nil) - l2blockHash := stateBlock.Hash() - rpcL2Block := rpctypes.Block{ - Hash: &l2blockHash, - Number: rpctypes.ArgUint64(lastL2Block), - } + //l2blockHash := stateBlock.Hash() + // rpcL2Block := rpctypes.Block{ + // Hash: &l2blockHash, + // Number: rpctypes.ArgUint64(lastL2Block), + // } + // create a types.Block object + + rpcL2Block := types.NewBlock(&types.Header{ + Number: big.NewInt(int64(lastL2Block)), + }, nil, nil, nil, nil) - data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(&rpcL2Block, nil) + data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(rpcL2Block, nil) err := data.sut.CheckL2Block(context.Background(), nil) require.NoError(t, err) } -func TestCheckL2BlockHashMissmatch(t *testing.T) { +func TestCheckL2BlockHashMismatch(t *testing.T) { data := newCheckL2BlocksTestData(t, 1, 10) lastL2Block := uint64(14) lastL2BlockBigInt := big.NewInt(int64(lastL2Block)) @@ -119,13 +123,14 @@ func TestCheckL2BlockHashMissmatch(t *testing.T) { data.mockState.EXPECT().GetLastL2BlockNumber(mock.Anything, mock.Anything).Return(lastL2Block, nil) data.mockState.EXPECT().GetL2BlockByNumber(mock.Anything, lastL2Block, mock.Anything).Return(stateBlock, nil) - l2blockHash := common.HexToHash("0x1234") - rpcL2Block := rpctypes.Block{ - Hash: &l2blockHash, - Number: rpctypes.ArgUint64(lastL2Block), - } + //l2blockHash := common.HexToHash("0x1234") + + rpcL2Block := types.NewBlock(&types.Header{ + Number: big.NewInt(int64(lastL2Block)), + ParentHash: common.HexToHash("0x1234"), + }, nil, nil, nil, nil) - data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(&rpcL2Block, nil) + data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(rpcL2Block, nil) err := data.sut.CheckL2Block(context.Background(), nil) require.Error(t, err) } diff --git a/synchronizer/common/syncinterfaces/mocks/zkevm_client_ethereum_compatible_interface.go b/synchronizer/common/syncinterfaces/mocks/zkevm_client_ethereum_compatible_interface.go new file mode 100644 index 0000000000..09c0b0f235 --- /dev/null +++ b/synchronizer/common/syncinterfaces/mocks/zkevm_client_ethereum_compatible_interface.go @@ -0,0 +1,98 @@ +// Code generated by mockery. DO NOT EDIT. + +package mock_syncinterfaces + +import ( + context "context" + big "math/big" + + mock "github.com/stretchr/testify/mock" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// ZKEVMClientEthereumCompatibleInterface is an autogenerated mock type for the ZKEVMClientEthereumCompatibleInterface type +type ZKEVMClientEthereumCompatibleInterface struct { + mock.Mock +} + +type ZKEVMClientEthereumCompatibleInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *ZKEVMClientEthereumCompatibleInterface) EXPECT() *ZKEVMClientEthereumCompatibleInterface_Expecter { + return &ZKEVMClientEthereumCompatibleInterface_Expecter{mock: &_m.Mock} +} + +// BlockByNumber provides a mock function with given fields: ctx, number +func (_m *ZKEVMClientEthereumCompatibleInterface) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { + ret := _m.Called(ctx, number) + + if len(ret) == 0 { + panic("no return value specified for BlockByNumber") + } + + var r0 *types.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Block, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Block); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BlockByNumber' +type ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call struct { + *mock.Call +} + +// BlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - number *big.Int +func (_e *ZKEVMClientEthereumCompatibleInterface_Expecter) BlockByNumber(ctx interface{}, number interface{}) *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call { + return &ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call{Call: _e.mock.On("BlockByNumber", ctx, number)} +} + +func (_c *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*big.Int)) + }) + return _c +} + +func (_c *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call) Return(_a0 *types.Block, _a1 error) *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Block, error)) *ZKEVMClientEthereumCompatibleInterface_BlockByNumber_Call { + _c.Call.Return(run) + return _c +} + +// NewZKEVMClientEthereumCompatibleInterface creates a new instance of ZKEVMClientEthereumCompatibleInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewZKEVMClientEthereumCompatibleInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ZKEVMClientEthereumCompatibleInterface { + mock := &ZKEVMClientEthereumCompatibleInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/synchronizer/common/syncinterfaces/zkevm_ethereum_compatible_client.go b/synchronizer/common/syncinterfaces/zkevm_ethereum_compatible_client.go new file mode 100644 index 0000000000..416371dfce --- /dev/null +++ b/synchronizer/common/syncinterfaces/zkevm_ethereum_compatible_client.go @@ -0,0 +1,21 @@ +package syncinterfaces + +import ( + "context" + "math/big" + + "github.com/ethereum/go-ethereum/core/types" +) + +// ZKEVMClientEthereumCompatibleInterface contains the methods required to interact with zkEVM-RPC as a ethereum-API compatible +// +// Reason behind: the zkEVMClient have some extensions to ethereum-API that are not compatible with all nodes. So if you need to maximize +// the compatibility the idea is to use a regular ethereum-API compatible client +type ZKEVMClientEthereumCompatibleInterface interface { + ZKEVMClientEthereumCompatibleL2BlockGetter +} + +// ZKEVMClientEthereumCompatibleL2BlockGetter contains the methods required to interact with zkEVM-RPC as a ethereum-API compatible for obtain Block information +type ZKEVMClientEthereumCompatibleL2BlockGetter interface { + BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) +} diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 280cfe201f..6b6bceefca 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -52,17 +52,18 @@ type ClientSynchronizer struct { etherMan syncinterfaces.EthermanFullInterface latestFlushID uint64 // If true the lastFlushID is stored in DB and we don't need to check again - latestFlushIDIsFulfilled bool - etherManForL1 []syncinterfaces.EthermanFullInterface - state syncinterfaces.StateFullInterface - pool syncinterfaces.PoolInterface - ethTxManager syncinterfaces.EthTxManager - zkEVMClient syncinterfaces.ZKEVMClientInterface - eventLog syncinterfaces.EventLogInterface - ctx context.Context - cancelCtx context.CancelFunc - genesis state.Genesis - cfg Config + latestFlushIDIsFulfilled bool + etherManForL1 []syncinterfaces.EthermanFullInterface + state syncinterfaces.StateFullInterface + pool syncinterfaces.PoolInterface + ethTxManager syncinterfaces.EthTxManager + zkEVMClient syncinterfaces.ZKEVMClientInterface + zkEVMClientEthereumCompatible syncinterfaces.ZKEVMClientEthereumCompatibleInterface + eventLog syncinterfaces.EventLogInterface + ctx context.Context + cancelCtx context.CancelFunc + genesis state.Genesis + cfg Config // Id of the 'process' of the executor. Each time that it starts this value changes // This value is obtained from the call state.GetStoredFlushID // It starts as an empty string and it is filled in the first call @@ -85,6 +86,7 @@ func NewSynchronizer( pool syncinterfaces.PoolInterface, ethTxManager syncinterfaces.EthTxManager, zkEVMClient syncinterfaces.ZKEVMClientInterface, + zkEVMClientEthereumCompatible syncinterfaces.ZKEVMClientEthereumCompatibleInterface, eventLog syncinterfaces.EventLogInterface, genesis state.Genesis, cfg Config, @@ -92,23 +94,24 @@ func NewSynchronizer( ctx, cancel := context.WithCancel(context.Background()) metrics.Register() res := &ClientSynchronizer{ - isTrustedSequencer: isTrustedSequencer, - state: st, - etherMan: ethMan, - etherManForL1: etherManForL1, - pool: pool, - ctx: ctx, - cancelCtx: cancel, - ethTxManager: ethTxManager, - zkEVMClient: zkEVMClient, - eventLog: eventLog, - genesis: genesis, - cfg: cfg, - proverID: "", - previousExecutorFlushID: 0, - l1SyncOrchestration: nil, - l1EventProcessors: nil, - halter: syncCommon.NewCriticalErrorHalt(eventLog, 5*time.Second), //nolint:gomnd + isTrustedSequencer: isTrustedSequencer, + state: st, + etherMan: ethMan, + etherManForL1: etherManForL1, + pool: pool, + ctx: ctx, + cancelCtx: cancel, + ethTxManager: ethTxManager, + zkEVMClient: zkEVMClient, + zkEVMClientEthereumCompatible: zkEVMClientEthereumCompatible, + eventLog: eventLog, + genesis: genesis, + cfg: cfg, + proverID: "", + previousExecutorFlushID: 0, + l1SyncOrchestration: nil, + l1EventProcessors: nil, + halter: syncCommon.NewCriticalErrorHalt(eventLog, 5*time.Second), //nolint:gomnd } if !isTrustedSequencer { @@ -143,7 +146,7 @@ func NewSynchronizer( log.Errorf("error getting last L2Block number from state. Error: %v", err) return nil, err } - l1checkerL2Blocks = actions.NewCheckL2BlockHash(res.state, res.zkEVMClient, initialL2Block, cfg.L1SyncCheckL2BlockNumberhModulus) + l1checkerL2Blocks = actions.NewCheckL2BlockHash(res.state, res.zkEVMClientEthereumCompatible, initialL2Block, cfg.L1SyncCheckL2BlockNumberhModulus) } else { log.Infof("Trusted Node can't check L2Block hash, ignoring parameter") } From 4d2c48f6cf78f9069fec41959dc4751805e7d295 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:14:12 +0200 Subject: [PATCH 2/6] remove unused code --- cmd/run.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 301b5ba954..e39341309a 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -307,9 +307,8 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS } ethClientForL2, err := newL2EthClient(trustedSequencerURL) if err != nil { - log.Fatal(err) + log.Fatalf("Can't create L2 ethereum client. Err:%w", err) } - ethClientForL2.BlockByNumber(context.Background(), nil) zkEVMClient := client.NewClient(trustedSequencerURL) etherManForL1 := []syncinterfaces.EthermanFullInterface{} // If synchronizer are using sequential mode, we only need one etherman client From 44908974c21e27d143e77e9edd1a287e40375573 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:31:45 +0200 Subject: [PATCH 3/6] migrate docker-compose to v2 because ubuntu:latest have deprecated it --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index 7b6df67f6d..dc3921c542 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -DOCKERCOMPOSE := docker-compose -f docker-compose.yml +DOCKERCOMPOSE := docker compose -f docker compose.yml DOCKERCOMPOSEAPPSEQ := zkevm-sequencer DOCKERCOMPOSEAPPSEQV1TOV2 := zkevm-sequencer-v1tov2 DOCKERCOMPOSEAPPSEQSENDER := zkevm-sequence-sender From 3a4fa3f4ace091c2dbda7e524c7fa88722913583 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:48:30 +0200 Subject: [PATCH 4/6] fix docker-compose --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index dc3921c542..306cb71c98 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -DOCKERCOMPOSE := docker compose -f docker compose.yml +DOCKERCOMPOSE := docker compose -f docker-compose.yml DOCKERCOMPOSEAPPSEQ := zkevm-sequencer DOCKERCOMPOSEAPPSEQV1TOV2 := zkevm-sequencer-v1tov2 DOCKERCOMPOSEAPPSEQSENDER := zkevm-sequence-sender From 7443e41be8efa8f44db16ffeb3bf49d3b4ba1d17 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:54:52 +0200 Subject: [PATCH 5/6] fix unittest --- synchronizer/synchronizer_test.go | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index bdf3b505b6..4702ef1986 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -32,12 +32,13 @@ const ( ) type mocks struct { - Etherman *mock_syncinterfaces.EthermanFullInterface - State *mock_syncinterfaces.StateFullInterface - Pool *mock_syncinterfaces.PoolInterface - EthTxManager *mock_syncinterfaces.EthTxManager - DbTx *syncMocks.DbTxMock - ZKEVMClient *mock_syncinterfaces.ZKEVMClientInterface + Etherman *mock_syncinterfaces.EthermanFullInterface + State *mock_syncinterfaces.StateFullInterface + Pool *mock_syncinterfaces.PoolInterface + EthTxManager *mock_syncinterfaces.EthTxManager + DbTx *syncMocks.DbTxMock + ZKEVMClient *mock_syncinterfaces.ZKEVMClientInterface + zkEVMClientEthereumCompatible *mock_syncinterfaces.ZKEVMClientEthereumCompatibleInterface //EventLog *eventLogMock } @@ -47,7 +48,7 @@ type mocks struct { func TestGivenPermissionlessNodeWhenSyncronizeAgainSameBatchThenUseTheOneInMemoryInstaeadOfGettingFromDb(t *testing.T) { genesis, cfg, m := setupGenericTest(t) ethermanForL1 := []syncinterfaces.EthermanFullInterface{m.Etherman} - syncInterface, err := NewSynchronizer(false, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, nil, *genesis, *cfg, false) + syncInterface, err := NewSynchronizer(false, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, m.zkEVMClientEthereumCompatible, nil, *genesis, *cfg, false) require.NoError(t, err) sync, ok := syncInterface.(*ClientSynchronizer) require.EqualValues(t, true, ok, "Can't convert to underlaying struct the interface of syncronizer") @@ -87,7 +88,7 @@ func TestGivenPermissionlessNodeWhenSyncronizeAgainSameBatchThenUseTheOneInMemor func TestGivenPermissionlessNodeWhenSyncronizeFirstTimeABatchThenStoreItInALocalVar(t *testing.T) { genesis, cfg, m := setupGenericTest(t) ethermanForL1 := []syncinterfaces.EthermanFullInterface{m.Etherman} - syncInterface, err := NewSynchronizer(false, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, nil, *genesis, *cfg, false) + syncInterface, err := NewSynchronizer(false, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, m.zkEVMClientEthereumCompatible, nil, *genesis, *cfg, false) require.NoError(t, err) sync, ok := syncInterface.(*ClientSynchronizer) require.EqualValues(t, true, ok, "Can't convert to underlaying struct the interface of syncronizer") @@ -135,7 +136,7 @@ func TestForcedBatchEtrog(t *testing.T) { ZKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), } ethermanForL1 := []syncinterfaces.EthermanFullInterface{m.Etherman} - sync, err := NewSynchronizer(false, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, nil, genesis, cfg, false) + sync, err := NewSynchronizer(false, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, m.zkEVMClientEthereumCompatible, nil, genesis, cfg, false) require.NoError(t, err) // state preparation @@ -388,7 +389,7 @@ func TestSequenceForcedBatchIncaberry(t *testing.T) { ZKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), } ethermanForL1 := []syncinterfaces.EthermanFullInterface{m.Etherman} - sync, err := NewSynchronizer(true, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, nil, genesis, cfg, false) + sync, err := NewSynchronizer(true, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, m.zkEVMClientEthereumCompatible, nil, genesis, cfg, false) require.NoError(t, err) // state preparation @@ -631,12 +632,13 @@ func setupGenericTest(t *testing.T) (*state.Genesis, *Config, *mocks) { } m := mocks{ - Etherman: mock_syncinterfaces.NewEthermanFullInterface(t), - State: mock_syncinterfaces.NewStateFullInterface(t), - Pool: mock_syncinterfaces.NewPoolInterface(t), - DbTx: syncMocks.NewDbTxMock(t), - ZKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), - EthTxManager: mock_syncinterfaces.NewEthTxManager(t), + Etherman: mock_syncinterfaces.NewEthermanFullInterface(t), + State: mock_syncinterfaces.NewStateFullInterface(t), + Pool: mock_syncinterfaces.NewPoolInterface(t), + DbTx: syncMocks.NewDbTxMock(t), + ZKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), + zkEVMClientEthereumCompatible: mock_syncinterfaces.NewZKEVMClientEthereumCompatibleInterface(t), + EthTxManager: mock_syncinterfaces.NewEthTxManager(t), //EventLog: newEventLogMock(t), } return &genesis, &cfg, &m From 39a489c203ee2b4bccb6cc27b36b4f1560476709 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:41:12 +0200 Subject: [PATCH 6/6] fix case trusted URL is not set --- cmd/run.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index e39341309a..cbc3f835e2 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -305,9 +305,16 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS } log.Info("trustedSequencerURL ", trustedSequencerURL) } - ethClientForL2, err := newL2EthClient(trustedSequencerURL) - if err != nil { - log.Fatalf("Can't create L2 ethereum client. Err:%w", err) + var ethClientForL2 *ethclient.Client + if trustedSequencerURL != "" { + log.Infof("Creating L2 ethereum client %s", trustedSequencerURL) + ethClientForL2, err = newL2EthClient(trustedSequencerURL) + if err != nil { + log.Fatalf("Can't create L2 ethereum client. Err:%w", err) + } + } else { + ethClientForL2 = nil + log.Infof("skipping creating L2 ethereum client because URL is empty") } zkEVMClient := client.NewClient(trustedSequencerURL) etherManForL1 := []syncinterfaces.EthermanFullInterface{}