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

Commit f8ee06f

Browse files
committed
Expose the AccountRoot and RewardsRoot and print them on engine start
1 parent bc05f4a commit f8ee06f

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ func (t *Tracker) RewardsRoot(epoch iotago.EpochIndex) (iotago.Identifier, error
1818
return iotago.Identifier{}, err
1919
}
2020

21-
return m.Root(), nil
21+
root := m.Root()
22+
23+
t.LogDebug("RewardsRoot", "epoch", epoch, "root", root, "WasRestoredFromStorage", m.WasRestoredFromStorage())
24+
if err := m.Stream(func(accountID iotago.AccountID, poolRewards *model.PoolRewards) error {
25+
t.LogDebug("RewardsRoot", "accountID", accountID, "poolRewards", poolRewards)
26+
return nil
27+
}); err != nil {
28+
panic(err)
29+
}
30+
31+
return root, nil
2232
}
2333

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

pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ func (o *SybilProtection) CommitSlot(slot iotago.SlotIndex) (committeeRoot iotag
225225
return committeeRoot, rewardsRoot, nil
226226
}
227227

228+
func (o *SybilProtection) RewardsRoot(epoch iotago.EpochIndex) (rewardsRoot iotago.Identifier, err error) {
229+
return o.performanceTracker.RewardsRoot(epoch)
230+
}
231+
228232
func (o *SybilProtection) committeeRoot(targetCommitteeEpoch iotago.EpochIndex) (committeeRoot iotago.Identifier, err error) {
229233
committee, exists := o.performanceTracker.LoadCommitteeForEpoch(targetCommitteeEpoch)
230234
if !exists {

0 commit comments

Comments
 (0)