package txselector import ( "sort" "github.com/hermeznetwork/hermez-node/tx-selector/common" "github.com/hermeznetwork/hermez-node/tx-selector/mock" ) // txs implements the interface Sort for an array of Tx type txs []common.Tx func (t txs) Len() int { return len(t) } func (t txs) Swap(i, j int) { t[i], t[j] = t[j], t[i] } func (t txs) Less(i, j int) bool { return t[i].UserFeeAbsolute > t[j].UserFeeAbsolute } type TxSelector struct { // NMax is the maximum L1-user-tx for a batch NMax uint64 // MMax is the maximum L1-operator-tx for a batch MMax uint64 // PMax is the maximum L2-tx for a batch PMax uint64 // DB is a pointer to the database interface DB *mock.MockDB } func NewTxSelector(db *mock.MockDB, nMax, mMax, pMax uint64) *TxSelector { return &TxSelector{ NMax: nMax, MMax: mMax, PMax: pMax, DB: db, } } func (txsel *TxSelector) updateLocalAccountDB(batchId uint64) error { // if batchID > max(localAccountDB.BatchID) + 1 // make a checkpoint of AccountDB at BatchID to a localAccountDB // use localAccountDB[inputBatchID-1] return nil } func (txsel *TxSelector) GetL2TxSelection(batchID uint64) ([]common.Tx, error) { err := txsel.updateLocalAccountDB(batchID) if err != nil { return nil, err } // get pending l2-tx from tx-pool txsRaw := txsel.DB.GetTxs(batchID) // discard the txs that don't have an Account in the AccountDB var validTxs txs for _, tx := range txsRaw { accountID := getAccountID(tx.ToEthAddr, tx.TokenID) if _, ok := txsel.DB.AccountDB[accountID]; ok { validTxs = append(validTxs, tx) } } // get most profitable L2-tx (len