Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,25 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch) error {
if !ok {
return nil
}
// Commit all the children and then the current node too
for _, child := range node.childs() {
if err := db.commit(child, batch); err != nil {
return err
}
}
if err := batch.Put(hash[:], node.rlp()); err != nil {
blob := node.rlp()
if err := batch.Put(hash[:], blob); err != nil {
return err
}
// Move the flushed node into the clean cache to prevent insta-reloads. This
// move should really be done **after** flushing the batch. The issue is that
// the RLP of the data is lost at that point, requiring reencoding everything.
// By doing the move here we open a window of opportunity for failure **if**
// writing the data errors out, but at that point we might have bigger issues
// anyway.
if db.cleans != nil {
db.cleans.Set(string(hash[:]), blob)
}
// If we've reached an optimal batch size, commit and start over
if batch.ValueSize() >= ethdb.IdealBatchSize {
if err := batch.Write(); err != nil {
Expand Down