Skip to content

Commit

Permalink
Refactor: reverted more
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Dec 3, 2023
1 parent 5beda14 commit 2b819f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (c *Chain) addCommitment(newCommitment *Commitment) (shutdown func()) {

return lo.Batch(
newCommitment.IsAttested.OnTrigger(func() { c.LatestAttestedCommitment.Set(newCommitment) }),
newCommitment.IsCommitted.OnTrigger(func() { c.LatestProducedCommitment.Set(newCommitment) }),
newCommitment.IsVerified.OnTrigger(func() { c.LatestProducedCommitment.Set(newCommitment) }),
newCommitment.IsFullyBooked.OnTrigger(func() { c.LatestFullyBookedSlot.Set(newCommitment.Slot()) }),
)
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ type Commitment struct {
// IsCommittable contains a flag indicating if this Commitment is committable (we have received all blocks and all attestations).
IsCommittable reactive.Event

// IsCommitted contains a flag indicating if we Commitment produced this Commitment ourselves by replaying all the
// blocks of the Commitment.
IsCommitted reactive.Event
// IsVerified contains a flag indicating if this Commitment is verified (we produced this Commitment ourselves by
// booking all the contained blocks and transactions).
IsVerified reactive.Event

// IsAboveLatestVerifiedCommitment contains a flag indicating if this Commitment is above the latest verified
// Commitment.
Expand Down Expand Up @@ -102,7 +102,7 @@ func newCommitment(commitments *Commitments, model *model.Commitment) *Commitmen
IsAttested: reactive.NewEvent(),
IsFullyBooked: reactive.NewEvent(),
IsCommittable: reactive.NewEvent(),
IsCommitted: reactive.NewEvent(),
IsVerified: reactive.NewEvent(),
IsAboveLatestVerifiedCommitment: reactive.NewVariable[bool](),
ReplayDroppedBlocks: reactive.NewVariable[bool](),
IsEvicted: reactive.NewEvent(),
Expand Down Expand Up @@ -145,7 +145,7 @@ func (c *Commitment) initLogger() (shutdown func()) {
c.IsAttested.LogUpdates(c, log.LevelTrace, "IsAttested"),
c.IsFullyBooked.LogUpdates(c, log.LevelTrace, "IsFullyBooked"),
c.IsCommittable.LogUpdates(c, log.LevelTrace, "IsCommittable"),
c.IsCommitted.LogUpdates(c, log.LevelTrace, "IsCommitted"),
c.IsVerified.LogUpdates(c, log.LevelTrace, "IsVerified"),
c.ReplayDroppedBlocks.LogUpdates(c, log.LevelTrace, "ReplayDroppedBlocks"),
c.IsEvicted.LogUpdates(c, log.LevelTrace, "IsEvicted"),

Expand All @@ -156,12 +156,12 @@ func (c *Commitment) initLogger() (shutdown func()) {
// initDerivedProperties initializes the behavior of this Commitment by setting up the relations between its properties.
func (c *Commitment) initDerivedProperties() (shutdown func()) {
return lo.Batch(
// mark commitments that are marked as root as committed
c.IsCommitted.InheritFrom(c.IsRoot),
// mark commitments that are marked as root as verified
c.IsVerified.InheritFrom(c.IsRoot),

// mark commitments that are marked as committed as attested and fully booked
c.IsAttested.InheritFrom(c.IsCommitted),
c.IsFullyBooked.InheritFrom(c.IsCommitted),
// mark commitments that are marked as verified as attested and fully booked
c.IsAttested.InheritFrom(c.IsVerified),
c.IsFullyBooked.InheritFrom(c.IsVerified),

c.Parent.WithNonEmptyValue(func(parent *Commitment) func() {
// the weight can be fixed as a one time operation (as it only relies on static information from the parent
Expand Down Expand Up @@ -258,7 +258,7 @@ func (c *Commitment) deriveCumulativeAttestedWeight(parent *Commitment) func() {
func (c *Commitment) deriveIsAboveLatestVerifiedCommitment(parent *Commitment) func() {
return c.IsAboveLatestVerifiedCommitment.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, parentAboveLatestVerifiedCommitment bool, parentIsCommitted bool, isCommitted bool) bool {
return parentAboveLatestVerifiedCommitment || (parentIsCommitted && !isCommitted)
}, parent.IsAboveLatestVerifiedCommitment, parent.IsCommitted, c.IsCommitted))
}, parent.IsAboveLatestVerifiedCommitment, parent.IsVerified, c.IsVerified))
}

// deriveRequestAttestations derives the RequestAttestations flag of this Commitment which is true if our Chain is
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/commitments.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *Commitments) publishEngineCommitments(chain *Chain, engine *engine.Engi
// mark it as produced by ourselves and force it to be on the right chain (in case our chain produced a
// different commitment than the one we erroneously expected it to be - we always trust our engine most).
publishedCommitment.AttestedWeight.Set(publishedCommitment.Weight.Get())
publishedCommitment.IsCommitted.Set(true)
publishedCommitment.IsVerified.Set(true)
publishedCommitment.forceChain(chain)
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/protocol_warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (w *WarpSyncProtocol) ProcessResponse(commitmentID iotago.CommitmentID, blo

// force commit one by one and wait for the parent to be committed before we can commit the next one
commitment.Parent.WithNonEmptyValue(func(parent *Commitment) (teardown func()) {
return parent.IsCommitted.WithNonEmptyValue(func(_ bool) (teardown func()) {
return parent.IsVerified.WithNonEmptyValue(func(_ bool) (teardown func()) {
return commitment.IsCommittable.OnTrigger(forceCommitmentFunc)
})
})
Expand Down

0 comments on commit 2b819f9

Please sign in to comment.