Add the config option to forge batch when the coordinator we are not the auction winner and reach the slot deadline

This commit is contained in:
Danilo Pantani
2021-03-04 13:55:06 -03:00
parent 6bf8584a82
commit d361abb8cd
6 changed files with 43 additions and 29 deletions

View File

@@ -63,6 +63,7 @@ SyncRetryInterval = "1s"
ForgeDelay = "10s" ForgeDelay = "10s"
ForgeNoTxsDelay = "0s" ForgeNoTxsDelay = "0s"
PurgeByExtDelInterval = "1m" PurgeByExtDelInterval = "1m"
MustForgeAtSlotDeadline = true
[Coordinator.FeeAccount] [Coordinator.FeeAccount]
Address = "0x56232B1c5B10038125Bc7345664B4AFD745bcF8E" Address = "0x56232B1c5B10038125Bc7345664B4AFD745bcF8E"

View File

@@ -101,6 +101,9 @@ type Coordinator struct {
// to 0s, the coordinator will continuously forge even if the batches // to 0s, the coordinator will continuously forge even if the batches
// are empty. // are empty.
ForgeNoTxsDelay Duration `validate:"-"` ForgeNoTxsDelay Duration `validate:"-"`
// MustForgeAtSlotDeadline enables the coordinator to forge slots if
// the empty slots reach the slot deadline.
MustForgeAtSlotDeadline bool
// SyncRetryInterval is the waiting interval between calls to the main // SyncRetryInterval is the waiting interval between calls to the main
// handler of a synced block after an error // handler of a synced block after an error
SyncRetryInterval Duration `validate:"required"` SyncRetryInterval Duration `validate:"required"`

View File

@@ -84,6 +84,9 @@ type Config struct {
// to 0s, the coordinator will continuously forge even if the batches // to 0s, the coordinator will continuously forge even if the batches
// are empty. // are empty.
ForgeNoTxsDelay time.Duration ForgeNoTxsDelay time.Duration
// MustForgeAtSlotDeadline enables the coordinator to forge slots if
// the empty slots reach the slot deadline.
MustForgeAtSlotDeadline bool
// SyncRetryInterval is the waiting interval between calls to the main // SyncRetryInterval is the waiting interval between calls to the main
// handler of a synced block after an error // handler of a synced block after an error
SyncRetryInterval time.Duration SyncRetryInterval time.Duration
@@ -318,7 +321,8 @@ func (c *Coordinator) syncSCVars(vars synchronizer.SCVariablesPtr) {
} }
func canForge(auctionConstants *common.AuctionConstants, auctionVars *common.AuctionVariables, func canForge(auctionConstants *common.AuctionConstants, auctionVars *common.AuctionVariables,
currentSlot *common.Slot, nextSlot *common.Slot, addr ethCommon.Address, blockNum int64) bool { currentSlot *common.Slot, nextSlot *common.Slot, addr ethCommon.Address, blockNum int64,
mustForgeAtDeadline bool) bool {
if blockNum < auctionConstants.GenesisBlockNum { if blockNum < auctionConstants.GenesisBlockNum {
log.Infow("canForge: requested blockNum is < genesis", "blockNum", blockNum, log.Infow("canForge: requested blockNum is < genesis", "blockNum", blockNum,
"genesis", auctionConstants.GenesisBlockNum) "genesis", auctionConstants.GenesisBlockNum)
@@ -343,7 +347,7 @@ func canForge(auctionConstants *common.AuctionConstants, auctionVars *common.Auc
"block", blockNum) "block", blockNum)
anyoneForge = true anyoneForge = true
} }
if slot.Forger == addr || anyoneForge { if slot.Forger == addr || (anyoneForge && mustForgeAtDeadline) {
return true return true
} }
log.Debugw("canForge: can't forge", "slot.Forger", slot.Forger) log.Debugw("canForge: can't forge", "slot.Forger", slot.Forger)
@@ -353,14 +357,14 @@ func canForge(auctionConstants *common.AuctionConstants, auctionVars *common.Auc
func (c *Coordinator) canForgeAt(blockNum int64) bool { func (c *Coordinator) canForgeAt(blockNum int64) bool {
return canForge(&c.consts.Auction, &c.vars.Auction, return canForge(&c.consts.Auction, &c.vars.Auction,
&c.stats.Sync.Auction.CurrentSlot, &c.stats.Sync.Auction.NextSlot, &c.stats.Sync.Auction.CurrentSlot, &c.stats.Sync.Auction.NextSlot,
c.cfg.ForgerAddress, blockNum) c.cfg.ForgerAddress, blockNum, c.cfg.MustForgeAtSlotDeadline)
} }
func (c *Coordinator) canForge() bool { func (c *Coordinator) canForge() bool {
blockNum := c.stats.Eth.LastBlock.Num + 1 blockNum := c.stats.Eth.LastBlock.Num + 1
return canForge(&c.consts.Auction, &c.vars.Auction, return canForge(&c.consts.Auction, &c.vars.Auction,
&c.stats.Sync.Auction.CurrentSlot, &c.stats.Sync.Auction.NextSlot, &c.stats.Sync.Auction.CurrentSlot, &c.stats.Sync.Auction.NextSlot,
c.cfg.ForgerAddress, blockNum) c.cfg.ForgerAddress, blockNum, c.cfg.MustForgeAtSlotDeadline)
} }
func (c *Coordinator) syncStats(ctx context.Context, stats *synchronizer.Stats) error { func (c *Coordinator) syncStats(ctx context.Context, stats *synchronizer.Stats) error {

View File

@@ -159,14 +159,15 @@ func newTestCoordinator(t *testing.T, forgerAddr ethCommon.Address, ethClient *t
deleteme = append(deleteme, debugBatchPath) deleteme = append(deleteme, debugBatchPath)
conf := Config{ conf := Config{
ForgerAddress: forgerAddr, ForgerAddress: forgerAddr,
ConfirmBlocks: 5, ConfirmBlocks: 5,
L1BatchTimeoutPerc: 0.5, L1BatchTimeoutPerc: 0.5,
EthClientAttempts: 5, EthClientAttempts: 5,
SyncRetryInterval: 400 * time.Microsecond, SyncRetryInterval: 400 * time.Microsecond,
EthClientAttemptsDelay: 100 * time.Millisecond, EthClientAttemptsDelay: 100 * time.Millisecond,
TxManagerCheckInterval: 300 * time.Millisecond, TxManagerCheckInterval: 300 * time.Millisecond,
DebugBatchPath: debugBatchPath, DebugBatchPath: debugBatchPath,
MustForgeAtSlotDeadline: true,
Purger: PurgerCfg{ Purger: PurgerCfg{
PurgeBatchDelay: 10, PurgeBatchDelay: 10,
PurgeBlockDelay: 10, PurgeBlockDelay: 10,
@@ -391,6 +392,10 @@ func TestCoordCanForge(t *testing.T) {
assert.Equal(t, true, coord.canForge()) assert.Equal(t, true, coord.canForge())
assert.Equal(t, true, bootCoord.canForge()) assert.Equal(t, true, bootCoord.canForge())
// Anyone can forge but the node MustForgeAtSlotDeadline as set as false
coord.cfg.MustForgeAtSlotDeadline = false
assert.Equal(t, false, coord.canForge())
// Slot 3. coordinator bid, so the winner is the coordinator // Slot 3. coordinator bid, so the winner is the coordinator
stats.Eth.LastBlock.Num = ethClientSetup.AuctionConstants.GenesisBlockNum + stats.Eth.LastBlock.Num = ethClientSetup.AuctionConstants.GenesisBlockNum +
3*int64(ethClientSetup.AuctionConstants.BlocksPerSlot) 3*int64(ethClientSetup.AuctionConstants.BlocksPerSlot)

View File

@@ -608,7 +608,7 @@ func (t *TxManager) removeBadBatchInfos(ctx context.Context) error {
func (t *TxManager) canForgeAt(blockNum int64) bool { func (t *TxManager) canForgeAt(blockNum int64) bool {
return canForge(&t.consts.Auction, &t.vars.Auction, return canForge(&t.consts.Auction, &t.vars.Auction,
&t.stats.Sync.Auction.CurrentSlot, &t.stats.Sync.Auction.NextSlot, &t.stats.Sync.Auction.CurrentSlot, &t.stats.Sync.Auction.NextSlot,
t.cfg.ForgerAddress, blockNum) t.cfg.ForgerAddress, blockNum, t.cfg.MustForgeAtSlotDeadline)
} }
func (t *TxManager) mustL1L2Batch(blockNum int64) bool { func (t *TxManager) mustL1L2Batch(blockNum int64) bool {

View File

@@ -332,22 +332,23 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
coord, err = coordinator.NewCoordinator( coord, err = coordinator.NewCoordinator(
coordinator.Config{ coordinator.Config{
ForgerAddress: cfg.Coordinator.ForgerAddress, ForgerAddress: cfg.Coordinator.ForgerAddress,
ConfirmBlocks: cfg.Coordinator.ConfirmBlocks, ConfirmBlocks: cfg.Coordinator.ConfirmBlocks,
L1BatchTimeoutPerc: cfg.Coordinator.L1BatchTimeoutPerc, L1BatchTimeoutPerc: cfg.Coordinator.L1BatchTimeoutPerc,
ForgeRetryInterval: cfg.Coordinator.ForgeRetryInterval.Duration, ForgeRetryInterval: cfg.Coordinator.ForgeRetryInterval.Duration,
ForgeDelay: cfg.Coordinator.ForgeDelay.Duration, ForgeDelay: cfg.Coordinator.ForgeDelay.Duration,
ForgeNoTxsDelay: cfg.Coordinator.ForgeNoTxsDelay.Duration, MustForgeAtSlotDeadline: cfg.Coordinator.MustForgeAtSlotDeadline,
SyncRetryInterval: cfg.Coordinator.SyncRetryInterval.Duration, ForgeNoTxsDelay: cfg.Coordinator.ForgeNoTxsDelay.Duration,
PurgeByExtDelInterval: cfg.Coordinator.PurgeByExtDelInterval.Duration, SyncRetryInterval: cfg.Coordinator.SyncRetryInterval.Duration,
EthClientAttempts: cfg.Coordinator.EthClient.Attempts, PurgeByExtDelInterval: cfg.Coordinator.PurgeByExtDelInterval.Duration,
EthClientAttemptsDelay: cfg.Coordinator.EthClient.AttemptsDelay.Duration, EthClientAttempts: cfg.Coordinator.EthClient.Attempts,
EthNoReuseNonce: cfg.Coordinator.EthClient.NoReuseNonce, EthClientAttemptsDelay: cfg.Coordinator.EthClient.AttemptsDelay.Duration,
EthTxResendTimeout: cfg.Coordinator.EthClient.TxResendTimeout.Duration, EthNoReuseNonce: cfg.Coordinator.EthClient.NoReuseNonce,
MaxGasPrice: cfg.Coordinator.EthClient.MaxGasPrice, EthTxResendTimeout: cfg.Coordinator.EthClient.TxResendTimeout.Duration,
GasPriceIncPerc: cfg.Coordinator.EthClient.GasPriceIncPerc, MaxGasPrice: cfg.Coordinator.EthClient.MaxGasPrice,
TxManagerCheckInterval: cfg.Coordinator.EthClient.CheckLoopInterval.Duration, GasPriceIncPerc: cfg.Coordinator.EthClient.GasPriceIncPerc,
DebugBatchPath: cfg.Coordinator.Debug.BatchPath, TxManagerCheckInterval: cfg.Coordinator.EthClient.CheckLoopInterval.Duration,
DebugBatchPath: cfg.Coordinator.Debug.BatchPath,
Purger: coordinator.PurgerCfg{ Purger: coordinator.PurgerCfg{
PurgeBatchDelay: cfg.Coordinator.L2DB.PurgeBatchDelay, PurgeBatchDelay: cfg.Coordinator.L2DB.PurgeBatchDelay,
InvalidateBatchDelay: cfg.Coordinator.L2DB.InvalidateBatchDelay, InvalidateBatchDelay: cfg.Coordinator.L2DB.InvalidateBatchDelay,