@@ -111,7 +111,7 @@ type syncMemBatch struct {
111
111
nodes map [string ][]byte // In-memory membatch of recently completed nodes
112
112
hashes map [string ]common.Hash // Hashes of recently completed nodes
113
113
codes map [common.Hash ][]byte // In-memory membatch of recently completed codes
114
- size uint64
114
+ size uint64 // Estimated batch-size of in-memory data.
115
115
}
116
116
117
117
// newSyncMemBatch allocates a new memory-buffer for not-yet persisted trie nodes.
@@ -339,6 +339,7 @@ func (s *Sync) Commit(dbw ethdb.Batch) error {
339
339
return nil
340
340
}
341
341
342
+ // MemSize returns an estimated size (in bytes) of the data held in the membatch.
342
343
func (s * Sync ) MemSize () uint64 {
343
344
return s .membatch .size
344
345
}
@@ -484,7 +485,10 @@ func (s *Sync) commitNodeRequest(req *nodeRequest) error {
484
485
// Write the node content to the membatch
485
486
s .membatch .nodes [string (req .path )] = req .data
486
487
s .membatch .hashes [string (req .path )] = req .hash
487
- s .membatch .size += 2 * uint64 (len (req .path )) + 32 + uint64 (len (req .data ))
488
+ // The size tracking refers to the db-batch, not the in-memory data.
489
+ // Therefore, we ignore the req.path, and account only for the hash+data
490
+ // which eventually is written to db.
491
+ s .membatch .size += common .HashLength + uint64 (len (req .data ))
488
492
delete (s .nodeReqs , string (req .path ))
489
493
s .fetches [len (req .path )]--
490
494
@@ -506,7 +510,7 @@ func (s *Sync) commitNodeRequest(req *nodeRequest) error {
506
510
func (s * Sync ) commitCodeRequest (req * codeRequest ) error {
507
511
// Write the node content to the membatch
508
512
s .membatch .codes [req .hash ] = req .data
509
- s .membatch .size += uint64 ( 32 + len (req .data ))
513
+ s .membatch .size += common . HashLength + uint64 ( len (req .data ))
510
514
delete (s .codeReqs , req .hash )
511
515
s .fetches [len (req .path )]--
512
516
0 commit comments