Skip to content

Commit

Permalink
Made changed based on PR #161#pullrequestreview-1941023244
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
abhi3700 committed Mar 18, 2024
1 parent 15532b8 commit bd5fbd7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
50 changes: 49 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"
Expand All @@ -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.
Expand Down
21 changes: 11 additions & 10 deletions src/backend/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
}
Expand Down

0 comments on commit bd5fbd7

Please sign in to comment.