Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local/Shibuya v1 governance integration #1260

Merged
merged 31 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c218080
v1 governance integration
Dinonard Jun 7, 2024
49af40b
Separate register & unregister origins for dApp staking
Dinonard Jun 12, 2024
78b43b6
Init treasury integration
Dinonard Jun 12, 2024
21a6831
Treasury
Dinonard Jun 13, 2024
94e8123
Community council
Dinonard Jun 13, 2024
0ebf987
Community treasury
Dinonard Jun 13, 2024
b76e588
Remove redundant function
Dinonard Jun 14, 2024
21e8896
Community proxy attempt
Dinonard Jun 14, 2024
379117a
Rename
Dinonard Jun 20, 2024
60687e0
Missing box dep
Dinonard Jun 20, 2024
2cea07a
Dummy weights
Dinonard Jun 20, 2024
d23e37a
Tests
Dinonard Jun 20, 2024
973e331
Fixes
Dinonard Jun 20, 2024
122d8fc
Shibuya governance
Dinonard Jun 25, 2024
f5824e2
Merge remote-tracking branch 'origin/master' into feat/governance-shi…
Dinonard Jun 26, 2024
fc4005b
Cargo
Dinonard Jun 26, 2024
a5bfa0c
Zepter
Dinonard Jun 26, 2024
5861b92
dApp staking improvements
Dinonard Jun 26, 2024
cc64799
Align local
Dinonard Jun 26, 2024
89fc2aa
Remove TODOs
Dinonard Jun 26, 2024
771d47d
Extra UT
Dinonard Jun 26, 2024
5599b30
Formating
Dinonard Jun 26, 2024
e1c70c2
Benchmarks
Dinonard Jun 26, 2024
6905fa4
clippy
Dinonard Jun 26, 2024
a5198d9
fix tests
Dinonard Jun 26, 2024
0498ddf
Integration tests setup
Dinonard Jun 27, 2024
1217806
Basic governance integration tests
Dinonard Jun 27, 2024
4d21b40
Finish integration tests
Dinonard Jun 27, 2024
57a0913
Review comment
Dinonard Jun 28, 2024
463b29d
Review comments
Dinonard Jul 2, 2024
3710a35
Benchmarks
Dinonard Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk", branch
pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-democracy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }

# EVM & Ethereum
# (wasm)
Expand Down
43 changes: 39 additions & 4 deletions bin/collator/src/local/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
//! Chain specifications.

use local_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, DappStakingConfig,
EVMConfig, GrandpaConfig, GrandpaId, InflationConfig, InflationParameters, Precompiles,
RuntimeGenesisConfig, Signature, SudoConfig, SystemConfig, TierThreshold, VestingConfig, AST,
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig,
CommunityCouncilMembershipConfig, CommunityTreasuryPalletId, CouncilMembershipConfig,
DappStakingConfig, EVMConfig, GrandpaConfig, GrandpaId, InflationConfig, InflationParameters,
Precompiles, RuntimeGenesisConfig, Signature, SudoConfig, SystemConfig,
TechnicalCommitteeMembershipConfig, TierThreshold, TreasuryPalletId, VestingConfig, AST,
};
use sc_service::ChainType;
use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
traits::{AccountIdConversion, IdentifyAccount, Verify},
Permill,
};

Expand Down Expand Up @@ -75,6 +77,8 @@ pub fn development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
TreasuryPalletId::get().into_account_truncating(),
CommunityTreasuryPalletId::get().into_account_truncating(),
// Arrakis.TEST account in MetaMask
// Import known test account with private key
// 0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391
Expand All @@ -98,6 +102,11 @@ fn testnet_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
) -> RuntimeGenesisConfig {
let accounts: Vec<AccountId> = vec!["Alice", "Bob", "Charlie", "Dave", "Eve"]
.iter()
.map(|s| get_account_id_from_seed::<sr25519::Public>(s))
.collect();

// This is supposed the be the simplest bytecode to revert without returning any data.
// We will pre-deploy it under all of our precompiles to ensure they can be called from
// within contracts.
Expand Down Expand Up @@ -186,6 +195,32 @@ fn testnet_genesis(
params: InflationParameters::default(),
..Default::default()
},
council_membership: CouncilMembershipConfig {
members: accounts
.clone()
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
technical_committee_membership: TechnicalCommitteeMembershipConfig {
members: accounts[..3]
.to_vec()
.try_into()
.expect("Should support at least 3 members."),
phantom: Default::default(),
},
community_council_membership: CommunityCouncilMembershipConfig {
members: accounts
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
council: Default::default(),
technical_committee: Default::default(),
community_council: Default::default(),
democracy: Default::default(),
treasury: Default::default(),
community_treasury: Default::default(),
}
}

Expand Down
22 changes: 14 additions & 8 deletions pallets/dapp-staking-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ pub mod pallet {
+ MaxEncodedLen
+ SmartContractHandle<Self::AccountId>;

/// Privileged origin that is allowed to register smart contracts to the protocol.
type ContractRegisterOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;

/// Privileged origin that is allowed to unregister smart contracts from the protocol.
type ContractUnregisterOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;

/// Privileged origin for managing dApp staking pallet.
type ManagerOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;

Expand Down Expand Up @@ -656,7 +662,7 @@ pub mod pallet {
smart_contract: T::SmartContract,
) -> DispatchResult {
Self::ensure_pallet_enabled()?;
T::ManagerOrigin::ensure_origin(origin)?;
T::ContractRegisterOrigin::ensure_origin(origin)?;

ensure!(
!IntegratedDApps::<T>::contains_key(&smart_contract),
Expand Down Expand Up @@ -744,7 +750,7 @@ pub mod pallet {
new_owner: T::AccountId,
) -> DispatchResult {
Self::ensure_pallet_enabled()?;
let origin = Self::ensure_signed_or_manager(origin)?;
let origin = Self::ensure_signed_or_root(origin)?;
Dinonard marked this conversation as resolved.
Show resolved Hide resolved

IntegratedDApps::<T>::try_mutate(
&smart_contract,
Expand Down Expand Up @@ -783,7 +789,7 @@ pub mod pallet {
smart_contract: T::SmartContract,
) -> DispatchResult {
Self::ensure_pallet_enabled()?;
T::ManagerOrigin::ensure_origin(origin)?;
T::ContractUnregisterOrigin::ensure_origin(origin)?;

let dapp_info =
IntegratedDApps::<T>::get(&smart_contract).ok_or(Error::<T>::ContractNotFound)?;
Expand Down Expand Up @@ -1565,7 +1571,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::force())]
pub fn force(origin: OriginFor<T>, forcing_type: ForcingType) -> DispatchResult {
Self::ensure_pallet_enabled()?;
T::ManagerOrigin::ensure_origin(origin)?;
ensure_root(origin)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we still have the possibility to dispatch root calls on live env ? Will Manager still be relevant ?
Also please update the fn description

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, via democracy pallet.

And of course, sudo 🙂


ensure!(!Safeguard::<T>::get(), Error::<T>::ForceNotAllowed);

Expand Down Expand Up @@ -1609,13 +1615,13 @@ pub mod pallet {
}
}

/// Ensure that the origin is either the `ManagerOrigin` or a signed origin.
/// Ensure that the origin is either the root or a signed origin.
///
/// In case of manager, `Ok(None)` is returned, and if signed origin `Ok(Some(AccountId))` is returned.
pub(crate) fn ensure_signed_or_manager(
/// In case of root, `Ok(None)` is returned, and if signed origin `Ok(Some(AccountId))` is returned.
fn ensure_signed_or_root(
origin: T::RuntimeOrigin,
) -> Result<Option<T::AccountId>, BadOrigin> {
if T::ManagerOrigin::ensure_origin(origin.clone()).is_ok() {
if ensure_root(origin.clone()).is_ok() {
return Ok(None);
}
let who = ensure_signed(origin)?;
Expand Down
19 changes: 16 additions & 3 deletions pallets/dapp-staking-v3/src/test/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::{
};

use frame_support::{
construct_runtime, parameter_types,
traits::{fungible::Mutate as FunMutate, ConstU128, ConstU32},
construct_runtime, ord_parameter_types, parameter_types,
traits::{fungible::Mutate as FunMutate, ConstU128, ConstU32, EitherOfDiverse},
weights::Weight,
};
use sp_arithmetic::fixed_point::FixedU128;
Expand All @@ -40,6 +40,7 @@ use astar_primitives::{
dapp_staking::{Observer as DappStakingObserver, SmartContract, StandardTierSlots},
Balance, BlockNumber,
};
use frame_system::{EnsureRoot, EnsureSignedBy};

pub(crate) type AccountId = u64;

Expand Down Expand Up @@ -198,13 +199,25 @@ impl AccountCheck<AccountId> for DummyAccountCheck {
parameter_types! {
pub const BaseNativeCurrencyPrice: FixedU128 = FixedU128::from_rational(5, 100);
}
ord_parameter_types! {
pub const ContractRegisterAccount: AccountId = 1337;
pub const ContractUnregisterAccount: AccountId = 1779;
pub const ManagerAccount: AccountId = 25711;
}

impl pallet_dapp_staking::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeFreezeReason = RuntimeFreezeReason;
type Currency = Balances;
type SmartContract = MockSmartContract;
type ManagerOrigin = frame_system::EnsureRoot<AccountId>;
type ContractRegisterOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureSignedBy<ContractRegisterAccount, AccountId>>;
type ContractUnregisterOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureSignedBy<ContractUnregisterAccount, AccountId>,
>;
type ManagerOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureSignedBy<ManagerAccount, AccountId>>;
type NativePriceProvider = DummyPriceProvider;
type StakingRewardHandler = DummyStakingRewardHandler;
type CycleConfiguration = DummyCycleConfiguration;
Expand Down
52 changes: 51 additions & 1 deletion pallets/dapp-staking-v3/src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,44 @@ fn register_is_ok() {
// Register two contracts using the same owner
assert_register(7, &MockSmartContract::Wasm(2));
assert_register(7, &MockSmartContract::Wasm(3));

// Register a contract using non-root origin
let smart_contract = MockSmartContract::Wasm(4);
let owner = 11;
let dapp_id = NextDAppId::<Test>::get();
assert_ok!(DappStaking::register(
RuntimeOrigin::signed(ContractRegisterAccount::get()),
owner,
smart_contract.clone()
));
System::assert_last_event(RuntimeEvent::DappStaking(Event::DAppRegistered {
owner,
smart_contract,
dapp_id,
}));
})
}

#[test]
fn register_with_incorrect_origin_fails() {
ExtBuilder::build().execute_with(|| {
// Test assumes that Contract registry & Manager origins are different.
assert_noop!(
DappStaking::register(RuntimeOrigin::signed(1), 3, MockSmartContract::Wasm(2)),
DappStaking::register(
RuntimeOrigin::signed(ManagerAccount::get()),
3,
MockSmartContract::Wasm(2)
),
BadOrigin
);

// Test assumes register & unregister origins are different.
assert_noop!(
DappStaking::register(
RuntimeOrigin::signed(ContractUnregisterAccount::get()),
3,
MockSmartContract::Wasm(2)
),
BadOrigin
);
})
Expand Down Expand Up @@ -427,6 +457,19 @@ fn unregister_no_stake_is_ok() {

// Nothing staked on contract, just unregister it.
assert_unregister(&smart_contract);

// Prepare another dApp, unregister it using non-root origin
let smart_contract = MockSmartContract::Wasm(5);
assert_register(owner, &smart_contract);

assert_ok!(DappStaking::unregister(
RuntimeOrigin::signed(ContractUnregisterAccount::get()),
smart_contract.clone(),
));
System::assert_last_event(RuntimeEvent::DappStaking(Event::DAppUnregistered {
smart_contract: smart_contract.clone(),
era: ActiveProtocolState::<Test>::get().era,
}));
})
}

Expand Down Expand Up @@ -463,6 +506,13 @@ fn unregister_fails() {
DappStaking::unregister(RuntimeOrigin::signed(owner), smart_contract),
BadOrigin
);
assert_noop!(
DappStaking::unregister(
RuntimeOrigin::signed(ContractRegisterAccount::get()),
smart_contract
),
BadOrigin
);

// Cannot unregister same contract twice
assert_unregister(&smart_contract);
Expand Down
2 changes: 2 additions & 0 deletions precompiles/dapp-staking-v3/src/test/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ impl pallet_dapp_staking_v3::Config for Test {
type RuntimeFreezeReason = RuntimeFreezeReason;
type Currency = Balances;
type SmartContract = MockSmartContract;
type ContractRegisterOrigin = frame_system::EnsureRoot<AccountId>;
type ContractUnregisterOrigin = frame_system::EnsureRoot<AccountId>;
type ManagerOrigin = frame_system::EnsureRoot<AccountId>;
type NativePriceProvider = DummyPriceProvider;
type StakingRewardHandler = DummyStakingRewardHandler;
Expand Down
8 changes: 7 additions & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fp-evm = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-assets = { workspace = true }
pallet-collective = { workspace = true }
pallet-membership = { workspace = true }
pallet-treasury = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
Expand Down Expand Up @@ -57,7 +60,10 @@ std = [
"ethereum/std",
"fp-evm/std",
"frame-support/std",
"pallet-treasury/std",
"frame-system/std",
"pallet-membership/std",
"pallet-collective/std",
"sp-std/std",
"sp-runtime/std",
"sp-core/std",
Expand All @@ -77,4 +83,4 @@ std = [
"sp-arithmetic/std",
]
runtime-benchmarks = ["xcm-builder/runtime-benchmarks", "pallet-assets/runtime-benchmarks"]
try-runtime = ["pallet-contracts/try-runtime"]
try-runtime = ["pallet-contracts/try-runtime", "pallet-membership/try-runtime", "pallet-collective/try-runtime", "pallet-treasury/try-runtime"]
Loading
Loading