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

Commit b28efc9

Browse files
authored
Merge pull request #955 from iotaledger/feat/import-export-logs
Better Snapshot Import/Export debug logs
2 parents 5690ffe + 8994615 commit b28efc9

File tree

16 files changed

+171
-2
lines changed

16 files changed

+171
-2
lines changed

pkg/model/account_diff.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/iotaledger/hive.go/ierrors"
77
"github.com/iotaledger/hive.go/lo"
88
"github.com/iotaledger/hive.go/serializer/v2/stream"
9+
"github.com/iotaledger/hive.go/stringify"
910
iotago "github.com/iotaledger/iota.go/v4"
1011
)
1112

@@ -74,6 +75,26 @@ func (d *AccountDiff) Clone() *AccountDiff {
7475
}
7576
}
7677

78+
func (d *AccountDiff) String() string {
79+
builder := stringify.NewStructBuilder("AccountDiff")
80+
builder.AddField(stringify.NewStructField("BICChange", int64(d.BICChange)))
81+
builder.AddField(stringify.NewStructField("PreviousUpdatedSlot", uint32(d.PreviousUpdatedSlot)))
82+
builder.AddField(stringify.NewStructField("NewExpirySlot", uint32(d.NewExpirySlot)))
83+
builder.AddField(stringify.NewStructField("PreviousExpirySlot", uint32(d.PreviousExpirySlot)))
84+
builder.AddField(stringify.NewStructField("NewOutputID", d.NewOutputID))
85+
builder.AddField(stringify.NewStructField("PreviousOutputID", d.PreviousOutputID))
86+
builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", d.BlockIssuerKeysAdded))
87+
builder.AddField(stringify.NewStructField("BlockIssuerKeysRemoved", d.BlockIssuerKeysRemoved))
88+
builder.AddField(stringify.NewStructField("ValidatorStakeChange", d.ValidatorStakeChange))
89+
builder.AddField(stringify.NewStructField("DelegationStakeChange", d.DelegationStakeChange))
90+
builder.AddField(stringify.NewStructField("FixedCostChange", d.FixedCostChange))
91+
builder.AddField(stringify.NewStructField("StakeEndEpochChange", d.StakeEndEpochChange))
92+
builder.AddField(stringify.NewStructField("NewLatestSupportedVersionAndHash", d.NewLatestSupportedVersionAndHash))
93+
builder.AddField(stringify.NewStructField("PrevLatestSupportedVersionAndHash", d.PrevLatestSupportedVersionAndHash))
94+
95+
return builder.String()
96+
}
97+
7798
func (d *AccountDiff) Bytes() ([]byte, error) {
7899
byteBuffer := stream.NewByteBuffer()
79100

pkg/model/poolstats.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/iotaledger/hive.go/ierrors"
77
"github.com/iotaledger/hive.go/serializer/v2/stream"
8+
"github.com/iotaledger/hive.go/stringify"
89
iotago "github.com/iotaledger/iota.go/v4"
910
)
1011

@@ -59,6 +60,14 @@ func (p *PoolsStats) Bytes() ([]byte, error) {
5960
return byteBuffer.Bytes()
6061
}
6162

63+
func (p *PoolsStats) String() string {
64+
return stringify.Struct("PoolsStats",
65+
stringify.NewStructField("TotalStake", uint64(p.TotalStake)),
66+
stringify.NewStructField("TotalValidatorStake", uint64(p.TotalValidatorStake)),
67+
stringify.NewStructField("ProfitMargin", p.ProfitMargin),
68+
)
69+
}
70+
6271
type PoolRewards struct {
6372
// Total stake of the validator including delegations
6473
PoolStake iotago.BaseToken
@@ -111,3 +120,11 @@ func (p *PoolRewards) Bytes() ([]byte, error) {
111120

112121
return byteBuffer.Bytes()
113122
}
123+
124+
func (p *PoolRewards) String() string {
125+
return stringify.Struct("PoolRewards",
126+
stringify.NewStructField("PoolStake", uint64(p.PoolStake)),
127+
stringify.NewStructField("PoolRewards", uint64(p.PoolRewards)),
128+
stringify.NewStructField("FixedCost", uint64(p.FixedCost)),
129+
)
130+
}

pkg/model/signaled_block.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/iotaledger/hive.go/lo"
8+
"github.com/iotaledger/hive.go/stringify"
89
iotago "github.com/iotaledger/iota.go/v4"
910
)
1011

@@ -60,3 +61,12 @@ func SignaledBlockFromBytesFunc(decodeAPI iotago.API) func([]byte) (*SignaledBlo
6061
return signaledBlock, consumedBytes, nil
6162
}
6263
}
64+
65+
func (s *SignaledBlock) String() string {
66+
return stringify.Struct("SignaledBlock",
67+
stringify.NewStructField("ID", s.ID),
68+
stringify.NewStructField("IssuingTime", s.IssuingTime),
69+
stringify.NewStructField("HighestSupportedVersion", s.HighestSupportedVersion),
70+
stringify.NewStructField("ProtocolParametersHash", s.ProtocolParametersHash),
71+
)
72+
}

pkg/model/validator_performance.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/iotaledger/hive.go/ierrors"
77
"github.com/iotaledger/hive.go/serializer/v2/stream"
8+
"github.com/iotaledger/hive.go/stringify"
89
)
910

1011
type ValidatorPerformance struct {
@@ -66,3 +67,11 @@ func (p *ValidatorPerformance) Bytes() ([]byte, error) {
6667

6768
return byteBuffer.Bytes()
6869
}
70+
71+
func (p *ValidatorPerformance) String() string {
72+
return stringify.Struct("ValidatorPerformance",
73+
stringify.NewStructField("SlotActivityVector", p.SlotActivityVector),
74+
stringify.NewStructField("BlocksIssuedCount", p.BlocksIssuedCount),
75+
stringify.NewStructField("HighestSupportedVersionAndHash", p.HighestSupportedVersionAndHash),
76+
)
77+
}

pkg/model/version_and_hash.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/iotaledger/hive.go/ierrors"
55
"github.com/iotaledger/hive.go/lo"
66
"github.com/iotaledger/hive.go/serializer/v2/byteutils"
7+
"github.com/iotaledger/hive.go/stringify"
78
iotago "github.com/iotaledger/iota.go/v4"
89
)
910

@@ -32,3 +33,10 @@ func VersionAndHashFromBytes(bytes []byte) (VersionAndHash, int, error) {
3233

3334
return VersionAndHash{version, hash}, versionBytesConsumed + hashBytesConsumed, nil
3435
}
36+
37+
func (v VersionAndHash) String() string {
38+
return stringify.Struct("VersionAndHash",
39+
stringify.NewStructField("Version", byte(v.Version)),
40+
stringify.NewStructField("Hash", v.Hash),
41+
)
42+
}

pkg/protocol/engine/accounts/accounts.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/iotaledger/hive.go/ierrors"
77
"github.com/iotaledger/hive.go/runtime/options"
88
"github.com/iotaledger/hive.go/serializer/v2/stream"
9+
"github.com/iotaledger/hive.go/stringify"
910
"github.com/iotaledger/iota-core/pkg/model"
1011
iotago "github.com/iotaledger/iota.go/v4"
1112
)
@@ -165,6 +166,21 @@ func (a *AccountData) Bytes() ([]byte, error) {
165166
return byteBuffer.Bytes()
166167
}
167168

169+
func (a *AccountData) String() string {
170+
return stringify.Struct("AccountData",
171+
stringify.NewStructField("ID", a.ID),
172+
stringify.NewStructField("Credits", a.Credits),
173+
stringify.NewStructField("ExpirySlot", uint32(a.ExpirySlot)),
174+
stringify.NewStructField("OutputID", a.OutputID),
175+
stringify.NewStructField("BlockIssuerKeys", a.BlockIssuerKeys),
176+
stringify.NewStructField("ValidatorStake", uint64(a.ValidatorStake)),
177+
stringify.NewStructField("DelegationStake", uint64(a.DelegationStake)),
178+
stringify.NewStructField("FixedCost", uint64(a.FixedCost)),
179+
stringify.NewStructField("StakeEndEpoch", uint64(a.StakeEndEpoch)),
180+
stringify.NewStructField("LatestSupportedProtocolVersionAndHash", a.LatestSupportedProtocolVersionAndHash),
181+
)
182+
}
183+
168184
func WithCredits(credits *BlockIssuanceCredits) options.Option[AccountData] {
169185
return func(a *AccountData) {
170186
a.Credits = credits

pkg/protocol/engine/accounts/accountsledger/snapshot.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (m *Manager) Import(reader io.ReadSeeker) error {
2727
return ierrors.Wrapf(err, "unable to set account %s", accountData.ID)
2828
}
2929

30-
m.LogDebug("Imported account", "accountID", accountData.ID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot)
30+
m.LogDebug("Imported account", "accountData", accountData)
3131

3232
return nil
3333
}); err != nil {
@@ -189,6 +189,8 @@ func (m *Manager) readSlotDiffs(reader io.ReadSeeker) error {
189189
accountDiff = model.NewAccountDiff()
190190
}
191191

192+
m.LogDebug("Imported account diff", "slot", slot, "accountID", accountID, "destroyed", destroyed, "accountDiff", accountDiff)
193+
192194
if err := diffStore.Store(accountID, accountDiff, destroyed); err != nil {
193195
return ierrors.Wrapf(err, "unable to store slot diff for accountID %s", accountID)
194196
}
@@ -250,6 +252,8 @@ func (m *Manager) writeSlotDiffs(writer io.WriteSeeker, targetSlot iotago.SlotIn
250252
}
251253
}
252254

255+
m.LogDebug("Exported account diff", "slot", slot, "accountID", accountID, "destroyed", destroyed, "accountDiff", accountDiff)
256+
253257
accountsInDiffCount++
254258

255259
return true

pkg/protocol/engine/accounts/credits.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/iotaledger/hive.go/ierrors"
55
"github.com/iotaledger/hive.go/serializer/v2"
66
"github.com/iotaledger/hive.go/serializer/v2/stream"
7+
"github.com/iotaledger/hive.go/stringify"
78
iotago "github.com/iotaledger/iota.go/v4"
89
)
910

@@ -23,6 +24,13 @@ func NewBlockIssuanceCredits(value iotago.BlockIssuanceCredits, updateTime iotag
2324
}
2425
}
2526

27+
func (c *BlockIssuanceCredits) String() string {
28+
return stringify.Struct("BlockIssuanceCredits",
29+
stringify.NewStructField("Value", int64(c.Value)),
30+
stringify.NewStructField("UpdateSlot", uint32(c.UpdateSlot)),
31+
)
32+
}
33+
2634
// Bytes returns a serialized version of the Credits.
2735
func (c *BlockIssuanceCredits) Bytes() ([]byte, error) {
2836
byteBuffer := stream.NewByteBuffer()

pkg/protocol/engine/accounts/mana.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package accounts
22

33
import (
44
"github.com/iotaledger/hive.go/runtime/syncutils"
5+
"github.com/iotaledger/hive.go/stringify"
56
iotago "github.com/iotaledger/iota.go/v4"
67
)
78

@@ -42,3 +43,14 @@ func (m *Mana) UpdateTime() iotago.SlotIndex {
4243

4344
return m.updateTime
4445
}
46+
47+
func (m *Mana) String() string {
48+
m.mutex.RLock()
49+
defer m.mutex.RUnlock()
50+
51+
return stringify.Struct("Mana",
52+
stringify.NewStructField("Value", uint64(m.value)),
53+
stringify.NewStructField("ExcessBaseTokens", uint64(m.excessBaseTokens)),
54+
stringify.NewStructField("UpdateTime", uint32(m.updateTime)),
55+
)
56+
}

pkg/protocol/engine/engine.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ func New(
253253
e.InitializedEvent().Trigger()
254254

255255
e.LogTrace("initialized", "settings", e.Storage.Settings().String())
256+
257+
latestCommitment := e.Storage.Settings().LatestCommitment()
258+
e.LogInfo("LatestCommitment", "slot", latestCommitment.Slot(), "ID", latestCommitment.ID())
259+
e.LogInfo("Ledger state", "AccountRoot", e.Ledger.AccountRoot(), "latestCommitment.Slot", latestCommitment.Slot())
260+
261+
currentEpoch := e.CommittedAPI().TimeProvider().EpochFromSlot(latestCommitment.Slot())
262+
e.LogInfo("Rewards state", "RewardsRoot", lo.PanicOnErr(e.SybilProtection.RewardsRoot(currentEpoch)), "epoch", currentEpoch, "latestCommitment.Slot", latestCommitment.Slot())
263+
264+
if currentEpoch > 0 {
265+
prevEpoch := currentEpoch - 1
266+
e.LogInfo("Rewards state", "RewardsRoot", lo.PanicOnErr(e.SybilProtection.RewardsRoot(prevEpoch)), "epoch", prevEpoch, "lastSlot", e.CommittedAPI().TimeProvider().EpochEnd(prevEpoch))
267+
}
256268
},
257269
)
258270
}

pkg/protocol/engine/ledger/ledger.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type Ledger interface {
4343
Export(writer io.WriteSeeker, targetSlot iotago.SlotIndex) error
4444
TrackBlock(block *blocks.Block)
4545

46+
AccountRoot() iotago.Identifier
47+
4648
// Reset resets the component to a clean state as if it was created at the last commitment.
4749
Reset()
4850

pkg/protocol/engine/ledger/ledger/ledger.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier,
221221
return stateTreeRoot, stateDiff.Mutations().Root(), l.accountsLedger.AccountsTreeRoot(), outputs, spenders, mutations, nil
222222
}
223223

224+
func (l *Ledger) AccountRoot() iotago.Identifier {
225+
return l.accountsLedger.AccountsTreeRoot()
226+
}
227+
224228
func (l *Ledger) AddAccount(output *utxoledger.Output, blockIssuanceCredits iotago.BlockIssuanceCredits) error {
225229
return l.accountsLedger.AddAccount(output, blockIssuanceCredits)
226230
}

pkg/protocol/sybilprotection/sybilprotection.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ type SybilProtection interface {
3939
// Reset resets the component to a clean state as if it was created at the last commitment.
4040
Reset()
4141

42+
RewardsRoot(epoch iotago.EpochIndex) (rewardsRoot iotago.Identifier, err error)
43+
4244
module.Module
4345
}

pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package performance
22

33
import (
4+
"fmt"
5+
46
"github.com/iotaledger/hive.go/ads"
57
"github.com/iotaledger/hive.go/core/safemath"
68
"github.com/iotaledger/hive.go/ierrors"
79
"github.com/iotaledger/hive.go/lo"
10+
"github.com/iotaledger/hive.go/stringify"
811
"github.com/iotaledger/iota-core/pkg/model"
912
iotago "github.com/iotaledger/iota.go/v4"
1013
)
@@ -18,7 +21,23 @@ func (t *Tracker) RewardsRoot(epoch iotago.EpochIndex) (iotago.Identifier, error
1821
return iotago.Identifier{}, err
1922
}
2023

21-
return m.Root(), nil
24+
root := m.Root()
25+
26+
builder := stringify.NewStructBuilder("RewardsRoot")
27+
builder.AddField(stringify.NewStructField("Root", root))
28+
builder.AddField(stringify.NewStructField("WasRestoredFromStorage", m.WasRestoredFromStorage()))
29+
30+
if err := m.Stream(func(accountID iotago.AccountID, poolRewards *model.PoolRewards) error {
31+
builder.AddField(stringify.NewStructField(fmt.Sprintf("account[%s]", accountID.String()), poolRewards))
32+
33+
return nil
34+
}); err != nil {
35+
panic(err)
36+
}
37+
38+
t.LogDebug("RewardsRoot", "epoch", epoch, "rewardsMap", builder)
39+
40+
return root, nil
2241
}
2342

2443
func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakingFeature *iotago.StakingFeature, claimingEpoch iotago.EpochIndex) (validatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) {

0 commit comments

Comments
 (0)