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

Commit 2c098a9

Browse files
authored
Merge pull request #928 from iotaledger/fix/initial-cumulative-attested-weight
Initialize CumulativeAttestedWeight for the root commitment
2 parents 1c1bf72 + cf0062b commit 2c098a9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/protocol/commitment.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ func (c *Commitment) initDerivedProperties() (shutdown func()) {
243243
c.IsVerified.InheritFrom(c.IsRoot),
244244
c.IsSolid.InheritFrom(c.IsRoot),
245245

246+
c.IsRoot.OnTrigger(func() {
247+
c.CumulativeAttestedWeight.Set(c.Commitment.CumulativeWeight())
248+
}),
249+
246250
// mark commitments that are marked as verified as attested and synced
247251
c.IsAttested.InheritFrom(c.IsVerified),
248252
c.IsSynced.InheritFrom(c.IsVerified),
@@ -336,9 +340,13 @@ func (c *Commitment) deriveChain(parent *Commitment) func() {
336340
// deriveCumulativeAttestedWeight derives the CumulativeAttestedWeight of this Commitment which is the sum of the
337341
// parent's CumulativeAttestedWeight and the AttestedWeight of this Commitment.
338342
func (c *Commitment) deriveCumulativeAttestedWeight(parent *Commitment) func() {
339-
return c.CumulativeAttestedWeight.DeriveValueFrom(reactive.NewDerivedVariable2(func(_ uint64, parentCumulativeAttestedWeight uint64, attestedWeight uint64) uint64 {
343+
return c.CumulativeAttestedWeight.DeriveValueFrom(reactive.NewDerivedVariable3(func(currentCumulativeAttestedWeight uint64, parentCumulativeAttestedWeight uint64, attestedWeight uint64, isAttested bool) uint64 {
344+
if !isAttested {
345+
return currentCumulativeAttestedWeight
346+
}
347+
340348
return parentCumulativeAttestedWeight + attestedWeight
341-
}, parent.CumulativeAttestedWeight, c.AttestedWeight))
349+
}, parent.CumulativeAttestedWeight, c.AttestedWeight, c.IsAttested))
342350
}
343351

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

0 commit comments

Comments
 (0)