From bd5fbd77b7ebd8b8073c93562d2ac8437f11f5ee Mon Sep 17 00:00:00 2001 From: Abhijit Roy Date: Mon, 18 Mar 2024 12:46:46 +0530 Subject: [PATCH] Made changed based on PR #161#pullrequestreview-1941023244 - Sorted sp-api alphabetically - Synced '[profile.dev.package]' from 'main' branch - Reverted 'total_space_pledged' formula to original one - Added snippet to fetch SLOT_PROBABILITY from runtime api client directly. TODO: uncomment later. --- Cargo.toml | 50 ++++++++++++++++++++++++++++++++++++++++++++- src/backend/node.rs | 21 ++++++++++--------- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca7d8a1c..ff00bf8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ semver = "1.0.22" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" simple_moving_average = "1.0.2" +sp-api = "28.0.0" sp-core = { git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", default-features = false } sp-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "b96ae888720551b22ece25cf1adba00615721fa9" } sp-domains-fraud-proof = { git = "https://github.com/subspace/subspace", rev = "b96ae888720551b22ece25cf1adba00615721fa9" } @@ -97,7 +98,6 @@ thread-priority = "0.16.0" tokio = { version = "1.36.0", features = ["fs", "time"] } tracing = "0.1.40" tracing-subscriber = "0.3.18" -sp-api = "28.0.0" [target.'cfg(windows)'.build-dependencies] winres = "0.1.12" @@ -116,11 +116,59 @@ numa = [ # # This list is ordered alphabetically. [profile.dev.package] +bitvec = { opt-level = 3 } +blake2 = { opt-level = 3 } +blake3 = { opt-level = 3 } +blake2b_simd = { opt-level = 3 } +blst = { opt-level = 3 } +rust-kzg-blst = { opt-level = 3 } +chacha20 = { opt-level = 3 } +chacha20poly1305 = { opt-level = 3 } +cranelift-codegen = { opt-level = 3 } +cranelift-wasm = { opt-level = 3 } +crc32fast = { opt-level = 3 } +crossbeam-deque = { opt-level = 3 } +crypto-mac = { opt-level = 3 } +curve25519-dalek = { opt-level = 3 } +ed25519-zebra = { opt-level = 3 } +flate2 = { opt-level = 3 } +futures-channel = { opt-level = 3 } +hashbrown = { opt-level = 3 } +hash-db = { opt-level = 3 } +hmac = { opt-level = 3 } +httparse = { opt-level = 3 } +integer-sqrt = { opt-level = 3 } +k256 = { opt-level = 3 } +keccak = { opt-level = 3 } +kzg = { opt-level = 3 } +libsecp256k1 = { opt-level = 3 } +libz-sys = { opt-level = 3 } +mio = { opt-level = 3 } +nalgebra = { opt-level = 3 } +num-bigint = { opt-level = 3 } parking_lot = { opt-level = 3 } +parking_lot_core = { opt-level = 3 } +percent-encoding = { opt-level = 3 } +primitive-types = { opt-level = 3 } +ring = { opt-level = 3 } +rustls = { opt-level = 3 } +secp256k1 = { opt-level = 3 } +sha2 = { opt-level = 3 } +sha3 = { opt-level = 3 } +smallvec = { opt-level = 3 } +snow = { opt-level = 3 } +subspace-archiving = { opt-level = 3 } subspace-core-primitives = { opt-level = 3 } subspace-erasure-coding = { opt-level = 3 } subspace-farmer-components = { opt-level = 3 } subspace-proof-of-space = { opt-level = 3 } +subspace-proof-of-time = { opt-level = 3 } +twox-hash = { opt-level = 3 } +uint = { opt-level = 3 } +x25519-dalek = { opt-level = 3 } +yamux = { opt-level = 3 } +zeroize = { opt-level = 3 } + [profile.release] # Substrate runtime requires unwinding. diff --git a/src/backend/node.rs b/src/backend/node.rs index 75bd56f2..7a5e0f9f 100644 --- a/src/backend/node.rs +++ b/src/backend/node.rs @@ -282,8 +282,6 @@ fn get_total_account_balance( Some(account_data.free + account_data.reserved + account_data.frozen) } -// defined here: https://github.com/subspace/subspace/blob/5d8b65740ff054b01ebcbaf5a905e74274c1a5d0/crates/subspace-core-primitives/src/pieces.rs#L803 -const PIECE_SIZE: usize = 1048672/* the actual piece size from your runtime */; // TODO: needs to be moved to runtime constants or somewhere else const SLOT_PROBABILITY: (u64, u64) = (1, 6); @@ -303,16 +301,19 @@ where .map(|solution_ranges| solution_ranges.current) .expect("Failed to get current solution range"); + // TODO: Uncomment later. + // let slot_probability = client + // .runtime_api() + // .chain_constants(block_hash) + // .map(|chain_constants| chain_constants.slot_probability()) + // .unwrap(); + // Calculate the total space pledged let total_space_pledged = u128::from(u64::MAX) - .checked_mul(PIECE_SIZE as u128) - .expect("Multiplication with piece size works; qed") - .checked_mul(u128::from(SLOT_PROBABILITY.0)) - .expect("Multiplication with slot probability_0 works; qed") - .checked_div(u128::from(current_solution_range)) - .expect("Division by current solution range works; qed") - .checked_div(u128::from(SLOT_PROBABILITY.1)) - .expect("Division by slot probability_1 works; qed"); + .saturating_mul(subspace_core_primitives::Piece::SIZE as u128) + .saturating_mul(u128::from(SLOT_PROBABILITY.0)) + / u128::from(current_solution_range) + / u128::from(SLOT_PROBABILITY.1); Ok(total_space_pledged) }