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.
This commit is contained in:
Vadim Macagon 2019-01-30 13:45:18 +07:00
parent c4f3537b02
commit efd5bfcded

View file

@ -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
}