From 9157660cfdc50b8b2ae007b4a359fdf3aa8d8c06 Mon Sep 17 00:00:00 2001 From: Adam Dossa Date: Mon, 20 Jul 2020 17:30:11 +0100 Subject: [PATCH] Aldebaran 1.1.3 (#476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added staking events (#421) * MESH-790/ Add RPC filtering by Link type (#398) * Misc. fixes (#416) * Misc. fixes * Fix * lint * lint Co-authored-by: Satyam Agrawal * Batch Dispath in Utility Module (#414) * UT added * Update V1 * CodeReview: Remove unused elements * UT added * Update V1 * CodeReview: Remove unused elements Co-authored-by: Adam Dossa Co-authored-by: poly-auto-merge[bot] <65769705+poly-auto-merge[bot]@users.noreply.github.com> * Mesh 1040/Add reserved peer logging (#417) * logging resered nodes * rename peers to nodes Co-authored-by: satyam Co-authored-by: Adam Dossa * Mesh 991/granular errors (#402) * wip * Added internal functions * wired the rpc * Added new structure * Updated structure * some fixes * Added test cases * updated schema * fixed typo in schema * fixed merge Co-authored-by: Adam Dossa Co-authored-by: poly-auto-merge[bot] <65769705+poly-auto-merge[bot]@users.noreply.github.com> * Mesh 1042/rename validator to operator (#425) * introduced --operator as the alias for the validator * add dev comment * fix linting Co-authored-by: satyam Co-authored-by: poly-auto-merge[bot] <65769705+poly-auto-merge[bot]@users.noreply.github.com> * fix: handle optional parameters correctly (#426) * Workaround in Committe module (#424) * Remove unused functions Incorrectly chosen by cherry-pick * Mesh 1049/Allow signing keys to leave their identities (#422) * functions for leaving an identity * Added tests * review comments * bump spec_version & impl_version * MESH-972/ Add new getDidStatus() RPC (#431) * Remove incorrect cherry-picked code * Mesh 1033: Transfer events (#435) * Simplify transfer events * Fix tests * Remove bootnodes 4 - 10 (#436) Co-authored-by: poly-auto-merge[bot] <65769705+poly-auto-merge[bot]@users.noreply.github.com> * linting * RPC to get historical pip voting by address (#433) * Fix lock file (#440) * Bridge batching fix (#445) * Bump versions * Fix fees and adjust bridge limit (#446) * Fix for multisig refactor * Adjust base fee from 0.01 POLYX to 1 POLYX (#448) * Change chain_spec back to reflect genesis * MESH-1102, MESH-1101, MESH-1100: Fix events, errors, kill_proposal and set_proposal_cool_off_period #452 * Bump versions * fixed custodian allowance bug (#455) * Pay with master key (#462) * Temp pay via master key * Fixes * linting and version bump * Fix CDD check * Allow sudo / PIPs to prune old PIPs (#473) * Allow sudo / PIPs to prune old PIPs * Remove PipPruned * Fix upgrade bug and bump versions * Use root origin rather than committee origin * Reset version for Aldebaran release Co-authored-by: Mudit Gupta Co-authored-by: Satyam Agrawal Co-authored-by: Francisco Miguel García Co-authored-by: poly-auto-merge[bot] <65769705+poly-auto-merge[bot]@users.noreply.github.com> Co-authored-by: satyam Co-authored-by: Jeremías Díaz Co-authored-by: Vladimir Komendantskiy --- pallets/pips/src/lib.rs | 27 ++++++++++ pallets/runtime/common/tests/all/pips_test.rs | 50 ++++++++++++++++++- pallets/runtime/develop/src/fee_details.rs | 6 ++- pallets/runtime/develop/src/runtime.rs | 4 +- pallets/runtime/testnet-v1/src/fee_details.rs | 6 ++- pallets/runtime/testnet-v1/src/runtime.rs | 4 +- 6 files changed, 88 insertions(+), 9 deletions(-) diff --git a/pallets/pips/src/lib.rs b/pallets/pips/src/lib.rs index 3e9da5955c..942c5e875e 100644 --- a/pallets/pips/src/lib.rs +++ b/pallets/pips/src/lib.rs @@ -859,6 +859,33 @@ decl_module! { Self::prune_data(id, Self::prune_historical_pips()); } + /// An emergency stop measure to kill a proposal. Governance committee can kill + /// a proposal at any time. + #[weight = SimpleDispatchInfo::FixedOperational(100_000)] + pub fn prune_proposal(origin, id: PipId) { + T::CommitteeOrigin::try_origin(origin).map_err(|_| Error::::BadOrigin)?; + // Check that the proposal is in a state valid for pruning + let proposal = Self::proposals(id).ok_or_else(|| Error::::NoSuchProposal)?; + if proposal.state == ProposalState::Referendum { + // Check that the referendum is in a state valid for pruning + let referendum = Self::referendums(id).ok_or_else(|| Error::::NoSuchProposal)?; + ensure!( + referendum.state == ReferendumState::Rejected || + referendum.state == ReferendumState::Failed || + referendum.state == ReferendumState::Executed, + Error::::IncorrectReferendumState + ); + } else { + ensure!( + proposal.state == ProposalState::Cancelled || + proposal.state == ProposalState::Killed || + proposal.state == ProposalState::Rejected, + Error::::IncorrectProposalState + ); + } + Self::prune_data(id, true); + } + /// Any governance committee member can fast track a proposal and turn it into a referendum /// that will be voted on by the committee. #[weight = SimpleDispatchInfo::FixedOperational(200_000)] diff --git a/pallets/runtime/common/tests/all/pips_test.rs b/pallets/runtime/common/tests/all/pips_test.rs index daeac06fb7..5436fa7343 100644 --- a/pallets/runtime/common/tests/all/pips_test.rs +++ b/pallets/runtime/common/tests/all/pips_test.rs @@ -156,6 +156,8 @@ fn creating_a_referendum_works_we() { let (alice_signer, _) = make_account_with_balance(alice_acc, 300).unwrap(); let bob_acc = AccountKeyring::Bob.public(); let (bob_signer, _) = make_account_with_balance(bob_acc, 200).unwrap(); + // Voting majority + let root = Origin::from(frame_system::RawOrigin::Root); assert_ok!(Pips::propose( alice_signer.clone(), @@ -166,6 +168,12 @@ fn creating_a_referendum_works_we() { None )); + // Cannot prune proposal at this stage + assert_err!( + Pips::prune_proposal(root.clone(), 0), + Error::::IncorrectProposalState + ); + assert_err!( Pips::vote(bob_signer.clone(), 0, true, 50), Error::::ProposalOnCoolOffPeriod @@ -173,6 +181,12 @@ fn creating_a_referendum_works_we() { fast_forward_to(101); assert_ok!(Pips::vote(bob_signer.clone(), 0, true, 50)); + // Cannot prune proposal at this stage + assert_err!( + Pips::prune_proposal(root.clone(), 0), + Error::::IncorrectProposalState + ); + assert_eq!( Pips::proposal_result(0), VotingResult { @@ -188,6 +202,12 @@ fn creating_a_referendum_works_we() { fast_forward_to(120); + // Cannot prune referendum at this stage + assert_err!( + Pips::prune_proposal(root.clone(), 0), + Error::::IncorrectReferendumState + ); + assert_eq!( Pips::referendums(0), Some(Referendum { @@ -253,6 +273,12 @@ fn enacting_a_referendum_works_we() { fast_forward_to(120); + // Cannot prune referendum at this stage + assert_err!( + Pips::prune_proposal(root.clone(), 0), + Error::::IncorrectReferendumState + ); + assert_eq!( Pips::referendums(0), Some(Referendum { @@ -267,7 +293,7 @@ fn enacting_a_referendum_works_we() { Pips::enact_referendum(bob_signer.clone(), 0), Error::::BadOrigin ); - assert_ok!(Pips::enact_referendum(root, 0)); + assert_ok!(Pips::enact_referendum(root.clone(), 0)); assert_eq!( Pips::referendums(0), @@ -279,6 +305,12 @@ fn enacting_a_referendum_works_we() { }) ); + // Cannot prune referendum at this stage + assert_err!( + Pips::prune_proposal(root.clone(), 0), + Error::::IncorrectReferendumState + ); + fast_forward_to(221); assert_eq!( @@ -290,6 +322,13 @@ fn enacting_a_referendum_works_we() { enactment_period: 220, }) ); + + // Can now prune referendum + assert_ok!(Pips::prune_proposal(root.clone(), 0)); + + assert_eq!(Pips::referendums(0), None); + assert_eq!(Pips::proposals(0), None); + assert_eq!(Pips::proposal_metadata(0), None); } #[test] @@ -668,6 +707,7 @@ fn cancel_pips_during_cool_off_period_we() { let (alice, _) = make_account(AccountKeyring::Alice.public()).unwrap(); let (bob, _) = make_account(AccountKeyring::Bob.public()).unwrap(); + let root = Origin::from(frame_system::RawOrigin::Root); // 1. Create Pips proposals assert_ok!(Pips::propose( @@ -692,6 +732,14 @@ fn cancel_pips_during_cool_off_period_we() { fast_forward_to(50); assert_ok!(Pips::cancel_proposal(alice.clone(), 0)); + // Can prune cancelled proposals + assert_ok!(Pips::prune_proposal(root.clone(), 0)); + + // Check proposal is pruned from storage + assert_eq!(Pips::referendums(0), None); + assert_eq!(Pips::proposals(0), None); + assert_eq!(Pips::proposal_metadata(0), None); + // 3. Try to cancel Bob's proposal after cool-off period. fast_forward_to(101); assert_err!( diff --git a/pallets/runtime/develop/src/fee_details.rs b/pallets/runtime/develop/src/fee_details.rs index 9660f43672..1f2d717205 100644 --- a/pallets/runtime/develop/src/fee_details.rs +++ b/pallets/runtime/develop/src/fee_details.rs @@ -235,8 +235,10 @@ fn is_auth_valid( if let AuthorizationData::JoinIdentity(did) = auth.authorization_data { // make sure that the auth was created by the master key of an identity with valid CDD let master = Identity::did_records(&did).master_key; - if auth.authorized_by == Signatory::from(master) { - return check_cdd(&did); + let master_signatory = Signatory::AccountKey(master); + if auth.authorized_by == master_signatory { + let _ = check_cdd(&did)?; + return Ok(Some(master_signatory)); } } } diff --git a/pallets/runtime/develop/src/runtime.rs b/pallets/runtime/develop/src/runtime.rs index 6e27268229..763fe51c04 100644 --- a/pallets/runtime/develop/src/runtime.rs +++ b/pallets/runtime/develop/src/runtime.rs @@ -95,8 +95,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("polymesh"), impl_name: create_runtime_str!("polymath-polymesh"), authoring_version: 1, - spec_version: 1007, - impl_version: 1007, + spec_version: 1008, + impl_version: 1008, apis: RUNTIME_API_VERSIONS, }; diff --git a/pallets/runtime/testnet-v1/src/fee_details.rs b/pallets/runtime/testnet-v1/src/fee_details.rs index 20aed14245..3b1c384a18 100644 --- a/pallets/runtime/testnet-v1/src/fee_details.rs +++ b/pallets/runtime/testnet-v1/src/fee_details.rs @@ -233,8 +233,10 @@ fn is_auth_valid( if let AuthorizationData::JoinIdentity(did) = auth.authorization_data { // make sure that the auth was created by the master key of an identity with valid CDD let master = Identity::did_records(&did).master_key; - if auth.authorized_by == Signatory::from(master) { - return check_cdd(&did); + let master_signatory = Signatory::AccountKey(master); + if auth.authorized_by == master_signatory { + let _ = check_cdd(&did)?; + return Ok(Some(master_signatory)); } } } diff --git a/pallets/runtime/testnet-v1/src/runtime.rs b/pallets/runtime/testnet-v1/src/runtime.rs index 4ef047c796..5cff976463 100644 --- a/pallets/runtime/testnet-v1/src/runtime.rs +++ b/pallets/runtime/testnet-v1/src/runtime.rs @@ -86,8 +86,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("polymesh"), impl_name: create_runtime_str!("polymath-polymesh"), authoring_version: 1, - spec_version: 1007, - impl_version: 1007, + spec_version: 1008, + impl_version: 1008, apis: RUNTIME_API_VERSIONS, };