From 7f38f9cf101e5fca0d763183ffa528c81f86ad9e Mon Sep 17 00:00:00 2001 From: Honza <115138297+Supremesource@users.noreply.github.com> Date: Sun, 25 Aug 2024 23:25:56 +0200 Subject: [PATCH] fix: false `InsufficientStake` error (#207) * fix: `InsufficientStake` when voting * feat: bump spec ver * refac: delegator stake in proposal --- CHANGELOG.md | 4 ++++ Cargo.lock | 2 +- pallets/governance/Cargo.toml | 2 +- pallets/governance/src/voting.rs | 13 +++++++------ runtime/src/lib.rs | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a6be0380..d56bec21e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +spec version `121` + +Fixing `InsufficientStake` bug in proposal voting + spec version `120` Storages: diff --git a/Cargo.lock b/Cargo.lock index a9752383b..0c04be1cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5138,7 +5138,7 @@ dependencies = [ [[package]] name = "pallet-governance" -version = "1.1.0" +version = "1.1.1" dependencies = [ "bty", "frame-benchmarking", diff --git a/pallets/governance/Cargo.toml b/pallets/governance/Cargo.toml index e8002f0fc..1a5560554 100644 --- a/pallets/governance/Cargo.toml +++ b/pallets/governance/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-governance" -version = "1.1.0" +version = "1.1.1" description = "FRAME pallet for runtime logic of Subspace Blockchain." authors = ["Commune Community"] homepage = "https://communeai.org/" diff --git a/pallets/governance/src/voting.rs b/pallets/governance/src/voting.rs index e736381f0..d05097223 100644 --- a/pallets/governance/src/voting.rs +++ b/pallets/governance/src/voting.rs @@ -29,14 +29,15 @@ impl Pallet { Error::::AlreadyVoted ); - let voter_stake = pallet_subspace::Pallet::::get_delegated_stake(&key); + let voter_delegated_stake = pallet_subspace::Pallet::::get_delegated_stake(&key); + let voter_owned_stake = pallet_subspace::Pallet::::get_owned_stake(&key); - ensure!(voter_stake > 0, Error::::InsufficientStake); + ensure!( + voter_delegated_stake > 0 || voter_owned_stake > 0, + Error::::InsufficientStake + ); - let stake_from_vector = pallet_subspace::Pallet::::get_stake_from_vector(&key); - let has_stake_from = - || stake_from_vector.iter().any(|(k, stakes)| k == &key && *stakes > 0); - if !NotDelegatingVotingPower::::get().contains(&key) && !has_stake_from() { + if !NotDelegatingVotingPower::::get().contains(&key) && voter_delegated_stake == 0 { return Err(Error::::VoterIsDelegatingVotingPower.into()); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 90d6e550b..df61eaf63 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -125,7 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 120, + spec_version: 121, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,