mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
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:
@@ -264,10 +264,22 @@ func checkAlreadyPendingToCreate(l1CoordinatorTxs []common.L1Tx, addr ethCommon.
|
||||
return false
|
||||
}
|
||||
|
||||
// getL2Profitable returns the profitable selection of L2Txssorted by Nonce
|
||||
func (txsel *TxSelector) getL2Profitable(txs txs, max uint64) txs {
|
||||
sort.Sort(txs)
|
||||
if len(txs) < int(max) {
|
||||
return txs
|
||||
}
|
||||
return txs[:max]
|
||||
txs = txs[:max]
|
||||
|
||||
// sort l2Txs by Nonce. This can be done in many different ways, what
|
||||
// is needed is to output the txs where the Nonce of txs for each
|
||||
// Account is sorted, but the txs can not be grouped by sender Account
|
||||
// neither by Fee. This is because later on the Nonces will need to be
|
||||
// sequential for the zkproof generation.
|
||||
sort.SliceStable(txs, func(i, j int) bool {
|
||||
return txs[i].Nonce < txs[j].Nonce
|
||||
})
|
||||
|
||||
return txs
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package txselector
|
||||
|
||||
/*
|
||||
TODO update transactions generation
|
||||
func initTest(t *testing.T, testSet string) *TxSelector {
|
||||
func initTest(t *testing.T, testSet string, maxL1UserTxs, maxL1OperatorTxs, maxTxs uint64) *TxSelector {
|
||||
pass := os.Getenv("POSTGRES_PASS")
|
||||
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
||||
require.Nil(t, err)
|
||||
@@ -15,7 +15,7 @@ func initTest(t *testing.T, testSet string) *TxSelector {
|
||||
|
||||
txselDir, err := ioutil.TempDir("", "tmpTxSelDB")
|
||||
require.Nil(t, err)
|
||||
txsel, err := NewTxSelector(txselDir, sdb, l2DB, 100, 100, 1000)
|
||||
txsel, err := NewTxSelector(txselDir, sdb, l2DB, maxL1UserTxs, maxL1OperatorTxs, maxTxs)
|
||||
require.Nil(t, err)
|
||||
|
||||
return txsel
|
||||
@@ -29,15 +29,15 @@ func addL2Txs(t *testing.T, txsel *TxSelector, poolL2Txs []common.PoolL2Tx) {
|
||||
|
||||
func addTokens(t *testing.T, tokens []common.Token, db *sqlx.DB) {
|
||||
hdb := historydb.NewHistoryDB(db)
|
||||
assert.NoError(t, hdb.Reorg(-1))
|
||||
assert.NoError(t, hdb.AddBlock(&common.Block{
|
||||
assert.Nil(t, hdb.Reorg(-1))
|
||||
assert.Nil(t, hdb.AddBlock(&common.Block{
|
||||
EthBlockNum: 1,
|
||||
}))
|
||||
assert.NoError(t, hdb.AddTokens(tokens))
|
||||
assert.Nil(t, hdb.AddTokens(tokens))
|
||||
}
|
||||
|
||||
func TestGetL2TxSelection(t *testing.T) {
|
||||
txsel := initTest(t, transakcio.SetPool0)
|
||||
txsel := initTest(t, transakcio.SetPool0, 5, 5, 10)
|
||||
test.CleanL2DB(txsel.l2db.DB())
|
||||
|
||||
// generate test transactions
|
||||
@@ -54,6 +54,12 @@ func TestGetL2TxSelection(t *testing.T) {
|
||||
_, _, _, err = txsel.GetL1L2TxSelection(0, l1Txs[0])
|
||||
assert.Nil(t, err)
|
||||
|
||||
// TODO once L2DB is updated to return error in case that AddTxTest
|
||||
// fails, and the Transakcio is updated, update this test, checking that the
|
||||
// selected PoolL2Tx are correctly sorted by Nonce
|
||||
|
||||
|
||||
|
||||
// txs, err := txsel.GetL2TxSelection(0)
|
||||
// assert.Nil(t, err)
|
||||
// for _, tx := range txs {
|
||||
|
||||
Reference in New Issue
Block a user