From 281409d63ff9627982f9b859778207fafb9e043c Mon Sep 17 00:00:00 2001 From: Alonso Date: Wed, 15 Mar 2023 17:01:49 +0100 Subject: [PATCH 1/6] avoid execute batch twice --- state/state.go | 16 +++++++-------- synchronizer/interfaces.go | 2 +- synchronizer/mock_state.go | 19 ++++++++++++----- synchronizer/synchronizer.go | 34 +++++++++++++++++-------------- synchronizer/synchronizer_test.go | 4 ++-- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/state/state.go b/state/state.go index bb6b2e79ee..97691b83bc 100644 --- a/state/state.go +++ b/state/state.go @@ -775,24 +775,24 @@ func (s *State) ProcessAndStoreClosedBatch( encodedTxs []byte, dbTx pgx.Tx, caller CallerLabel, -) error { +) (*pb.ProcessBatchResponse, error) { // Decode transactions decodedTransactions, _, err := DecodeTxs(encodedTxs) if err != nil && !errors.Is(err, InvalidData) { log.Debugf("error decoding transactions: %v", err) - return err + return nil, err } // Open the batch and process the txs if dbTx == nil { - return ErrDBTxNil + return nil, ErrDBTxNil } if err := s.OpenBatch(ctx, processingCtx, dbTx); err != nil { - return err + return nil, err } processed, err := s.processBatch(ctx, processingCtx.BatchNumber, encodedTxs, caller, dbTx) if err != nil { - return err + return nil, err } // Sanity check @@ -823,19 +823,19 @@ func (s *State) ProcessAndStoreClosedBatch( processedBatch, err := s.convertToProcessBatchResponse(decodedTransactions, processed) if err != nil { - return err + return nil, err } if len(processedBatch.Responses) > 0 { // Store processed txs into the batch err = s.StoreTransactions(ctx, processingCtx.BatchNumber, processedBatch.Responses, dbTx) if err != nil { - return err + return nil, err } } // Close batch - return s.closeBatch(ctx, ProcessingReceipt{ + return processed, s.closeBatch(ctx, ProcessingReceipt{ BatchNumber: processingCtx.BatchNumber, StateRoot: processedBatch.NewStateRoot, LocalExitRoot: processedBatch.NewLocalExitRoot, diff --git a/synchronizer/interfaces.go b/synchronizer/interfaces.go index f63d27259b..c810c8f7bc 100644 --- a/synchronizer/interfaces.go +++ b/synchronizer/interfaces.go @@ -37,7 +37,7 @@ type stateInterface interface { // GetNextForcedBatches returns the next forcedBatches in FIFO order GetNextForcedBatches(ctx context.Context, nextForcedBatches int, dbTx pgx.Tx) ([]state.ForcedBatch, error) AddVerifiedBatch(ctx context.Context, verifiedBatch *state.VerifiedBatch, dbTx pgx.Tx) error - ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) error + ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) (*pb.ProcessBatchResponse, error) SetGenesis(ctx context.Context, block state.Block, genesis state.Genesis, dbTx pgx.Tx) ([]byte, error) OpenBatch(ctx context.Context, processingContext state.ProcessingContext, dbTx pgx.Tx) error CloseBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error diff --git a/synchronizer/mock_state.go b/synchronizer/mock_state.go index 9fe666828e..eb65fd2fdd 100644 --- a/synchronizer/mock_state.go +++ b/synchronizer/mock_state.go @@ -413,17 +413,26 @@ func (_m *stateMock) OpenBatch(ctx context.Context, processingContext state.Proc } // ProcessAndStoreClosedBatch provides a mock function with given fields: ctx, processingCtx, encodedTxs, dbTx, caller -func (_m *stateMock) ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) error { +func (_m *stateMock) ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) (*pb.ProcessBatchResponse, error) { ret := _m.Called(ctx, processingCtx, encodedTxs, dbTx, caller) - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) error); ok { + var r0 *pb.ProcessBatchResponse + if rf, ok := ret.Get(0).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) *pb.ProcessBatchResponse); ok { r0 = rf(ctx, processingCtx, encodedTxs, dbTx, caller) } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pb.ProcessBatchResponse) + } } - return r0 + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) error); ok { + r1 = rf(ctx, processingCtx, encodedTxs, dbTx, caller) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } // ProcessSequencerBatch provides a mock function with given fields: ctx, batchNumber, batchL2Data, caller, dbTx diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 3616e450b9..9133641db5 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -660,18 +660,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. ForcedBatchNum: batch.ForcedBatchNum, } - // Reprocess batch to compare the stateRoot with tBatch.StateRoot and get accInputHash - p, err := s.state.ExecuteBatch(s.ctx, batch, false, dbTx) - if err != nil { - log.Errorf("error executing L1 batch: %+v, error: %v", batch, err) - rollbackErr := dbTx.Rollback(s.ctx) - if rollbackErr != nil { - log.Fatalf("error rolling back state. BatchNumber: %d, BlockNumber: %d, rollbackErr: %s, error : %v", batch.BatchNumber, blockNumber, rollbackErr.Error(), err) - } - log.Fatalf("error executing L1 batch: %+v, error: %v", batch, err) - } - newRoot := common.BytesToHash(p.NewStateRoot) - accumulatedInputHash := common.BytesToHash(p.NewAccInputHash) + var newRoot common.Hash // First get trusted batch from db tBatch, err := s.state.GetBatchByNumber(s.ctx, batch.BatchNumber, dbTx) @@ -679,7 +668,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. if errors.Is(err, state.ErrNotFound) || errors.Is(err, state.ErrStateNotSynchronized) { log.Debugf("BatchNumber: %d, not found in trusted state. Storing it...", batch.BatchNumber) // If it is not found, store batch - err = s.state.ProcessAndStoreClosedBatch(s.ctx, processCtx, batch.BatchL2Data, dbTx, state.SynchronizerCallerLabel) + p, err := s.state.ProcessAndStoreClosedBatch(s.ctx, processCtx, batch.BatchL2Data, dbTx, state.SynchronizerCallerLabel) if err != nil { log.Errorf("error storing trustedBatch. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, blockNumber, err) rollbackErr := dbTx.Rollback(s.ctx) @@ -690,6 +679,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. log.Errorf("error storing batch. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, blockNumber, err) return err } + newRoot = common.BytesToHash(p.NewStateRoot) tBatch = &batch tBatch.StateRoot = newRoot } else { @@ -702,6 +692,20 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. return err } } else { + // Reprocess batch to compare the stateRoot with tBatch.StateRoot and get accInputHash + p, err := s.state.ExecuteBatch(s.ctx, batch, false, dbTx) + if err != nil { + log.Errorf("error executing L1 batch: %+v, error: %v", batch, err) + rollbackErr := dbTx.Rollback(s.ctx) + if rollbackErr != nil { + log.Errorf("error rolling back state. BatchNumber: %d, BlockNumber: %d, rollbackErr: %s, error : %v", batch.BatchNumber, blockNumber, rollbackErr.Error(), err) + return rollbackErr + } + return err + } + newRoot = common.BytesToHash(p.NewStateRoot) + accumulatedInputHash := common.BytesToHash(p.NewAccInputHash) + //AddAccumulatedInputHash err = s.state.AddAccumulatedInputHash(s.ctx, batch.BatchNumber, accumulatedInputHash, dbTx) if err != nil { @@ -744,7 +748,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. log.Errorf("error resetting trusted state. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, blockNumber, err) return err } - err = s.state.ProcessAndStoreClosedBatch(s.ctx, processCtx, batch.BatchL2Data, dbTx, state.SynchronizerCallerLabel) + _, err = s.state.ProcessAndStoreClosedBatch(s.ctx, processCtx, batch.BatchL2Data, dbTx, state.SynchronizerCallerLabel) if err != nil { log.Errorf("error storing trustedBatch. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, blockNumber, err) rollbackErr := dbTx.Rollback(s.ctx) @@ -868,7 +872,7 @@ func (s *ClientSynchronizer) processSequenceForceBatch(sequenceForceBatch []ethe ForcedBatchNum: &forcedBatches[i].ForcedBatchNumber, } // Process batch - err := s.state.ProcessAndStoreClosedBatch(s.ctx, batch, forcedBatches[i].RawTxsData, dbTx, state.SynchronizerCallerLabel) + _, err := s.state.ProcessAndStoreClosedBatch(s.ctx, batch, forcedBatches[i].RawTxsData, dbTx, state.SynchronizerCallerLabel) if err != nil { log.Errorf("error processing batch in processSequenceForceBatch. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, block.BlockNumber, err) rollbackErr := dbTx.Rollback(s.ctx) diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index 4a78e52903..bffe3f5b3a 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -218,7 +218,7 @@ func TestTrustedStateReorg(t *testing.T) { m.State. On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). - Return(nil). + Return(&pb.ProcessBatchResponse{NewStateRoot: trustedBatch.StateRoot.Bytes()},nil). Once() virtualBatch := &state.VirtualBatch{ @@ -727,7 +727,7 @@ func TestSequenceForcedBatch(t *testing.T) { m.State. On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedForceBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). - Return(nil). + Return(&pb.ProcessBatchResponse{},nil). Once() virtualBatch := &state.VirtualBatch{ From 1b8bddd1fb40a5ff29f3a4f5c4f71e3f7da604a2 Mon Sep 17 00:00:00 2001 From: Alonso Date: Wed, 15 Mar 2023 17:02:00 +0100 Subject: [PATCH 2/6] fix make run-rpc --- docker-compose.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f925ba72f0..e45f54d9f5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,8 +17,6 @@ services: ports: - 8545:8545 - 9091:9091 # needed if metrics enabled - environment: - - ZKEVM_NODE_ETHERMAN_URL=${ZKEVM_NODE_ETHERMAN_URL} volumes: - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.node.config.toml:/app/config.toml - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.genesis.config.json:/app/genesis.json @@ -34,8 +32,6 @@ services: zkevm-state-db: condition: service_healthy image: zkevm-node - environment: - - ZKEVM_NODE_ETHERMAN_URL=${ZKEVM_NODE_ETHERMAN_URL} volumes: - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.node.config.toml:/app/config.toml - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.genesis.config.json:/app/genesis.json @@ -63,7 +59,6 @@ services: - 5432:5432 volumes: - ./db/scripts/init_prover_db.sql:/docker-entrypoint-initdb.d/init.sql - - ${ZKEVM_NODE_STATEDB_DATA_DIR}:/var/lib/postgresql/data environment: - POSTGRES_USER=state_user - POSTGRES_PASSWORD=state_password @@ -87,8 +82,6 @@ services: memory: 1G ports: - 5433:5432 - volumes: - - ${ZKEVM_NODE_POOLDB_DATA_DIR}:/var/lib/postgresql/data environment: - POSTGRES_USER=pool_user - POSTGRES_PASSWORD=pool_password From 88390a725c9d4da6eb20387412631fafa96ea949 Mon Sep 17 00:00:00 2001 From: Alonso Date: Wed, 15 Mar 2023 17:09:43 +0100 Subject: [PATCH 3/6] linter --- synchronizer/synchronizer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index bffe3f5b3a..0008be9258 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -218,7 +218,7 @@ func TestTrustedStateReorg(t *testing.T) { m.State. On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). - Return(&pb.ProcessBatchResponse{NewStateRoot: trustedBatch.StateRoot.Bytes()},nil). + Return(&pb.ProcessBatchResponse{NewStateRoot: trustedBatch.StateRoot.Bytes()}, nil). Once() virtualBatch := &state.VirtualBatch{ @@ -727,7 +727,7 @@ func TestSequenceForcedBatch(t *testing.T) { m.State. On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedForceBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). - Return(&pb.ProcessBatchResponse{},nil). + Return(&pb.ProcessBatchResponse{}, nil). Once() virtualBatch := &state.VirtualBatch{ From 9555afcb04cfa16db11f9bd787cfe1136e500aef Mon Sep 17 00:00:00 2001 From: Alonso Date: Wed, 15 Mar 2023 17:02:00 +0100 Subject: [PATCH 4/6] Revert "fix make run-rpc" This reverts commit 1b8bddd1fb40a5ff29f3a4f5c4f71e3f7da604a2. --- docker-compose.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index e45f54d9f5..f925ba72f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,8 @@ services: ports: - 8545:8545 - 9091:9091 # needed if metrics enabled + environment: + - ZKEVM_NODE_ETHERMAN_URL=${ZKEVM_NODE_ETHERMAN_URL} volumes: - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.node.config.toml:/app/config.toml - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.genesis.config.json:/app/genesis.json @@ -32,6 +34,8 @@ services: zkevm-state-db: condition: service_healthy image: zkevm-node + environment: + - ZKEVM_NODE_ETHERMAN_URL=${ZKEVM_NODE_ETHERMAN_URL} volumes: - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.node.config.toml:/app/config.toml - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/public}/public.genesis.config.json:/app/genesis.json @@ -59,6 +63,7 @@ services: - 5432:5432 volumes: - ./db/scripts/init_prover_db.sql:/docker-entrypoint-initdb.d/init.sql + - ${ZKEVM_NODE_STATEDB_DATA_DIR}:/var/lib/postgresql/data environment: - POSTGRES_USER=state_user - POSTGRES_PASSWORD=state_password @@ -82,6 +87,8 @@ services: memory: 1G ports: - 5433:5432 + volumes: + - ${ZKEVM_NODE_POOLDB_DATA_DIR}:/var/lib/postgresql/data environment: - POSTGRES_USER=pool_user - POSTGRES_PASSWORD=pool_password From a6c1272ab7c025a68b764903a79b8b5da9c72c12 Mon Sep 17 00:00:00 2001 From: Alonso Date: Wed, 22 Mar 2023 16:54:38 +0100 Subject: [PATCH 5/6] suggestion --- state/state.go | 16 ++++++++-------- synchronizer/interfaces.go | 2 +- synchronizer/mock_state.go | 13 ++++++++----- synchronizer/synchronizer.go | 4 ++-- synchronizer/synchronizer_test.go | 11 ++++++----- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/state/state.go b/state/state.go index b155ad8f62..0fd9bca5c8 100644 --- a/state/state.go +++ b/state/state.go @@ -782,24 +782,24 @@ func (s *State) ProcessAndStoreClosedBatch( encodedTxs []byte, dbTx pgx.Tx, caller CallerLabel, -) (*pb.ProcessBatchResponse, error) { +) (common.Hash, error) { // Decode transactions decodedTransactions, _, err := DecodeTxs(encodedTxs) if err != nil && !errors.Is(err, InvalidData) { log.Debugf("error decoding transactions: %v", err) - return nil, err + return common.Hash{}, err } // Open the batch and process the txs if dbTx == nil { - return nil, ErrDBTxNil + return common.Hash{}, ErrDBTxNil } if err := s.OpenBatch(ctx, processingCtx, dbTx); err != nil { - return nil, err + return common.Hash{}, err } processed, err := s.processBatch(ctx, processingCtx.BatchNumber, encodedTxs, caller, dbTx) if err != nil { - return nil, err + return common.Hash{}, err } // Sanity check @@ -830,19 +830,19 @@ func (s *State) ProcessAndStoreClosedBatch( processedBatch, err := s.convertToProcessBatchResponse(decodedTransactions, processed) if err != nil { - return nil, err + return common.Hash{}, err } if len(processedBatch.Responses) > 0 { // Store processed txs into the batch err = s.StoreTransactions(ctx, processingCtx.BatchNumber, processedBatch.Responses, dbTx) if err != nil { - return nil, err + return common.Hash{}, err } } // Close batch - return processed, s.closeBatch(ctx, ProcessingReceipt{ + return common.BytesToHash(processed.NewStateRoot), s.closeBatch(ctx, ProcessingReceipt{ BatchNumber: processingCtx.BatchNumber, StateRoot: processedBatch.NewStateRoot, LocalExitRoot: processedBatch.NewLocalExitRoot, diff --git a/synchronizer/interfaces.go b/synchronizer/interfaces.go index 406abfba6c..3ce6e5eb1e 100644 --- a/synchronizer/interfaces.go +++ b/synchronizer/interfaces.go @@ -38,7 +38,7 @@ type stateInterface interface { AddVirtualBatch(ctx context.Context, virtualBatch *state.VirtualBatch, dbTx pgx.Tx) error GetNextForcedBatches(ctx context.Context, nextForcedBatches int, dbTx pgx.Tx) ([]state.ForcedBatch, error) AddVerifiedBatch(ctx context.Context, verifiedBatch *state.VerifiedBatch, dbTx pgx.Tx) error - ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) (*pb.ProcessBatchResponse, error) + ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) (common.Hash, error) SetGenesis(ctx context.Context, block state.Block, genesis state.Genesis, dbTx pgx.Tx) ([]byte, error) OpenBatch(ctx context.Context, processingContext state.ProcessingContext, dbTx pgx.Tx) error CloseBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error diff --git a/synchronizer/mock_state.go b/synchronizer/mock_state.go index a5ca4b00cd..0175e5eec1 100644 --- a/synchronizer/mock_state.go +++ b/synchronizer/mock_state.go @@ -470,19 +470,22 @@ func (_m *stateMock) OpenBatch(ctx context.Context, processingContext state.Proc } // ProcessAndStoreClosedBatch provides a mock function with given fields: ctx, processingCtx, encodedTxs, dbTx, caller -func (_m *stateMock) ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) (*pb.ProcessBatchResponse, error) { +func (_m *stateMock) ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx, caller state.CallerLabel) (common.Hash, error) { ret := _m.Called(ctx, processingCtx, encodedTxs, dbTx, caller) - var r0 *pb.ProcessBatchResponse - if rf, ok := ret.Get(0).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) *pb.ProcessBatchResponse); ok { + var r0 common.Hash + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) (common.Hash, error)); ok { + return rf(ctx, processingCtx, encodedTxs, dbTx, caller) + } + if rf, ok := ret.Get(0).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) common.Hash); ok { r0 = rf(ctx, processingCtx, encodedTxs, dbTx, caller) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*pb.ProcessBatchResponse) + r0 = ret.Get(0).(common.Hash) } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, state.ProcessingContext, []byte, pgx.Tx, state.CallerLabel) error); ok { r1 = rf(ctx, processingCtx, encodedTxs, dbTx, caller) } else { diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index f6bab27c7d..b86cccedfb 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -705,7 +705,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. if errors.Is(err, state.ErrNotFound) || errors.Is(err, state.ErrStateNotSynchronized) { log.Debugf("BatchNumber: %d, not found in trusted state. Storing it...", batch.BatchNumber) // If it is not found, store batch - p, err := s.state.ProcessAndStoreClosedBatch(s.ctx, processCtx, batch.BatchL2Data, dbTx, state.SynchronizerCallerLabel) + newStateRoot, err := s.state.ProcessAndStoreClosedBatch(s.ctx, processCtx, batch.BatchL2Data, dbTx, state.SynchronizerCallerLabel) if err != nil { log.Errorf("error storing trustedBatch. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, blockNumber, err) rollbackErr := dbTx.Rollback(s.ctx) @@ -716,7 +716,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman. log.Errorf("error storing batch. BatchNumber: %d, BlockNumber: %d, error: %v", batch.BatchNumber, blockNumber, err) return err } - newRoot = common.BytesToHash(p.NewStateRoot) + newRoot = newStateRoot tBatch = &batch tBatch.StateRoot = newRoot } else { diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index ff1fd55c7d..6018e5ce53 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -27,6 +27,7 @@ type mocks struct { ZKEVMClient *zkEVMClientMock } +// Test commented until we remove the fatal in checkTrustedReorg function // func TestTrustedStateReorg(t *testing.T) { // type testCase struct { // Name string @@ -208,10 +209,10 @@ type mocks struct { // GlobalExitRoot: sequencedBatch.GlobalExitRoot, // } - m.State. - On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). - Return(&pb.ProcessBatchResponse{NewStateRoot: trustedBatch.StateRoot.Bytes()}, nil). - Once() +// m.State. +// On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). +// Return(trustedBatch.StateRoot, nil). +// Once() // virtualBatch := &state.VirtualBatch{ // BatchNumber: sequencedBatch.BatchNumber, @@ -717,7 +718,7 @@ func TestSequenceForcedBatch(t *testing.T) { m.State. On("ProcessAndStoreClosedBatch", ctx, processingContext, sequencedForceBatch.Transactions, m.DbTx, state.SynchronizerCallerLabel). - Return(&pb.ProcessBatchResponse{}, nil). + Return(common.Hash{}, nil). Once() virtualBatch := &state.VirtualBatch{ From d0e58459bc7c680e84d0e5bfdf458562378961dd Mon Sep 17 00:00:00 2001 From: Alonso Date: Thu, 23 Mar 2023 10:57:50 +0100 Subject: [PATCH 6/6] remove log --- jsonrpc/client/zkevm.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/jsonrpc/client/zkevm.go b/jsonrpc/client/zkevm.go index 26a2119e74..f2e78aa4af 100644 --- a/jsonrpc/client/zkevm.go +++ b/jsonrpc/client/zkevm.go @@ -8,7 +8,6 @@ import ( "github.com/0xPolygonHermez/zkevm-node/hex" "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" - "github.com/0xPolygonHermez/zkevm-node/log" ) // BatchNumber returns the latest batch number @@ -47,7 +46,6 @@ func (c *Client) BatchByNumber(ctx context.Context, number *big.Int) (*types.Bat } var result *types.Batch - log.Debugf(string(response.Result)) err = json.Unmarshal(response.Result, &result) if err != nil { return nil, err