Browse Source

Merge pull request #353 from hermeznetwork/fix/process-l2txs

Add TxType before processing L2 tx
feature/sql-semaphore1
Eduard S 3 years ago
committed by GitHub
parent
commit
b53cf10b35
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 19 deletions
  1. +27
    -19
      synchronizer/synchronizer.go
  2. +1
    -0
      synchronizer/synchronizer_test.go

+ 27
- 19
synchronizer/synchronizer.go

@ -752,6 +752,17 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
// Insert all the txs forged in this batch (l1UserTxs, // Insert all the txs forged in this batch (l1UserTxs,
// L1CoordinatorTxs, PoolL2Txs) into stateDB so that they are // L1CoordinatorTxs, PoolL2Txs) into stateDB so that they are
// processed. // 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 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). // ProcessTxs updates poolL2Txs adding: Nonce (and also TokenID, but we don't use it).
@ -767,6 +778,22 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) 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 // Set the BatchNum in the forged L1UserTxs
for i := range l1UserTxs { for i := range l1UserTxs {
l1UserTxs[i].BatchNum = &batchNum l1UserTxs[i].BatchNum = &batchNum
@ -780,25 +807,6 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
} }
batchData.ExitTree = processTxsOut.ExitInfos 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 { for i := range processTxsOut.CreatedAccounts {
createdAccount := &processTxsOut.CreatedAccounts[i] createdAccount := &processTxsOut.CreatedAccounts[i]
createdAccount.Nonce = 0 createdAccount.Nonce = 0

+ 1
- 0
synchronizer/synchronizer_test.go

@ -485,6 +485,7 @@ func TestSync(t *testing.T) {
// Block 3 // Block 3
syncBlock, discards, err = s.Sync2(ctx, nil) syncBlock, discards, err = s.Sync2(ctx, nil)
assert.NoError(t, err)
require.Nil(t, err) require.Nil(t, err)
require.Nil(t, discards) require.Nil(t, discards)
require.NotNil(t, syncBlock) require.NotNil(t, syncBlock)

Loading…
Cancel
Save