Skip to content

Commit

Permalink
fix: fix the healer commit
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Jul 16, 2024
1 parent 44decdf commit c476d15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
8 changes: 4 additions & 4 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
}
Expand Down
24 changes: 15 additions & 9 deletions trie/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand Down

0 comments on commit c476d15

Please sign in to comment.