From a3ba09d8f67bdb88446f0388b9a933ed0cf5fc93 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Mon, 6 Nov 2023 20:50:20 +0100 Subject: [PATCH] Fix: fixed race conditions --- pkg/protocol/block_dispatcher.go | 5 ++++- pkg/protocol/engine/engine.go | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/protocol/block_dispatcher.go b/pkg/protocol/block_dispatcher.go index d718ee350..376b6e3a7 100644 --- a/pkg/protocol/block_dispatcher.go +++ b/pkg/protocol/block_dispatcher.go @@ -242,7 +242,10 @@ func (b *BlockDispatcher) processWarpSyncResponse(commitmentID iotago.Commitment b.processedWarpSyncRequests.Add(commitmentID) - // make sure the engine is clean before we start processing the blocks + // make sure the engine is clean and requires a warp-sync before we start processing the blocks + if targetEngine.Workers.WaitChildren(); targetEngine.Storage.Settings().LatestCommitment().ID().Slot() > commitmentID.Slot() { + return nil + } targetEngine.Reset() // Once all blocks are booked we diff --git a/pkg/protocol/engine/engine.go b/pkg/protocol/engine/engine.go index 2db383500..677572c90 100644 --- a/pkg/protocol/engine/engine.go +++ b/pkg/protocol/engine/engine.go @@ -212,6 +212,7 @@ func New( func(e *Engine) { fmt.Println("Engine Settings", e.Storage.Settings().String()) }, + (*Engine).Reset, (*Engine).TriggerInitialized, ) } @@ -223,8 +224,6 @@ func (e *Engine) ProcessBlockFromPeer(block *model.Block, source peer.ID) { // Reset resets the component to a clean state as if it was created at the last commitment. func (e *Engine) Reset() { - e.Workers.WaitChildren() - e.BlockRequester.Clear() e.Storage.Reset() e.EvictionState.Reset()