From 8e67f8ac9a25f6d2546f2445e68b77208eecb8ee Mon Sep 17 00:00:00 2001 From: sidenaio Date: Tue, 12 Oct 2021 11:02:19 +0500 Subject: [PATCH 1/2] Broadcast open short answers 2 minutes after the start of validation --- core/ceremony/ceremony.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/ceremony/ceremony.go b/core/ceremony/ceremony.go index 1f549803..5d85d2ab 100644 --- a/core/ceremony/ceremony.go +++ b/core/ceremony/ceremony.go @@ -321,6 +321,21 @@ func (vc *ValidationCeremony) restoreState() { if stopFlipKeysStopTime.Before(time.Now().UTC()) { vc.stopFlipKeysSync() } + go vc.shortSessionAnswersBroadcastLoop() +} + +func (vc *ValidationCeremony) shortSessionAnswersBroadcastLoop() { + for { + time.Sleep(time.Second * 5) + if vc.appState.State.ValidationPeriod() != state.NonePeriod { + if vc.appState.EvidenceMap.IsCompleted() { + if vc.shouldInteractWithNetwork() { + time.Sleep(time.Duration(rand.Intn(MaxShortAnswersBroadcastDelaySec)) * time.Second) + vc.broadcastShortAnswersTx() + } + } + } + } } func (vc *ValidationCeremony) startValidationShortSessionTimer() { @@ -472,7 +487,6 @@ func (vc *ValidationCeremony) startShortSession(appState *appstate.AppState) { func (vc *ValidationCeremony) handleLongSessionPeriod(block *types.Block) { if block.Header.Flags().HasFlag(types.LongSessionStarted) { vc.logInfoWithInteraction("Long session started") - go vc.delayedShortAnswersTxBroadcast() } vc.processCeremonyTxs(block) @@ -758,13 +772,6 @@ func (vc *ValidationCeremony) processCeremonyTxs(block *types.Block) { } } -func (vc *ValidationCeremony) delayedShortAnswersTxBroadcast() { - if vc.shouldInteractWithNetwork() { - time.Sleep(time.Duration(rand.Intn(MaxShortAnswersBroadcastDelaySec)) * time.Second) - vc.broadcastShortAnswersTx() - } -} - func (vc *ValidationCeremony) broadcastShortAnswersTx() { if vc.shortAnswersSent || !vc.shouldInteractWithNetwork() || !vc.isParticipant() { return From 1b2fd20310a14379cc925334e1da087cfae646da Mon Sep 17 00:00:00 2001 From: sidenaio Date: Wed, 13 Oct 2021 15:29:21 +0500 Subject: [PATCH 2/2] small fix --- core/ceremony/ceremony.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ceremony/ceremony.go b/core/ceremony/ceremony.go index 5d85d2ab..9d89b9e5 100644 --- a/core/ceremony/ceremony.go +++ b/core/ceremony/ceremony.go @@ -328,7 +328,7 @@ func (vc *ValidationCeremony) shortSessionAnswersBroadcastLoop() { for { time.Sleep(time.Second * 5) if vc.appState.State.ValidationPeriod() != state.NonePeriod { - if vc.appState.EvidenceMap.IsCompleted() { + if !vc.shortAnswersSent && vc.appState.EvidenceMap.IsCompleted() { if vc.shouldInteractWithNetwork() { time.Sleep(time.Duration(rand.Intn(MaxShortAnswersBroadcastDelaySec)) * time.Second) vc.broadcastShortAnswersTx()