@@ -141,16 +141,15 @@ func (g *StateSizeGenerator) generate() {
141
141
142
142
// initialize starts the initialization process if not already initialized
143
143
func (g * StateSizeGenerator ) initialize () chan struct {} {
144
- initDone := make (chan struct {})
145
-
146
144
// Check if we already have existing metrics
147
145
if g .hasExistingMetrics () {
148
146
log .Info ("State size metrics already initialized" )
149
147
g .initialized .Store (true )
150
- close (initDone )
151
- return initDone
148
+ return nil
152
149
}
153
150
151
+ initDone := make (chan struct {})
152
+
154
153
// Wait for snapshot completion and then initialize
155
154
go func () {
156
155
defer close (initDone )
@@ -166,6 +165,7 @@ func (g *StateSizeGenerator) initialize() chan struct{} {
166
165
root , done := g .triedb .SnapshotCompleted ()
167
166
if done {
168
167
g .metrics .Root = root
168
+ g .buffered .Root = root
169
169
break LOOP
170
170
}
171
171
time .Sleep (10 * time .Second )
@@ -190,8 +190,9 @@ func (g *StateSizeGenerator) initialize() chan struct{} {
190
190
191
191
// mergeBufferedMetrics merges buffered metrics into main metrics
192
192
func (g * StateSizeGenerator ) mergeBufferedMetrics () {
193
- if g .buffered != nil && g . buffered . Root != (common. Hash {}) {
193
+ if g .buffered != nil {
194
194
log .Info ("Merging buffered metrics into main metrics" )
195
+ g .metrics .Root = g .buffered .Root
195
196
g .metrics .AccountCount += g .buffered .AccountCount
196
197
g .metrics .AccountBytes += g .buffered .AccountBytes
197
198
g .metrics .StorageCount += g .buffered .StorageCount
@@ -201,8 +202,7 @@ func (g *StateSizeGenerator) mergeBufferedMetrics() {
201
202
g .metrics .ContractCount += g .buffered .ContractCount
202
203
g .metrics .ContractBytes += g .buffered .ContractBytes
203
204
204
- // Reset buffered metrics
205
- g .buffered = & StateSizeMetrics {Root : g .metrics .Root }
205
+ g .buffered = nil
206
206
}
207
207
}
208
208
0 commit comments