@@ -111,7 +111,7 @@ type syncMemBatch struct {
111111 nodes map [string ][]byte // In-memory membatch of recently completed nodes
112112 hashes map [string ]common.Hash // Hashes of recently completed nodes
113113 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.
115115}
116116
117117// newSyncMemBatch allocates a new memory-buffer for not-yet persisted trie nodes.
@@ -339,6 +339,7 @@ func (s *Sync) Commit(dbw ethdb.Batch) error {
339339 return nil
340340}
341341
342+ // MemSize returns an estimated size (in bytes) of the data held in the membatch.
342343func (s * Sync ) MemSize () uint64 {
343344 return s .membatch .size
344345}
@@ -484,7 +485,10 @@ func (s *Sync) commitNodeRequest(req *nodeRequest) error {
484485 // Write the node content to the membatch
485486 s .membatch .nodes [string (req .path )] = req .data
486487 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 ))
488492 delete (s .nodeReqs , string (req .path ))
489493 s .fetches [len (req .path )]--
490494
@@ -506,7 +510,7 @@ func (s *Sync) commitNodeRequest(req *nodeRequest) error {
506510func (s * Sync ) commitCodeRequest (req * codeRequest ) error {
507511 // Write the node content to the membatch
508512 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 ))
510514 delete (s .codeReqs , req .hash )
511515 s .fetches [len (req .path )]--
512516
0 commit comments