-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Execute tortoise beacon round only if node is synced at the start of the epoch #2715
[Merged by Bors] - Execute tortoise beacon round only if node is synced at the start of the epoch #2715
Changes from 3 commits
5b64908
ea59b2a
6f666f2
b1c83e1
a4ac09a
54045fa
5fa30ce
fc087d7
8ef7c77
dfcb3d0
fbeef78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,11 @@ type layerClock interface { | |
LayerToTime(id types.LayerID) time.Time | ||
} | ||
|
||
// SyncState interface to check the state the sync. | ||
type SyncState interface { | ||
IsSynced(context.Context) bool | ||
} | ||
|
||
// New returns a new TortoiseBeacon. | ||
func New( | ||
conf Config, | ||
|
@@ -120,6 +125,7 @@ type TortoiseBeacon struct { | |
layerDuration time.Duration | ||
nodeID types.NodeID | ||
|
||
sync SyncState | ||
net broadcaster | ||
atxDB activationDB | ||
tortoiseBeaconDB tortoiseBeaconDB | ||
|
@@ -156,13 +162,24 @@ type TortoiseBeacon struct { | |
proposalChans map[types.EpochID]chan *proposalMessageWithReceiptData | ||
} | ||
|
||
// SetSyncState updates sync state provider. Must be executed only once. | ||
func (tb *TortoiseBeacon) SetSyncState(sync SyncState) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename |
||
if tb.sync != nil { | ||
tb.Log.Panic("sync state provider can be updated only once") | ||
} | ||
tb.sync = sync | ||
} | ||
|
||
// Start starts listening for layers and outputs. | ||
func (tb *TortoiseBeacon) Start(ctx context.Context) error { | ||
if !atomic.CompareAndSwapUint64(&tb.closed, 0, 1) { | ||
tb.Log.Warning("attempt to start tortoise beacon more than once") | ||
return nil | ||
} | ||
tb.Log.Info("Starting %v with the following config: %+v", protoName, tb.config) | ||
tb.Log.Info("starting %v with the following config: %+v", protoName, tb.config) | ||
if tb.sync == nil { | ||
tb.Log.Panic("update sync state provider can't be nil") | ||
} | ||
|
||
ctx, cancel := context.WithCancel(ctx) | ||
tb.tg = taskgroup.New(taskgroup.WithContext(ctx)) | ||
|
@@ -359,6 +376,10 @@ func (tb *TortoiseBeacon) handleEpoch(ctx context.Context, epoch types.EpochID) | |
|
||
return | ||
} | ||
if !tb.sync.IsSynced(ctx) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or you can register a channel to be notified when the node turned synced. see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would be better. but if node goes out of sync again i will need to re-register. and for that, i still need a pointer |
||
tb.Log.With().Info("tortoise beacon protocol is skipped while node is not synced", epoch) | ||
return | ||
} | ||
|
||
tb.Log.With().Info("Handling epoch", | ||
log.Uint32("epoch_id", uint32(epoch))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try
RegisterChForSynced
in syncer.go?