Update txs constructors and helpers

For each tx, move the logic of setting the Type and TxID to separate functions,
so that they can be called when necessary.

In synchronizer, set all the required fields using the `SetID` and `SetType`
for l2txs when needed.  This is necessary because the `ProcessTxs()` works with
`common.PoolL2Tx`, which misses some fields from `common.L2Tx`, and because
`ProcessTxs()` needs the Type to be set, but at the same time `ProcessTxs()`
sets the Nonce, which is required for the `TxID`.
This commit is contained in:
Eduard S
2020-12-16 15:25:55 +01:00
parent 61255d730c
commit 7a30294688
6 changed files with 207 additions and 157 deletions

View File

@@ -753,13 +753,11 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
// L1CoordinatorTxs, PoolL2Txs) into stateDB so that they are
// processed.
// Add TxID, TxType, Position, BlockNum and BatchNum to L2 txs
// Set TxType to the forged L2Txs
for i := range forgeBatchArgs.L2TxsData {
nTx, err := common.NewL2Tx(&forgeBatchArgs.L2TxsData[i])
if err != nil {
if err := forgeBatchArgs.L2TxsData[i].SetType(); err != nil {
return nil, tracerr.Wrap(err)
}
forgeBatchArgs.L2TxsData[i] = *nTx
}
// Transform L2 txs to PoolL2Txs
@@ -780,20 +778,23 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
}
// 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
l2Txs, err := common.PoolL2TxsToL2Txs(poolL2Txs) // NOTE: This is a big uggly, find a better way
if err != nil {
return nil, tracerr.Wrap(err)
}
// Set TxID, BlockNum, BatchNum and Position to the forged L2Txs
for i := range l2Txs {
if err := l2Txs[i].SetID(); err != nil {
return nil, err
}
l2Txs[i].EthBlockNum = blockNum
l2Txs[i].BatchNum = batchNum
l2Txs[i].Position = position
position++
}
batchData.L2Txs = l2Txs
// Set the BatchNum in the forged L1UserTxs
for i := range l1UserTxs {
l1UserTxs[i].BatchNum = &batchNum