Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
18 changes: 18 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pallet-vesting = { path = "./pallets/vesting", default-features = false }
pallet-balances = { path="./pallets/balances", default-features = false }
pallet-reversible-transfers = { path="./pallets/reversible-transfers", default-features = false }
pallet-conviction-voting = { version = "39.1.0", default-features = false }
pallet-membership = { version="39.0.0", default-features = false}
pallet-preimage = { version = "39.0.0", default-features = false }
pallet-referenda = { version = "39.1.0", default-features = false }
pallet-scheduler = { version = "40.1.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub fn create_benchmark_extrinsic(
resonance_runtime::transaction_extensions::ReversibleTransactionExtension::<
runtime::Runtime,
>::new(),
resonance_runtime::transaction_extensions::TechCollectiveExtension::<
runtime::Runtime>::new(),
);

let raw_payload = runtime::SignedPayload::from_raw(
Expand All @@ -153,6 +155,7 @@ pub fn create_benchmark_extrinsic(
(),
None,
(),
(),
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down
4 changes: 4 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ frame-executive.workspace = true
frame-metadata-hash-extension.workspace = true
pallet-balances.workspace = true
pallet-conviction-voting = { workspace = true, default-features = false }
pallet-membership = {workspace = true, default-features = false}
pallet-preimage = { workspace = true, default-features = false }
pallet-referenda = {workspace = true, default-features = false }
pallet-scheduler = { workspace = true, default-features = false }
Expand Down Expand Up @@ -94,6 +95,7 @@ std = [
"pallet-faucet/std",
"pallet-mining-rewards/std",
"pallet-conviction-voting/std",
"pallet-membership/std",
"pallet-preimage/std",
"pallet-referenda/std",
"pallet-scheduler/std",
Expand Down Expand Up @@ -137,6 +139,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
Expand All @@ -161,6 +164,7 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-vesting/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-membership/try-runtime",
"sp-runtime/try-runtime",
]

Expand Down
17 changes: 17 additions & 0 deletions runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ impl pallet_preimage::Config for Runtime {
type Consideration = PreimageDeposit;
}

parameter_types! {
pub const MaxMembers: u32 = 13; // Maximum number of members allowed
}

impl pallet_membership::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
type AddOrigin = frame_system::EnsureRoot<AccountId>;
type RemoveOrigin = frame_system::EnsureRoot<AccountId>;
type SwapOrigin = frame_system::EnsureRoot<AccountId>;
type ResetOrigin = frame_system::EnsureRoot<AccountId>;
type PrimeOrigin = frame_system::EnsureRoot<AccountId>;
type MembershipInitialized = ();
type MembershipChanged = ();
type MaxMembers = MaxMembers;
}

impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);

parameter_types! {
Expand Down
96 changes: 49 additions & 47 deletions runtime/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig};
use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, TechCollectiveConfig};
use alloc::{vec, vec::Vec};
use frame_support::BoundedVec;
use dilithium_crypto::pair::{crystal_alice, dilithium_bob, crystal_charlie};
use serde_json::Value;
use sp_core::crypto::Ss58Codec;
Expand All @@ -27,10 +28,27 @@ use sp_runtime::traits::IdentifyAccount;
/// Identifier for the live testnet runtime preset.
pub const LIVE_TESTNET_RUNTIME_PRESET: &str = "live_testnet";

fn test_root_account() -> AccountId {
account_from_ss58("5FktBKPnRkY5QvF2NmFNUNh55mJvBtgMth5QoBjFJ4E4BbFf")
}
Comment thread
czareko marked this conversation as resolved.
fn tech_collective_members() -> Vec<AccountId> {
vec![
account_from_ss58("5G1BRLFXNQwePnJhMgjb1gXrhwPLn7QXmFw4f4J8ENsuuBBd"),
account_from_ss58("5Hpmk1NeonhmTTu1MvQ5hYwBTSkUjWAEuotcS93MQWaLA6oj"),
]
}
fn dilithium_default_accounts() -> Vec<AccountId> {
vec![
crystal_alice().into_account(),
dilithium_bob().into_account(),
crystal_charlie().into_account(),
]
}
// Returns the genesis config presets populated with given parameters.
fn testnet_genesis(
fn genesis_template(
endowed_accounts: Vec<AccountId>,
root: AccountId,
tech_collective_members: Vec<AccountId>
) -> Value {
let config = RuntimeGenesisConfig {
balances: BalancesConfig {
Expand All @@ -40,7 +58,12 @@ fn testnet_genesis(
.map(|k| (k, 1u128 << 60))
.collect::<Vec<_>>(),
},
sudo: SudoConfig { key: Some(root) },
sudo: SudoConfig { key: Some(root.clone()) },
tech_collective: TechCollectiveConfig {
members: BoundedVec::try_from(tech_collective_members)
.expect("Initial tech collective members are valid."),
phantom: Default::default(),
},
..Default::default()
};

Expand All @@ -49,65 +72,41 @@ fn testnet_genesis(

/// Return the development genesis config.
pub fn development_config_genesis() -> Value {
let mut endowed_accounts = vec![
AccountKeyring::Alice.to_account_id(),
AccountKeyring::Bob.to_account_id(),
AccountKeyring::AliceStash.to_account_id(),
AccountKeyring::BobStash.to_account_id(),
];

// Add Dilithium-based accounts
let dilithium_accounts = vec![
crystal_alice().into_account(),
dilithium_bob().into_account(),
crystal_charlie().into_account(),
];
endowed_accounts.extend(dilithium_accounts);

//use sp_core::crypto::ByteArray;

//log::info!("crystal_alice: {:?}", crystal_alice().public().into_account());
//log::info!("dilithium_bob: {:?}", dilithium_bob().public().as_slice());
//log::info!("crystal_charlie: {:?}", crystal_charlie().public().as_slice());

// crystal_alice: 5DzUw8DMrf54xf49UeARmYvcGxJFrupDCT1SYxB3w2RXF9Eq
// dilithium_bob: 5CxEUqBNycBAW5VvTaRXgkr4uK5HpMuS921gaTLVV9b3QYJx
// crystal_charlie: 5Fj6VYnJGMeAPg9y5oWzEyXakZbJMGSy9VdbehdE5suDvB4t
// crystal_alice: 553ffb66c8f627b6b6bd982ef564e144e779fc745f24241fdedac7e43f3ea486 (5DzUw8DM...)
// dilithium_bob: 274c9a7ecffb52c25173be718b5fcf2d383bf6e465d63a34cbc26de56efa24f0 (5CxEUqBN...)
// crystal_charlie: a1fc398e6f48f42c820cb3dcc3da40758a57f1a3243674ffe81832cd051c094c (5Fj6VYnJ...)


testnet_genesis(
endowed_accounts,
AccountKeyring::Alice.to_account_id(), // Keep Alice as sudo
)
let mut endowed_accounts = vec![];
endowed_accounts.extend(tech_collective_members());
endowed_accounts.extend(dilithium_default_accounts());

genesis_template(
endowed_accounts,
crystal_alice().into_account(),
tech_collective_members()
)
}

/// Return the live testnet genesis config.
///
/// Endows only the specified test account and sets it as Sudo.
pub fn live_testnet_config_genesis() -> Value {
let test_account_id = AccountId::from_ss58check("5FktBKPnRkY5QvF2NmFNUNh55mJvBtgMth5QoBjFJ4E4BbFf")
.expect("Failed to decode testnet account ID");

let endowed_accounts = vec![test_account_id.clone()];
log::info!("endowed account: {:?}", test_account_id.to_ss58check());

testnet_genesis(
endowed_accounts,
test_account_id, // Set the test account as sudo for this testnet
let mut endowed_accounts = vec![test_root_account()];
endowed_accounts.extend(tech_collective_members());
log::info!("endowed account: {:?}", test_root_account().to_ss58check());

genesis_template(
endowed_accounts,
test_root_account(),
tech_collective_members()
)
}

/// Return the local genesis config preset.
pub fn local_config_genesis() -> Value {
testnet_genesis(
genesis_template(
AccountKeyring::iter()
.filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two)
.map(|v| v.to_account_id())
.collect::<Vec<_>>(),
AccountKeyring::Alice.to_account_id(),
test_root_account(),
tech_collective_members()
)
}

Expand All @@ -125,6 +124,9 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
.into_bytes(),
)
}
fn account_from_ss58(ss58: &str) -> AccountId {
AccountId::from_ss58check(ss58).expect("Failed to decode SS58 address")
}

/// List of supported presets.
pub fn preset_names() -> Vec<PresetId> {
Expand Down
32 changes: 12 additions & 20 deletions runtime/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,19 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
max_deciding: 1, // Only 1 referendum can be in deciding phase at a time
decision_deposit: 10 * UNIT, // Highest deposit requirement to prevent spam
prepare_period: 1 * DAYS, // 1 day preparation before voting begins
decision_period: 14 * DAYS, // 2 weeks for community to vote
decision_period: 14 * DAYS, // 2 weeks for community to vote - even if all members vote, we will wait for execution
confirm_period: 1 * DAYS, // 1 day confirmation period once passing
min_enactment_period: 1 * DAYS, // At least 1 day between approval and execution
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50), // Minimum 50% approval at end
floor: Perbill::from_percent(75), // Minimum 75% approval at end
ceil: Perbill::from_percent(100), // Requires 100% approval at start
},
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(10), // At least 10% support at end
ceil: Perbill::from_percent(50), // 50% support required at start
length: Perbill::from_percent(0),
Comment thread
czareko marked this conversation as resolved.
Outdated
//In this way support param is off.
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(0),
},
},
),
Expand Down Expand Up @@ -155,31 +156,21 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
&TRACKS
}

// fn track_for(origin: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
// if origin.eq(&frame_support::dispatch::RawOrigin::Root.into()) {
// Ok(0)
// } else {
// Err(())
// }
// }

fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
// Check for system origins first
if let Some(system_origin) = id.as_system_ref() {
match system_origin {
frame_system::RawOrigin::Root => return Ok(0),
frame_system::RawOrigin::None => return Ok(2),
frame_system::RawOrigin::Root => return Ok(0), // Root can use track 0
frame_system::RawOrigin::None => return Ok(2), // None origin uses track 2
_ => {}
}
}

// Check for other custom origins
// This syntax depends on exactly how your custom origins are implemented
if let Some(_) = id.as_signed() {
// Check for signed origins - simplified version
if let Some(_signer) = id.as_signed() {
return Ok(1);
}

// No match found
Err(())
}

Expand All @@ -201,4 +192,5 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
}
Ok(())
}
}
}

6 changes: 5 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub type TxExtension = (
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
transaction_extensions::ReversibleTransactionExtension<Runtime>,
transaction_extensions::TechCollectiveExtension<Runtime>
);

/// Unchecked extrinsic type as expected by this runtime.
Expand Down Expand Up @@ -264,6 +265,9 @@ mod runtime {
#[runtime::pallet_index(14)]
pub type ConvictionVoting = pallet_conviction_voting;

#[runtime::pallet_index(15)]
#[runtime::pallet_index(15)]
pub type TechCollective = pallet_membership;

#[runtime::pallet_index(16)]
pub type Faucet = pallet_faucet;
}
Loading