Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor database-related structs and modules #69

Merged
merged 5 commits into from
Oct 25, 2022
Merged
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: 3 additions & 4 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ use crate::{
ProcessingCounters,
},
processes::{
block_at_depth::BlockDepthManager, coinbase::CoinbaseManager, dagtraversalmanager::DagTraversalManager,
difficulty::DifficultyManager, ghostdag::protocol::GhostdagManager, mass::MassCalculator, parents_builder::ParentsManager,
pastmediantime::PastMedianTimeManager, pruning::PruningManager, reachability::inquirer as reachability,
transaction_validator::TransactionValidator,
block_depth::BlockDepthManager, coinbase::CoinbaseManager, difficulty::DifficultyManager, ghostdag::protocol::GhostdagManager,
mass::MassCalculator, parents_builder::ParentsManager, past_median_time::PastMedianTimeManager, pruning::PruningManager,
reachability::inquirer as reachability, transaction_validator::TransactionValidator, traversal_manager::DagTraversalManager,
},
};
use consensus_core::block::Block;
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/consensus/test_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
},
params::Params,
pipeline::{body_processor::BlockBodyProcessor, ProcessingCounters},
processes::{dagtraversalmanager::DagTraversalManager, pastmediantime::PastMedianTimeManager},
processes::{past_median_time::PastMedianTimeManager, traversal_manager::DagTraversalManager},
test_helpers::header_from_precomputed_hash,
};

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use itertools::Itertools;
use thiserror::Error;

#[derive(Clone, Debug)]

pub struct VecDisplay<T: Display>(pub Vec<T>);
impl<T: Display> Display for VecDisplay<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "[{}]", self.0.iter().map(|item| item.to_string()).join(", "))
}
}

#[derive(Clone, Debug)]
pub struct TwoDimVecDisplay<T: Display + Clone>(pub Vec<Vec<T>>);
impl<T: Display + Clone> Display for TwoDimVecDisplay<T> {
Expand Down
10 changes: 7 additions & 3 deletions consensus/src/model/stores/acceptance_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::{caching::CachedDbAccess, errors::StoreError, DB};
use super::{
database::prelude::{BatchDbWriter, CachedDbAccess, DirectDbWriter},
errors::StoreError,
DB,
};
use hashes::Hash;
use rocksdb::WriteBatch;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -39,7 +43,7 @@ impl DbAcceptanceDataStore {
if self.cached_access.has(hash)? {
return Err(StoreError::KeyAlreadyExists(hash.to_string()));
}
self.cached_access.write_batch(batch, hash, &acceptance_data)?;
self.cached_access.write(BatchDbWriter::new(batch), hash, &acceptance_data)?;
Ok(())
}
}
Expand All @@ -55,7 +59,7 @@ impl AcceptanceDataStore for DbAcceptanceDataStore {
if self.cached_access.has(hash)? {
return Err(StoreError::KeyAlreadyExists(hash.to_string()));
}
self.cached_access.write(hash, &acceptance_data)?;
self.cached_access.write(DirectDbWriter::new(&self.raw_db), hash, &acceptance_data)?;
Ok(())
}
}
10 changes: 7 additions & 3 deletions consensus/src/model/stores/block_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::sync::Arc;

use super::{caching::CachedDbAccess, errors::StoreError, DB};
use super::{
database::prelude::{BatchDbWriter, CachedDbAccess, DirectDbWriter},
errors::StoreError,
DB,
};
use consensus_core::tx::Transaction;
use hashes::Hash;
use rocksdb::WriteBatch;
Expand Down Expand Up @@ -37,7 +41,7 @@ impl DbBlockTransactionsStore {
if self.cached_access.has(hash)? {
return Err(StoreError::KeyAlreadyExists(hash.to_string()));
}
self.cached_access.write_batch(batch, hash, &transactions)?;
self.cached_access.write(BatchDbWriter::new(batch), hash, &transactions)?;
Ok(())
}
}
Expand All @@ -53,7 +57,7 @@ impl BlockTransactionsStore for DbBlockTransactionsStore {
if self.cached_access.has(hash)? {
return Err(StoreError::KeyAlreadyExists(hash.to_string()));
}
self.cached_access.write(hash, &transactions)?;
self.cached_access.write(DirectDbWriter::new(&self.raw_db), hash, &transactions)?;
Ok(())
}
}
7 changes: 2 additions & 5 deletions consensus/src/model/stores/block_window_cache.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::{cmp::Reverse, collections::BinaryHeap, sync::Arc};

use super::database::prelude::Cache;
use crate::processes::ghostdag::ordering::SortableBlock;

use hashes::Hash;

use super::caching::Cache;
use std::{cmp::Reverse, collections::BinaryHeap, sync::Arc};

pub type BlockWindowHeap = BinaryHeap<Reverse<SortableBlock>>;

Expand Down
Loading