Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Merge pull request #928 from iotaledger/fix/initial-cumulative-attest…
Browse files Browse the repository at this point in the history
…ed-weight

Initialize CumulativeAttestedWeight for the root commitment
  • Loading branch information
alexsporn authored Apr 23, 2024
2 parents 1c1bf72 + cf0062b commit 2c098a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func (c *Commitment) initDerivedProperties() (shutdown func()) {
c.IsVerified.InheritFrom(c.IsRoot),
c.IsSolid.InheritFrom(c.IsRoot),

c.IsRoot.OnTrigger(func() {
c.CumulativeAttestedWeight.Set(c.Commitment.CumulativeWeight())
}),

// mark commitments that are marked as verified as attested and synced
c.IsAttested.InheritFrom(c.IsVerified),
c.IsSynced.InheritFrom(c.IsVerified),
Expand Down Expand Up @@ -336,9 +340,13 @@ func (c *Commitment) deriveChain(parent *Commitment) func() {
// deriveCumulativeAttestedWeight derives the CumulativeAttestedWeight of this Commitment which is the sum of the
// parent's CumulativeAttestedWeight and the AttestedWeight of this Commitment.
func (c *Commitment) deriveCumulativeAttestedWeight(parent *Commitment) func() {
return c.CumulativeAttestedWeight.DeriveValueFrom(reactive.NewDerivedVariable2(func(_ uint64, parentCumulativeAttestedWeight uint64, attestedWeight uint64) uint64 {
return c.CumulativeAttestedWeight.DeriveValueFrom(reactive.NewDerivedVariable3(func(currentCumulativeAttestedWeight uint64, parentCumulativeAttestedWeight uint64, attestedWeight uint64, isAttested bool) uint64 {
if !isAttested {
return currentCumulativeAttestedWeight
}

return parentCumulativeAttestedWeight + attestedWeight
}, parent.CumulativeAttestedWeight, c.AttestedWeight))
}, parent.CumulativeAttestedWeight, c.AttestedWeight, c.IsAttested))
}

// deriveCumulativeVerifiedWeight derives the CumulativeVerifiedWeight of this Commitment which is the same as the
Expand Down

0 comments on commit 2c098a9

Please sign in to comment.