From efd5bfcdedaf306062effb0431cec1c89e3301d0 Mon Sep 17 00:00:00 2001 From: Vadim Macagon Date: Wed, 30 Jan 2019 13:45:18 +0700 Subject: [PATCH] Force trie.Database.Commit() to write everything out in a single batch Iteration order over db.preimages is not deterministic, sorting the batch contents when the batch is written can be used to work around this. However, when multiple batches are written out the contents of each batch will differ every time, therefore sorting the contents of each batch is not sufficient to ensure deterministic in-order writes to the underlying store. These changes ensure the trie.Database.Commit() writes everything out in a single batch to avoid that particular problem. --- trie/database.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/trie/database.go b/trie/database.go index d0691b637e..e071121143 100644 --- a/trie/database.go +++ b/trie/database.go @@ -622,12 +622,6 @@ func (db *Database) Commit(node common.Hash, report bool) error { db.lock.RUnlock() return err } - if batch.ValueSize() > ethdb.IdealBatchSize { - if err := batch.Write(); err != nil { - return err - } - batch.Reset() - } } // Move the trie itself into the batch, flushing if enough data is accumulated nodes, storage := len(db.nodes), db.nodesSize @@ -686,13 +680,6 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch) error { if err := batch.Put(hash[:], node.rlp()); err != nil { return err } - // If we've reached an optimal batch size, commit and start over - if batch.ValueSize() >= ethdb.IdealBatchSize { - if err := batch.Write(); err != nil { - return err - } - batch.Reset() - } return nil }