Skip to content

Commit 7cdff2b

Browse files
committed
Fix fork choice in test runtime
1 parent 66c5ee0 commit 7cdff2b

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/subspace-verification/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ std = [
3333
"subspace-kzg?/std",
3434
"thiserror/std"
3535
]
36+
# Activate test APIs and workarounds
37+
testing = []

crates/subspace-verification/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ pub struct VerifySolutionParams {
189189
/// Calculate the block's contribution to the fork weight, which is derived from the provided
190190
/// solution range.
191191
pub fn calculate_block_fork_weight(solution_range: SolutionRange) -> BlockForkWeight {
192+
// Work around the test runtime accepting all solutions, which causes blocks to have zero
193+
// fork weight. This makes each node keep its own blocks, and never reorg to a common chain.
194+
#[cfg(feature = "testing")]
195+
let solution_range = if solution_range == SolutionRange::MAX {
196+
SolutionRange::MAX - 1
197+
} else {
198+
solution_range
199+
};
200+
192201
BlockForkWeight::from(SolutionRange::MAX - solution_range)
193202
}
194203

test/subspace-test-runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static_assertions.workspace = true
6363
subspace-core-primitives.workspace = true
6464
subspace-runtime-primitives.workspace = true
6565
subspace-test-primitives.workspace = true
66+
# Activate a testing workaround for the fork choice rule
67+
subspace-verification = { workspace = true, features = ["testing"] }
6668

6769
[build-dependencies]
6870
substrate-wasm-builder = { workspace = true, optional = true }

0 commit comments

Comments
 (0)