Skip to content

Commit

Permalink
Merge branch 'kip10-tn11-hf' of https://github.com/kaspanet/rusty-kaspa
Browse files Browse the repository at this point in the history
… into pnn-v1
  • Loading branch information
aspect committed Dec 1, 2024
2 parents 76e57b8 + 14b1e10 commit 2b3f55f
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 132 deletions.
116 changes: 58 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ members = [

[workspace.package]
rust-version = "1.82.0"
version = "0.15.3"
version = "0.15.4"
authors = ["Kaspa developers"]
license = "ISC"
repository = "https://github.com/kaspanet/rusty-kaspa"
Expand All @@ -80,61 +80,61 @@ include = [
]

[workspace.dependencies]
# kaspa-testing-integration = { version = "0.15.3", path = "testing/integration" }
kaspa-addresses = { version = "0.15.3", path = "crypto/addresses" }
kaspa-addressmanager = { version = "0.15.3", path = "components/addressmanager" }
kaspa-bip32 = { version = "0.15.3", path = "wallet/bip32" }
kaspa-cli = { version = "0.15.3", path = "cli" }
kaspa-connectionmanager = { version = "0.15.3", path = "components/connectionmanager" }
kaspa-consensus = { version = "0.15.3", path = "consensus" }
kaspa-consensus-core = { version = "0.15.3", path = "consensus/core" }
kaspa-consensus-client = { version = "0.15.3", path = "consensus/client" }
kaspa-consensus-notify = { version = "0.15.3", path = "consensus/notify" }
kaspa-consensus-wasm = { version = "0.15.3", path = "consensus/wasm" }
kaspa-consensusmanager = { version = "0.15.3", path = "components/consensusmanager" }
kaspa-core = { version = "0.15.3", path = "core" }
kaspa-daemon = { version = "0.15.3", path = "daemon" }
kaspa-database = { version = "0.15.3", path = "database" }
kaspa-grpc-client = { version = "0.15.3", path = "rpc/grpc/client" }
kaspa-grpc-core = { version = "0.15.3", path = "rpc/grpc/core" }
kaspa-grpc-server = { version = "0.15.3", path = "rpc/grpc/server" }
kaspa-hashes = { version = "0.15.3", path = "crypto/hashes" }
kaspa-index-core = { version = "0.15.3", path = "indexes/core" }
kaspa-index-processor = { version = "0.15.3", path = "indexes/processor" }
kaspa-math = { version = "0.15.3", path = "math" }
kaspa-merkle = { version = "0.15.3", path = "crypto/merkle" }
kaspa-metrics-core = { version = "0.15.3", path = "metrics/core" }
kaspa-mining = { version = "0.15.3", path = "mining" }
kaspa-mining-errors = { version = "0.15.3", path = "mining/errors" }
kaspa-muhash = { version = "0.15.3", path = "crypto/muhash" }
kaspa-notify = { version = "0.15.3", path = "notify" }
kaspa-p2p-flows = { version = "0.15.3", path = "protocol/flows" }
kaspa-p2p-lib = { version = "0.15.3", path = "protocol/p2p" }
kaspa-perf-monitor = { version = "0.15.3", path = "metrics/perf_monitor" }
kaspa-pow = { version = "0.15.3", path = "consensus/pow" }
kaspa-rpc-core = { version = "0.15.3", path = "rpc/core" }
kaspa-rpc-macros = { version = "0.15.3", path = "rpc/macros" }
kaspa-rpc-service = { version = "0.15.3", path = "rpc/service" }
kaspa-txscript = { version = "0.15.3", path = "crypto/txscript" }
kaspa-txscript-errors = { version = "0.15.3", path = "crypto/txscript/errors" }
kaspa-utils = { version = "0.15.3", path = "utils" }
kaspa-utils-tower = { version = "0.15.3", path = "utils/tower" }
kaspa-utxoindex = { version = "0.15.3", path = "indexes/utxoindex" }
kaspa-wallet = { version = "0.15.3", path = "wallet/native" }
kaspa-wallet-cli-wasm = { version = "0.15.3", path = "wallet/wasm" }
kaspa-wallet-keys = { version = "0.15.3", path = "wallet/keys" }
kaspa-wallet-pskt = { version = "0.15.3", path = "wallet/pskt" }
kaspa-wallet-core = { version = "0.15.3", path = "wallet/core" }
kaspa-wallet-macros = { version = "0.15.3", path = "wallet/macros" }
kaspa-wasm = { version = "0.15.3", path = "wasm" }
kaspa-wasm-core = { version = "0.15.3", path = "wasm/core" }
kaspa-wrpc-client = { version = "0.15.3", path = "rpc/wrpc/client" }
kaspa-wrpc-proxy = { version = "0.15.3", path = "rpc/wrpc/proxy" }
kaspa-wrpc-server = { version = "0.15.3", path = "rpc/wrpc/server" }
kaspa-wrpc-wasm = { version = "0.15.3", path = "rpc/wrpc/wasm" }
kaspa-wrpc-example-subscriber = { version = "0.15.3", path = "rpc/wrpc/examples/subscriber" }
kaspad = { version = "0.15.3", path = "kaspad" }
kaspa-alloc = { version = "0.15.3", path = "utils/alloc" }
# kaspa-testing-integration = { version = "0.15.4", path = "testing/integration" }
kaspa-addresses = { version = "0.15.4", path = "crypto/addresses" }
kaspa-addressmanager = { version = "0.15.4", path = "components/addressmanager" }
kaspa-bip32 = { version = "0.15.4", path = "wallet/bip32" }
kaspa-cli = { version = "0.15.4", path = "cli" }
kaspa-connectionmanager = { version = "0.15.4", path = "components/connectionmanager" }
kaspa-consensus = { version = "0.15.4", path = "consensus" }
kaspa-consensus-core = { version = "0.15.4", path = "consensus/core" }
kaspa-consensus-client = { version = "0.15.4", path = "consensus/client" }
kaspa-consensus-notify = { version = "0.15.4", path = "consensus/notify" }
kaspa-consensus-wasm = { version = "0.15.4", path = "consensus/wasm" }
kaspa-consensusmanager = { version = "0.15.4", path = "components/consensusmanager" }
kaspa-core = { version = "0.15.4", path = "core" }
kaspa-daemon = { version = "0.15.4", path = "daemon" }
kaspa-database = { version = "0.15.4", path = "database" }
kaspa-grpc-client = { version = "0.15.4", path = "rpc/grpc/client" }
kaspa-grpc-core = { version = "0.15.4", path = "rpc/grpc/core" }
kaspa-grpc-server = { version = "0.15.4", path = "rpc/grpc/server" }
kaspa-hashes = { version = "0.15.4", path = "crypto/hashes" }
kaspa-index-core = { version = "0.15.4", path = "indexes/core" }
kaspa-index-processor = { version = "0.15.4", path = "indexes/processor" }
kaspa-math = { version = "0.15.4", path = "math" }
kaspa-merkle = { version = "0.15.4", path = "crypto/merkle" }
kaspa-metrics-core = { version = "0.15.4", path = "metrics/core" }
kaspa-mining = { version = "0.15.4", path = "mining" }
kaspa-mining-errors = { version = "0.15.4", path = "mining/errors" }
kaspa-muhash = { version = "0.15.4", path = "crypto/muhash" }
kaspa-notify = { version = "0.15.4", path = "notify" }
kaspa-p2p-flows = { version = "0.15.4", path = "protocol/flows" }
kaspa-p2p-lib = { version = "0.15.4", path = "protocol/p2p" }
kaspa-perf-monitor = { version = "0.15.4", path = "metrics/perf_monitor" }
kaspa-pow = { version = "0.15.4", path = "consensus/pow" }
kaspa-rpc-core = { version = "0.15.4", path = "rpc/core" }
kaspa-rpc-macros = { version = "0.15.4", path = "rpc/macros" }
kaspa-rpc-service = { version = "0.15.4", path = "rpc/service" }
kaspa-txscript = { version = "0.15.4", path = "crypto/txscript" }
kaspa-txscript-errors = { version = "0.15.4", path = "crypto/txscript/errors" }
kaspa-utils = { version = "0.15.4", path = "utils" }
kaspa-utils-tower = { version = "0.15.4", path = "utils/tower" }
kaspa-utxoindex = { version = "0.15.4", path = "indexes/utxoindex" }
kaspa-wallet = { version = "0.15.4", path = "wallet/native" }
kaspa-wallet-cli-wasm = { version = "0.15.4", path = "wallet/wasm" }
kaspa-wallet-keys = { version = "0.15.4", path = "wallet/keys" }
kaspa-wallet-pskt = { version = "0.15.4", path = "wallet/pskt" }
kaspa-wallet-core = { version = "0.15.4", path = "wallet/core" }
kaspa-wallet-macros = { version = "0.15.4", path = "wallet/macros" }
kaspa-wasm = { version = "0.15.4", path = "wasm" }
kaspa-wasm-core = { version = "0.15.4", path = "wasm/core" }
kaspa-wrpc-client = { version = "0.15.4", path = "rpc/wrpc/client" }
kaspa-wrpc-proxy = { version = "0.15.4", path = "rpc/wrpc/proxy" }
kaspa-wrpc-server = { version = "0.15.4", path = "rpc/wrpc/server" }
kaspa-wrpc-wasm = { version = "0.15.4", path = "rpc/wrpc/wasm" }
kaspa-wrpc-example-subscriber = { version = "0.15.4", path = "rpc/wrpc/examples/subscriber" }
kaspad = { version = "0.15.4", path = "kaspad" }
kaspa-alloc = { version = "0.15.4", path = "utils/alloc" }

# external
aes = "0.8.3"
Expand Down
2 changes: 1 addition & 1 deletion consensus/core/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub mod perf {

/// The default slack interval used by the reachability
/// algorithm to encounter for blocks out of the selected chain.
pub const DEFAULT_REINDEX_SLACK: u64 = 1 << 12;
pub const DEFAULT_REINDEX_SLACK: u64 = 1 << 14;

const BASELINE_HEADER_DATA_CACHE_SIZE: usize = 10_000;
const BASELINE_BLOCK_DATA_CACHE_SIZE: usize = 200;
Expand Down
6 changes: 3 additions & 3 deletions consensus/core/src/config/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,12 @@ pub const TESTNET11_PARAMS: Params = Params {

storage_mass_parameter: STORAGE_MASS_PARAMETER,
storage_mass_activation: ForkActivation::always(),
kip10_activation: ForkActivation::never(),
// Roughly at Dec 3, 2024 1800 UTC
kip10_activation: ForkActivation::new(287238000),
payload_activation: ForkActivation::new(287238000),

skip_proof_of_work: false,
max_block_level: 250,

payload_activation: ForkActivation::never(),
};

pub const SIMNET_PARAMS: Params = Params {
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/consensus/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ impl ConsensusStorage {
// Budgets in bytes. All byte budgets overall sum up to ~1GB of memory (which obviously takes more low level alloc space)
let daa_excluded_budget = scaled(30_000_000);
let statuses_budget = scaled(30_000_000);
let reachability_data_budget = scaled(20_000_000);
let reachability_sets_budget = scaled(20_000_000); // x 2 for tree children and future covering set
let reachability_data_budget = scaled(100_000_000);
let reachability_sets_budget = scaled(100_000_000); // x 2 for tree children and future covering set
let ghostdag_compact_budget = scaled(15_000_000);
let headers_compact_budget = scaled(5_000_000);
let parents_budget = scaled(40_000_000); // x 3 for reachability and levels
let children_budget = scaled(5_000_000); // x 3 for reachability and levels
let parents_budget = scaled(80_000_000); // x 3 for reachability and levels
let children_budget = scaled(20_000_000); // x 3 for reachability and levels
let ghostdag_budget = scaled(80_000_000); // x 2 for levels
let headers_budget = scaled(80_000_000);
let transactions_budget = scaled(40_000_000);
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/model/services/reachability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ pub trait ReachabilityService {
/// Note that we use the graph theory convention here which defines that a block is also an ancestor of itself.
fn is_chain_ancestor_of(&self, this: Hash, queried: Hash) -> bool;

/// Result version of [`is_dag_ancestor_of`] (avoids unwrapping internally)
/// Result version of [`Self::is_dag_ancestor_of`] (avoids unwrapping internally)
fn is_dag_ancestor_of_result(&self, this: Hash, queried: Hash) -> Result<bool>;

/// Returns true if `this` is a DAG ancestor of `queried` (i.e., `queried ∈ future(this) ∪ {this}`).
/// Note: this method will return true if `this == queried`.
/// The complexity of this method is `O(log(|future_covering_set(this)|))`
fn is_dag_ancestor_of(&self, this: Hash, queried: Hash) -> bool;

/// Checks if `this` is DAG ancestor of any of the blocks in `queried`. See [`is_dag_ancestor_of`] as well.
/// Checks if `this` is DAG ancestor of any of the blocks in `queried`. See [`Self::is_dag_ancestor_of`] as well.
fn is_dag_ancestor_of_any(&self, this: Hash, queried: &mut impl Iterator<Item = Hash>) -> bool;

/// Checks if any of the blocks in `list` is DAG ancestor of `queried`. See [`is_dag_ancestor_of`] as well.
/// Checks if any of the blocks in `list` is DAG ancestor of `queried`. See [`Self::is_dag_ancestor_of`] as well.
fn is_any_dag_ancestor(&self, list: &mut impl Iterator<Item = Hash>, queried: Hash) -> bool;

/// Result version of [`is_any_dag_ancestor`] (avoids unwrapping internally)
/// Result version of [`Self::is_any_dag_ancestor`] (avoids unwrapping internally)
fn is_any_dag_ancestor_result(&self, list: &mut impl Iterator<Item = Hash>, queried: Hash) -> Result<bool>;

/// Finds the tree child of `ancestor` which is also a chain ancestor of `descendant`.
Expand Down
31 changes: 31 additions & 0 deletions consensus/src/pipeline/virtual_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub struct VirtualStateProcessor {

// Storage mass hardfork DAA score
pub(crate) storage_mass_activation: ForkActivation,
pub(crate) kip10_activation: ForkActivation,
}

impl VirtualStateProcessor {
Expand Down Expand Up @@ -230,6 +231,7 @@ impl VirtualStateProcessor {
notification_root,
counters,
storage_mass_activation: params.storage_mass_activation,
kip10_activation: params.kip10_activation,
}
}

Expand Down Expand Up @@ -905,6 +907,23 @@ impl VirtualStateProcessor {
virtual_state.daa_score,
virtual_state.past_median_time,
)?;
// Temp TN11 HF logic:
// Switching from kip9 alpha to beta requires making sure that mass is calculated by the actual virtual DAA score of this block template
if self.storage_mass_activation.is_active(virtual_state.daa_score) {
use kaspa_consensus_core::mass::Kip9Version;
let kip9_version =
if self.kip10_activation.is_active(virtual_state.daa_score) { Kip9Version::Beta } else { Kip9Version::Alpha };
// Skip mass check since we will recalculate it correctly in a moment
let vtx =
self.validate_transaction_in_utxo_context(tx, utxo_view, virtual_state.daa_score, TxValidationFlags::SkipMassCheck)?;
let contextual_mass = self
.transaction_validator
.mass_calculator
.calc_tx_overall_mass(&vtx, None, kip9_version)
.ok_or(kaspa_consensus_core::errors::tx::TxRuleError::MassIncomputable)?;
tx.set_mass(contextual_mass);
return Ok(vtx.calculated_fee);
}
let ValidatedTransaction { calculated_fee, .. } =
self.validate_transaction_in_utxo_context(tx, utxo_view, virtual_state.daa_score, TxValidationFlags::Full)?;
Ok(calculated_fee)
Expand Down Expand Up @@ -979,6 +998,18 @@ impl VirtualStateProcessor {
// At this point we can safely drop the read lock
drop(virtual_read);

// Temp TN11 HF logic:
// In the very unlikely event where virtual DAA score decreased and total mass increased, remove some txs
if self.storage_mass_activation.is_active(virtual_state.daa_score) {
let mut total_mass = 0;
if let Some(pos) = txs.iter().position(|tx| {
total_mass += tx.mass();
total_mass > 500_000
}) {
txs.truncate(pos);
}
}

// Build the template
self.build_block_template_from_virtual_state(virtual_state, miner_data, txs, calculated_fees)
}
Expand Down
9 changes: 7 additions & 2 deletions consensus/src/pipeline/virtual_processor/utxo_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,13 @@ impl VirtualStateProcessor {

// For non-activated nets (mainnet, TN10) we can update mempool rules to KIP9 beta asap. For
// TN11 we need to hard-fork consensus first (since the new beta rules are more permissive)
let kip9_version =
if self.storage_mass_activation == ForkActivation::never() { Kip9Version::Beta } else { Kip9Version::Alpha };
// Also for TN11, we switch to KIP9 beta upon KIP10 activation
let kip9_version = if self.storage_mass_activation == ForkActivation::never() || self.kip10_activation.is_active(pov_daa_score)
{
Kip9Version::Beta
} else {
Kip9Version::Alpha
};

// Calc the full contextual mass including storage mass
let contextual_mass = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl TransactionValidator {
let fee = total_in - total_out;
if flags != TxValidationFlags::SkipMassCheck && self.storage_mass_activation.is_active(pov_daa_score) {
// Storage mass hardfork was activated
self.check_mass_commitment(tx)?;
self.check_mass_commitment(tx, pov_daa_score)?;

if self.storage_mass_activation.is_within_range_from_activation(pov_daa_score, 10) {
warn!("--------- Storage mass hardfork was activated successfully!!! --------- (DAA score: {})", pov_daa_score);
Expand Down Expand Up @@ -125,9 +125,11 @@ impl TransactionValidator {
Ok(total_out)
}

fn check_mass_commitment(&self, tx: &impl VerifiableTransaction) -> TxResult<()> {
fn check_mass_commitment(&self, tx: &impl VerifiableTransaction, pov_daa_score: u64) -> TxResult<()> {
// HF to use the beta version in consensus if KIP10 is activated
let kip9_version = if self.kip10_activation.is_active(pov_daa_score) { Kip9Version::Beta } else { Kip9Version::Alpha };
let calculated_contextual_mass =
self.mass_calculator.calc_tx_overall_mass(tx, None, Kip9Version::Alpha).ok_or(TxRuleError::MassIncomputable)?;
self.mass_calculator.calc_tx_overall_mass(tx, None, kip9_version).ok_or(TxRuleError::MassIncomputable)?;
let committed_contextual_mass = tx.tx().mass();
if committed_contextual_mass != calculated_contextual_mass {
return Err(TxRuleError::WrongMass(calculated_contextual_mass, committed_contextual_mass));
Expand Down
2 changes: 1 addition & 1 deletion wallet/core/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct SignMessageOptions {
/// side-channel attacks. Providing it definitely improves security, but omitting it
/// should not be considered dangerous, as most legacy signature schemes don't provide
/// mitigations against such attacks. To read more about the relevant discussions that
/// arose in adding this randomness please see: https://github.com/sipa/bips/issues/195
/// arose in adding this randomness please see: <https://github.com/sipa/bips/issues/195>
pub no_aux_rand: bool,
}

Expand Down

0 comments on commit 2b3f55f

Please sign in to comment.