mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #322 from hermeznetwork/feature/integration20
Advance coordinator implementation
This commit is contained in:
@@ -177,6 +177,9 @@ func (l2db *L2DB) GetPendingTxs() ([]common.PoolL2Tx, error) {
|
||||
// StartForging updates the state of the transactions that will begin the forging process.
|
||||
// The state of the txs referenced by txIDs will be changed from Pending -> Forging
|
||||
func (l2db *L2DB) StartForging(txIDs []common.TxID, batchNum common.BatchNum) error {
|
||||
if len(txIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
query, args, err := sqlx.In(
|
||||
`UPDATE tx_pool
|
||||
SET state = ?, batch_num = ?
|
||||
@@ -197,6 +200,9 @@ func (l2db *L2DB) StartForging(txIDs []common.TxID, batchNum common.BatchNum) er
|
||||
// DoneForging updates the state of the transactions that have been forged
|
||||
// so the state of the txs referenced by txIDs will be changed from Forging -> Forged
|
||||
func (l2db *L2DB) DoneForging(txIDs []common.TxID, batchNum common.BatchNum) error {
|
||||
if len(txIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
query, args, err := sqlx.In(
|
||||
`UPDATE tx_pool
|
||||
SET state = ?, batch_num = ?
|
||||
@@ -217,6 +223,9 @@ func (l2db *L2DB) DoneForging(txIDs []common.TxID, batchNum common.BatchNum) err
|
||||
// InvalidateTxs updates the state of the transactions that are invalid.
|
||||
// The state of the txs referenced by txIDs will be changed from * -> Invalid
|
||||
func (l2db *L2DB) InvalidateTxs(txIDs []common.TxID, batchNum common.BatchNum) error {
|
||||
if len(txIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
query, args, err := sqlx.In(
|
||||
`UPDATE tx_pool
|
||||
SET state = ?, batch_num = ?
|
||||
@@ -236,6 +245,9 @@ func (l2db *L2DB) InvalidateTxs(txIDs []common.TxID, batchNum common.BatchNum) e
|
||||
// CheckNonces invalidate txs with nonces that are smaller or equal than their respective accounts nonces.
|
||||
// The state of the affected txs will be changed from Pending -> Invalid
|
||||
func (l2db *L2DB) CheckNonces(updatedAccounts []common.Account, batchNum common.BatchNum) (err error) {
|
||||
if len(updatedAccounts) == 0 {
|
||||
return nil
|
||||
}
|
||||
txn, err := l2db.db.Beginx()
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
|
||||
@@ -541,7 +541,8 @@ func (l *LocalStateDB) Reset(batchNum common.BatchNum, fromSynchronizer bool) er
|
||||
// use checkpoint from SynchronizerStateDB
|
||||
if _, err := os.Stat(synchronizerCheckpointPath); os.IsNotExist(err) {
|
||||
// if synchronizerStateDB does not have checkpoint at batchNum, return err
|
||||
return tracerr.Wrap(fmt.Errorf("Checkpoint not exist in Synchronizer"))
|
||||
return tracerr.Wrap(fmt.Errorf("Checkpoint \"%v\" not exist in Synchronizer",
|
||||
synchronizerCheckpointPath))
|
||||
}
|
||||
|
||||
if err := l.db.Pebble().Close(); err != nil {
|
||||
@@ -576,11 +577,13 @@ func (l *LocalStateDB) Reset(batchNum common.BatchNum, fromSynchronizer bool) er
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
// open the MT for the current s.db
|
||||
mt, err := merkletree.NewMerkleTree(l.db.WithPrefix(PrefixKeyMT), l.mt.MaxLevels())
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
if l.mt != nil {
|
||||
mt, err := merkletree.NewMerkleTree(l.db.WithPrefix(PrefixKeyMT), l.mt.MaxLevels())
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
l.mt = mt
|
||||
}
|
||||
l.mt = mt
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user