Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Jan 10, 2024
1 parent bbf5fcf commit a249e13
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 173 deletions.
2 changes: 1 addition & 1 deletion consensus/src/consensus/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct MultiConsensusMetadata {
version: u32,
}

const LATEST_DB_VERSION: u32 = 3;
const LATEST_DB_VERSION: u32 = 4;
impl Default for MultiConsensusMetadata {
fn default() -> Self {
Self {
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl Consensus {
block_processors_pool,
db.clone(),
storage.statuses_store.clone(),
storage.ghostdag_store.clone(),
storage.ghostdag_primary_store.clone(),
storage.headers_store.clone(),
storage.block_transactions_store.clone(),
storage.body_tips_store.clone(),
Expand Down Expand Up @@ -473,7 +473,7 @@ impl ConsensusApi for Consensus {

fn get_virtual_merge_depth_blue_work_threshold(&self) -> BlueWorkType {
// PRUNE SAFETY: merge depth root is never close to being pruned (in terms of block depth)
self.get_virtual_merge_depth_root().map_or(BlueWorkType::ZERO, |root| self.ghostdag_store.get_blue_work(root).unwrap())
self.get_virtual_merge_depth_root().map_or(BlueWorkType::ZERO, |root| self.ghostdag_primary_store.get_blue_work(root).unwrap())
}

fn get_sink(&self) -> Hash {
Expand Down Expand Up @@ -791,7 +791,7 @@ impl ConsensusApi for Consensus {
Some(BlockStatus::StatusInvalid) => return Err(ConsensusError::InvalidBlock(hash)),
_ => {}
};
let ghostdag = self.ghostdag_store.get_data(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash))?;
let ghostdag = self.ghostdag_primary_store.get_data(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash))?;
Ok((&*ghostdag).into())
}

Expand Down Expand Up @@ -843,7 +843,7 @@ impl ConsensusApi for Consensus {
Ok(self
.services
.window_manager
.block_window(&self.ghostdag_store.get_data(hash).unwrap(), WindowType::SampledDifficultyWindow)
.block_window(&self.ghostdag_primary_store.get_data(hash).unwrap(), WindowType::SampledDifficultyWindow)
.unwrap()
.deref()
.iter()
Expand Down Expand Up @@ -882,7 +882,7 @@ impl ConsensusApi for Consensus {
match start_hash {
Some(hash) => {
self.validate_block_exists(hash)?;
let ghostdag_data = self.ghostdag_store.get_data(hash).unwrap();
let ghostdag_data = self.ghostdag_primary_store.get_data(hash).unwrap();
self.estimate_network_hashes_per_second_impl(&ghostdag_data, window_size)
}
None => {
Expand Down
36 changes: 14 additions & 22 deletions consensus/src/consensus/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub struct ConsensusServices {
pub reachability_service: MTReachabilityService<DbReachabilityStore>,
pub window_manager: DbWindowManager,
pub dag_traversal_manager: DbDagTraversalManager,
pub proof_levels_ghostdag_managers: Arc<Vec<DbGhostdagManager>>,
pub ghostdag_manager: DbGhostdagManager,
pub ghostdag_managers: Arc<Vec<DbGhostdagManager>>,
pub ghostdag_primary_manager: DbGhostdagManager,
pub coinbase_manager: CoinbaseManager,
pub pruning_point_manager: DbPruningPointManager,
pub pruning_proof_manager: Arc<PruningProofManager>,
Expand Down Expand Up @@ -82,13 +82,13 @@ impl ConsensusServices {
let reachability_service = MTReachabilityService::new(storage.reachability_store.clone());
let dag_traversal_manager = DagTraversalManager::new(
params.genesis.hash,
storage.ghostdag_store.clone(),
storage.ghostdag_primary_store.clone(),
relations_service.clone(),
reachability_service.clone(),
);
let window_manager = DualWindowManager::new(
&params.genesis,
storage.ghostdag_store.clone(),
storage.ghostdag_primary_store.clone(),
storage.headers_store.clone(),
storage.daa_excluded_store.clone(),
storage.block_window_cache_for_difficulty.clone(),
Expand All @@ -110,11 +110,11 @@ impl ConsensusServices {
params.genesis.hash,
storage.depth_store.clone(),
reachability_service.clone(),
storage.ghostdag_store.clone(),
storage.ghostdag_primary_store.clone(),
);
let proof_levels_ghostdag_managers = Arc::new(
let ghostdag_managers = Arc::new(
storage
.proof_levels_ghostdag_stores
.ghostdag_stores
.iter()
.cloned()
.enumerate()
Expand All @@ -131,15 +131,7 @@ impl ConsensusServices {
})
.collect_vec(),
);
let ghostdag_manager = GhostdagManager::new(
params.genesis.hash,
params.ghostdag_k,
storage.ghostdag_store.clone(),
relations_services[0].clone(),
storage.headers_store.clone(),
reachability_service.clone(),
false,
);
let ghostdag_primary_manager = ghostdag_managers[0].clone();

let coinbase_manager = CoinbaseManager::new(
params.coinbase_payload_script_public_key_max_len,
Expand Down Expand Up @@ -174,7 +166,7 @@ impl ConsensusServices {
params.finality_depth,
params.genesis.hash,
reachability_service.clone(),
storage.ghostdag_store.clone(),
storage.ghostdag_primary_store.clone(),
storage.headers_store.clone(),
storage.past_pruning_points_store.clone(),
storage.headers_selected_tip_store.clone(),
Expand All @@ -193,8 +185,8 @@ impl ConsensusServices {
&storage,
parents_manager.clone(),
reachability_service.clone(),
proof_levels_ghostdag_managers.clone(),
ghostdag_manager.clone(),
ghostdag_managers.clone(),
ghostdag_primary_manager.clone(),
dag_traversal_manager.clone(),
window_manager.clone(),
params.max_block_level,
Expand All @@ -209,7 +201,7 @@ impl ConsensusServices {
params.mergeset_size_limit as usize,
reachability_service.clone(),
dag_traversal_manager.clone(),
storage.ghostdag_store.clone(),
storage.ghostdag_primary_store.clone(),
storage.selected_chain_store.clone(),
storage.headers_selected_tip_store.clone(),
storage.pruning_point_store.clone(),
Expand All @@ -223,8 +215,8 @@ impl ConsensusServices {
reachability_service,
window_manager,
dag_traversal_manager,
proof_levels_ghostdag_managers,
ghostdag_manager,
ghostdag_managers,
ghostdag_primary_manager,
coinbase_manager,
pruning_point_manager,
pruning_proof_manager,
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/consensus/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ pub struct ConsensusStorage {
pub selected_chain_store: Arc<RwLock<DbSelectedChainStore>>,

// Append-only stores
pub proof_levels_ghostdag_stores: Arc<Vec<Arc<DbGhostdagStore>>>,
pub ghostdag_store: Arc<DbGhostdagStore>,
pub ghostdag_stores: Arc<Vec<Arc<DbGhostdagStore>>>,
pub ghostdag_primary_store: Arc<DbGhostdagStore>,
pub headers_store: Arc<DbHeadersStore>,
pub block_transactions_store: Arc<DbBlockTransactionsStore>,
pub past_pruning_points_store: Arc<DbPastPruningPointsStore>,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl ConsensusStorage {
parents_builder.build(),
children_builder.build(),
)));
let proof_levels_ghostdag_stores = Arc::new(
let ghostdag_stores = Arc::new(
(0..=params.max_block_level)
.map(|level| {
Arc::new(DbGhostdagStore::new(
Expand Down Expand Up @@ -237,8 +237,8 @@ impl ConsensusStorage {
relations_stores,
reachability_relations_store,
reachability_store,
proof_levels_ghostdag_stores,
ghostdag_store,
ghostdag_stores,
ghostdag_primary_store,
pruning_point_store,
headers_selected_tip_store,
body_tips_store,
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/consensus/test_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl TestConsensus {

pub fn build_header_with_parents(&self, hash: Hash, parents: Vec<Hash>) -> Header {
let mut header = header_from_precomputed_hash(hash, parents);
let ghostdag_data = self.consensus.services.ghostdag_manager.ghostdag(header.direct_parents());
let ghostdag_data = self.consensus.services.ghostdag_primary_manager.ghostdag(header.direct_parents());
header.pruning_point = self
.consensus
.services
Expand Down Expand Up @@ -200,7 +200,7 @@ impl TestConsensus {
}

pub fn ghostdag_store(&self) -> &Arc<DbGhostdagStore> {
&self.consensus.ghostdag_store
&self.consensus.ghostdag_primary_store
}

pub fn reachability_store(&self) -> &Arc<RwLock<DbReachabilityStore>> {
Expand Down Expand Up @@ -232,7 +232,7 @@ impl TestConsensus {
}

pub fn ghostdag_manager(&self) -> &DbGhostdagManager {
&self.consensus.services.ghostdag_manager
&self.consensus.services.ghostdag_primary_manager
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl BlockBodyProcessor {
}

fn check_block_transactions_in_context(self: &Arc<Self>, block: &Block) -> BlockProcessResult<()> {
let (pmt, _) = self.window_manager.calc_past_median_time(&self.ghostdag_store.get_data(block.hash()).unwrap())?;
let (pmt, _) = self.window_manager.calc_past_median_time(&self.ghostdag_primary_store.get_data(block.hash()).unwrap())?;
for tx in block.transactions.iter() {
if let Err(e) = self.transaction_validator.utxo_free_tx_validation(tx, block.header.daa_score, pmt) {
return Err(RuleError::TxInContextFailed(tx.id(), e));
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/pipeline/body_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct BlockBodyProcessor {

// Stores
pub(super) statuses_store: Arc<RwLock<DbStatusesStore>>,
pub(super) ghostdag_store: Arc<DbGhostdagStore>,
pub(super) ghostdag_primary_store: Arc<DbGhostdagStore>,
pub(super) headers_store: Arc<DbHeadersStore>,
pub(super) block_transactions_store: Arc<DbBlockTransactionsStore>,
pub(super) body_tips_store: Arc<RwLock<DbTipsStore>>,
Expand Down Expand Up @@ -92,7 +92,7 @@ impl BlockBodyProcessor {

db: Arc<DB>,
statuses_store: Arc<RwLock<DbStatusesStore>>,
ghostdag_store: Arc<DbGhostdagStore>,
ghostdag_primary_store: Arc<DbGhostdagStore>,
headers_store: Arc<DbHeadersStore>,
block_transactions_store: Arc<DbBlockTransactionsStore>,
body_tips_store: Arc<RwLock<DbTipsStore>>,
Expand All @@ -116,7 +116,7 @@ impl BlockBodyProcessor {
db,
statuses_store,
reachability_service,
ghostdag_store,
ghostdag_primary_store,
headers_store,
block_transactions_store,
body_tips_store,
Expand Down
Loading

0 comments on commit a249e13

Please sign in to comment.