mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Add TokenID to L2Tx
L2Tx.TokenID is not on the data obtained by the Synchronizer from the blockchain, but is set by the TxProcessor when processing the transactions in the StateDB.
This commit is contained in:
@@ -205,6 +205,7 @@ func (tx L1Tx) TxCompressedData(chainID uint16) (*big.Int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BytesDataAvailability encodes a L1Tx into []byte for the Data Availability
|
// BytesDataAvailability encodes a L1Tx into []byte for the Data Availability
|
||||||
|
// [ fromIdx | toIdx | amountFloat16 | Fee ]
|
||||||
func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
|
func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
|
||||||
idxLen := nLevels / 8 //nolint:gomnd
|
idxLen := nLevels / 8 //nolint:gomnd
|
||||||
|
|
||||||
|
|||||||
@@ -10,16 +10,19 @@ import (
|
|||||||
// L2Tx is a struct that represents an already forged L2 tx
|
// L2Tx is a struct that represents an already forged L2 tx
|
||||||
type L2Tx struct {
|
type L2Tx struct {
|
||||||
// Stored in DB: mandatory fileds
|
// Stored in DB: mandatory fileds
|
||||||
TxID TxID `meddler:"id"`
|
TxID TxID `meddler:"id"`
|
||||||
BatchNum BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged.
|
BatchNum BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged.
|
||||||
Position int `meddler:"position"`
|
Position int `meddler:"position"`
|
||||||
FromIdx Idx `meddler:"from_idx"`
|
FromIdx Idx `meddler:"from_idx"`
|
||||||
ToIdx Idx `meddler:"to_idx"`
|
ToIdx Idx `meddler:"to_idx"`
|
||||||
Amount *big.Int `meddler:"amount,bigint"`
|
// TokenID is filled by the TxProcessor
|
||||||
Fee FeeSelector `meddler:"fee"`
|
TokenID TokenID `meddler:"token_id"`
|
||||||
Nonce Nonce `meddler:"nonce"`
|
Amount *big.Int `meddler:"amount,bigint"`
|
||||||
Type TxType `meddler:"type"`
|
Fee FeeSelector `meddler:"fee"`
|
||||||
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L2Tx was added to the queue
|
// Nonce is filled by the TxProcessor
|
||||||
|
Nonce Nonce `meddler:"nonce"`
|
||||||
|
Type TxType `meddler:"type"`
|
||||||
|
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L2Tx was added to the queue
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewL2Tx returns the given L2Tx with the TxId & Type parameters calculated
|
// NewL2Tx returns the given L2Tx with the TxId & Type parameters calculated
|
||||||
@@ -92,6 +95,7 @@ func (tx *L2Tx) Tx() *Tx {
|
|||||||
Position: tx.Position,
|
Position: tx.Position,
|
||||||
FromIdx: tx.FromIdx,
|
FromIdx: tx.FromIdx,
|
||||||
ToIdx: tx.ToIdx,
|
ToIdx: tx.ToIdx,
|
||||||
|
TokenID: tx.TokenID,
|
||||||
Amount: tx.Amount,
|
Amount: tx.Amount,
|
||||||
BatchNum: batchNum,
|
BatchNum: batchNum,
|
||||||
EthBlockNum: tx.EthBlockNum,
|
EthBlockNum: tx.EthBlockNum,
|
||||||
@@ -107,6 +111,7 @@ func (tx L2Tx) PoolL2Tx() *PoolL2Tx {
|
|||||||
TxID: tx.TxID,
|
TxID: tx.TxID,
|
||||||
FromIdx: tx.FromIdx,
|
FromIdx: tx.FromIdx,
|
||||||
ToIdx: tx.ToIdx,
|
ToIdx: tx.ToIdx,
|
||||||
|
TokenID: tx.TokenID,
|
||||||
Amount: tx.Amount,
|
Amount: tx.Amount,
|
||||||
Fee: tx.Fee,
|
Fee: tx.Fee,
|
||||||
Nonce: tx.Nonce,
|
Nonce: tx.Nonce,
|
||||||
@@ -134,6 +139,7 @@ func TxIDsFromL2Txs(txs []L2Tx) []TxID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BytesDataAvailability encodes a L2Tx into []byte for the Data Availability
|
// BytesDataAvailability encodes a L2Tx into []byte for the Data Availability
|
||||||
|
// [ fromIdx | toIdx | amountFloat16 | Fee ]
|
||||||
func (tx L2Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
|
func (tx L2Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
|
||||||
idxLen := nLevels / 8 //nolint:gomnd
|
idxLen := nLevels / 8 //nolint:gomnd
|
||||||
|
|
||||||
|
|||||||
@@ -281,7 +281,8 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) {
|
|||||||
return bi, nil
|
return bi, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashToSign returns the computed Poseidon hash from the *PoolL2Tx that will be signed by the sender.
|
// HashToSign returns the computed Poseidon hash from the *PoolL2Tx that will
|
||||||
|
// be signed by the sender.
|
||||||
func (tx *PoolL2Tx) HashToSign(chainID uint16) (*big.Int, error) {
|
func (tx *PoolL2Tx) HashToSign(chainID uint16) (*big.Int, error) {
|
||||||
toCompressedData, err := tx.TxCompressedData(chainID)
|
toCompressedData, err := tx.TxCompressedData(chainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -331,6 +332,7 @@ func (tx PoolL2Tx) L2Tx() L2Tx {
|
|||||||
TxID: tx.TxID,
|
TxID: tx.TxID,
|
||||||
FromIdx: tx.FromIdx,
|
FromIdx: tx.FromIdx,
|
||||||
ToIdx: toIdx,
|
ToIdx: toIdx,
|
||||||
|
TokenID: tx.TokenID,
|
||||||
Amount: tx.Amount,
|
Amount: tx.Amount,
|
||||||
Fee: tx.Fee,
|
Fee: tx.Fee,
|
||||||
Nonce: tx.Nonce,
|
Nonce: tx.Nonce,
|
||||||
|
|||||||
@@ -906,6 +906,7 @@ func (hdb *HistoryDB) addL2Txs(d meddler.DB, l2txs []common.L2Tx) error {
|
|||||||
FromIdx: &l2txs[i].FromIdx,
|
FromIdx: &l2txs[i].FromIdx,
|
||||||
EffectiveFromIdx: &l2txs[i].FromIdx,
|
EffectiveFromIdx: &l2txs[i].FromIdx,
|
||||||
ToIdx: l2txs[i].ToIdx,
|
ToIdx: l2txs[i].ToIdx,
|
||||||
|
TokenID: l2txs[i].TokenID,
|
||||||
Amount: l2txs[i].Amount,
|
Amount: l2txs[i].Amount,
|
||||||
AmountFloat: amountFloat,
|
AmountFloat: amountFloat,
|
||||||
BatchNum: &l2txs[i].BatchNum,
|
BatchNum: &l2txs[i].BatchNum,
|
||||||
@@ -1278,8 +1279,8 @@ func (hdb *HistoryDB) GetAllL2Txs() ([]common.L2Tx, error) {
|
|||||||
err := meddler.QueryAll(
|
err := meddler.QueryAll(
|
||||||
hdb.db, &txs,
|
hdb.db, &txs,
|
||||||
`SELECT tx.id, tx.batch_num, tx.position,
|
`SELECT tx.id, tx.batch_num, tx.position,
|
||||||
tx.from_idx, tx.to_idx, tx.amount, tx.fee, tx.nonce,
|
tx.from_idx, tx.to_idx, tx.amount, tx.token_id,
|
||||||
tx.type, tx.eth_block_num
|
tx.fee, tx.nonce, tx.type, tx.eth_block_num
|
||||||
FROM tx WHERE is_l1 = FALSE ORDER BY item_id;`,
|
FROM tx WHERE is_l1 = FALSE ORDER BY item_id;`,
|
||||||
)
|
)
|
||||||
return db.SlicePtrsToSlice(txs).([]common.L2Tx), tracerr.Wrap(err)
|
return db.SlicePtrsToSlice(txs).([]common.L2Tx), tracerr.Wrap(err)
|
||||||
|
|||||||
@@ -818,6 +818,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
|||||||
// - blocks[].Rollup.Batch.L2Txs[].TxID
|
// - blocks[].Rollup.Batch.L2Txs[].TxID
|
||||||
// - blocks[].Rollup.Batch.L2Txs[].Position
|
// - blocks[].Rollup.Batch.L2Txs[].Position
|
||||||
// - blocks[].Rollup.Batch.L2Txs[].Nonce
|
// - blocks[].Rollup.Batch.L2Txs[].Nonce
|
||||||
|
// - blocks[].Rollup.Batch.L2Txs[].TokenID
|
||||||
// - blocks[].Rollup.Batch.ExitTree
|
// - blocks[].Rollup.Batch.ExitTree
|
||||||
// - blocks[].Rollup.Batch.CreatedAccounts
|
// - blocks[].Rollup.Batch.CreatedAccounts
|
||||||
// - blocks[].Rollup.Batch.FeeIdxCoordinator
|
// - blocks[].Rollup.Batch.FeeIdxCoordinator
|
||||||
@@ -915,6 +916,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
|
|||||||
tx.Position = position
|
tx.Position = position
|
||||||
position++
|
position++
|
||||||
tx.Nonce = tc.extra.nonces[tx.FromIdx]
|
tx.Nonce = tc.extra.nonces[tx.FromIdx]
|
||||||
|
tx.TokenID = tc.accountsByIdx[int(tx.FromIdx)].TokenID
|
||||||
tc.extra.nonces[tx.FromIdx]++
|
tc.extra.nonces[tx.FromIdx]++
|
||||||
if err := tx.SetID(); err != nil {
|
if err := tx.SetID(); err != nil {
|
||||||
return tracerr.Wrap(err)
|
return tracerr.Wrap(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user