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

Clean the pruning log and add config for parallel and parents count #4372

Open
wants to merge 23 commits into
base: dag-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions chain/mock/src/mock_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use anyhow::{format_err, Result};
use starcoin_account_api::AccountInfo;
use starcoin_chain::{BlockChain, ChainReader, ChainWriter};
use starcoin_config::miner_config::G_MAX_PARENTS_COUNT;
use starcoin_config::ChainNetwork;
use starcoin_consensus::Consensus;
use starcoin_crypto::HashValue;
Expand Down Expand Up @@ -266,6 +267,7 @@ impl MockChain {
prevous_ghostdata.as_ref(),
4,
3,
G_MAX_PARENTS_COUNT,
)?;

debug!(
Expand Down
16 changes: 15 additions & 1 deletion chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ impl BlockChain {
)?;
let excluded_txns = opened_block.push_txns(user_txns)?;
let template = opened_block.finalize()?;

Ok((template, excluded_txns))
}

Expand Down Expand Up @@ -1381,7 +1382,20 @@ impl ChainReader for BlockChain {
uncles: &[BlockHeader],
header: &BlockHeader,
) -> Result<starcoin_dag::types::ghostdata::GhostdagData> {
Ok(self.dag().verify_and_ghostdata(uncles, header)?)
let latest_pruning_point = {
match self.storage.get_startup_info().unwrap_or(None) {
Some(startup_info) => self
.storage
.get_block_header_by_hash(startup_info.main)
.unwrap_or(None)
.map(|head_block| head_block.pruning_point()),
None => None,
}
};

Ok(self
.dag()
.verify_and_ghostdata(uncles, header, latest_pruning_point)?)
}

fn is_dag_ancestor_of(&self, ancestor: HashValue, descendant: HashValue) -> Result<bool> {
Expand Down
2 changes: 1 addition & 1 deletion config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod genesis_config;
mod helper;
mod logger_config;
mod metrics_config;
mod miner_config;
pub mod miner_config;
mod network_config;
mod rpc_config;
mod storage_config;
Expand Down
14 changes: 14 additions & 0 deletions config/src/miner_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use clap::Parser;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

pub static G_MAX_PARENTS_COUNT: u64 = 16;

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, Parser)]
#[serde(deny_unknown_fields)]
pub struct MinerConfig {
Expand Down Expand Up @@ -34,6 +36,10 @@ pub struct MinerConfig {
#[serde(skip)]
#[clap(skip)]
base: Option<Arc<BaseConfig>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[clap(long = "maximum-parents-count")]
pub maximum_parents_count: Option<u64>,
}

impl MinerConfig {
Expand All @@ -60,6 +66,10 @@ impl MinerConfig {
enable_stderr: true,
})
}

pub fn maximum_parents_count(&self) -> u64 {
self.maximum_parents_count.unwrap_or(G_MAX_PARENTS_COUNT)
}
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
Expand Down Expand Up @@ -103,6 +113,10 @@ impl ConfigModule for MinerConfig {
self.block_gas_limit = opt.miner.block_gas_limit;
}

if opt.miner.maximum_parents_count.is_some() {
self.maximum_parents_count = opt.miner.maximum_parents_count;
}

Ok(())
}
}
20 changes: 20 additions & 0 deletions config/src/sync_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ pub struct SyncConfig {
help = "max retry times once sync block failed, default 15."
)]
max_retry_times: Option<u64>,

/// the maximum gap between the current head block's number and the peer's block's number
/// and if the block height broadcast by a peer node is greater than the height of the local head block by this maximum value,
/// a regular sync process will be initiated;
/// otherwise, a lightweight sync process will be triggered, strengthening the reference relationship between nodes.
#[serde(skip_serializing_if = "Option::is_none")]
#[clap(
name = "lightweight-sync-max-gap",
long,
help = "The height difference threshold for triggering a lightweight sync."
)]
lightweight_sync_max_gap: Option<u64>,
}

impl SyncConfig {
Expand All @@ -38,6 +50,10 @@ impl SyncConfig {
pub fn max_retry_times(&self) -> u64 {
self.max_retry_times.unwrap_or(15)
}

pub fn lightweight_sync_max_gap(&self) -> Option<u64> {
self.lightweight_sync_max_gap
}
}

impl ConfigModule for SyncConfig {
Expand All @@ -50,6 +66,10 @@ impl ConfigModule for SyncConfig {
self.max_retry_times = opt.sync.max_retry_times;
}

if opt.sync.lightweight_sync_max_gap.is_some() {
self.lightweight_sync_max_gap = opt.sync.lightweight_sync_max_gap;
}

Ok(())
}
}
Loading
Loading