Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 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 @@ -46,6 +46,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-ranked-collective = { 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
49 changes: 0 additions & 49 deletions pallets/qpow/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,55 +333,6 @@ fn test_total_distance_threshold_increases_with_each_block() {
});
}

/*
TODO - we should catch events in tests - this should be possible
#[test]
fn test_submit_nonce_emits_event() {
new_test_ext().execute_with(|| {
// Set up data
let header = [1u8; 32];

// Get the current distance_threshold so we know what we're targeting
let distance_threshold = QPow::get_distance_threshold();
println!("Current distance_threshold: {}", distance_threshold);

// Create a nonce that we know works
let mut nonce = [0u8; 64];
nonce[63] = 14;

// Calculate the distance for this nonce
let distance = QPow::get_nonce_distance(header, nonce);
let threshold = MAX_DISTANCE - distance_threshold;

println!("Nonce: {:?}, Distance: {}, Threshold: {}",
&nonce[62..64], distance, threshold);

// Wyczyść zdarzenia systemu przed wysłaniem nonce
System::reset_events();

// Submit nonce (zakładamy, że jest prawidłowy)
assert!(QPow::submit_nonce(header, nonce));

// Sprawdź, czy zdarzenie zostało wyemitowane
let events = System::events();
println!("Events: {:?}", events);

// Sprawdź, czy istnieje zdarzenie ProofSubmitted
let proof_submitted_event_found = events.iter().any(|record| {
match &record.event {
RuntimeEvent::QPow(Event::ProofSubmitted { nonce: event_nonce }) => {
// Sprawdź, czy nonce w zdarzeniu zgadza się z tym, który wysłaliśmy
*event_nonce == nonce
},
_ => false,
}
});

assert!(proof_submitted_event_found, "ProofSubmitted event was not emitted or had incorrect data");
});
}
*/

#[test]
fn test_integrated_verification_flow() {
new_test_ext().execute_with(|| {
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-ranked-collective = { 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 @@ -95,6 +96,7 @@ std = [
"pallet-faucet/std",
"pallet-mining-rewards/std",
"pallet-conviction-voting/std",
"pallet-ranked-collective/std",
"pallet-preimage/std",
"pallet-referenda/std",
"pallet-scheduler/std",
Expand Down Expand Up @@ -139,6 +141,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
Expand All @@ -164,6 +167,7 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-vesting/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-ranked-collective/try-runtime",
"sp-runtime/try-runtime",
]

Expand Down
92 changes: 88 additions & 4 deletions runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
// For more information, please refer to <http://unlicense.org>

// Substrate and Polkadot dependencies
use crate::governance::{PreimageDeposit, TracksInfo};
use frame_support::traits::ConstU64;
use crate::governance::{RootOrMemberForTechReferendaOrigin, GlobalMaxMembers, MinRankOfClassConverter, PreimageDeposit, RootOrMemberForCollectiveOrigin, CommunityTracksInfo, TechCollectiveTracksInfo};
use frame_support::traits::{ConstU64, NeverEnsureOrigin};
use frame_support::PalletId;
use frame_support::{
derive_impl, parameter_types,
Expand All @@ -37,6 +37,7 @@ use frame_support::{
};
use frame_system::limits::{BlockLength, BlockWeights};
use frame_system::EnsureRoot;
use pallet_ranked_collective::Linear;
use pallet_referenda::impl_tracksinfo_get;
use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier};
use pallet_vesting::VestingPalletId;
Expand Down Expand Up @@ -201,7 +202,8 @@ impl pallet_preimage::Config for Runtime {
type Consideration = PreimageDeposit;
}

impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);

impl_tracksinfo_get!(CommunityTracksInfo, Balance, BlockNumber);

parameter_types! {
// Default voting period (28 days)
Expand Down Expand Up @@ -254,7 +256,89 @@ impl pallet_referenda::Config for Runtime {
/// The frequency at which the pallet checks for expired or ready-to-timeout referenda.
type AlarmInterval = AlarmInterval;
/// Defines the different referendum tracks (categories with distinct parameters).
type Tracks = TracksInfo;
type Tracks = CommunityTracksInfo;
/// The pallet used to store preimages (detailed proposal content) for referenda.
type Preimages = Preimage;
}

parameter_types! {
pub const MinRankOfClassDelta: u16 = 0;
pub const MaxMemberCount: u32 = 13;
}
impl pallet_ranked_collective::Config for Runtime {
type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Runtime>;
type RuntimeEvent = RuntimeEvent;
type AddOrigin = RootOrMemberForCollectiveOrigin;
type RemoveOrigin = RootOrMemberForCollectiveOrigin;
type PromoteOrigin = NeverEnsureOrigin<u16>;
type DemoteOrigin = NeverEnsureOrigin<u16>;
type ExchangeOrigin = NeverEnsureOrigin<u16>;
type Polls = pallet_referenda::Pallet<Runtime, TechReferendaInstance>;
type MinRankOfClass = MinRankOfClassConverter<MinRankOfClassDelta>;
type MemberSwappedHandler = ();
type VoteWeight = Linear;
type MaxMemberCount = GlobalMaxMembers<MaxMemberCount>;

#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = ();
}

parameter_types! {
// Default voting period (28 days)
pub const TechReferendumDefaultVotingPeriod: BlockNumber = 28 * DAYS;
// Minimum time before a successful referendum can be enacted (4 days)
pub const TechReferendumMinEnactmentPeriod: BlockNumber = 4 * DAYS;
// Maximum number of active referenda
pub const TechReferendumMaxProposals: u32 = 100;
// Submission deposit for referenda
pub const TechReferendumSubmissionDeposit: Balance = 100 * UNIT;
// Undeciding timeout (90 days)
pub const TechUndecidingTimeout: BlockNumber = 45 * DAYS;
pub const TechAlarmInterval: BlockNumber = 1;
}

pub type TechReferendaInstance = pallet_referenda::Instance1;

impl_tracksinfo_get!(TechCollectiveTracksInfo, Balance, BlockNumber);

impl pallet_referenda::Config<TechReferendaInstance> for Runtime {
/// The type of call dispatched by referenda upon approval and execution.
type RuntimeCall = RuntimeCall;
/// The overarching event type for the runtime.
type RuntimeEvent = RuntimeEvent;
/// Provides weights for the pallet operations to properly charge transaction fees.
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Runtime>;
/// The scheduler pallet used to delay execution of successful referenda.
type Scheduler = Scheduler;
/// The currency mechanism used for handling deposits and voting.
type Currency = Balances;
/// The origin allowed to submit referenda - in this case any signed account.
type SubmitOrigin = RootOrMemberForTechReferendaOrigin;
/// The privileged origin allowed to cancel an ongoing referendum - only root can do this.
type CancelOrigin = EnsureRoot<AccountId>;
/// The privileged origin allowed to kill a referendum that's not passing - only root can do this.
type KillOrigin = EnsureRoot<AccountId>;
/// Destination for slashed deposits when a referendum is cancelled or killed.
/// Leaving () here, will burn all slashed deposits. It's possible to use here the same idea
/// as we have for TransactionFees (OnUnbalanced) - with this it should be possible to
/// do something more sophisticated with this.
type Slash = (); // Will discard any slashed deposits
/// The voting mechanism used to collect votes and determine how they're counted.
/// Connected to the conviction voting pallet to allow conviction-weighted votes.
type Votes = pallet_ranked_collective::Votes;
/// The method to tally votes and determine referendum outcome.
/// Uses conviction voting's tally system with a maximum turnout threshold.
type Tally = pallet_ranked_collective::TallyOf<Runtime>;
/// The deposit required to submit a referendum proposal.
type SubmissionDeposit = ReferendumSubmissionDeposit;
/// Maximum number of referenda that can be in the deciding phase simultaneously.
type MaxQueued = ReferendumMaxProposals;
/// Time period after which an undecided referendum will be automatically rejected.
type UndecidingTimeout = UndecidingTimeout;
/// The frequency at which the pallet checks for expired or ready-to-timeout referenda.
type AlarmInterval = AlarmInterval;
/// Defines the different referendum tracks (categories with distinct parameters).
type Tracks = TechCollectiveTracksInfo;
/// The pallet used to store preimages (detailed proposal content) for referenda.
type Preimages = Preimage;
}
Expand Down
72 changes: 28 additions & 44 deletions runtime/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ 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")
}
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,
) -> Value {
Expand All @@ -40,7 +50,7 @@ fn testnet_genesis(
.map(|k| (k, 1u128 << 60))
.collect::<Vec<_>>(),
},
sudo: SudoConfig { key: Some(root) },
sudo: SudoConfig { key: Some(root.clone()) },
..Default::default()
};

Expand All @@ -49,65 +59,36 @@ 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;
let mut endowed_accounts = vec![];
endowed_accounts.extend(dilithium_default_accounts());

//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
)
genesis_template(
endowed_accounts,
crystal_alice().into_account()
)
}

/// 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());
let endowed_accounts = vec![test_root_account()];
log::info!("endowed account: {:?}", test_root_account().to_ss58check());

testnet_genesis(
endowed_accounts,
test_account_id, // Set the test account as sudo for this testnet
genesis_template(
endowed_accounts,
test_root_account()
)
}

/// 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()
)
}

Expand All @@ -125,6 +106,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
Loading