Update Synchronizer (node) implementation

- node:
    - Extend config to add initial variables of the smart contracts used as
      defaults before they are changed via events.
    - In stopped channels, set size 1 so that panics are not witheld until the
      node stops completely.
- common:
    - In Smart Contract variables, comment:
      - `WDelayerVariables.HermezRollupAddress` because it's not needed.
      - `RollupVariables.Buckets` because there are no events for it, and for
        now it's not used.
- historydb:
    - Add functions to get and set smart contract variables.
- db:
    - Add `Rollback` function in `utils.go` to reduce boilerplate in sql
      transaction rollbacks in defers in db functions.
    - Update `rollup_vars` and `auction_vars` (renamed from `consensus_vars`)
      table, and add `wdelayer_vars` table.
- synchronizer:
    - Synchronize WDelayer
    - Handle SC variables properly
- test/ethclient:
    - Add essential implementation of WDelayer
This commit is contained in:
Eduard S
2020-10-28 16:09:05 +01:00
parent 11dbf67377
commit 6e4b9b4b70
20 changed files with 671 additions and 153 deletions

View File

@@ -17,6 +17,7 @@ type ClientInterface interface {
EthereumInterface
RollupInterface
AuctionInterface
WDelayerInterface
}
//
@@ -28,6 +29,7 @@ type Client struct {
EthereumClient
AuctionClient
RollupClient
WDelayerClient
}
// TokenConfig is used to define the information about token
@@ -47,11 +49,17 @@ type AuctionConfig struct {
TokenHEZ TokenConfig
}
// WDelayerConfig is the configuration for the WDelayer smart contract interface
type WDelayerConfig struct {
Address ethCommon.Address
}
// ClientConfig is the configuration of the Client
type ClientConfig struct {
Ethereum EthereumConfig
Rollup RollupConfig
Auction AuctionConfig
WDelayer WDelayerConfig
}
// NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
@@ -61,13 +69,18 @@ func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeyst
if err != nil {
return nil, err
}
rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ)
rollupClient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ)
if err != nil {
return nil, err
}
wDelayerClient, err := NewWDelayerClient(ethereumClient, cfg.WDelayer.Address)
if err != nil {
return nil, err
}
return &Client{
EthereumClient: *ethereumClient,
AuctionClient: *auctionClient,
RollupClient: *rollupCient,
RollupClient: *rollupClient,
WDelayerClient: *wDelayerClient,
}, nil
}

View File

@@ -510,9 +510,6 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
return nil, nil, err
}
if len(logs) > 0 {
for i := range logs {
log.Debugw("log", "i", i, "blockHash", logs[i].BlockHash)
}
blockHash = &logs[0].BlockHash
}
for _, vLog := range logs {

View File

@@ -114,7 +114,7 @@ type WDelayerInterface interface {
WDelayerGetEmergencyModeStartingTime() (*big.Int, error)
WDelayerEnableEmergencyMode() (*types.Transaction, error)
WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (*types.Transaction, error)
WDelayerDepositInfo(owner, token ethCommon.Address) (*big.Int, uint64)
WDelayerDepositInfo(owner, token ethCommon.Address) (depositInfo DepositState, err error)
WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int) (*types.Transaction, error)
WDelayerWithdrawal(owner, token ethCommon.Address) (*types.Transaction, error)
WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address, amount *big.Int) (*types.Transaction, error)
@@ -340,7 +340,8 @@ func (c *WDelayerClient) WDelayerEscapeHatchWithdrawal(to, token ethCommon.Addre
}
// WDelayerConstants returns the Constants of the WDelayer Smart Contract
func (c *WDelayerClient) WDelayerConstants() (constants common.WDelayerConstants, err error) {
func (c *WDelayerClient) WDelayerConstants() (constants *common.WDelayerConstants, err error) {
constants = new(common.WDelayerConstants)
if err := c.client.Call(func(ec *ethclient.Client) error {
constants.MaxWithdrawalDelay, err = c.wdelayer.MAXWITHDRAWALDELAY(nil)
if err != nil {
@@ -377,7 +378,7 @@ var (
// there are no events in that block, blockHash is nil.
func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, *ethCommon.Hash, error) {
var wdelayerEvents WDelayerEvents
var blockHash ethCommon.Hash
var blockHash *ethCommon.Hash
query := ethereum.FilterQuery{
FromBlock: big.NewInt(blockNum),
@@ -394,10 +395,10 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents,
return nil, nil, err
}
if len(logs) > 0 {
blockHash = logs[0].BlockHash
blockHash = &logs[0].BlockHash
}
for _, vLog := range logs {
if vLog.BlockHash != blockHash {
if vLog.BlockHash != *blockHash {
log.Errorw("Block hash mismatch", "expected", blockHash.String(), "got", vLog.BlockHash.String())
return nil, nil, ErrBlockHashMismatchEvent
}
@@ -470,5 +471,5 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents,
wdelayerEvents.NewHermezGovernanceDAOAddress = append(wdelayerEvents.NewHermezGovernanceDAOAddress, governanceDAOAddress)
}
}
return &wdelayerEvents, &blockHash, nil
return &wdelayerEvents, blockHash, nil
}