Skip to content

Commit

Permalink
Refactor: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Dec 3, 2023
1 parent b6b430f commit 5beda14
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
16 changes: 3 additions & 13 deletions pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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),
)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/protocol/engine/clock/blocktime/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions pkg/protocol/engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/loss_of_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestLossOfAcceptanceFromGenesis(t *testing.T) {
5,
),
),
testsuite.WithWaitFor(30*time.Second),
testsuite.WithWaitFor(15*time.Second),
)
defer ts.Shutdown()

Expand Down

0 comments on commit 5beda14

Please sign in to comment.