Skip to content

Commit f9fbae2

Browse files
authored
telemetry: add CatchpointRootUpdateEvent (#4704)
1 parent 260e226 commit f9fbae2

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

ledger/catchpointtracker.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (ct *catchpointTracker) commitRound(ctx context.Context, tx *sql.Tx, dcc *d
532532
dcc.stats.MerkleTrieUpdateDuration = time.Duration(time.Now().UnixNano())
533533
}
534534

535-
err = ct.accountsUpdateBalances(dcc.compactAccountDeltas, dcc.compactResourcesDeltas, dcc.compactKvDeltas)
535+
err = ct.accountsUpdateBalances(dcc.compactAccountDeltas, dcc.compactResourcesDeltas, dcc.compactKvDeltas, dcc.oldBase, dcc.newBase)
536536
if err != nil {
537537
return err
538538
}
@@ -928,7 +928,7 @@ func (ct *catchpointTracker) close() {
928928
}
929929

930930
// accountsUpdateBalances applies the given compactAccountDeltas to the merkle trie
931-
func (ct *catchpointTracker) accountsUpdateBalances(accountsDeltas compactAccountDeltas, resourcesDeltas compactResourcesDeltas, kvDeltas map[string]modifiedKvValue) (err error) {
931+
func (ct *catchpointTracker) accountsUpdateBalances(accountsDeltas compactAccountDeltas, resourcesDeltas compactResourcesDeltas, kvDeltas map[string]modifiedKvValue, oldBase basics.Round, newBase basics.Round) (err error) {
932932
if !ct.catchpointEnabled() {
933933
return nil
934934
}
@@ -1045,10 +1045,32 @@ func (ct *catchpointTracker) accountsUpdateBalances(accountsDeltas compactAccoun
10451045
}
10461046

10471047
// write it all to disk.
1048+
var cstats merkletrie.CommitStats
10481049
if accumulatedChanges > 0 {
1049-
_, err = ct.balancesTrie.Commit()
1050+
cstats, err = ct.balancesTrie.Commit()
10501051
}
10511052

1053+
if ct.log.GetTelemetryEnabled() {
1054+
root, rootErr := ct.balancesTrie.RootHash()
1055+
if rootErr != nil {
1056+
ct.log.Infof("accountsUpdateBalances: error retrieving balances trie root: %v", rootErr)
1057+
return
1058+
}
1059+
ct.log.EventWithDetails(telemetryspec.Accounts, telemetryspec.CatchpointRootUpdateEvent, telemetryspec.CatchpointRootUpdateEventDetails{
1060+
Root: root.String(),
1061+
OldBase: uint64(oldBase),
1062+
NewBase: uint64(newBase),
1063+
NewPageCount: cstats.NewPageCount,
1064+
NewNodeCount: cstats.NewNodeCount,
1065+
UpdatedPageCount: cstats.UpdatedPageCount,
1066+
UpdatedNodeCount: cstats.UpdatedNodeCount,
1067+
DeletedPageCount: cstats.DeletedPageCount,
1068+
FanoutReallocatedNodeCount: cstats.FanoutReallocatedNodeCount,
1069+
PackingReallocatedNodeCount: cstats.PackingReallocatedNodeCount,
1070+
LoadedPages: cstats.LoadedPages,
1071+
})
1072+
1073+
}
10521074
return
10531075
}
10541076

logging/telemetryspec/event.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ type CatchpointGenerationEventDetails struct {
327327
CatchpointLabel string
328328
}
329329

330+
// CatchpointRootUpdateEvent event
331+
const CatchpointRootUpdateEvent Event = "CatchpointRoot"
332+
333+
// CatchpointRootUpdateEventDetails is generated when the catchpoint merkle trie root is updated, when
334+
// account updates for rounds are flushed to disk.
335+
type CatchpointRootUpdateEventDetails struct {
336+
Root string
337+
OldBase uint64
338+
NewBase uint64
339+
NewPageCount int `json:"npc"`
340+
NewNodeCount int `json:"nnc"`
341+
UpdatedPageCount int `json:"upc"`
342+
UpdatedNodeCount int `json:"unc"`
343+
DeletedPageCount int `json:"dpc"`
344+
FanoutReallocatedNodeCount int `json:"frnc"`
345+
PackingReallocatedNodeCount int `json:"prnc"`
346+
LoadedPages int `json:"lp"`
347+
}
348+
330349
// BalancesAccountVacuumEvent event
331350
const BalancesAccountVacuumEvent Event = "VacuumBalances"
332351

0 commit comments

Comments
 (0)