arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
TxProc merge multiple exits into single ExitInfo

Fix #497
arnaucube root@arnaucube.com
Wed, 20 Jan 2021 16:37:13 +0100
commit

b20ffd826edd7ba9994f287bcf0a43e7e5b66ec7

parent

699b9deef0ba7caf1ac2d1468fb76d89748d793f

2 files changed, 10 insertions(+), 6 deletions(-)

jump to
M txprocessor/txprocessor.go → txprocessor/txprocessor.go

@@ -328,7 +328,8 @@ for i := last; i < int(tp.config.MaxTx); i++ {

if i < int(tp.config.MaxTx)-1 { tp.zki.ISOutIdx[i] = tp.s.CurrentIdx().BigInt() tp.zki.ISStateRoot[i] = tp.s.MT.Root().BigInt() - tp.zki.ISAccFeeOut[i] = formatAccumulatedFees(collectedFees, tp.zki.FeePlanTokens, coordIdxs) + tp.zki.ISAccFeeOut[i] = formatAccumulatedFees(collectedFees, + tp.zki.FeePlanTokens, coordIdxs) tp.zki.ISExitRoot[i] = exitTree.Root().BigInt() } if i >= tp.i {

@@ -396,6 +397,7 @@

// once all txs processed (exitTree root frozen), for each Exit, // generate common.ExitInfo data var exitInfos []common.ExitInfo + exitInfosByIdx := make(map[common.Idx]*common.ExitInfo) for i := 0; i < nTx; i++ { if !exits[i].exit { continue

@@ -415,7 +417,12 @@ AccountIdx: exitIdx,

MerkleProof: p, Balance: exitAccount.Balance, } - exitInfos = append(exitInfos, ei) + if prevExit, ok := exitInfosByIdx[exitIdx]; !ok { + exitInfos = append(exitInfos, ei) + exitInfosByIdx[exitIdx] = &exitInfos[len(exitInfos)-1] + } else { + *prevExit = ei + } } if tp.s.Typ == statedb.TypeSynchronizer {
M txprocessor/txprocessor_test.go → txprocessor/txprocessor_test.go

@@ -3,7 +3,6 @@

import ( "encoding/binary" "encoding/hex" - "fmt" "io/ioutil" "math/big" "os"

@@ -463,7 +462,7 @@ ptOut, err = tp.ProcessTxs(coordIdxs, blocks[1].Rollup.L1UserTxs,

blocks[1].Rollup.Batches[1].L1CoordinatorTxs, l2Txs) require.NoError(t, err) - assert.Equal(t, 2, len(ptOut.ExitInfos)) // 2, as previous batch was without L1UserTxs, and has pending the 'ForceExit(1) A: 5' + assert.Equal(t, 1, len(ptOut.ExitInfos)) // 1, as previous batch was without L1UserTxs, and has pending the 'ForceExit(1) A: 5', and the 2 exit transactions get grouped under 1 ExitInfo assert.Equal(t, 1, len(ptOut.CreatedAccounts)) assert.Equal(t, 4, len(ptOut.CollectedFees)) assert.Equal(t, "0", ptOut.CollectedFees[common.TokenID(0)].String())

@@ -842,10 +841,8 @@ tp := NewTxProcessor(sdb, config)

ptOuts := []*ProcessTxOutput{} for _, block := range blocks { for _, batch := range block.Rollup.Batches { - // fmt.Printf("Batch %v\n%#v\n", batch.Batch.BatchNum, batch.L1UserTxs) ptOut, err := tp.ProcessTxs(nil, batch.L1UserTxs, nil, nil) require.NoError(t, err) - fmt.Printf("Exits (batch %v)\n%#v\n", batch.Batch.BatchNum, ptOut.ExitInfos) ptOuts = append(ptOuts, ptOut) } }