From 5beda14f877c893f1cb08570b23d3f34b803b8ca Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Sun, 3 Dec 2023 23:53:25 +0100 Subject: [PATCH] Refactor: revert --- pkg/protocol/chain.go | 16 +++------------- pkg/protocol/commitment.go | 8 ++++---- pkg/protocol/engine/clock/blocktime/clock.go | 4 +--- pkg/protocol/engines.go | 3 --- pkg/tests/loss_of_acceptance_test.go | 2 +- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pkg/protocol/chain.go b/pkg/protocol/chain.go index 43ef38211..a2f2671bd 100644 --- a/pkg/protocol/chain.go +++ b/pkg/protocol/chain.go @@ -156,8 +156,6 @@ func (c *Chain) DispatchBlock(block *model.Block, src peer.ID) (dispatched bool) func (c *Chain) Commitment(slot iotago.SlotIndex) (commitment *Commitment, exists bool) { for currentChain := c; currentChain != nil; { switch forkingPoint := currentChain.ForkingPoint.Get(); { - case forkingPoint == nil: - return nil, false case forkingPoint.Slot() == slot: return forkingPoint, true case slot > forkingPoint.Slot(): @@ -214,17 +212,9 @@ func (c *Chain) initDerivedProperties() (shutdown func()) { c.deriveLatestAttestedWeight(), c.deriveWarpSyncMode(), - c.ForkingPoint.WithValue(func(forkingPoint *Commitment) (shutdown func()) { - return c.deriveParentChain(forkingPoint) - }), - - c.ParentChain.WithNonEmptyValue(func(parentChain *Chain) (shutdown func()) { - return parentChain.deriveChildChains(c) - }), - - c.Engine.WithNonEmptyValue(func(engineInstance *engine.Engine) (shutdown func()) { - return c.deriveOutOfSyncThreshold(engineInstance) - }), + c.ForkingPoint.WithValue(c.deriveParentChain), + c.ParentChain.WithNonEmptyValue(lo.Bind(c, (*Chain).deriveChildChains)), + c.Engine.WithNonEmptyValue(c.deriveOutOfSyncThreshold), ) } diff --git a/pkg/protocol/commitment.go b/pkg/protocol/commitment.go index 4ce7b79da..1e0898be4 100644 --- a/pkg/protocol/commitment.go +++ b/pkg/protocol/commitment.go @@ -272,16 +272,16 @@ func (c *Commitment) deriveRequestAttestations(chain *Chain, parent *Commitment) // deriveWarpSyncBlocks derives the WarpSyncBlocks flag of this Commitment which is true if our Chain is requesting // warp sync, and we are the directly above the latest verified Commitment. func (c *Commitment) deriveWarpSyncBlocks(chain *Chain, parent *Commitment) func() { - return c.WarpSyncBlocks.DeriveValueFrom(reactive.NewDerivedVariable4(func(_ bool, engineInstance *engine.Engine, warpSyncModeEnabled bool, parentIsFullyBooked bool, isFullyBooked bool) bool { - return engineInstance != nil && warpSyncModeEnabled && parentIsFullyBooked && !isFullyBooked + return c.WarpSyncBlocks.DeriveValueFrom(reactive.NewDerivedVariable4(func(_ bool, engineInstance *engine.Engine, warpSync bool, parentIsFullyBooked bool, isFullyBooked bool) bool { + return engineInstance != nil && warpSync && parentIsFullyBooked && !isFullyBooked }, chain.Engine, chain.WarpSyncMode, parent.IsFullyBooked, c.IsFullyBooked)) } // deriveReplayDroppedBlocks derives the ReplayDroppedBlocks flag of this Commitment which is true if our Chain has an // engine, is no longer requesting warp sync, and we are above the latest verified Commitment. func (c *Commitment) deriveReplayDroppedBlocks(chain *Chain) func() { - return c.ReplayDroppedBlocks.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, engineInstance *engine.Engine, warpSyncModeEnabled bool, isAboveLatestVerifiedCommitment bool) bool { - return engineInstance != nil && !warpSyncModeEnabled && isAboveLatestVerifiedCommitment + return c.ReplayDroppedBlocks.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, engineInstance *engine.Engine, warpSyncing bool, isAboveLatestVerifiedCommitment bool) bool { + return engineInstance != nil && !warpSyncing && isAboveLatestVerifiedCommitment }, chain.Engine, chain.WarpSyncMode, c.IsAboveLatestVerifiedCommitment)) } diff --git a/pkg/protocol/engine/clock/blocktime/clock.go b/pkg/protocol/engine/clock/blocktime/clock.go index 51801187b..506387df0 100644 --- a/pkg/protocol/engine/clock/blocktime/clock.go +++ b/pkg/protocol/engine/clock/blocktime/clock.go @@ -55,9 +55,7 @@ func NewProvider(opts ...options.Option[Clock]) module.Provider[*engine.Engine, asyncOpt := event.WithWorkerPool(c.workerPool) c.HookStopped(lo.Batch( e.Events.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) { - block.Notarized().OnTrigger(func() { - c.acceptedTime.Advance(block.IssuingTime()) - }) + c.acceptedTime.Advance(block.IssuingTime()) }, asyncOpt).Unhook, e.Events.BlockGadget.BlockConfirmed.Hook(func(block *blocks.Block) { diff --git a/pkg/protocol/engines.go b/pkg/protocol/engines.go index e30cfe19f..781dc0d32 100644 --- a/pkg/protocol/engines.go +++ b/pkg/protocol/engines.go @@ -9,7 +9,6 @@ import ( "github.com/iotaledger/hive.go/ds/reactive" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" - "github.com/iotaledger/hive.go/log" "github.com/iotaledger/hive.go/runtime/ioutils" "github.com/iotaledger/hive.go/runtime/module" "github.com/iotaledger/hive.go/runtime/workerpool" @@ -159,8 +158,6 @@ func (e *Engines) ForkAtSlot(slot iotago.SlotIndex) (*engine.Engine, error) { return nil, ierrors.Wrap(err, "error while rolling back attestations storage on candidate engine") } - e.Log("forked engine", log.LevelTrace, "name", newEngineAlias[0:8], "slot", slot) - return candidateEngine, nil } diff --git a/pkg/tests/loss_of_acceptance_test.go b/pkg/tests/loss_of_acceptance_test.go index 93ec48b57..eae12a80c 100644 --- a/pkg/tests/loss_of_acceptance_test.go +++ b/pkg/tests/loss_of_acceptance_test.go @@ -32,7 +32,7 @@ func TestLossOfAcceptanceFromGenesis(t *testing.T) { 5, ), ), - testsuite.WithWaitFor(30*time.Second), + testsuite.WithWaitFor(15*time.Second), ) defer ts.Shutdown()