Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
selected_chain::SelectedChainStore,
statuses::StatusesStoreReader,
tips::{TipsStore, TipsStoreReader},
utxo_set::{UtxoSetStore, UtxoSetStoreReader},
utxo_set::UtxoSetStoreReader,
virtual_state::VirtualState,
DB,
},
Expand Down Expand Up @@ -1074,7 +1074,10 @@ impl ConsensusApi for Consensus {

fn append_imported_pruning_point_utxos(&self, utxoset_chunk: &[(TransactionOutpoint, UtxoEntry)], current_multiset: &mut MuHash) {
let mut pruning_meta_write = self.pruning_meta_stores.write();
pruning_meta_write.utxo_set.write_many(utxoset_chunk).unwrap();
let mut batch = WriteBatch::default();
pruning_meta_write.utxo_set.write_many_batch(&mut batch, utxoset_chunk).unwrap();
self.db.write(batch).unwrap();
drop(pruning_meta_write);

// Parallelize processing using the context of an existing thread pool.
let inner_multiset = self.virtual_processor.install(|| {
Expand Down
9 changes: 9 additions & 0 deletions consensus/src/model/stores/utxo_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ impl DbUtxoSetStore {
self.access.write_many_without_cache(&mut writer, &mut utxos.into_iter().map(|(o, e)| (o.into(), e)))?;
Ok(())
}

/// Write many UTXOs using a WriteBatch (for better performance during IBD).
/// This method skips cache updates and writes directly to the batch.
/// NOTE: This action also clears the cache.
pub fn write_many_batch(&mut self, batch: &mut WriteBatch, utxos: &[(TransactionOutpoint, UtxoEntry)]) -> Result<(), StoreError> {
let mut writer = BatchDbWriter::new(batch);
self.access.write_many_without_cache(&mut writer, &mut utxos.iter().map(|(o, e)| ((*o).into(), Arc::new(e.clone()))))?;
Ok(())
}
}

impl UtxoView for DbUtxoSetStore {
Expand Down