Use init SC vars and start block from events

Previously the Synchronizer required the initial variables of the smart
contracts to be passed as a configuration parameter (that the node took from
the configuration file).  The same applied to the blockNumber.

The last update of the smart contracts introduced events for each smart
contract constructor (initializer), which allows querying the initial variables
as well as the initial block number for each smart contract.

Now the synchronizer uses this information, and thus the initial variables and
the starting block numbers have been removed from the configuration.
This commit is contained in:
Eduard S
2020-12-18 11:57:52 +01:00
parent 0bde608a1b
commit b59f790c04
10 changed files with 194 additions and 146 deletions

View File

@@ -69,6 +69,26 @@ type AuctionEventInitialize struct {
AllocationRatio [3]uint16
}
// AuctionVariables returns the AuctionVariables from the initialize event
func (ei *AuctionEventInitialize) AuctionVariables(InitialMinimalBidding *big.Int) *common.AuctionVariables {
return &common.AuctionVariables{
EthBlockNum: 0,
DonationAddress: ei.DonationAddress,
BootCoordinator: ei.BootCoordinatorAddress,
BootCoordinatorURL: ei.BootCoordinatorURL,
DefaultSlotSetBid: [6]*big.Int{
InitialMinimalBidding, InitialMinimalBidding, InitialMinimalBidding,
InitialMinimalBidding, InitialMinimalBidding, InitialMinimalBidding,
},
DefaultSlotSetBidSlotNum: 0,
ClosedAuctionSlots: ei.ClosedAuctionSlots,
OpenAuctionSlots: ei.OpenAuctionSlots,
AllocationRatio: ei.AllocationRatio,
Outbidding: ei.Outbidding,
SlotDeadline: ei.SlotDeadline,
}
}
// AuctionEventNewBid is an event of the Auction Smart Contract
type AuctionEventNewBid struct {
Slot int64
@@ -235,6 +255,7 @@ type AuctionInterface interface {
AuctionConstants() (*common.AuctionConstants, error)
AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error)
AuctionEventInit() (*AuctionEventInitialize, int64, error)
}
//

View File

@@ -59,6 +59,27 @@ type RollupEventInitialize struct {
WithdrawalDelay uint64
}
// RollupVariables returns the RollupVariables from the initialize event
func (ei *RollupEventInitialize) RollupVariables() *common.RollupVariables {
var buckets [common.RollupConstNumBuckets]common.BucketParams
for i := range buckets {
buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0),
Withdrawals: big.NewInt(0),
BlockWithdrawalRate: big.NewInt(0),
MaxWithdrawals: big.NewInt(0),
}
}
return &common.RollupVariables{
EthBlockNum: 0,
FeeAddToken: ei.FeeAddToken,
ForgeL1L2BatchTimeout: int64(ei.ForgeL1L2BatchTimeout),
WithdrawalDelay: ei.WithdrawalDelay,
Buckets: buckets,
SafeMode: false,
}
}
// RollupEventL1UserTx is an event of the Rollup Smart Contract
type RollupEventL1UserTx struct {
// ToForgeL1TxsNum int64 // QueueIndex *big.Int
@@ -245,6 +266,7 @@ type RollupInterface interface {
RollupConstants() (*common.RollupConstants, error)
RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethCommon.Hash, error)
RollupForgeBatchArgs(ethCommon.Hash, uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error)
RollupEventInit() (*RollupEventInitialize, int64, error)
}
//

View File

@@ -33,6 +33,18 @@ type WDelayerEventInitialize struct {
InitialEmergencyCouncil ethCommon.Address
}
// WDelayerVariables returns the WDelayerVariables from the initialize event
func (ei *WDelayerEventInitialize) WDelayerVariables() *common.WDelayerVariables {
return &common.WDelayerVariables{
EthBlockNum: 0,
HermezGovernanceAddress: ei.InitialHermezGovernanceAddress,
EmergencyCouncilAddress: ei.InitialEmergencyCouncil,
WithdrawalDelay: ei.InitialWithdrawalDelay,
EmergencyModeStartingBlock: 0,
EmergencyMode: false,
}
}
// WDelayerEventDeposit is an event of the WithdrawalDelayer Smart Contract
type WDelayerEventDeposit struct {
Owner ethCommon.Address
@@ -124,6 +136,7 @@ type WDelayerInterface interface {
WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, *ethCommon.Hash, error)
WDelayerConstants() (*common.WDelayerConstants, error)
WDelayerEventInit() (*WDelayerEventInitialize, int64, error)
}
//