Update synchronizer and DB with last contracts updates

- API
	- When updating network info, handle cases where no batches exists and
	  where no forgers exists
- cli/node
	- Update `cfg.buidler.toml` config file to a working version
- common
	- Add new smart contract structs and extend some existing ones to
	  reflect updates regarding events from the smart contracts
- SQL
	- Add new tables and extend existing ones to reflect updates regarding
	  events from the smart contracts
- db/historydb
	- Add functions to insert new smart contract events data
	- Fix unclosed rows that led to inconsistent sql driver state (replace
	  NamedQuery by NamedExec).  This fixes the error:
	  `pq: unexpected Parse response 'C'`
- db/l2db
	- Close rows after usage
- eth
	- In Rollup event, introduce a new UpdateBucketsParameter when there's a
	  SafeMode event, with `SafeMode = true`
- synchronizer
	- synchronize new events
	- avoid calling `auction.CanForge` before the genesisBlock to avoid
	  getting a revert.
This commit is contained in:
Eduard S
2020-12-09 15:22:32 +01:00
parent a7e4e8ff6c
commit 20b8d0561f
16 changed files with 543 additions and 198 deletions

View File

@@ -59,26 +59,26 @@ func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error
// GetAccountCreationAuth returns an account creation authorization from the DB
func (l2db *L2DB) GetAccountCreationAuth(addr ethCommon.Address) (*common.AccountCreationAuth, error) {
auth := new(common.AccountCreationAuth)
return auth, meddler.QueryRow(
return auth, tracerr.Wrap(meddler.QueryRow(
l2db.db, auth,
"SELECT * FROM account_creation_auth WHERE eth_addr = $1;",
addr,
)
))
}
// GetAccountCreationAuthAPI returns an account creation authorization from the DB
func (l2db *L2DB) GetAccountCreationAuthAPI(addr ethCommon.Address) (*AccountCreationAuthAPI, error) {
auth := new(AccountCreationAuthAPI)
return auth, meddler.QueryRow(
return auth, tracerr.Wrap(meddler.QueryRow(
l2db.db, auth,
"SELECT * FROM account_creation_auth WHERE eth_addr = $1;",
addr,
)
))
}
// AddTx inserts a tx to the pool
func (l2db *L2DB) AddTx(tx *PoolL2TxWrite) error {
return meddler.Insert(l2db.db, "tx_pool", tx)
return tracerr.Wrap(meddler.Insert(l2db.db, "tx_pool", tx))
}
// AddTxTest inserts a tx into the L2DB. This is useful for test purposes,
@@ -122,7 +122,7 @@ func (l2db *L2DB) AddTxTest(tx *common.PoolL2Tx) error {
amountF, _ := f.Float64()
insertTx.AmountFloat = amountF
// insert tx
return meddler.Insert(l2db.db, "tx_pool", insertTx)
return tracerr.Wrap(meddler.Insert(l2db.db, "tx_pool", insertTx))
}
// selectPoolTxAPI select part of queries to get PoolL2TxRead
@@ -147,21 +147,21 @@ FROM tx_pool INNER JOIN token ON tx_pool.token_id = token.token_id `
// GetTx return the specified Tx in common.PoolL2Tx format
func (l2db *L2DB) GetTx(txID common.TxID) (*common.PoolL2Tx, error) {
tx := new(common.PoolL2Tx)
return tx, meddler.QueryRow(
return tx, tracerr.Wrap(meddler.QueryRow(
l2db.db, tx,
selectPoolTxCommon+"WHERE tx_id = $1;",
txID,
)
))
}
// GetTxAPI return the specified Tx in PoolTxAPI format
func (l2db *L2DB) GetTxAPI(txID common.TxID) (*PoolTxAPI, error) {
tx := new(PoolTxAPI)
return tx, meddler.QueryRow(
return tx, tracerr.Wrap(meddler.QueryRow(
l2db.db, tx,
selectPoolTxAPI+"WHERE tx_id = $1;",
txID,
)
))
}
// GetPendingTxs return all the pending txs of the L2DB, that have a non NULL AbsoluteFee
@@ -252,6 +252,7 @@ func (l2db *L2DB) GetPendingUniqueFromIdxs() ([]common.Idx, error) {
if err != nil {
return nil, tracerr.Wrap(err)
}
defer db.RowsClose(rows)
var idx common.Idx
for rows.Next() {
err = rows.Scan(&idx)
@@ -285,7 +286,7 @@ func (l2db *L2DB) CheckNonces(updatedAccounts []common.IdxNonce, batchNum common
// named query which works with slices, and doens't handle an extra
// individual argument.
query := fmt.Sprintf(checkNoncesQuery, batchNum)
if _, err := sqlx.NamedQuery(l2db.db, query, updatedAccounts); err != nil {
if _, err := sqlx.NamedExec(l2db.db, query, updatedAccounts); err != nil {
return tracerr.Wrap(err)
}
return nil