diff --git a/db/src/block_stapler.rs b/db/src/block_stapler.rs index 088814f8..20d2cf45 100644 --- a/db/src/block_stapler.rs +++ b/db/src/block_stapler.rs @@ -49,4 +49,8 @@ pub trait BlockStapler { /// insert pre-processed block in the storage fn insert_indexed_block(&self, block: &IndexedBlock) -> Result; + + /// flushes the underlined store (if applicable) + fn flush(&self); + } diff --git a/db/src/storage.rs b/db/src/storage.rs index c9a41ae2..78f51ca1 100644 --- a/db/src/storage.rs +++ b/db/src/storage.rs @@ -464,6 +464,7 @@ impl Storage { .map(|header| header.bits.to_f64()) .unwrap_or(1.0f64) } + } impl BlockHeaderProvider for Storage { @@ -680,6 +681,10 @@ impl BlockStapler for Storage { } } } + + fn flush(&self) { + self.database.flush().expect("Failed to flush database. Out of disk space?"); + } } impl TransactionProvider for Storage { diff --git a/db/src/test_storage.rs b/db/src/test_storage.rs index ce4bd280..c9aab2ce 100644 --- a/db/src/test_storage.rs +++ b/db/src/test_storage.rs @@ -170,6 +170,9 @@ impl BlockStapler for TestStorage { _ => None } } + + fn flush(&self) { + } } impl TransactionProvider for TestStorage { diff --git a/db/src/update_context.rs b/db/src/update_context.rs index eb93e17f..be9aaaa5 100644 --- a/db/src/update_context.rs +++ b/db/src/update_context.rs @@ -28,7 +28,7 @@ impl UpdateContext { self.db_transaction.put(Some(COL_TRANSACTIONS_META), &*hash, &meta.into_bytes()); } - try!(db.write(self.db_transaction)); + db.write_buffered(self.db_transaction); trace!("Applied transaction for block {:?}", &self.target.to_reversed_str()); Ok(()) diff --git a/verification/src/chain_verifier.rs b/verification/src/chain_verifier.rs index 265182c0..554b1757 100644 --- a/verification/src/chain_verifier.rs +++ b/verification/src/chain_verifier.rs @@ -318,6 +318,7 @@ impl ChainVerifier { for task in transaction_tasks.iter_mut() { scope.execute(move || task.progress(self)) } + self.store.flush(); });