From 36c1ba84df5db0c2d063f764ba7cc61e8f4a43f7 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Wed, 17 Mar 2021 13:21:27 +0200 Subject: [PATCH 1/2] Fix Synchronizer not setting slot.ForgerCommitment to true until fully synced and after reorgs --- synchronizer/synchronizer.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index c8005f8..0a591e2 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -354,16 +354,14 @@ func (s *Synchronizer) updateCurrentSlot(slot *common.Slot, reset bool, hasBatch } slot.SlotNum = slotNum slot.StartBlock, slot.EndBlock = s.consts.Auction.SlotBlocks(slot.SlotNum) + if hasBatch && s.consts.Auction.RelativeBlock(firstBatchBlockNum) < int64(s.vars.Auction.SlotDeadline) { + slot.ForgerCommitment = true + } // If Synced, update the current coordinator if s.stats.Synced() && blockNum >= s.consts.Auction.GenesisBlockNum { if err := s.setSlotCoordinator(slot); err != nil { return tracerr.Wrap(err) } - if hasBatch && - s.consts.Auction.RelativeBlock(firstBatchBlockNum) < - int64(s.vars.Auction.SlotDeadline) { - slot.ForgerCommitment = true - } // TODO: Remove this SANITY CHECK once this code is tested enough // BEGIN SANITY CHECK From eb89ab84f28015eb20496316bb2584f8a651328d Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Wed, 17 Mar 2021 14:41:06 +0200 Subject: [PATCH 2/2] Rename the variable to match the meaning --- synchronizer/synchronizer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 0a591e2..3a7e009 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -335,7 +335,7 @@ func (s *Synchronizer) updateCurrentSlot(slot *common.Slot, reset bool, hasBatch // We want the next block because the current one is already mined blockNum := s.stats.Sync.LastBlock.Num + 1 slotNum := s.consts.Auction.SlotNum(blockNum) - firstBatchBlockNum := s.stats.Sync.LastBlock.Num + syncLastBlockNum := s.stats.Sync.LastBlock.Num if reset { // Using this query only to know if there dbFirstBatchBlockNum, err := s.historyDB.GetFirstBatchBlockNumBySlot(slotNum) @@ -345,7 +345,7 @@ func (s *Synchronizer) updateCurrentSlot(slot *common.Slot, reset bool, hasBatch hasBatch = false } else { hasBatch = true - firstBatchBlockNum = dbFirstBatchBlockNum + syncLastBlockNum = dbFirstBatchBlockNum } slot.ForgerCommitment = false } else if slotNum > slot.SlotNum { @@ -354,7 +354,7 @@ func (s *Synchronizer) updateCurrentSlot(slot *common.Slot, reset bool, hasBatch } slot.SlotNum = slotNum slot.StartBlock, slot.EndBlock = s.consts.Auction.SlotBlocks(slot.SlotNum) - if hasBatch && s.consts.Auction.RelativeBlock(firstBatchBlockNum) < int64(s.vars.Auction.SlotDeadline) { + if hasBatch && s.consts.Auction.RelativeBlock(syncLastBlockNum) < int64(s.vars.Auction.SlotDeadline) { slot.ForgerCommitment = true } // If Synced, update the current coordinator