arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #353 from hermeznetwork/fix/process-l2txs

Add TxType before processing L2 tx
Eduard S eduard@iden3.io
Wed, 16 Dec 2020 13:31:41 +0100
commit

b53cf10b3506331f1b461aa11242763ab2f4f648

parent

8e1bfd150d423bf0452b47509993ee3c7a84b0b6

2 files changed, 28 insertions(+), 19 deletions(-)

jump to
M synchronizer/synchronizer.go → synchronizer/synchronizer.go

@@ -752,6 +752,17 @@

// Insert all the txs forged in this batch (l1UserTxs, // L1CoordinatorTxs, PoolL2Txs) into stateDB so that they are // processed. + + // Add TxID, TxType, Position, BlockNum and BatchNum to L2 txs + for i := range forgeBatchArgs.L2TxsData { + nTx, err := common.NewL2Tx(&forgeBatchArgs.L2TxsData[i]) + if err != nil { + return nil, tracerr.Wrap(err) + } + forgeBatchArgs.L2TxsData[i] = *nTx + } + + // Transform L2 txs to PoolL2Txs poolL2Txs := common.L2TxsToPoolL2Txs(forgeBatchArgs.L2TxsData) // NOTE: This is a big ugly, find a better way // ProcessTxs updates poolL2Txs adding: Nonce (and also TokenID, but we don't use it).

@@ -767,6 +778,22 @@ l1UserTxs, batchData.L1CoordinatorTxs, poolL2Txs)

if err != nil { return nil, tracerr.Wrap(err) } + + // Transform processed PoolL2 txs to L2 and store in BatchData + if poolL2Txs != nil { + l2Txs, err := common.PoolL2TxsToL2Txs(poolL2Txs) // NOTE: This is a big uggly, find a better way + if err != nil { + return nil, tracerr.Wrap(err) + } + for i := range l2Txs { + l2Txs[i].Position = position + l2Txs[i].EthBlockNum = blockNum + l2Txs[i].BatchNum = batchNum + position++ + } + batchData.L2Txs = l2Txs + } + // Set the BatchNum in the forged L1UserTxs for i := range l1UserTxs { l1UserTxs[i].BatchNum = &batchNum

@@ -779,25 +806,6 @@ exit := &processTxsOut.ExitInfos[i]

exit.BatchNum = batchNum } batchData.ExitTree = processTxsOut.ExitInfos - - l2Txs, err := common.PoolL2TxsToL2Txs(poolL2Txs) // NOTE: This is a big uggly, find a better way - if err != nil { - return nil, tracerr.Wrap(err) - } - - for i := range l2Txs { - tx := &l2Txs[i] - tx.Position = position - tx.EthBlockNum = blockNum - tx.BatchNum = batchNum - nTx, err := common.NewL2Tx(tx) - if err != nil { - return nil, tracerr.Wrap(err) - } - - batchData.L2Txs = append(batchData.L2Txs, *nTx) - position++ - } for i := range processTxsOut.CreatedAccounts { createdAccount := &processTxsOut.CreatedAccounts[i]
M synchronizer/synchronizer_test.go → synchronizer/synchronizer_test.go

@@ -485,6 +485,7 @@

// Block 3 syncBlock, discards, err = s.Sync2(ctx, nil) + assert.NoError(t, err) require.Nil(t, err) require.Nil(t, discards) require.NotNil(t, syncBlock)