mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #135 from hermeznetwork/feature/synchronizer-sc
Smart Contracts Data Synchronization
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
|
||||
// TODO(Edu): Document here how HistoryDB is kept consistent
|
||||
|
||||
// HistoryDB persist the historic of the rollup
|
||||
type HistoryDB struct {
|
||||
db *sqlx.DB
|
||||
@@ -127,10 +129,11 @@ func (hdb *HistoryDB) GetLastBatchNum() (common.BatchNum, error) {
|
||||
return batchNum, row.Scan(&batchNum)
|
||||
}
|
||||
|
||||
// GetLastL1TxsNum returns the greatest ForgeL1TxsNum in the DB
|
||||
func (hdb *HistoryDB) GetLastL1TxsNum() (uint32, error) {
|
||||
// GetLastL1TxsNum returns the greatest ForgeL1TxsNum in the DB. If there's no
|
||||
// batch in the DB (nil, nil) is returned.
|
||||
func (hdb *HistoryDB) GetLastL1TxsNum() (*int64, error) {
|
||||
row := hdb.db.QueryRow("SELECT MAX(forge_l1_txs_num) FROM batch;")
|
||||
var lastL1TxsNum uint32
|
||||
lastL1TxsNum := new(int64)
|
||||
return lastL1TxsNum, row.Scan(&lastL1TxsNum)
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,12 @@ func TestBatches(t *testing.T) {
|
||||
// Generate fake batches
|
||||
const nBatches = 9
|
||||
batches := test.GenBatches(nBatches, blocks)
|
||||
// Test GetLastL1TxsNum with no batches
|
||||
fetchedLastL1TxsNum, err := historyDB.GetLastL1TxsNum()
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, fetchedLastL1TxsNum)
|
||||
// Add batches to the DB
|
||||
err := historyDB.AddBatches(batches)
|
||||
err = historyDB.AddBatches(batches)
|
||||
assert.NoError(t, err)
|
||||
// Get batches from the DB
|
||||
fetchedBatches, err := historyDB.GetBatches(0, common.BatchNum(nBatches))
|
||||
@@ -103,9 +107,9 @@ func TestBatches(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, batches[len(batches)-1].BatchNum, fetchedLastBatchNum)
|
||||
// Test GetLastL1TxsNum
|
||||
fetchedLastL1TxsNum, err := historyDB.GetLastL1TxsNum()
|
||||
fetchedLastL1TxsNum, err = historyDB.GetLastL1TxsNum()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, batches[nBatches-1].ForgeL1TxsNum, fetchedLastL1TxsNum)
|
||||
assert.Equal(t, batches[nBatches-1].ForgeL1TxsNum, *fetchedLastL1TxsNum)
|
||||
}
|
||||
|
||||
func TestBids(t *testing.T) {
|
||||
|
||||
@@ -16,6 +16,8 @@ import (
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
|
||||
// TODO(Edu): Check DB consistency while there's concurrent use from Coordinator/TxSelector & API
|
||||
|
||||
// L2DB stores L2 txs and authorization registers received by the coordinator and keeps them until they are no longer relevant
|
||||
// due to them being forged or invalid after a safety period
|
||||
type L2DB struct {
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
"github.com/iden3/go-merkletree/db/pebble"
|
||||
)
|
||||
|
||||
// TODO(Edu): Document here how StateDB is kept consistent
|
||||
|
||||
// ErrStateDBWithoutMT is used when a method that requires a MerkleTree is
|
||||
// called in a StateDB that does not have a MerkleTree defined
|
||||
var ErrStateDBWithoutMT = errors.New("Can not call method to use MerkleTree in a StateDB without MerkleTree")
|
||||
|
||||
Reference in New Issue
Block a user