diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index dcf0fa4cb0..56d48649dd 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -2345,11 +2345,11 @@ func (s *Syncer) commitHealer(force bool) { return } batch := s.db.NewBatch() - var trieBatch ethdb.Batch + var stateBatch ethdb.Batch var err error if s.db.StateStore() != nil { - trieBatch = s.db.StateStore().NewBatch() - err = s.healer.scheduler.Commit(batch, trieBatch) + stateBatch = s.db.StateStore().NewBatch() + err = s.healer.scheduler.Commit(batch, stateBatch) } else { err = s.healer.scheduler.Commit(batch, nil) } @@ -2360,7 +2360,7 @@ func (s *Syncer) commitHealer(force bool) { log.Crit("Failed to persist healing data", "err", err) } if s.db.StateStore() != nil { - if err := trieBatch.Write(); err != nil { + if err := stateBatch.Write(); err != nil { log.Crit("Failed to persist healing data", "err", err) } } diff --git a/trie/sync.go b/trie/sync.go index db83f61da7..5c74dfcc03 100644 --- a/trie/sync.go +++ b/trie/sync.go @@ -426,19 +426,21 @@ func (s *Sync) Commit(dbw ethdb.Batch, stateBatch ethdb.Batch) error { account int storage int ) - var trieBatch ethdb.Batch - if stateBatch != nil { - trieBatch = stateBatch - } else { - trieBatch = dbw - } for _, op := range s.membatch.nodes { if op.isDelete() { // node deletion is only supported in path mode. if op.owner == (common.Hash{}) { - rawdb.DeleteAccountTrieNode(trieBatch, op.path) + if stateBatch != nil { + rawdb.DeleteAccountTrieNode(stateBatch, op.path) + } else { + rawdb.DeleteAccountTrieNode(dbw, op.path) + } } else { - rawdb.DeleteStorageTrieNode(trieBatch, op.owner, op.path) + if stateBatch != nil { + rawdb.DeleteStorageTrieNode(stateBatch, op.owner, op.path) + } else { + rawdb.DeleteStorageTrieNode(dbw, op.owner, op.path) + } } deletionGauge.Inc(1) } else { @@ -447,7 +449,11 @@ func (s *Sync) Commit(dbw ethdb.Batch, stateBatch ethdb.Batch) error { } else { storage += 1 } - rawdb.WriteTrieNode(trieBatch, op.owner, op.path, op.hash, op.blob, s.scheme) + if stateBatch != nil { + rawdb.WriteTrieNode(stateBatch, op.owner, op.path, op.hash, op.blob, s.scheme) + } else { + rawdb.WriteTrieNode(dbw, op.owner, op.path, op.hash, op.blob, s.scheme) + } } } accountNodeSyncedGauge.Inc(int64(account))