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

@@ -647,7 +647,8 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co
big.NewInt(10),
12,
13,
[5]common.Bucket{},
[5]common.BucketParams{},
false,
}
//nolint:govet
auction := &common.AuctionVariables{
@@ -937,6 +938,87 @@ func TestGetBestBidCoordinator(t *testing.T) {
require.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err))
}
func TestAddBucketUpdates(t *testing.T) {
test.WipeDB(historyDB.DB())
const fromBlock int64 = 1
const toBlock int64 = 5 + 1
setTestBlocks(fromBlock, toBlock)
bucketUpdates := []common.BucketUpdate{
{
EthBlockNum: 4,
NumBucket: 0,
BlockStamp: 4,
Withdrawals: big.NewInt(123),
},
{
EthBlockNum: 5,
NumBucket: 2,
BlockStamp: 5,
Withdrawals: big.NewInt(42),
},
}
err := historyDB.addBucketUpdates(historyDB.db, bucketUpdates)
require.NoError(t, err)
dbBucketUpdates, err := historyDB.GetAllBucketUpdates()
require.NoError(t, err)
assert.Equal(t, bucketUpdates, dbBucketUpdates)
}
func TestAddTokenExchanges(t *testing.T) {
test.WipeDB(historyDB.DB())
const fromBlock int64 = 1
const toBlock int64 = 5 + 1
setTestBlocks(fromBlock, toBlock)
tokenExchanges := []common.TokenExchange{
{
EthBlockNum: 4,
Address: ethCommon.BigToAddress(big.NewInt(111)),
ValueUSD: 12345,
},
{
EthBlockNum: 5,
Address: ethCommon.BigToAddress(big.NewInt(222)),
ValueUSD: 67890,
},
}
err := historyDB.addTokenExchanges(historyDB.db, tokenExchanges)
require.NoError(t, err)
dbTokenExchanges, err := historyDB.GetAllTokenExchanges()
require.NoError(t, err)
assert.Equal(t, tokenExchanges, dbTokenExchanges)
}
func TestAddEscapeHatchWithdrawals(t *testing.T) {
test.WipeDB(historyDB.DB())
const fromBlock int64 = 1
const toBlock int64 = 5 + 1
setTestBlocks(fromBlock, toBlock)
escapeHatchWithdrawals := []common.WDelayerEscapeHatchWithdrawal{
{
EthBlockNum: 4,
Who: ethCommon.BigToAddress(big.NewInt(111)),
To: ethCommon.BigToAddress(big.NewInt(222)),
TokenAddr: ethCommon.BigToAddress(big.NewInt(333)),
Amount: big.NewInt(10002),
},
{
EthBlockNum: 5,
Who: ethCommon.BigToAddress(big.NewInt(444)),
To: ethCommon.BigToAddress(big.NewInt(555)),
TokenAddr: ethCommon.BigToAddress(big.NewInt(666)),
Amount: big.NewInt(20003),
},
}
err := historyDB.addEscapeHatchWithdrawals(historyDB.db, escapeHatchWithdrawals)
require.NoError(t, err)
dbEscapeHatchWithdrawals, err := historyDB.GetAllEscapeHatchWithdrawals()
require.NoError(t, err)
assert.Equal(t, escapeHatchWithdrawals, dbEscapeHatchWithdrawals)
}
// setTestBlocks WARNING: this will delete the blocks and recreate them
func setTestBlocks(from, to int64) []common.Block {
test.WipeDB(historyDB.DB())