Skip to content

Commit

Permalink
Refactor: reverted more code
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Dec 3, 2023
1 parent a3a5c72 commit 0ce46e7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ func (c *Chain) initDerivedProperties() (shutdown func()) {
}),

c.Engine.WithNonEmptyValue(func(engineInstance *engine.Engine) (shutdown func()) {
return c.OutOfSyncThreshold.DeriveValueFrom(reactive.NewDerivedVariable(func(_ iotago.SlotIndex, latestSeenSlot iotago.SlotIndex) iotago.SlotIndex {
return outOfSyncThreshold(engineInstance, latestSeenSlot)
}, c.chains.LatestSeenSlot))
return c.deriveOutOfSyncThreshold(engineInstance)
}),
)
}
Expand All @@ -245,7 +243,7 @@ func (c *Chain) deriveWarpSyncMode() func() {

// deriveClaimedWeight defines how a chain determines its claimed weight (by setting the cumulative weight of the
// latest commitment).
func (c *Chain) deriveClaimedWeight() func() {
func (c *Chain) deriveClaimedWeight() (shutdown func()) {
return c.ClaimedWeight.DeriveValueFrom(reactive.NewDerivedVariable(func(_ uint64, latestCommitment *Commitment) uint64 {
if latestCommitment == nil {
return 0
Expand Down Expand Up @@ -305,6 +303,14 @@ func (c *Chain) deriveParentChain(forkingPoint *Commitment) (shutdown func()) {
return nil
}

// deriveOutOfSyncThreshold defines how a chain determines its "out of sync" threshold (the latest seen slot minus 2
// times the max committable age or 0 if this would cause an overflow to the negative numbers).
func (c *Chain) deriveOutOfSyncThreshold(engineInstance *engine.Engine) func() {
return c.OutOfSyncThreshold.DeriveValueFrom(reactive.NewDerivedVariable(func(_ iotago.SlotIndex, latestSeenSlot iotago.SlotIndex) iotago.SlotIndex {
return outOfSyncThreshold(engineInstance, latestSeenSlot)
}, c.chains.LatestSeenSlot))
}

// addCommitment adds the given commitment to this chain.
func (c *Chain) addCommitment(newCommitment *Commitment) (shutdown func()) {
c.commitments.Set(newCommitment.Slot(), newCommitment)
Expand Down

0 comments on commit 0ce46e7

Please sign in to comment.