Skip to content

Commit

Permalink
Merge 323e42c into 8d448e3
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhhuang authored Jan 27, 2025
2 parents 8d448e3 + 323e42c commit 502789b
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 65 deletions.
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

0 comments on commit 502789b

Please sign in to comment.