From 51b758e2d9cec395b0405ad7f8579411de754848 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 2 May 2024 16:51:00 +0200 Subject: [PATCH 1/5] Added String() methods to a lot of our internal models so they can be logged more easily --- pkg/model/account_diff.go | 21 +++++++++++++++++++++ pkg/model/poolstats.go | 17 +++++++++++++++++ pkg/model/signaled_block.go | 10 ++++++++++ pkg/model/validator_performance.go | 9 +++++++++ pkg/model/version_and_hash.go | 8 ++++++++ pkg/protocol/engine/accounts/accounts.go | 16 ++++++++++++++++ pkg/protocol/engine/accounts/credits.go | 8 ++++++++ pkg/protocol/engine/accounts/mana.go | 12 ++++++++++++ 8 files changed, 101 insertions(+) diff --git a/pkg/model/account_diff.go b/pkg/model/account_diff.go index 80647fb5e..9b13863eb 100644 --- a/pkg/model/account_diff.go +++ b/pkg/model/account_diff.go @@ -6,6 +6,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/serializer/v2/stream" + "github.com/iotaledger/hive.go/stringify" iotago "github.com/iotaledger/iota.go/v4" ) @@ -74,6 +75,26 @@ func (d *AccountDiff) Clone() *AccountDiff { } } +func (d *AccountDiff) String() string { + builder := stringify.NewStructBuilder("AccountDiff") + builder.AddField(stringify.NewStructField("BICChange", d.BICChange)) + builder.AddField(stringify.NewStructField("PreviousUpdatedSlot", d.PreviousUpdatedSlot)) + builder.AddField(stringify.NewStructField("NewExpirySlot", d.NewExpirySlot)) + builder.AddField(stringify.NewStructField("PreviousExpirySlot", d.PreviousExpirySlot)) + builder.AddField(stringify.NewStructField("NewOutputID", d.NewOutputID)) + builder.AddField(stringify.NewStructField("PreviousOutputID", d.PreviousOutputID)) + builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", d.BlockIssuerKeysAdded)) + builder.AddField(stringify.NewStructField("BlockIssuerKeysRemoved", d.BlockIssuerKeysRemoved)) + builder.AddField(stringify.NewStructField("ValidatorStakeChange", d.ValidatorStakeChange)) + builder.AddField(stringify.NewStructField("DelegationStakeChange", d.DelegationStakeChange)) + builder.AddField(stringify.NewStructField("FixedCostChange", d.FixedCostChange)) + builder.AddField(stringify.NewStructField("StakeEndEpochChange", d.StakeEndEpochChange)) + builder.AddField(stringify.NewStructField("NewLatestSupportedVersionAndHash", d.NewLatestSupportedVersionAndHash)) + builder.AddField(stringify.NewStructField("PrevLatestSupportedVersionAndHash", d.PrevLatestSupportedVersionAndHash)) + + return builder.String() +} + func (d *AccountDiff) Bytes() ([]byte, error) { byteBuffer := stream.NewByteBuffer() diff --git a/pkg/model/poolstats.go b/pkg/model/poolstats.go index eada06d32..50ca3965d 100644 --- a/pkg/model/poolstats.go +++ b/pkg/model/poolstats.go @@ -5,6 +5,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/serializer/v2/stream" + "github.com/iotaledger/hive.go/stringify" iotago "github.com/iotaledger/iota.go/v4" ) @@ -59,6 +60,14 @@ func (p *PoolsStats) Bytes() ([]byte, error) { return byteBuffer.Bytes() } +func (p *PoolsStats) String() string { + return stringify.Struct("PoolsStats", + stringify.NewStructField("TotalStake", p.TotalStake), + stringify.NewStructField("TotalValidatorStake", p.TotalValidatorStake), + stringify.NewStructField("ProfitMargin", p.ProfitMargin), + ) +} + type PoolRewards struct { // Total stake of the validator including delegations PoolStake iotago.BaseToken @@ -111,3 +120,11 @@ func (p *PoolRewards) Bytes() ([]byte, error) { return byteBuffer.Bytes() } + +func (p *PoolRewards) String() string { + return stringify.Struct("PoolRewards", + stringify.NewStructField("PoolStake", p.PoolStake), + stringify.NewStructField("PoolRewards", p.PoolRewards), + stringify.NewStructField("FixedCost", p.FixedCost), + ) +} diff --git a/pkg/model/signaled_block.go b/pkg/model/signaled_block.go index ec3db401a..b603b6733 100644 --- a/pkg/model/signaled_block.go +++ b/pkg/model/signaled_block.go @@ -5,6 +5,7 @@ import ( "time" "github.com/iotaledger/hive.go/lo" + "github.com/iotaledger/hive.go/stringify" iotago "github.com/iotaledger/iota.go/v4" ) @@ -60,3 +61,12 @@ func SignaledBlockFromBytesFunc(decodeAPI iotago.API) func([]byte) (*SignaledBlo return signaledBlock, consumedBytes, nil } } + +func (s *SignaledBlock) String() string { + return stringify.Struct("SignaledBlock", + stringify.NewStructField("ID", s.ID), + stringify.NewStructField("IssuingTime", s.IssuingTime), + stringify.NewStructField("HighestSupportedVersion", s.HighestSupportedVersion), + stringify.NewStructField("ProtocolParametersHash", s.ProtocolParametersHash), + ) +} diff --git a/pkg/model/validator_performance.go b/pkg/model/validator_performance.go index d632123e8..94e81b70e 100644 --- a/pkg/model/validator_performance.go +++ b/pkg/model/validator_performance.go @@ -5,6 +5,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/serializer/v2/stream" + "github.com/iotaledger/hive.go/stringify" ) type ValidatorPerformance struct { @@ -66,3 +67,11 @@ func (p *ValidatorPerformance) Bytes() ([]byte, error) { return byteBuffer.Bytes() } + +func (p *ValidatorPerformance) String() string { + return stringify.Struct("ValidatorPerformance", + stringify.NewStructField("SlotActivityVector", p.SlotActivityVector), + stringify.NewStructField("BlocksIssuedCount", p.BlocksIssuedCount), + stringify.NewStructField("HighestSupportedVersionAndHash", p.HighestSupportedVersionAndHash), + ) +} diff --git a/pkg/model/version_and_hash.go b/pkg/model/version_and_hash.go index 3a8ab9a0f..ed92e67ac 100644 --- a/pkg/model/version_and_hash.go +++ b/pkg/model/version_and_hash.go @@ -4,6 +4,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/serializer/v2/byteutils" + "github.com/iotaledger/hive.go/stringify" iotago "github.com/iotaledger/iota.go/v4" ) @@ -32,3 +33,10 @@ func VersionAndHashFromBytes(bytes []byte) (VersionAndHash, int, error) { return VersionAndHash{version, hash}, versionBytesConsumed + hashBytesConsumed, nil } + +func (v VersionAndHash) String() string { + return stringify.Struct("VersionAndHash", + stringify.NewStructField("Version", v.Version), + stringify.NewStructField("Hash", v.Hash), + ) +} diff --git a/pkg/protocol/engine/accounts/accounts.go b/pkg/protocol/engine/accounts/accounts.go index 883f635c6..4bce7866a 100644 --- a/pkg/protocol/engine/accounts/accounts.go +++ b/pkg/protocol/engine/accounts/accounts.go @@ -6,6 +6,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/runtime/options" "github.com/iotaledger/hive.go/serializer/v2/stream" + "github.com/iotaledger/hive.go/stringify" "github.com/iotaledger/iota-core/pkg/model" iotago "github.com/iotaledger/iota.go/v4" ) @@ -165,6 +166,21 @@ func (a *AccountData) Bytes() ([]byte, error) { return byteBuffer.Bytes() } +func (a *AccountData) String() string { + return stringify.Struct("AccountData", + stringify.NewStructField("ID", a.ID), + stringify.NewStructField("Credits", a.Credits), + stringify.NewStructField("ExpirySlot", a.ExpirySlot), + stringify.NewStructField("OutputID", a.OutputID), + stringify.NewStructField("BlockIssuerKeys", a.BlockIssuerKeys), + stringify.NewStructField("ValidatorStake", a.ValidatorStake), + stringify.NewStructField("DelegationStake", a.DelegationStake), + stringify.NewStructField("FixedCost", a.FixedCost), + stringify.NewStructField("StakeEndEpoch", a.StakeEndEpoch), + stringify.NewStructField("LatestSupportedProtocolVersionAndHash", a.LatestSupportedProtocolVersionAndHash), + ) +} + func WithCredits(credits *BlockIssuanceCredits) options.Option[AccountData] { return func(a *AccountData) { a.Credits = credits diff --git a/pkg/protocol/engine/accounts/credits.go b/pkg/protocol/engine/accounts/credits.go index 3d04118c3..1850c8d89 100644 --- a/pkg/protocol/engine/accounts/credits.go +++ b/pkg/protocol/engine/accounts/credits.go @@ -4,6 +4,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/serializer/v2" "github.com/iotaledger/hive.go/serializer/v2/stream" + "github.com/iotaledger/hive.go/stringify" iotago "github.com/iotaledger/iota.go/v4" ) @@ -23,6 +24,13 @@ func NewBlockIssuanceCredits(value iotago.BlockIssuanceCredits, updateTime iotag } } +func (c *BlockIssuanceCredits) String() string { + return stringify.Struct("BlockIssuanceCredits", + stringify.NewStructField("Value", c.Value), + stringify.NewStructField("UpdateSlot", c.UpdateSlot), + ) +} + // Bytes returns a serialized version of the Credits. func (c *BlockIssuanceCredits) Bytes() ([]byte, error) { byteBuffer := stream.NewByteBuffer() diff --git a/pkg/protocol/engine/accounts/mana.go b/pkg/protocol/engine/accounts/mana.go index 05537009a..e72e121f4 100644 --- a/pkg/protocol/engine/accounts/mana.go +++ b/pkg/protocol/engine/accounts/mana.go @@ -2,6 +2,7 @@ package accounts import ( "github.com/iotaledger/hive.go/runtime/syncutils" + "github.com/iotaledger/hive.go/stringify" iotago "github.com/iotaledger/iota.go/v4" ) @@ -42,3 +43,14 @@ func (m *Mana) UpdateTime() iotago.SlotIndex { return m.updateTime } + +func (m *Mana) String() string { + m.mutex.RLock() + defer m.mutex.RUnlock() + + return stringify.Struct("Mana", + stringify.NewStructField("Value", m.value), + stringify.NewStructField("ExcessBaseTokens", m.excessBaseTokens), + stringify.NewStructField("UpdateTime", m.updateTime), + ) +} From bc05f4a52e43ec6f7de645d3a3da721f5efc981a Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 2 May 2024 16:52:38 +0200 Subject: [PATCH 2/5] Added debug logs when exporting/importing the account ledger and the performance stats --- .../accounts/accountsledger/snapshot.go | 6 +++++- .../sybilprotectionv1/performance/snapshot.go | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/protocol/engine/accounts/accountsledger/snapshot.go b/pkg/protocol/engine/accounts/accountsledger/snapshot.go index 5c26cb4c2..d729db9f5 100644 --- a/pkg/protocol/engine/accounts/accountsledger/snapshot.go +++ b/pkg/protocol/engine/accounts/accountsledger/snapshot.go @@ -27,7 +27,7 @@ func (m *Manager) Import(reader io.ReadSeeker) error { return ierrors.Wrapf(err, "unable to set account %s", accountData.ID) } - m.LogDebug("Imported account", "accountID", accountData.ID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot) + m.LogDebug("Imported account", "accountData", accountData) return nil }); err != nil { @@ -189,6 +189,8 @@ func (m *Manager) readSlotDiffs(reader io.ReadSeeker) error { accountDiff = model.NewAccountDiff() } + m.LogDebug("Imported account diff", "slot", slot, "accountID", accountID, "destroyed", destroyed, "accountDiff", accountDiff) + if err := diffStore.Store(accountID, accountDiff, destroyed); err != nil { return ierrors.Wrapf(err, "unable to store slot diff for accountID %s", accountID) } @@ -250,6 +252,8 @@ func (m *Manager) writeSlotDiffs(writer io.WriteSeeker, targetSlot iotago.SlotIn } } + m.LogDebug("Exported account diff", "slot", slot, "accountID", accountID, "destroyed", destroyed, "accountDiff", accountDiff) + accountsInDiffCount++ return true diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go index 3816c8c60..5113989a5 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go @@ -95,6 +95,8 @@ func (t *Tracker) importPerformanceFactor(reader io.ReadSeeker) error { return ierrors.Wrapf(err, "unable to store performance factor for account %s and slot index %d", accountID, slot) } + t.LogDebug("Importing performance factor", "accountID", accountID, "slot", slot, "performanceFactor", performanceFactor) + return nil }); err != nil { return ierrors.Wrapf(err, "unable to read performance factors for slot %d", slot) @@ -131,6 +133,8 @@ func (t *Tracker) importPoolRewards(reader io.ReadSeeker) error { return ierrors.Wrapf(err, "unable to read reward for account %s and epoch index %d", accountID, epoch) } + t.LogDebug("Importing reward", "accountID", accountID, "epoch", epoch, "reward", reward) + if err = rewardsTree.Set(accountID, reward); err != nil { return ierrors.Wrapf(err, "unable to set reward for account %s and epoch index %d", accountID, epoch) } @@ -168,6 +172,8 @@ func (t *Tracker) importPoolsStats(reader io.ReadSeeker) error { return ierrors.Wrapf(err, "unable to store pool stats for the epoch index %d", epoch) } + t.LogDebug("Importing pool stats", "epoch", epoch, "poolStats", poolStats) + return nil }); err != nil { return ierrors.Wrap(err, "unable to read pool stats collection") @@ -206,6 +212,8 @@ func (t *Tracker) importCommittees(reader io.ReadSeeker) error { committee.SetReused() } + t.LogDebug("Importing committee", "epoch", epoch, "committee", committee) + if err = t.committeeStore.Store(epoch, committee); err != nil { return ierrors.Wrap(err, "unable to store committee") } @@ -247,6 +255,8 @@ func (t *Tracker) exportPerformanceFactor(writer io.WriteSeeker, startSlot iotag return ierrors.Wrapf(err, "unable to write performance factor for accountID %s and slot index %d", accountID, currentSlot) } + t.LogDebug("Exporting performance factor", "accountID", accountID, "slot", currentSlot, "performanceFactor", pf) + accountsCount++ return nil @@ -292,9 +302,12 @@ func (t *Tracker) exportPoolRewards(writer io.WriteSeeker, targetEpoch iotago.Ep } // 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 err := stream.Write(writer, epoch); err != nil { return 0, ierrors.Wrapf(err, "unable to write epoch index for epoch index %d", epoch) } @@ -311,6 +324,8 @@ func (t *Tracker) exportPoolRewards(writer io.WriteSeeker, targetEpoch iotago.Ep 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) + accountCount++ return nil @@ -347,6 +362,7 @@ func (t *Tracker) exportPoolsStats(writer io.WriteSeeker, targetEpoch iotago.Epo if epoch > targetEpoch { // continue + t.LogDebug("Skipping epoch", "epoch", epoch, "reason", "epoch is greater than target epoch") return nil } @@ -358,6 +374,8 @@ func (t *Tracker) exportPoolsStats(writer io.WriteSeeker, targetEpoch iotago.Epo return ierrors.Wrapf(err, "unable to write pools stats for epoch %d", epoch) } + t.LogDebug("Exporting Pool Stats", "epoch", epoch, "poolStats", lo.Return1(model.PoolsStatsFromBytes(value))) + epochCount++ return nil @@ -399,6 +417,7 @@ func (t *Tracker) exportCommittees(writer io.WriteSeeker, targetSlot iotago.Slot // - we were able to rotate a committee, then we export it // - we were not able to rotate a committee (reused), then we don't export it if epoch > epochFromTargetSlot && targetSlot < pointOfNoReturn && committee.IsReused() { + t.LogDebug("Skipping committee", "epoch", epoch, "reason", "epoch is greater than target epoch and committee is reused") return nil } @@ -427,6 +446,8 @@ func (t *Tracker) exportCommittees(writer io.WriteSeeker, targetSlot iotago.Slot return ierrors.Wrapf(err, "unable to write reused flag for epoch %d", epoch) } + t.LogDebug("Exporting committee", "epoch", epoch, "committee", committee) + epochCount++ return nil From f8ee06f019ea47f34315d9bd218ecb9aad453a95 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 2 May 2024 16:53:05 +0200 Subject: [PATCH 3/5] Expose the AccountRoot and RewardsRoot and print them on engine start --- pkg/protocol/engine/engine.go | 12 ++++++++++++ pkg/protocol/engine/ledger/ledger.go | 2 ++ pkg/protocol/engine/ledger/ledger/ledger.go | 4 ++++ pkg/protocol/sybilprotection/sybilprotection.go | 2 ++ .../sybilprotectionv1/performance/rewards.go | 12 +++++++++++- .../sybilprotectionv1/sybilprotection.go | 4 ++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pkg/protocol/engine/engine.go b/pkg/protocol/engine/engine.go index 4865f8810..ca993ed0c 100644 --- a/pkg/protocol/engine/engine.go +++ b/pkg/protocol/engine/engine.go @@ -253,6 +253,18 @@ func New( e.InitializedEvent().Trigger() e.LogTrace("initialized", "settings", e.Storage.Settings().String()) + + latestCommitment := e.Storage.Settings().LatestCommitment() + e.LogInfo("LatestCommitment", "slot", latestCommitment.Slot(), "ID", latestCommitment.ID()) + e.LogInfo("Ledger state", "AccountRoot", e.Ledger.AccountRoot(), "latestCommitment.Slot", latestCommitment.Slot()) + + currentEpoch := e.CommittedAPI().TimeProvider().EpochFromSlot(latestCommitment.Slot()) + e.LogInfo("Rewards state", "RewardsRoot", lo.PanicOnErr(e.SybilProtection.RewardsRoot(currentEpoch)), "epoch", currentEpoch, "latestCommitment.Slot", latestCommitment.Slot()) + + if currentEpoch > 0 { + prevEpoch := currentEpoch - 1 + e.LogInfo("Rewards state", "RewardsRoot", lo.PanicOnErr(e.SybilProtection.RewardsRoot(prevEpoch)), "epoch", prevEpoch, "lastSlot", e.CommittedAPI().TimeProvider().EpochEnd(prevEpoch)) + } }, ) } diff --git a/pkg/protocol/engine/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger.go index f49a72e18..a4d843f07 100644 --- a/pkg/protocol/engine/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger.go @@ -43,6 +43,8 @@ type Ledger interface { Export(writer io.WriteSeeker, targetSlot iotago.SlotIndex) error TrackBlock(block *blocks.Block) + AccountRoot() iotago.Identifier + // Reset resets the component to a clean state as if it was created at the last commitment. Reset() diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index bb9b72f4b..98a81a6ca 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -221,6 +221,10 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier, return stateTreeRoot, stateDiff.Mutations().Root(), l.accountsLedger.AccountsTreeRoot(), outputs, spenders, mutations, nil } +func (l *Ledger) AccountRoot() iotago.Identifier { + return l.accountsLedger.AccountsTreeRoot() +} + func (l *Ledger) AddAccount(output *utxoledger.Output, blockIssuanceCredits iotago.BlockIssuanceCredits) error { return l.accountsLedger.AddAccount(output, blockIssuanceCredits) } diff --git a/pkg/protocol/sybilprotection/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotection.go index 731e65b38..9ede46edd 100644 --- a/pkg/protocol/sybilprotection/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotection.go @@ -39,5 +39,7 @@ type SybilProtection interface { // Reset resets the component to a clean state as if it was created at the last commitment. Reset() + RewardsRoot(epoch iotago.EpochIndex) (rewardsRoot iotago.Identifier, err error) + module.Module } diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go index ba3857281..4d16fc7c4 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go @@ -18,7 +18,17 @@ func (t *Tracker) RewardsRoot(epoch iotago.EpochIndex) (iotago.Identifier, error return iotago.Identifier{}, err } - return m.Root(), nil + root := m.Root() + + t.LogDebug("RewardsRoot", "epoch", epoch, "root", root, "WasRestoredFromStorage", m.WasRestoredFromStorage()) + if err := m.Stream(func(accountID iotago.AccountID, poolRewards *model.PoolRewards) error { + t.LogDebug("RewardsRoot", "accountID", accountID, "poolRewards", poolRewards) + return nil + }); err != nil { + panic(err) + } + + return root, nil } func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakingFeature *iotago.StakingFeature, claimingEpoch iotago.EpochIndex) (validatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) { diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index d5fbe9bfa..fe766d8fd 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -225,6 +225,10 @@ func (o *SybilProtection) CommitSlot(slot iotago.SlotIndex) (committeeRoot iotag return committeeRoot, rewardsRoot, nil } +func (o *SybilProtection) RewardsRoot(epoch iotago.EpochIndex) (rewardsRoot iotago.Identifier, err error) { + return o.performanceTracker.RewardsRoot(epoch) +} + func (o *SybilProtection) committeeRoot(targetCommitteeEpoch iotago.EpochIndex) (committeeRoot iotago.Identifier, err error) { committee, exists := o.performanceTracker.LoadCommitteeForEpoch(targetCommitteeEpoch) if !exists { From 1ff32343229ec80a02b2cb8eebd6e43a3df24f88 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 2 May 2024 17:03:30 +0200 Subject: [PATCH 4/5] Cast uint types so that stringify works --- pkg/model/account_diff.go | 8 ++++---- pkg/model/poolstats.go | 10 +++++----- pkg/model/version_and_hash.go | 2 +- pkg/protocol/engine/accounts/accounts.go | 10 +++++----- pkg/protocol/engine/accounts/credits.go | 4 ++-- pkg/protocol/engine/accounts/mana.go | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/model/account_diff.go b/pkg/model/account_diff.go index 9b13863eb..f07ad0a03 100644 --- a/pkg/model/account_diff.go +++ b/pkg/model/account_diff.go @@ -77,10 +77,10 @@ func (d *AccountDiff) Clone() *AccountDiff { func (d *AccountDiff) String() string { builder := stringify.NewStructBuilder("AccountDiff") - builder.AddField(stringify.NewStructField("BICChange", d.BICChange)) - builder.AddField(stringify.NewStructField("PreviousUpdatedSlot", d.PreviousUpdatedSlot)) - builder.AddField(stringify.NewStructField("NewExpirySlot", d.NewExpirySlot)) - builder.AddField(stringify.NewStructField("PreviousExpirySlot", d.PreviousExpirySlot)) + builder.AddField(stringify.NewStructField("BICChange", int64(d.BICChange))) + builder.AddField(stringify.NewStructField("PreviousUpdatedSlot", uint32(d.PreviousUpdatedSlot))) + builder.AddField(stringify.NewStructField("NewExpirySlot", uint32(d.NewExpirySlot))) + builder.AddField(stringify.NewStructField("PreviousExpirySlot", uint32(d.PreviousExpirySlot))) builder.AddField(stringify.NewStructField("NewOutputID", d.NewOutputID)) builder.AddField(stringify.NewStructField("PreviousOutputID", d.PreviousOutputID)) builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", d.BlockIssuerKeysAdded)) diff --git a/pkg/model/poolstats.go b/pkg/model/poolstats.go index 50ca3965d..52b773ede 100644 --- a/pkg/model/poolstats.go +++ b/pkg/model/poolstats.go @@ -62,8 +62,8 @@ func (p *PoolsStats) Bytes() ([]byte, error) { func (p *PoolsStats) String() string { return stringify.Struct("PoolsStats", - stringify.NewStructField("TotalStake", p.TotalStake), - stringify.NewStructField("TotalValidatorStake", p.TotalValidatorStake), + stringify.NewStructField("TotalStake", uint64(p.TotalStake)), + stringify.NewStructField("TotalValidatorStake", uint64(p.TotalValidatorStake)), stringify.NewStructField("ProfitMargin", p.ProfitMargin), ) } @@ -123,8 +123,8 @@ func (p *PoolRewards) Bytes() ([]byte, error) { func (p *PoolRewards) String() string { return stringify.Struct("PoolRewards", - stringify.NewStructField("PoolStake", p.PoolStake), - stringify.NewStructField("PoolRewards", p.PoolRewards), - stringify.NewStructField("FixedCost", p.FixedCost), + stringify.NewStructField("PoolStake", uint64(p.PoolStake)), + stringify.NewStructField("PoolRewards", uint64(p.PoolRewards)), + stringify.NewStructField("FixedCost", uint64(p.FixedCost)), ) } diff --git a/pkg/model/version_and_hash.go b/pkg/model/version_and_hash.go index ed92e67ac..944e0e24b 100644 --- a/pkg/model/version_and_hash.go +++ b/pkg/model/version_and_hash.go @@ -36,7 +36,7 @@ func VersionAndHashFromBytes(bytes []byte) (VersionAndHash, int, error) { func (v VersionAndHash) String() string { return stringify.Struct("VersionAndHash", - stringify.NewStructField("Version", v.Version), + stringify.NewStructField("Version", byte(v.Version)), stringify.NewStructField("Hash", v.Hash), ) } diff --git a/pkg/protocol/engine/accounts/accounts.go b/pkg/protocol/engine/accounts/accounts.go index 4bce7866a..d57288821 100644 --- a/pkg/protocol/engine/accounts/accounts.go +++ b/pkg/protocol/engine/accounts/accounts.go @@ -170,13 +170,13 @@ func (a *AccountData) String() string { return stringify.Struct("AccountData", stringify.NewStructField("ID", a.ID), stringify.NewStructField("Credits", a.Credits), - stringify.NewStructField("ExpirySlot", a.ExpirySlot), + stringify.NewStructField("ExpirySlot", uint32(a.ExpirySlot)), stringify.NewStructField("OutputID", a.OutputID), stringify.NewStructField("BlockIssuerKeys", a.BlockIssuerKeys), - stringify.NewStructField("ValidatorStake", a.ValidatorStake), - stringify.NewStructField("DelegationStake", a.DelegationStake), - stringify.NewStructField("FixedCost", a.FixedCost), - stringify.NewStructField("StakeEndEpoch", a.StakeEndEpoch), + stringify.NewStructField("ValidatorStake", uint64(a.ValidatorStake)), + stringify.NewStructField("DelegationStake", uint64(a.DelegationStake)), + stringify.NewStructField("FixedCost", uint64(a.FixedCost)), + stringify.NewStructField("StakeEndEpoch", uint64(a.StakeEndEpoch)), stringify.NewStructField("LatestSupportedProtocolVersionAndHash", a.LatestSupportedProtocolVersionAndHash), ) } diff --git a/pkg/protocol/engine/accounts/credits.go b/pkg/protocol/engine/accounts/credits.go index 1850c8d89..90c6cd11b 100644 --- a/pkg/protocol/engine/accounts/credits.go +++ b/pkg/protocol/engine/accounts/credits.go @@ -26,8 +26,8 @@ func NewBlockIssuanceCredits(value iotago.BlockIssuanceCredits, updateTime iotag func (c *BlockIssuanceCredits) String() string { return stringify.Struct("BlockIssuanceCredits", - stringify.NewStructField("Value", c.Value), - stringify.NewStructField("UpdateSlot", c.UpdateSlot), + stringify.NewStructField("Value", int64(c.Value)), + stringify.NewStructField("UpdateSlot", uint32(c.UpdateSlot)), ) } diff --git a/pkg/protocol/engine/accounts/mana.go b/pkg/protocol/engine/accounts/mana.go index e72e121f4..13a01425a 100644 --- a/pkg/protocol/engine/accounts/mana.go +++ b/pkg/protocol/engine/accounts/mana.go @@ -49,8 +49,8 @@ func (m *Mana) String() string { defer m.mutex.RUnlock() return stringify.Struct("Mana", - stringify.NewStructField("Value", m.value), - stringify.NewStructField("ExcessBaseTokens", m.excessBaseTokens), - stringify.NewStructField("UpdateTime", m.updateTime), + stringify.NewStructField("Value", uint64(m.value)), + stringify.NewStructField("ExcessBaseTokens", uint64(m.excessBaseTokens)), + stringify.NewStructField("UpdateTime", uint32(m.updateTime)), ) } From 8994615d41807a03e0649141111632bd6c9eaeff Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 2 May 2024 17:11:55 +0200 Subject: [PATCH 5/5] Better logs for RewardsRoot --- .../sybilprotectionv1/performance/rewards.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go index 4d16fc7c4..0e34abc8c 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go @@ -1,10 +1,13 @@ package performance import ( + "fmt" + "github.com/iotaledger/hive.go/ads" "github.com/iotaledger/hive.go/core/safemath" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" + "github.com/iotaledger/hive.go/stringify" "github.com/iotaledger/iota-core/pkg/model" iotago "github.com/iotaledger/iota.go/v4" ) @@ -20,14 +23,20 @@ func (t *Tracker) RewardsRoot(epoch iotago.EpochIndex) (iotago.Identifier, error root := m.Root() - t.LogDebug("RewardsRoot", "epoch", epoch, "root", root, "WasRestoredFromStorage", m.WasRestoredFromStorage()) + builder := stringify.NewStructBuilder("RewardsRoot") + builder.AddField(stringify.NewStructField("Root", root)) + builder.AddField(stringify.NewStructField("WasRestoredFromStorage", m.WasRestoredFromStorage())) + if err := m.Stream(func(accountID iotago.AccountID, poolRewards *model.PoolRewards) error { - t.LogDebug("RewardsRoot", "accountID", accountID, "poolRewards", poolRewards) + builder.AddField(stringify.NewStructField(fmt.Sprintf("account[%s]", accountID.String()), poolRewards)) + return nil }); err != nil { panic(err) } + t.LogDebug("RewardsRoot", "epoch", epoch, "rewardsMap", builder) + return root, nil }