diff --git a/crates/pallet-subspace/src/lib.rs b/crates/pallet-subspace/src/lib.rs index df4d4151c6..e7dfe1f25c 100644 --- a/crates/pallet-subspace/src/lib.rs +++ b/crates/pallet-subspace/src/lib.rs @@ -1558,7 +1558,11 @@ fn check_vote( .into(), ) { Ok(solution_distance) => { - if solution_distance <= vote_verification_data.solution_range { + if solution_distance <= vote_verification_data.solution_range / 2 { + debug!( + target: "runtime::subspace", + "Vote quality is too high" + ); return Err(CheckVoteError::QualityTooHigh); } } diff --git a/crates/pallet-subspace/src/tests.rs b/crates/pallet-subspace/src/tests.rs index f55c844934..a76fdbf535 100644 --- a/crates/pallet-subspace/src/tests.rs +++ b/crates/pallet-subspace/src/tests.rs @@ -768,7 +768,8 @@ fn vote_past_future_slot() { ); // Reset so that any solution works for votes - crate::pallet::SolutionRanges::::mutate(|solution_ranges| { + pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -785,8 +786,8 @@ fn vote_past_future_slot() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_err!( @@ -810,8 +811,8 @@ fn vote_past_future_slot() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_err!( @@ -834,8 +835,8 @@ fn vote_past_future_slot() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_ok!(super::check_vote::(&signed_vote, false)); @@ -860,6 +861,7 @@ fn vote_same_slot() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -875,8 +877,8 @@ fn vote_same_slot() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_ok!(super::check_vote::(&signed_vote, true)); @@ -895,8 +897,8 @@ fn vote_same_slot() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_err!( @@ -1018,28 +1020,49 @@ fn vote_solution_quality_too_high() { // Reset so that any solution works for votes, but also block solution range is almost the // same, resulting in quality being too high pallet::SolutionRanges::::mutate(|solution_ranges| { - solution_ranges.current = u64::MAX - 1; + solution_ranges.current = u64::MAX / 5; solution_ranges.voting_current = u64::MAX; }); - // Finally correct signature - let signed_vote = create_signed_vote( - &keypair, - 2, - frame_system::Pallet::::block_hash(1), - Subspace::current_slot() + 1, - Default::default(), - Default::default(), - &archived_segment.pieces, - 1, - SolutionRange::MIN, - SolutionRange::MAX, - ); + { + let signed_vote = create_signed_vote( + &keypair, + 2, + frame_system::Pallet::::block_hash(1), + Subspace::current_slot() + 1, + Default::default(), + Default::default(), + &archived_segment.pieces, + 1, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, + ); - assert_matches!( - super::check_vote::(&signed_vote, false), - Err(CheckVoteError::QualityTooHigh) - ); + // Good solution quality + assert_ok!(super::check_vote::(&signed_vote, false)); + } + + { + let signed_vote = create_signed_vote( + &keypair, + 2, + frame_system::Pallet::::block_hash(1), + Subspace::current_slot() + 1, + Default::default(), + Default::default(), + &archived_segment.pieces, + 1, + SolutionRange::MIN, + // Create vote for block level of quality + pallet::SolutionRanges::::get().current, + ); + + // Quality is too high + assert_matches!( + super::check_vote::(&signed_vote, false), + Err(CheckVoteError::QualityTooHigh) + ); + } }); } @@ -1070,6 +1093,7 @@ fn vote_invalid_proof_of_time() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -1093,8 +1117,8 @@ fn vote_invalid_proof_of_time() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_err!( @@ -1121,8 +1145,8 @@ fn vote_invalid_proof_of_time() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_ok!(super::check_vote::(&signed_vote, false)); @@ -1139,8 +1163,8 @@ fn vote_invalid_proof_of_time() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_err!( @@ -1167,8 +1191,8 @@ fn vote_invalid_proof_of_time() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_err!( @@ -1195,8 +1219,8 @@ fn vote_invalid_proof_of_time() { test_future_proof_of_time, &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_ok!(super::check_vote::(&signed_vote, true)); @@ -1219,6 +1243,7 @@ fn vote_correct_signature() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -1232,8 +1257,8 @@ fn vote_correct_signature() { Default::default(), &archived_segment.pieces, 1, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); assert_ok!(super::check_vote::(&signed_vote, false)); @@ -1255,6 +1280,7 @@ fn vote_equivocation_current_block_plus_vote() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -1270,8 +1296,8 @@ fn vote_equivocation_current_block_plus_vote() { Default::default(), &archived_segment.pieces, reward_address, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); // Parent block author + sector index + chunk + audit chunk index + slot matches that of the @@ -1311,6 +1337,7 @@ fn vote_equivocation_parent_block_plus_vote() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -1326,8 +1353,8 @@ fn vote_equivocation_parent_block_plus_vote() { Default::default(), &archived_segment.pieces, reward_address, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); // Parent block author + sector index + chunk + audit chunk index + slot matches that of the @@ -1375,6 +1402,7 @@ fn vote_equivocation_current_voters_duplicate() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -1392,8 +1420,8 @@ fn vote_equivocation_current_voters_duplicate() { Default::default(), &archived_segment.pieces, reward_address, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); CurrentBlockVoters::::put({ @@ -1461,6 +1489,7 @@ fn vote_equivocation_parent_voters_duplicate() { // Reset so that any solution works for votes pallet::SolutionRanges::::mutate(|solution_ranges| { + solution_ranges.current = u64::MIN; solution_ranges.voting_current = u64::MAX; }); @@ -1477,8 +1506,8 @@ fn vote_equivocation_parent_voters_duplicate() { Default::default(), &archived_segment.pieces, reward_address, - SolutionRange::MIN, - SolutionRange::MAX, + pallet::SolutionRanges::::get().current, + pallet::SolutionRanges::::get().voting_current, ); ParentBlockVoters::::put({ diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index 267993a488..702ef1fc29 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -108,7 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("subspace"), impl_name: create_runtime_str!("subspace"), authoring_version: 0, - spec_version: 1, + spec_version: 2, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 0,