From 984221be4b34a26c789f631248480697c7263265 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Tue, 14 May 2024 21:15:12 +0200 Subject: [PATCH 1/3] Fixed pool rewards not getting exported when creating a snapshot with targetEpoch 0 --- .../sybilprotectionv1/performance/snapshot.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go index 5113989a5..29639d3b3 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go @@ -293,9 +293,9 @@ func (t *Tracker) exportPoolRewards(writer io.WriteSeeker, targetEpoch iotago.Ep if err := stream.WriteCollection(writer, serializer.SeriLengthPrefixTypeAsUint32, func() (int, error) { var epochCount int - // Here underflow will not happen because we will stop iterating for epoch 0, because 0 is not greater than zero. - // Use safemath here anyway to avoid hard to trace problems stemming from an accidental underflow. - for epoch := targetEpoch; epoch > earliestRewardEpoch; epoch = lo.PanicOnErr(safemath.SafeSub(epoch, 1)) { + // Start at the targest epoch and go back in time until earliestRewardEpoch or epoch 0 (included) + epoch := targetEpoch + for { rewardsMap, err := t.rewardsMap(epoch) if err != nil { return 0, ierrors.Wrapf(err, "unable to get rewards tree for epoch %d", epoch) @@ -339,6 +339,12 @@ func (t *Tracker) exportPoolRewards(writer io.WriteSeeker, targetEpoch iotago.Ep } epochCount++ + + if epoch <= earliestRewardEpoch { + // Every reward before earliestRewardEpoch is already exported, so stop here + break + } + epoch = lo.PanicOnErr(safemath.SafeSub(epoch, 1)) } return epochCount, nil From 98642f3329947630d1acd50c534482d6cd13b0b9 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Tue, 14 May 2024 21:15:36 +0200 Subject: [PATCH 2/3] Change the committing log from debug to info so that we can see the roots in a normal info log --- pkg/protocol/engine/notarization/slotnotarization/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/protocol/engine/notarization/slotnotarization/manager.go b/pkg/protocol/engine/notarization/slotnotarization/manager.go index 9435a2c49..9ee41f4b7 100644 --- a/pkg/protocol/engine/notarization/slotnotarization/manager.go +++ b/pkg/protocol/engine/notarization/slotnotarization/manager.go @@ -272,7 +272,7 @@ func (m *Manager) createCommitment(slot iotago.SlotIndex) (*model.Commitment, er rmc, ) - m.LogDebug("Committing", "commitment", newCommitment, "roots ", roots) + m.LogInfo("Committing", "commitment", newCommitment, "roots ", roots) newModelCommitment, err := model.CommitmentFromCommitment(newCommitment, apiForSlot, serix.WithValidation()) if err != nil { From dc72db455c49bfb21ef1311e91516d954686d667 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Tue, 14 May 2024 21:44:01 +0200 Subject: [PATCH 3/3] Fixed genesis snapshot generation --- .../sybilprotectionv1/performance/snapshot.go | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go index 29639d3b3..385627a8c 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go @@ -300,46 +300,46 @@ func (t *Tracker) exportPoolRewards(writer io.WriteSeeker, targetEpoch iotago.Ep if err != nil { return 0, ierrors.Wrapf(err, "unable to get rewards tree for epoch %d", epoch) } - // if the map was not present in storage we can skip this epoch - if !rewardsMap.WasRestoredFromStorage() { - t.LogDebug("Skipping epoch", "epoch", epoch, "reason", "not restored from storage") - continue - } - t.LogDebug("Exporting Pool Rewards", "epoch", epoch) + if rewardsMap.WasRestoredFromStorage() { + t.LogDebug("Exporting Pool Rewards", "epoch", epoch) - if err := stream.Write(writer, epoch); err != nil { - return 0, ierrors.Wrapf(err, "unable to write epoch index for epoch index %d", epoch) - } + if err := stream.Write(writer, epoch); err != nil { + return 0, ierrors.Wrapf(err, "unable to write epoch index for epoch index %d", epoch) + } - if err := stream.WriteCollection(writer, serializer.SeriLengthPrefixTypeAsUint64, func() (int, error) { - var accountCount int + if err := stream.WriteCollection(writer, serializer.SeriLengthPrefixTypeAsUint64, func() (int, error) { + var accountCount int - if err = rewardsMap.Stream(func(key iotago.AccountID, value *model.PoolRewards) error { - if err := stream.Write(writer, key); err != nil { - return ierrors.Wrapf(err, "unable to write account id for epoch %d and accountID %s", epoch, key) - } + if err = rewardsMap.Stream(func(key iotago.AccountID, value *model.PoolRewards) error { + if err := stream.Write(writer, key); err != nil { + return ierrors.Wrapf(err, "unable to write account id for epoch %d and accountID %s", epoch, key) + } - if err := stream.WriteObject(writer, value, (*model.PoolRewards).Bytes); err != nil { - return ierrors.Wrapf(err, "unable to write account rewards for epoch index %d and accountID %s", epoch, key) - } + if err := stream.WriteObject(writer, value, (*model.PoolRewards).Bytes); err != nil { + return ierrors.Wrapf(err, "unable to write account rewards for epoch index %d and accountID %s", epoch, key) + } - t.LogDebug("Exporting Pool Reward", "epoch", epoch, "accountID", key, "rewards", value) + t.LogDebug("Exporting Pool Reward", "epoch", epoch, "accountID", key, "rewards", value) - accountCount++ + accountCount++ - return nil + return nil + }); err != nil { + return 0, ierrors.Wrapf(err, "unable to stream rewards for epoch index %d", epoch) + } + + return accountCount, nil }); err != nil { - return 0, ierrors.Wrapf(err, "unable to stream rewards for epoch index %d", epoch) + return 0, ierrors.Wrapf(err, "unable to write rewards for epoch index %d", epoch) } - return accountCount, nil - }); err != nil { - return 0, ierrors.Wrapf(err, "unable to write rewards for epoch index %d", epoch) + epochCount++ + } else { + // if the map was not present in storage we can skip this epoch + t.LogDebug("Skipping epoch", "epoch", epoch, "reason", "not restored from storage") } - epochCount++ - if epoch <= earliestRewardEpoch { // Every reward before earliestRewardEpoch is already exported, so stop here break