Add TxSel Nonce sort. Fix surplus from refactors

- Add TxSel Nonce sort
- Fix surplus from refactors
- StateDB reuse computation of ToIdx across Synchronizer, TxSelector,
BatchBuilder
This commit is contained in:
arnaucube
2020-10-14 10:44:09 +02:00
parent c6d71a48af
commit 1a2f769b5d
7 changed files with 60 additions and 59 deletions

View File

@@ -116,12 +116,12 @@ func (tx *L1Tx) CalcTxID() (*TxID, error) {
}
// Tx returns a *Tx from the L1Tx
func (tx *L1Tx) Tx() *Tx {
func (tx L1Tx) Tx() Tx {
f := new(big.Float).SetInt(tx.Amount)
amountFloat, _ := f.Float64()
userOrigin := new(bool)
*userOrigin = tx.UserOrigin
genericTx := &Tx{
genericTx := Tx{
IsL1: true,
TxID: tx.TxID,
Type: tx.Type,

View File

@@ -81,7 +81,7 @@ func (tx *L2Tx) Tx() *Tx {
// PoolL2Tx returns the data structure of PoolL2Tx with the parameters of a
// L2Tx filled
func (tx *L2Tx) PoolL2Tx() *PoolL2Tx {
func (tx L2Tx) PoolL2Tx() *PoolL2Tx {
return &PoolL2Tx{
TxID: tx.TxID,
FromIdx: tx.FromIdx,

View File

@@ -20,6 +20,7 @@ type PoolL2Tx struct {
TxID TxID `meddler:"tx_id"`
FromIdx Idx `meddler:"from_idx"`
ToIdx Idx `meddler:"to_idx,zeroisnull"`
AuxToIdx Idx `meddler:"-"` // AuxToIdx is only used internally at the StateDB to avoid repeated computation when processing transactions (from Synchronizer, TxSelector, BatchBuilder)
ToEthAddr ethCommon.Address `meddler:"to_eth_addr"`
ToBJJ *babyjub.PublicKey `meddler:"to_bjj"`
TokenID TokenID `meddler:"token_id"`
@@ -210,8 +211,8 @@ func (tx *PoolL2Tx) VerifySignature(pk *babyjub.PublicKey) bool {
}
// L2Tx returns a *L2Tx from the PoolL2Tx
func (tx *PoolL2Tx) L2Tx() (*L2Tx, error) {
return &L2Tx{
func (tx PoolL2Tx) L2Tx() L2Tx {
return L2Tx{
TxID: tx.TxID,
FromIdx: tx.FromIdx,
ToIdx: tx.ToIdx,
@@ -219,12 +220,12 @@ func (tx *PoolL2Tx) L2Tx() (*L2Tx, error) {
Fee: tx.Fee,
Nonce: tx.Nonce,
Type: tx.Type,
}, nil
}
}
// Tx returns a *Tx from the PoolL2Tx
func (tx *PoolL2Tx) Tx() (*Tx, error) {
return &Tx{
func (tx PoolL2Tx) Tx() Tx {
return Tx{
TxID: tx.TxID,
FromIdx: tx.FromIdx,
ToIdx: tx.ToIdx,
@@ -232,18 +233,14 @@ func (tx *PoolL2Tx) Tx() (*Tx, error) {
Nonce: &tx.Nonce,
Fee: &tx.Fee,
Type: tx.Type,
}, nil
}
}
// PoolL2TxsToL2Txs returns an array of []L2Tx from an array of []PoolL2Tx
func PoolL2TxsToL2Txs(txs []PoolL2Tx) ([]L2Tx, error) {
var r []L2Tx
for _, poolTx := range txs {
tx, err := poolTx.L2Tx()
if err != nil {
return nil, err
}
r = append(r, *tx)
r = append(r, poolTx.L2Tx())
}
return r, nil
}