mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Extend ethclient test, implement new TxID spec
- Implement new TxID spec that distinguishes L1UserTx and L1CoordinatorTx - Replace some type []*Foo by []Foo - Fix HistoryDB & L2DB bug: in case of error, a rollback was applied and the returned error was nil - Reorder inserts in historydb.NewHistoryDB() to follow foreign key dependencies - Add initial synchronizer test with test.Client (for now, only tested l1UserTxs, blocks, addToken) - Update L1UserTx event in test.Client
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
@@ -25,7 +26,7 @@ type HistoryDB struct {
|
||||
|
||||
// BlockData contains the information of a Block
|
||||
type BlockData struct {
|
||||
block *common.Block
|
||||
Block *common.Block
|
||||
// Rollup
|
||||
// L1UserTxs that were submitted in the block
|
||||
L1UserTxs []common.L1Tx
|
||||
@@ -33,10 +34,10 @@ type BlockData struct {
|
||||
RegisteredTokens []common.Token
|
||||
RollupVars *common.RollupVars
|
||||
// Auction
|
||||
Bids []common.Bid
|
||||
Coordinators []common.Coordinator
|
||||
AuctionVars *common.AuctionVars
|
||||
// WithdrawalDelayer
|
||||
Bids []common.Bid
|
||||
Coordinators []common.Coordinator
|
||||
AuctionVars *common.AuctionVars
|
||||
WithdrawDelayerVars *common.WithdrawDelayerVars
|
||||
// TODO: enable when common.WithdrawalDelayerVars is Merged from Synchronizer PR
|
||||
// WithdrawalDelayerVars *common.WithdrawalDelayerVars
|
||||
}
|
||||
@@ -53,6 +54,19 @@ type BatchData struct {
|
||||
Batch *common.Batch
|
||||
}
|
||||
|
||||
// NewBatchData creates an empty BatchData with the slices initialized.
|
||||
func NewBatchData() *BatchData {
|
||||
return &BatchData{
|
||||
L1Batch: false,
|
||||
L1UserTxs: make([]common.L1Tx, 0),
|
||||
L1CoordinatorTxs: make([]common.L1Tx, 0),
|
||||
L2Txs: make([]common.L2Tx, 0),
|
||||
CreatedAccounts: make([]common.Account, 0),
|
||||
ExitTree: make([]common.ExitInfo, 0),
|
||||
Batch: &common.Batch{},
|
||||
}
|
||||
}
|
||||
|
||||
// NewHistoryDB initialize the DB
|
||||
func NewHistoryDB(db *sqlx.DB) *HistoryDB {
|
||||
return &HistoryDB{db: db}
|
||||
@@ -536,27 +550,22 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *BlockData) (err error) {
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
err = txn.Rollback()
|
||||
errRollback := txn.Rollback()
|
||||
if errRollback != nil {
|
||||
log.Errorw("Rollback", "err", errRollback)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Add block
|
||||
err = hdb.addBlock(txn, blockData.block)
|
||||
err = hdb.addBlock(txn, blockData.Block)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Add l1 Txs
|
||||
if len(blockData.L1UserTxs) > 0 {
|
||||
err = hdb.addL1Txs(txn, blockData.L1UserTxs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add Tokens
|
||||
if len(blockData.RegisteredTokens) > 0 {
|
||||
err = hdb.addTokens(txn, blockData.RegisteredTokens)
|
||||
// Add Coordinators
|
||||
if len(blockData.Coordinators) > 0 {
|
||||
err = hdb.addCoordinators(txn, blockData.Coordinators)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -570,9 +579,17 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *BlockData) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add Coordinators
|
||||
if len(blockData.Coordinators) > 0 {
|
||||
err = hdb.addCoordinators(txn, blockData.Coordinators)
|
||||
// Add Tokens
|
||||
if len(blockData.RegisteredTokens) > 0 {
|
||||
err = hdb.addTokens(txn, blockData.RegisteredTokens)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add l1 Txs
|
||||
if len(blockData.L1UserTxs) > 0 {
|
||||
err = hdb.addL1Txs(txn, blockData.L1UserTxs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
@@ -212,7 +213,10 @@ func (l2db *L2DB) CheckNonces(updatedAccounts []common.Account, batchNum common.
|
||||
defer func() {
|
||||
// Rollback the transaction if there was an error.
|
||||
if err != nil {
|
||||
err = txn.Rollback()
|
||||
errRollback := txn.Rollback()
|
||||
if errRollback != nil {
|
||||
log.Errorw("Rollback", "err", errRollback)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for i := 0; i < len(updatedAccounts); i++ {
|
||||
@@ -257,7 +261,10 @@ func (l2db *L2DB) Purge(currentBatchNum common.BatchNum) (err error) {
|
||||
defer func() {
|
||||
// Rollback the transaction if there was an error.
|
||||
if err != nil {
|
||||
err = txn.Rollback()
|
||||
errRollback := txn.Rollback()
|
||||
if errRollback != nil {
|
||||
log.Errorw("Rollback", "err", errRollback)
|
||||
}
|
||||
}
|
||||
}()
|
||||
// Delete pending txs that have been in the pool after the TTL if maxTxs is reached
|
||||
|
||||
@@ -36,7 +36,7 @@ type processedExit struct {
|
||||
// type==TypeSynchronizer, assumes that the call is done from the Synchronizer,
|
||||
// returns common.ExitTreeLeaf that is later used by the Synchronizer to update
|
||||
// the HistoryDB, and adds Nonce & TokenID to the L2Txs.
|
||||
func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs []*common.PoolL2Tx) (*common.ZKInputs, []common.ExitInfo, error) {
|
||||
func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []common.L1Tx, l2txs []common.PoolL2Tx) (*common.ZKInputs, []common.ExitInfo, error) {
|
||||
var err error
|
||||
var exitTree *merkletree.MerkleTree
|
||||
|
||||
@@ -69,7 +69,7 @@ func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs [
|
||||
|
||||
// assumption: l1usertx are sorted by L1Tx.Position
|
||||
for _, tx := range l1usertxs {
|
||||
exitIdx, exitAccount, newExit, err := s.processL1Tx(exitTree, tx)
|
||||
exitIdx, exitAccount, newExit, err := s.processL1Tx(exitTree, &tx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs [
|
||||
}
|
||||
}
|
||||
for _, tx := range l1coordinatortxs {
|
||||
exitIdx, exitAccount, newExit, err := s.processL1Tx(exitTree, tx)
|
||||
exitIdx, exitAccount, newExit, err := s.processL1Tx(exitTree, &tx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs [
|
||||
}
|
||||
}
|
||||
for _, tx := range l2txs {
|
||||
exitIdx, exitAccount, newExit, err := s.processL2Tx(exitTree, tx)
|
||||
exitIdx, exitAccount, newExit, err := s.processL2Tx(exitTree, &tx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (s *StateDB) ProcessTxs(l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs [
|
||||
}
|
||||
|
||||
// getTokenIDsBigInt returns the list of TokenIDs in *big.Int format
|
||||
func (s *StateDB) getTokenIDsBigInt(l1usertxs, l1coordinatortxs []*common.L1Tx, l2txs []*common.PoolL2Tx) ([]*big.Int, error) {
|
||||
func (s *StateDB) getTokenIDsBigInt(l1usertxs, l1coordinatortxs []common.L1Tx, l2txs []common.PoolL2Tx) ([]*big.Int, error) {
|
||||
tokenIDs := make(map[common.TokenID]bool)
|
||||
for i := 0; i < len(l1usertxs); i++ {
|
||||
tokenIDs[l1usertxs[i].TokenID] = true
|
||||
|
||||
@@ -40,7 +40,7 @@ func InitSQLDB(port int, host, user, password, name string) (*sqlx.DB, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Info("successfully runt ", nMigrations, " migrations")
|
||||
log.Info("successfully ran ", nMigrations, " migrations")
|
||||
return db, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user