Skip to content

Commit

Permalink
feat: notify dummy miner for new work
Browse files Browse the repository at this point in the history
  • Loading branch information
quake authored and doitian committed Oct 10, 2023
1 parent 1e74aa3 commit f45505f
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/hashes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ tx_hash = "0xd5780747735fd22c9ba7363bde8afe59061658caa836962867253b03cbda264e"
index = 1

[ckb_dev]
spec_hash = "0x6cb679a15a7ff16596cad85f4680ab4335c87bcbf43956c591c23d11841719e4"
spec_hash = "0xab85c78cf9641a7709f9d48ba06415c283050888c9fb927d743bc521aa1ddfec"
genesis = "0x823b2ff5785b12da8b1363cac9a5cbe566d8b715a4311441b119c39a0367488c"
cellbase = "0xa563884b3686078ec7e7677a5f86449b15cf2693f3c1241766c6996f206cc541"

Expand Down
1 change: 1 addition & 0 deletions resource/specs/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ genesis_epoch_length = 1000
# For development and testing purposes only.
# Keep difficulty be permanent if the pow is Dummy. (default: false)
permanent_difficulty_in_dummy = true
starting_block_limiting_dao_withdrawing_lock = 0

[params.hardfork]
ckb2023 = 0
Expand Down
25 changes: 25 additions & 0 deletions spec/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ pub(crate) const SATOSHI_CELL_OCCUPIED_RATIO: Ratio = Ratio::new(6, 10);
pub(crate) const LC_MAINNET_ACTIVATION_THRESHOLD: Ratio = Ratio::new(8, 10);
pub(crate) const TESTNET_ACTIVATION_THRESHOLD: Ratio = Ratio::new(3, 4);

/// The starting block number from which the lock script size of a DAO withdrawing
/// cell shall be limited
pub(crate) const STARTING_BLOCK_LIMITING_DAO_WITHDRAWING_LOCK: u64 = 10_000_000;

/// The struct represent CKB two-step-transaction-confirmation params
///
/// [two-step-transaction-confirmation params](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0020-ckb-consensus-protocol/0020-ckb-consensus-protocol.md#two-step-transaction-confirmation)
Expand Down Expand Up @@ -289,6 +293,8 @@ impl ConsensusBuilder {
hardfork_switch: HardForks::new_mirana(),
deployments: HashMap::new(),
versionbits_caches: VersionbitsCache::default(),
starting_block_limiting_dao_withdrawing_lock:
STARTING_BLOCK_LIMITING_DAO_WITHDRAWING_LOCK,
},
}
}
Expand Down Expand Up @@ -483,6 +489,17 @@ impl ConsensusBuilder {
self.inner.deployments = deployments;
self
}

///The starting block number where Nervos DAO withdrawing cell's lock is
/// size limited.
pub fn starting_block_limiting_dao_withdrawing_lock(
mut self,
starting_block_limiting_dao_withdrawing_lock: u64,
) -> Self {
self.inner.starting_block_limiting_dao_withdrawing_lock =
starting_block_limiting_dao_withdrawing_lock;
self
}
}

/// Struct Consensus defines various parameters that influence chain consensus
Expand Down Expand Up @@ -563,6 +580,8 @@ pub struct Consensus {
pub deployments: HashMap<DeploymentPos, Deployment>,
/// Soft fork state cache
pub versionbits_caches: VersionbitsCache,
/// Starting block where DAO withdrawing lock is limited in size
pub starting_block_limiting_dao_withdrawing_lock: u64,
}

// genesis difficulty should not be zero
Expand Down Expand Up @@ -741,6 +760,12 @@ impl Consensus {
self.tx_proposal_window
}

/// The starting block number where Nervos DAO withdrawing cell's lock is
/// size limited.
pub fn starting_block_limiting_dao_withdrawing_lock(&self) -> u64 {
self.starting_block_limiting_dao_withdrawing_lock
}

// Apply the dampening filter on hash_rate estimation calculate
fn bounding_hash_rate(
&self,
Expand Down
23 changes: 22 additions & 1 deletion spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub mod default_params {
CELLBASE_MATURITY, DEFAULT_EPOCH_DURATION_TARGET, DEFAULT_ORPHAN_RATE_TARGET,
DEFAULT_PRIMARY_EPOCH_REWARD_HALVING_INTERVAL, DEFAULT_SECONDARY_EPOCH_REWARD,
GENESIS_EPOCH_LENGTH, INITIAL_PRIMARY_EPOCH_REWARD, MAX_BLOCK_BYTES, MAX_BLOCK_CYCLES,
MAX_BLOCK_PROPOSALS_LIMIT,
MAX_BLOCK_PROPOSALS_LIMIT, STARTING_BLOCK_LIMITING_DAO_WITHDRAWING_LOCK,
};
use ckb_types::core::{Capacity, Cycle, EpochNumber};

Expand Down Expand Up @@ -170,6 +170,13 @@ pub mod default_params {
pub fn orphan_rate_target() -> (u32, u32) {
DEFAULT_ORPHAN_RATE_TARGET
}

/// The default starting_block_limiting_dao_withdrawing_lock
///
/// Apply to [`starting_block_limiting_dao_withdrawing_lock`](../consensus/struct.Consensus.html#structfield.starting_block_limiting_dao_withdrawing_lock)
pub fn starting_block_limiting_dao_withdrawing_lock() -> u64 {
STARTING_BLOCK_LIMITING_DAO_WITHDRAWING_LOCK
}
}

/// Parameters for CKB block chain
Expand Down Expand Up @@ -231,6 +238,11 @@ pub struct Params {
/// See [`orphan_rate_target`](consensus/struct.Consensus.html#structfield.orphan_rate_target)
#[serde(skip_serializing_if = "Option::is_none")]
pub orphan_rate_target: Option<(u32, u32)>,
/// The starting_block_limiting_dao_withdrawing_lock.
///
/// See [`starting_block_limiting_dao_withdrawing_lock`](consensus/struct.Consensus.html#structfield.starting_block_limiting_dao_withdrawing_lock)
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_block_limiting_dao_withdrawing_lock: Option<u64>,
/// The parameters for hard fork features.
///
/// See [`hardfork_switch`](consensus/struct.Consensus.html#structfield.hardfork_switch)
Expand Down Expand Up @@ -304,6 +316,12 @@ impl Params {
self.orphan_rate_target
.unwrap_or_else(default_params::orphan_rate_target)
}

/// Return the `starting_block_limiting_dao_withdrawing_lock`, otherwise if None, returns the default value
pub fn starting_block_limiting_dao_withdrawing_lock(&self) -> u64 {
self.starting_block_limiting_dao_withdrawing_lock
.unwrap_or_else(default_params::starting_block_limiting_dao_withdrawing_lock)
}
}

/// The genesis information
Expand Down Expand Up @@ -585,6 +603,9 @@ impl ChainSpec {
.permanent_difficulty_in_dummy(self.params.permanent_difficulty_in_dummy())
.max_block_proposals_limit(self.params.max_block_proposals_limit())
.orphan_rate_target(self.params.orphan_rate_target())
.starting_block_limiting_dao_withdrawing_lock(
self.params.starting_block_limiting_dao_withdrawing_lock(),
)
.hardfork_switch(hardfork_switch);

if let Some(deployments) = self.softfork_deployments() {
Expand Down
31 changes: 31 additions & 0 deletions spec/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ fn test_default_params() {
};

assert_eq!(params, expected);

let test_params: &str = r#"
starting_block_limiting_dao_withdrawing_lock = 77
"#;

let params: Params = toml::from_str(test_params).unwrap();
let expected = Params {
starting_block_limiting_dao_withdrawing_lock: Some(77),
..Default::default()
};

assert_eq!(params, expected);
}

#[test]
Expand Down Expand Up @@ -256,3 +268,22 @@ fn test_default_genesis_epoch_ext() {

assert_eq!(genesis_epoch_ext, expected);
}

#[test]
fn test_devnet_limits_dao_withdrawing_lock_from_genesis() {
let chain_spec = load_spec_by_name("ckb_dev");
let consensus = chain_spec.build_consensus().unwrap();

assert_eq!(consensus.starting_block_limiting_dao_withdrawing_lock(), 0);
}

#[test]
fn test_mainnet_limits_dao_withdrawing_lock_from_10000000() {
let chain_spec = load_spec_by_name("ckb");
let consensus = chain_spec.build_consensus().unwrap();

assert_eq!(
consensus.starting_block_limiting_dao_withdrawing_lock(),
10000000
);
}
2 changes: 1 addition & 1 deletion tx-pool/src/chunk_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl ChunkProcess {
.and_then(|result| {
DaoScriptSizeVerifier::new(
Arc::clone(&rtx),
consensus.dao_type_hash(),
Arc::clone(&consensus),
data_loader.clone(),
)
.verify()?;
Expand Down
2 changes: 1 addition & 1 deletion tx-pool/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl TxPoolService {
ScriptVerifyResult::Completed(cycles) => {
if let Err(e) = DaoScriptSizeVerifier::new(
Arc::clone(&rtx),
self.consensus.dao_type_hash(),
Arc::clone(&self.consensus),
snapshot.as_data_loader(),
)
.verify()
Expand Down
4 changes: 2 additions & 2 deletions tx-pool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub(crate) fn verify_rtx(
.and_then(|result| {
DaoScriptSizeVerifier::new(
rtx,
snapshot.cloned_consensus().dao_type_hash(),
snapshot.cloned_consensus(),
snapshot.as_data_loader(),
)
.verify()?;
Expand All @@ -122,7 +122,7 @@ pub(crate) fn verify_rtx(
.and_then(|result| {
DaoScriptSizeVerifier::new(
rtx,
snapshot.cloned_consensus().dao_type_hash(),
snapshot.cloned_consensus(),
snapshot.as_data_loader(),
)
.verify()?;
Expand Down
2 changes: 1 addition & 1 deletion verification/contextual/src/contextual_block_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a,
if self.context.versionbits_active(DeploymentPos::LightClient, self.parent) {
DaoScriptSizeVerifier::new(
Arc::clone(tx),
self.context.consensus.dao_type_hash(),
Arc::clone(&self.context.consensus),
self.context.store.as_data_loader(),
).verify()?;
}
Expand Down
Loading

0 comments on commit f45505f

Please sign in to comment.