mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Sync ForgerCommitment and use it in coord
Previously the coordinator was erroneously using Slot.BatchesLen to determine when anyone can forge. The correct behaviour is implmenented with the boolean flag `ForgerCommitment`, that is set to true only when there's a batch before the deadline within a slot. Delete Slot.BatchesLen, and the synchronization code of this value from the Synchronizer, as this is not needed
This commit is contained in:
@@ -47,7 +47,7 @@ type BatchInfo struct {
|
||||
// DebugStore is a debug function to store the BatchInfo as a json text file in
|
||||
// storePath
|
||||
func (b *BatchInfo) DebugStore(storePath string) error {
|
||||
batchJSON, err := json.Marshal(b)
|
||||
batchJSON, err := json.MarshalIndent(b, "", " ")
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -190,9 +190,10 @@ func (c *Coordinator) syncSCVars(vars synchronizer.SCVariablesPtr) {
|
||||
|
||||
func (c *Coordinator) canForge(stats *synchronizer.Stats) bool {
|
||||
anyoneForge := false
|
||||
if stats.Sync.Auction.CurrentSlot.BatchesLen == 0 &&
|
||||
c.consts.Auction.RelativeBlock(stats.Eth.LastBlock.Num+1) > int64(c.vars.Auction.SlotDeadline) {
|
||||
log.Debug("Coordinator: anyone can forge in the current slot (slotDeadline passed)")
|
||||
if !stats.Sync.Auction.CurrentSlot.ForgerCommitment &&
|
||||
c.consts.Auction.RelativeBlock(stats.Eth.LastBlock.Num+1) >= int64(c.vars.Auction.SlotDeadline) {
|
||||
log.Debugw("Coordinator: anyone can forge in the current slot (slotDeadline passed)",
|
||||
"block", stats.Eth.LastBlock.Num)
|
||||
anyoneForge = true
|
||||
}
|
||||
if stats.Sync.Auction.CurrentSlot.Forger == c.cfg.ForgerAddress || anyoneForge {
|
||||
|
||||
@@ -213,6 +213,7 @@ func TestCoordinatorFlow(t *testing.T) {
|
||||
return
|
||||
}
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
var timer timer
|
||||
ethClient := test.NewClient(true, &timer, &bidder, ethClientSetup)
|
||||
modules := newTestModules(t)
|
||||
@@ -294,6 +295,7 @@ func TestCoordinatorFlow(t *testing.T) {
|
||||
|
||||
func TestCoordinatorStartStop(t *testing.T) {
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
var timer timer
|
||||
ethClient := test.NewClient(true, &timer, &bidder, ethClientSetup)
|
||||
modules := newTestModules(t)
|
||||
@@ -304,6 +306,7 @@ func TestCoordinatorStartStop(t *testing.T) {
|
||||
|
||||
func TestCoordCanForge(t *testing.T) {
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
bootForger := ethClientSetup.AuctionVariables.BootCoordinator
|
||||
|
||||
var timer timer
|
||||
@@ -356,6 +359,7 @@ func TestCoordCanForge(t *testing.T) {
|
||||
|
||||
func TestCoordHandleMsgSyncBlock(t *testing.T) {
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
bootForger := ethClientSetup.AuctionVariables.BootCoordinator
|
||||
|
||||
var timer timer
|
||||
@@ -417,6 +421,7 @@ func TestCoordHandleMsgSyncBlock(t *testing.T) {
|
||||
|
||||
func TestPipelineShouldL1L2Batch(t *testing.T) {
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
|
||||
var timer timer
|
||||
ctx := context.Background()
|
||||
@@ -562,6 +567,7 @@ func preloadSync(t *testing.T, ethClient *test.Client, sync *synchronizer.Synchr
|
||||
|
||||
func TestPipeline1(t *testing.T) {
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
|
||||
var timer timer
|
||||
ctx := context.Background()
|
||||
@@ -646,6 +652,7 @@ func TestCoordinatorStress(t *testing.T) {
|
||||
}
|
||||
log.Info("Begin Test Coord Stress")
|
||||
ethClientSetup := test.NewClientSetupExample()
|
||||
ethClientSetup.ChainID = big.NewInt(int64(chainID))
|
||||
var timer timer
|
||||
ethClient := test.NewClient(true, &timer, &bidder, ethClientSetup)
|
||||
modules := newTestModules(t)
|
||||
@@ -691,7 +698,7 @@ func TestCoordinatorStress(t *testing.T) {
|
||||
case <-ctx.Done():
|
||||
wg.Done()
|
||||
return
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
case <-time.After(1 * time.Second):
|
||||
ethClient.CtlMineBlock()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user