mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Fix unforged L1UserTxs query in forgeBatch
Previously the code was only querying the unforged L1UserTxs of a particular queue, but this was incorrect because there are always two non-forged queues: the frozen one and the open one. Replace it by a query to all the unforged L1UserTxs via a new HistoryDB method.
This commit is contained in:
@@ -763,6 +763,16 @@ func (hdb *HistoryDB) GetUnforgedL1UserTxs(toForgeL1TxsNum int64) ([]common.L1Tx
|
||||
return db.SlicePtrsToSlice(txs).([]common.L1Tx), tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
// GetUnforgedL1UserTxsCount returns the count of unforged L1Txs (either in
|
||||
// open or frozen queues that are not yet forged)
|
||||
func (hdb *HistoryDB) GetUnforgedL1UserTxsCount() (int, error) {
|
||||
row := hdb.dbRead.QueryRow(
|
||||
`SELECT COUNT(*) FROM tx WHERE batch_num IS NULL;`,
|
||||
)
|
||||
var count int
|
||||
return count, tracerr.Wrap(row.Scan(&count))
|
||||
}
|
||||
|
||||
// TODO: Think about chaning all the queries that return a last value, to queries that return the next valid value.
|
||||
|
||||
// GetLastTxsPosition for a given to_forge_l1_txs_num
|
||||
|
||||
@@ -720,6 +720,10 @@ func TestGetUnforgedL1UserTxs(t *testing.T) {
|
||||
assert.Equal(t, 5, len(l1UserTxs))
|
||||
assert.Equal(t, blocks[0].Rollup.L1UserTxs, l1UserTxs)
|
||||
|
||||
count, err := historyDB.GetUnforgedL1UserTxsCount()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 5, count)
|
||||
|
||||
// No l1UserTxs for this toForgeL1TxsNum
|
||||
l1UserTxs, err = historyDB.GetUnforgedL1UserTxs(2)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user