From 0ecde8a38ea836601ea27c9e762286868beee171 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 16 Mar 2023 20:22:00 +0600 Subject: [PATCH 001/544] An empty DAC Validator pallet crate --- Cargo.toml | 19 +++++++++++++++++++ README.md | 1 + src/lib.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..d9525b4df --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "pallet-ddc-validator" +version = "0.1.0" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } +frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } +scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", +] diff --git a/README.md b/README.md new file mode 100644 index 000000000..3a21d9d6c --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# DDC Validator diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..0cecc036b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,26 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +pub use frame_support::pallet_prelude::*; +pub use frame_system::pallet_prelude::*; +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type Event: From> + IsType<::Event>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event {} + + #[pallet::error] + pub enum Error {} +} From 922560e422e3247e8564307119bcee1e2c172c94 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 17 Mar 2023 16:38:15 +0600 Subject: [PATCH 002/544] Era counter with privileged inc for DAC Validator --- src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0cecc036b..a9b774968 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,10 +17,29 @@ pub mod pallet { type Event: From> + IsType<::Event>; } + #[pallet::storage] + #[pallet::getter(fn global_era_counter)] + pub type GlobalEraCounter = StorageValue<_, u32>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event {} #[pallet::error] pub enum Error {} + + #[pallet::call] + impl Pallet { + #[pallet::weight(100_000)] + pub fn inc_era(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + if let Some(era) = >::get() { + let new_era = era.checked_add(1).unwrap_or_default(); + >::put(new_era); + } else { + >::put(1); + } + Ok(()) + } + } } From 1a67ed7b3e62638bd4669ce2bcc86f902563ea91 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 17 Mar 2023 17:15:04 +0600 Subject: [PATCH 003/544] Hooks and storage items for DAC Validator --- Cargo.toml | 13 +++++++++++++ src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9525b4df..057a274a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,14 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } +log = { version = "0.4.17", default-features = false } +pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } +pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } +sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } [features] default = ["std"] @@ -15,5 +22,11 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "pallet-ddc-staking/std", + "pallet-staking/std", "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", ] diff --git a/src/lib.rs b/src/lib.rs index a9b774968..df766e369 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,27 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use frame_support::pallet_prelude::*; +pub use frame_support::{pallet_prelude::*, parameter_types, weights::Weight, BoundedVec}; pub use frame_system::pallet_prelude::*; +pub use pallet_ddc_staking::{self as ddc_staking}; +pub use pallet_staking::{self as staking}; pub use pallet::*; +pub use sp_std::prelude::*; + +parameter_types! { + pub DdcValidatorsQuorumSize: u32 = 3; +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub enum ValidationMethodKind { + ProofOfDelivery, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct Decision { + pub decision: Option, + pub method: ValidationMethodKind, + pub validator: AccountId, +} #[frame_support::pallet] pub mod pallet { @@ -13,14 +32,27 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + pallet_staking::Config + ddc_staking::Config { type Event: From> + IsType<::Event>; } + #[pallet::storage] + #[pallet::getter(fn tasks)] + pub type Tasks = StorageMap< + _, + Twox64Concat, + T::AccountId, + BoundedVec, DdcValidatorsQuorumSize>, + >; + #[pallet::storage] #[pallet::getter(fn global_era_counter)] pub type GlobalEraCounter = StorageValue<_, u32>; + #[pallet::storage] + #[pallet::getter(fn last_managed_era)] + pub type LastManagedEra = StorageValue<_, u32>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event {} @@ -42,4 +74,24 @@ pub mod pallet { Ok(()) } } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(block_number: T::BlockNumber) -> Weight { + let validators: Vec = >::iter_keys().collect(); + let edges: Vec = >::iter_keys().collect(); + log::info!( + "Block number: {:?}, global era: {:?}, last era: {:?}, validators: {:?}, edges: {:?}", + block_number, + >::get(), + >::get(), + validators, + edges, + ); + 0 + } + fn offchain_worker(block_number: T::BlockNumber) { + log::info!("Off-chain worker at block {:?}", block_number); + } + } } From f87d650f72ba721d39ed122a0ddee53ac77e0cd0 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 17 Mar 2023 14:25:39 +0100 Subject: [PATCH 004/544] add function fetch_tasks --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index df766e369..77d1d894b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,4 +94,20 @@ pub mod pallet { log::info!("Off-chain worker at block {:?}", block_number); } } + + impl Pallet { + /// Fetch the tasks related to current validator + fn fetch_tasks(validator: T::AccountId) -> Vec { + let mut cdn_nodes: Vec = vec![]; + for (cdn_id, cdn_tasks) in >::iter() { + for decision in cdn_tasks.iter() { + if decision.validator == validator { + cdn_nodes.push(cdn_id); + break; + } + } + } + cdn_nodes + } + } } From ec1d3a87d94080956e5e7365db919ecad60af31d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 20 Mar 2023 11:54:31 +0600 Subject: [PATCH 005/544] Assign a random DAC validator for each edge --- src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 77d1d894b..bb2dd7641 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use frame_support::{pallet_prelude::*, parameter_types, weights::Weight, BoundedVec}; +pub use frame_support::{ + pallet_prelude::*, parameter_types, traits::Randomness, weights::Weight, BoundedVec, +}; pub use frame_system::pallet_prelude::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; @@ -34,6 +36,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_staking::Config + ddc_staking::Config { type Event: From> + IsType<::Event>; + type Randomness: Randomness; } #[pallet::storage] @@ -79,15 +82,34 @@ pub mod pallet { impl Hooks> for Pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { let validators: Vec = >::iter_keys().collect(); + let validators_count = validators.len() as u32; let edges: Vec = >::iter_keys().collect(); log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators: {:?}, edges: {:?}", + "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", block_number, >::get(), >::get(), + validators_count, validators, edges, ); + + // A naive approach assigns random validators for each edge. + for edge in edges { + let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + Default::default(); + while !decisions.is_full() { + let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + let validator: T::AccountId = validators[validator_idx].clone(); + let assignment = Decision { + validator, + method: ValidationMethodKind::ProofOfDelivery, + decision: None, + }; + decisions.try_push(assignment).unwrap(); + } + Tasks::::insert(edge, decisions); + } 0 } fn offchain_worker(block_number: T::BlockNumber) { @@ -109,5 +131,31 @@ pub mod pallet { } cdn_nodes } + + fn choose(total: u32) -> Option { + if total == 0 { + return None + } + let mut random_number = Self::generate_random_number(0); + + // Best effort attempt to remove bias from modulus operator. + for i in 1..128 { + if random_number < u32::MAX - u32::MAX % total { + break + } + + random_number = Self::generate_random_number(i); + } + + Some(random_number % total) + } + + fn generate_random_number(seed: u32) -> u32 { + let (random_seed, _) = T::Randomness::random(&(b"ddc-validator", seed).encode()); + let random_number = ::decode(&mut random_seed.as_ref()) + .expect("secure hashes should always be bigger than u32; qed"); + + random_number + } } } From 82b8b88a82ae70804eff4dcaf81bd9941e3d29f2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 20 Mar 2023 14:27:15 +0600 Subject: [PATCH 006/544] Assign DAC validation tasks on era increment --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bb2dd7641..a88d229d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,6 +81,19 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { + match (>::get(), >::get()) { + (Some(global_era_counter), Some(last_managed_era)) => { + if last_managed_era >= global_era_counter { + return 0 + } + >::put(global_era_counter); + }, + (Some(global_era_counter), None) => { + >::put(global_era_counter); + }, + _ => { return 0 }, + }; + let validators: Vec = >::iter_keys().collect(); let validators_count = validators.len() as u32; let edges: Vec = >::iter_keys().collect(); From 0a53fb45bb2e9b12f4969c7fe27e669ff612f32c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 20 Mar 2023 14:54:08 +0600 Subject: [PATCH 007/544] Format DAC Validator files --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a88d229d4..344048de9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,9 @@ pub use frame_support::{ pallet_prelude::*, parameter_types, traits::Randomness, weights::Weight, BoundedVec, }; pub use frame_system::pallet_prelude::*; +pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; -pub use pallet::*; pub use sp_std::prelude::*; parameter_types! { @@ -91,7 +91,7 @@ pub mod pallet { (Some(global_era_counter), None) => { >::put(global_era_counter); }, - _ => { return 0 }, + _ => return 0, }; let validators: Vec = >::iter_keys().collect(); @@ -125,6 +125,7 @@ pub mod pallet { } 0 } + fn offchain_worker(block_number: T::BlockNumber) { log::info!("Off-chain worker at block {:?}", block_number); } @@ -138,7 +139,7 @@ pub mod pallet { for decision in cdn_tasks.iter() { if decision.validator == validator { cdn_nodes.push(cdn_id); - break; + break } } } From 134c2f43c1fc9ef70a1a8e1cc0367ad0b0936448 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 21 Mar 2023 15:15:39 +0100 Subject: [PATCH 008/544] adjust era --- src/lib.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 344048de9..10f72a1ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,16 @@ pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; pub use sp_std::prelude::*; +pub use sp_io::offchain::timestamp; parameter_types! { pub DdcValidatorsQuorumSize: u32 = 3; } +const TIME_START_MS: u64 = 1_672_531_200_000; +const ERA_DURATION_MS: u64 = 120_000; +const ERA_IN_BLOCKS: u8 = 20; + #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { ProofOfDelivery, @@ -48,10 +53,6 @@ pub mod pallet { BoundedVec, DdcValidatorsQuorumSize>, >; - #[pallet::storage] - #[pallet::getter(fn global_era_counter)] - pub type GlobalEraCounter = StorageValue<_, u32>; - #[pallet::storage] #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, u32>; @@ -63,21 +64,6 @@ pub mod pallet { #[pallet::error] pub enum Error {} - #[pallet::call] - impl Pallet { - #[pallet::weight(100_000)] - pub fn inc_era(origin: OriginFor) -> DispatchResult { - ensure_root(origin)?; - if let Some(era) = >::get() { - let new_era = era.checked_add(1).unwrap_or_default(); - >::put(new_era); - } else { - >::put(1); - } - Ok(()) - } - } - #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { @@ -100,7 +86,7 @@ pub mod pallet { log::info!( "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", block_number, - >::get(), + Self::get_current_era(), >::get(), validators_count, validators, @@ -170,6 +156,9 @@ pub mod pallet { .expect("secure hashes should always be bigger than u32; qed"); random_number + // Get the current era; Shall we start era count from 0 or from 1? + fn get_current_era() -> u64 { + (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS } } } From 2861d4441d39b7fdba33f93150cd40174a3fd030 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 21 Mar 2023 15:40:37 +0100 Subject: [PATCH 009/544] fix era --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 10f72a1ac..3d708a0a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -156,6 +156,8 @@ pub mod pallet { .expect("secure hashes should always be bigger than u32; qed"); random_number + } + // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> u64 { (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS From 9ebe1a973a685a930ea340443bd817001db057e5 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 22 Mar 2023 11:32:21 +0100 Subject: [PATCH 010/544] merge offchain worker with ddc validator --- Cargo.toml | 12 ++ src/lib.rs | 322 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 317 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 057a274a2..55172f684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,20 @@ version = "0.1.0" edition = "2021" [dependencies] +alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } log = { version = "0.4.17", default-features = false } +pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } +pallet-session = { version = "4.0.0-dev", path = "../session", default-features = false } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } +serde = { version = "1.0.101", optional = true } +serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } +sp-keystore = { version = "0.12.0", default-features = false, path = "../../primitives/keystore", optional = true } +sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } @@ -22,9 +29,14 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "pallet-contracts/std", "pallet-ddc-staking/std", "pallet-staking/std", + "pallet-session/std", "scale-info/std", + "serde", + "sp-keystore", + "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-staking/std", diff --git a/src/lib.rs b/src/lib.rs index 3d708a0a1..9cab6656c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,53 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub use alloc::{format, string::String}; +pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; +pub use codec::{Encode, Decode, MaxEncodedLen, HasCompact}; +pub use core::fmt::Debug; pub use frame_support::{ - pallet_prelude::*, parameter_types, traits::Randomness, weights::Weight, BoundedVec, + decl_event, decl_module, decl_storage, + log::{error, info, warn}, + pallet_prelude::*, + traits::{Randomness, Currency}, + weights::Weight, + dispatch::DispatchResult, + RuntimeDebug, + BoundedVec, + parameter_types, }; -pub use frame_system::pallet_prelude::*; +pub use frame_system::{ensure_signed, pallet_prelude::*, offchain::{CreateSignedTransaction, Signer, SigningTypes, AppCrypto, SendSignedTransaction}}; pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; +pub use pallet_session as session; +pub use scale_info::TypeInfo; +pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; +pub use sp_runtime::offchain::{http, Duration}; pub use sp_std::prelude::*; pub use sp_io::offchain::timestamp; +extern crate alloc; parameter_types! { pub DdcValidatorsQuorumSize: u32 = 3; } +type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +type ResultStr = Result; + + +pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); + +pub const HTTP_TIMEOUT_MS: u64 = 30_000; + const TIME_START_MS: u64 = 1_672_531_200_000; const ERA_DURATION_MS: u64 = 120_000; const ERA_IN_BLOCKS: u8 = 20; +const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; + #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { ProofOfDelivery, @@ -30,18 +60,112 @@ pub struct Decision { pub validator: AccountId, } +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] +pub struct ValidationResult { + era: String, + signer: AccountId, + val_res: bool, + cdn_node_pub_key: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct RedisFtAggregate { + #[serde(rename = "FT.AGGREGATE")] + pub ft_aggregate: (u32, Vec, Vec), +} + +#[derive(Clone)] +struct BytesSent { + node_public_key: String, + era: String, + sum: u32, +} + +impl BytesSent { + pub fn new(aggregate: RedisFtAggregate) -> BytesSent { + let (_, values, values2) = aggregate.ft_aggregate; + + BytesSent { + node_public_key: values[1].clone(), + era: values[3].clone(), + sum: values[5].parse::().expect("bytesSentSum must be convertable to u32"), + } + } +} + +#[derive(Clone)] +struct BytesReceived { + node_public_key: String, + era: String, + sum: u32, +} + +impl BytesReceived { + pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { + let (_, values, values2) = aggregate.ft_aggregate; + + BytesReceived { + node_public_key: values[1].clone(), + era: values[3].clone(), + sum: values[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + } + } +} + +pub mod crypto { + use super::KEY_TYPE; + use frame_system::offchain::AppCrypto; + use sp_core::sr25519::Signature as Sr25519Signature; + use sp_runtime::{ + app_crypto::{app_crypto, sr25519}, + traits::Verify, + }; + app_crypto!(sr25519, KEY_TYPE); + + use sp_runtime::{MultiSignature, MultiSigner}; + + pub struct TestAuthId; + + impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; + } + + impl AppCrypto for TestAuthId { + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; + } +} + #[frame_support::pallet] pub mod pallet { use super::*; #[pallet::pallet] + #[pallet::without_storage_info] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_staking::Config + ddc_staking::Config { + pub trait Config: + frame_system::Config + + pallet_contracts::Config + + pallet_session::Config::AccountId> + + pallet_staking::Config + + ddc_staking::Config + + CreateSignedTransaction> + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { type Event: From> + IsType<::Event>; type Randomness: Randomness; + type Call: From>; + type AuthorityId: AppCrypto; } #[pallet::storage] @@ -55,26 +179,34 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn last_managed_era)] - pub type LastManagedEra = StorageValue<_, u32>; + pub type LastManagedEra = StorageValue<_, u64>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event {} + pub enum Event + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + {} #[pallet::error] pub enum Error {} #[pallet::hooks] - impl Hooks> for Pallet { + impl Hooks> for Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { fn on_initialize(block_number: T::BlockNumber) -> Weight { - match (>::get(), >::get()) { - (Some(global_era_counter), Some(last_managed_era)) => { + match (Self::get_current_era(), >::get()) { + (global_era_counter, Some(last_managed_era)) => { if last_managed_era >= global_era_counter { return 0 } >::put(global_era_counter); }, - (Some(global_era_counter), None) => { + (global_era_counter, None) => { >::put(global_era_counter); }, _ => return 0, @@ -113,11 +245,172 @@ pub mod pallet { } fn offchain_worker(block_number: T::BlockNumber) { - log::info!("Off-chain worker at block {:?}", block_number); + let res = Self::offchain_worker_main(block_number); + + match res { + Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), + Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), + }; } } - impl Pallet { + #[pallet::call] + impl Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + #[pallet::weight(10000)] + pub fn save_validated_data(origin: OriginFor, val_res: bool, cdn_node_pub_key: String, era: String) -> DispatchResult { + let signer: T::AccountId = ensure_signed(origin)?; + + info!("[DAC Validator] author: {:?}", signer); + let mut v_results = ValidationResults::::get(); + + let cur_validation = ValidationResult:: { + era, + val_res, + cdn_node_pub_key, + signer, + }; + + v_results.push(cur_validation); + + ValidationResults::::set(v_results); + + Ok(()) + } + } + + impl Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { + info!("[DAC Validator] Validation data stored onchain: {:?}", ValidationResults::::get()); + + if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { + return Ok(()) + } + + let signer = match Self::get_signer() { + Err(e) => { + warn!("{:?}", e); + return Ok(()); + } + Ok(signer) => signer, + }; + + info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); + + // Read data from DataModel and do dumb validation + let current_era = Self::get_current_era() - 1u64; + let (bytes_sent, bytes_received) = Self::fetch_data(current_era); + let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + + let cdn_node_pub_key = bytes_sent.node_public_key.clone(); + let tx_res = signer.send_signed_transaction(|_acct| { + info!("[DAC Validator] Sending save_validated_data tx"); + + // This is the on-chain function + Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } + }); + + match &tx_res { + None | Some((_, Err(()))) => { + return Err("Error while submitting save_validated_data TX") + } + Some((_, Ok(()))) => {} + } + + Ok(()) + } + + fn get_signer() -> ResultStr> { + let signer = Signer::<_, _>::any_account(); + if !signer.can_sign() { + return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); + } + + Ok(signer) + } + + // Get the current era; Shall we start era count from 0 or from 1? + fn get_current_era() -> u64 { + (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS + } + + fn fetch_data(era: u64 ) -> (BytesSent, BytesReceived){ + info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + // Todo: handle the error + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + let bytes_sent = BytesSent::new(bytes_sent_res); + + // Todo: handle the error + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = + Self::http_get_json(&bytes_received_query).unwrap(); + info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + let bytes_received = BytesReceived::new(bytes_received_res); + + (bytes_sent, bytes_received) + } + + fn get_bytes_sent_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) + } + + fn get_bytes_received_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) + } + + fn http_get_json(url: &str) -> ResultStr { + let body = Self::http_get_request(url).map_err(|err| { + error!("[DAC Validator] Error while getting {}: {:?}", url, err); + "HTTP GET error" + })?; + + let parsed = serde_json::from_slice(&body).map_err(|err| { + warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); + "HTTP JSON parse error" + }); + + parsed + } + + fn http_get_request(http_url: &str) -> Result, http::Error> { + info!("[DAC Validator] Sending request to: {:?}", http_url); + + // Initiate an external HTTP GET request. This is using high-level wrappers from + // `sp_runtime`. + let request = http::Request::get(http_url); + + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + + let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + + let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + + if response.code != 200 { + warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + + // Next we fully read the response body and collect it to a vector of bytes. + Ok(response.body().collect::>()) + } + + fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { + return if bytes_sent.sum == bytes_received.sum { + true + } else { + false + } + } + /// Fetch the tasks related to current validator fn fetch_tasks(validator: T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; @@ -151,16 +444,11 @@ pub mod pallet { } fn generate_random_number(seed: u32) -> u32 { - let (random_seed, _) = T::Randomness::random(&(b"ddc-validator", seed).encode()); + let (random_seed, _) = ::Randomness::random(&(b"ddc-validator", seed).encode()); let random_number = ::decode(&mut random_seed.as_ref()) .expect("secure hashes should always be bigger than u32; qed"); random_number } - - // Get the current era; Shall we start era count from 0 or from 1? - fn get_current_era() -> u64 { - (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS - } } } From a4ee180c54a4961397482dd557c5261b2ed3d6db Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 22 Mar 2023 14:43:26 +0100 Subject: [PATCH 011/544] add proof of delivery --- src/lib.rs | 75 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9cab6656c..52219d6dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -181,6 +181,10 @@ pub mod pallet { #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, u64>; + #[pallet::storage] + #[pallet::getter(fn validation_results)] + pub(super) type ValidationResults = StorageValue<_, Vec>, ValueQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event @@ -209,7 +213,6 @@ pub mod pallet { (global_era_counter, None) => { >::put(global_era_counter); }, - _ => return 0, }; let validators: Vec = >::iter_keys().collect(); @@ -280,6 +283,27 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(10000)] + pub fn proof_of_delivery(origin: OriginFor, era: u64) -> DispatchResult { + let signer: T::AccountId = ensure_signed(origin)?; + + let cdn_nodes_to_validate = Self::fetch_tasks(&signer); + for cdn_node_id in cdn_nodes_to_validate { + let (bytes_sent, bytes_received) = Self::fetch_data(era, &cdn_node_id); + let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + + let decisions_for_cdn = >::get(cdn_node_id); + for decision in decisions_for_cdn.unwrap().iter_mut() { + if decision.validator == signer { + decision.decision = Some(val_res); + decision.method = ValidationMethodKind::ProofOfDelivery; + } + } + } + + Ok(()) + } } impl Pallet @@ -306,23 +330,26 @@ pub mod pallet { // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1u64; - let (bytes_sent, bytes_received) = Self::fetch_data(current_era); - let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - let cdn_node_pub_key = bytes_sent.node_public_key.clone(); - let tx_res = signer.send_signed_transaction(|_acct| { - info!("[DAC Validator] Sending save_validated_data tx"); + // for decision in &mut cdn_nodes_to_validate { - // This is the on-chain function - Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } - }); + // } + // let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + // let cdn_node_pub_key = bytes_sent.node_public_key.clone(); - match &tx_res { - None | Some((_, Err(()))) => { - return Err("Error while submitting save_validated_data TX") - } - Some((_, Ok(()))) => {} - } + // let tx_res = signer.send_signed_transaction(|_acct| { + // info!("[DAC Validator] Sending save_validated_data tx"); + + // // This is the on-chain function + // Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } + // }); + + // match &tx_res { + // None | Some((_, Err(()))) => { + // return Err("Error while submitting save_validated_data TX") + // } + // Some((_, Ok(()))) => {} + // } Ok(()) } @@ -341,16 +368,16 @@ pub mod pallet { (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS } - fn fetch_data(era: u64 ) -> (BytesSent, BytesReceived){ + fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_query = Self::get_bytes_sent_query_url(era, cdn_node); let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_query = Self::get_bytes_received_query_url(era, cdn_node); let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); @@ -359,12 +386,12 @@ pub mod pallet { (bytes_sent, bytes_received) } - fn get_bytes_sent_query_url(era: u64) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) + fn get_bytes_sent_query_url(era: u64, cdn_node: &T::AccountId) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era, *cdn_node) } - fn get_bytes_received_query_url(era: u64) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) + fn get_bytes_received_query_url(era: u64, cdn_node: &T::AccountId) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era, *cdn_node) } fn http_get_json(url: &str) -> ResultStr { @@ -412,11 +439,11 @@ pub mod pallet { } /// Fetch the tasks related to current validator - fn fetch_tasks(validator: T::AccountId) -> Vec { + fn fetch_tasks(validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; for (cdn_id, cdn_tasks) in >::iter() { for decision in cdn_tasks.iter() { - if decision.validator == validator { + if decision.validator == *validator { cdn_nodes.push(cdn_id); break } From 54783d40f432cb831d28a48c0111a55e0aa0ce18 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 22 Mar 2023 14:45:48 +0100 Subject: [PATCH 012/544] add PoD trigger in offchain worker --- src/lib.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 52219d6dc..d599567be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -331,25 +331,20 @@ pub mod pallet { // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1u64; - // for decision in &mut cdn_nodes_to_validate { + + let tx_res = signer.send_signed_transaction(|_acct| { + info!("[DAC Validator] Trigger proof of delivery"); - // } - // let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - // let cdn_node_pub_key = bytes_sent.node_public_key.clone(); - - // let tx_res = signer.send_signed_transaction(|_acct| { - // info!("[DAC Validator] Sending save_validated_data tx"); - - // // This is the on-chain function - // Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } - // }); + // This is the on-chain function + Call::proof_of_delivery { era: current_era } + }); - // match &tx_res { - // None | Some((_, Err(()))) => { - // return Err("Error while submitting save_validated_data TX") - // } - // Some((_, Ok(()))) => {} - // } + match &tx_res { + None | Some((_, Err(()))) => { + return Err("Error while submitting proof of delivery TX") + } + Some((_, Ok(()))) => {} + } Ok(()) } From 379c39dc7f2c1d8fde150a2fb4d496305115ea99 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 23 Mar 2023 11:47:35 +0100 Subject: [PATCH 013/544] Move JSON parsing fix to ddc-validator --- src/lib.rs | 58 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d599567be..2b1d5245e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,8 +72,16 @@ pub struct ValidationResult { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct RedisFtAggregate { - #[serde(rename = "FT.AGGREGATE")] - pub ft_aggregate: (u32, Vec, Vec), + #[serde(rename = "FT.AGGREGATE")] + pub ft_aggregate: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(crate = "alt_serde")] +#[serde(untagged)] +pub enum FtAggregate { + Length(u32), + Node(Vec), } #[derive(Clone)] @@ -84,15 +92,20 @@ struct BytesSent { } impl BytesSent { - pub fn new(aggregate: RedisFtAggregate) -> BytesSent { - let (_, values, values2) = aggregate.ft_aggregate; - - BytesSent { - node_public_key: values[1].clone(), - era: values[3].clone(), - sum: values[5].parse::().expect("bytesSentSum must be convertable to u32"), - } - } + pub fn new(aggregate: RedisFtAggregate) -> BytesSent { + let data = aggregate.ft_aggregate[1].clone(); + + match data { + FtAggregate::Node(node) => { + return BytesSent { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + } + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } } #[derive(Clone)] @@ -103,15 +116,20 @@ struct BytesReceived { } impl BytesReceived { - pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { - let (_, values, values2) = aggregate.ft_aggregate; - - BytesReceived { - node_public_key: values[1].clone(), - era: values[3].clone(), - sum: values[5].parse::().expect("bytesReceivedSum must be convertable to u32"), - } - } + pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { + let data = aggregate.ft_aggregate[1].clone(); + + match data { + FtAggregate::Node(node) => { + return BytesReceived { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + } + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } } pub mod crypto { From e1e9d3e9196e89ba549cf9567070470dce5a1aca Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 23 Mar 2023 15:23:09 +0100 Subject: [PATCH 014/544] fix timestamp bug --- src/lib.rs | 96 +++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b1d5245e..e7481fe6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ pub use frame_support::{ decl_event, decl_module, decl_storage, log::{error, info, warn}, pallet_prelude::*, - traits::{Randomness, Currency}, + traits::{Randomness, Currency, UnixTime}, weights::Weight, dispatch::DispatchResult, RuntimeDebug, @@ -22,9 +22,9 @@ pub use pallet_staking::{self as staking}; pub use pallet_session as session; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; -pub use sp_runtime::offchain::{http, Duration}; +pub use sp_runtime::offchain::{http, Duration, Timestamp}; pub use sp_std::prelude::*; -pub use sp_io::offchain::timestamp; + extern crate alloc; parameter_types! { @@ -42,8 +42,8 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const HTTP_TIMEOUT_MS: u64 = 30_000; -const TIME_START_MS: u64 = 1_672_531_200_000; -const ERA_DURATION_MS: u64 = 120_000; +const TIME_START_MS: u128 = 1_672_531_200_000; +const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; @@ -184,6 +184,7 @@ pub mod pallet { type Randomness: Randomness; type Call: From>; type AuthorityId: AppCrypto; + type TimeProvider: UnixTime; } #[pallet::storage] @@ -221,48 +222,53 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - match (Self::get_current_era(), >::get()) { - (global_era_counter, Some(last_managed_era)) => { - if last_managed_era >= global_era_counter { - return 0 + if block_number != 0u32.into() && block_number != 1u32.into() { + let era = Self::get_current_era(); + match (era, >::get()) { + (global_era_counter, Some(last_managed_era)) => { + if last_managed_era >= global_era_counter { + return 0 + } + >::put(global_era_counter); + }, + (global_era_counter, None) => { + >::put(global_era_counter); + }, + }; + + let validators: Vec = >::iter_keys().collect(); + let validators_count = validators.len() as u32; + let edges: Vec = >::iter_keys().collect(); + log::info!( + "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", + block_number, + era, + >::get(), + validators_count, + validators, + edges, + ); + + // A naive approach assigns random validators for each edge. + for edge in edges { + let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + Default::default(); + while !decisions.is_full() { + let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + let validator: T::AccountId = validators[validator_idx].clone(); + let assignment = Decision { + validator, + method: ValidationMethodKind::ProofOfDelivery, + decision: None, + }; + decisions.try_push(assignment).unwrap(); } - >::put(global_era_counter); - }, - (global_era_counter, None) => { - >::put(global_era_counter); - }, - }; - - let validators: Vec = >::iter_keys().collect(); - let validators_count = validators.len() as u32; - let edges: Vec = >::iter_keys().collect(); - log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", - block_number, - Self::get_current_era(), - >::get(), - validators_count, - validators, - edges, - ); - - // A naive approach assigns random validators for each edge. - for edge in edges { - let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = - Default::default(); - while !decisions.is_full() { - let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - let validator: T::AccountId = validators[validator_idx].clone(); - let assignment = Decision { - validator, - method: ValidationMethodKind::ProofOfDelivery, - decision: None, - }; - decisions.try_push(assignment).unwrap(); + Tasks::::insert(edge, decisions); } - Tasks::::insert(edge, decisions); + 0 + } else { + 0 } - 0 } fn offchain_worker(block_number: T::BlockNumber) { @@ -378,7 +384,7 @@ pub mod pallet { // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> u64 { - (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS + ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS).try_into().unwrap() } fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { From 4c001abcddd82dfde67b2b965444549544bc0383 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 24 Mar 2023 11:17:31 +0600 Subject: [PATCH 015/544] Autoformat DAC Validator files --- Cargo.toml | 8 +-- src/lib.rs | 205 +++++++++++++++++++++++++++-------------------------- 2 files changed, 109 insertions(+), 104 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55172f684..af7a0108e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,14 @@ frame-system = { version = "4.0.0-dev", default-features = false, path = "../sys log = { version = "0.4.17", default-features = false } pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } -pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } pallet-session = { version = "4.0.0-dev", path = "../session", default-features = false } +pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -sp-keystore = { version = "0.12.0", default-features = false, path = "../../primitives/keystore", optional = true } sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } +sp-keystore = { version = "0.12.0", default-features = false, path = "../../primitives/keystore", optional = true } sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } @@ -31,13 +31,13 @@ std = [ "frame-system/std", "pallet-contracts/std", "pallet-ddc-staking/std", - "pallet-staking/std", "pallet-session/std", + "pallet-staking/std", "scale-info/std", "serde", - "sp-keystore", "sp-core/std", "sp-io/std", + "sp-keystore", "sp-runtime/std", "sp-staking/std", "sp-std/std", diff --git a/src/lib.rs b/src/lib.rs index e7481fe6e..a2e6586a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,24 +2,27 @@ pub use alloc::{format, string::String}; pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; -pub use codec::{Encode, Decode, MaxEncodedLen, HasCompact}; +pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; pub use core::fmt::Debug; pub use frame_support::{ decl_event, decl_module, decl_storage, - log::{error, info, warn}, - pallet_prelude::*, - traits::{Randomness, Currency, UnixTime}, - weights::Weight, dispatch::DispatchResult, - RuntimeDebug, - BoundedVec, + log::{error, info, warn}, + pallet_prelude::*, parameter_types, + traits::{Currency, Randomness, UnixTime}, + weights::Weight, + BoundedVec, RuntimeDebug, +}; +pub use frame_system::{ + ensure_signed, + offchain::{AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes}, + pallet_prelude::*, }; -pub use frame_system::{ensure_signed, pallet_prelude::*, offchain::{CreateSignedTransaction, Signer, SigningTypes, AppCrypto, SendSignedTransaction}}; pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; -pub use pallet_staking::{self as staking}; pub use pallet_session as session; +pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; pub use sp_runtime::offchain::{http, Duration, Timestamp}; @@ -32,12 +35,11 @@ parameter_types! { } type BalanceOf = <::Currency as Currency< - ::AccountId, + ::AccountId, >>::Balance; type ResultStr = Result; - pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const HTTP_TIMEOUT_MS: u64 = 30_000; @@ -62,10 +64,10 @@ pub struct Decision { #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] pub struct ValidationResult { - era: String, - signer: AccountId, - val_res: bool, - cdn_node_pub_key: String, + era: String, + signer: AccountId, + val_res: bool, + cdn_node_pub_key: String, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -86,9 +88,9 @@ pub enum FtAggregate { #[derive(Clone)] struct BytesSent { - node_public_key: String, - era: String, - sum: u32, + node_public_key: String, + era: String, + sum: u32, } impl BytesSent { @@ -96,13 +98,12 @@ impl BytesSent { let data = aggregate.ft_aggregate[1].clone(); match data { - FtAggregate::Node(node) => { + FtAggregate::Node(node) => return BytesSent { node_public_key: node[1].clone(), era: node[3].clone(), sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), - } - } + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } @@ -110,9 +111,9 @@ impl BytesSent { #[derive(Clone)] struct BytesReceived { - node_public_key: String, - era: String, - sum: u32, + node_public_key: String, + era: String, + sum: u32, } impl BytesReceived { @@ -120,13 +121,14 @@ impl BytesReceived { let data = aggregate.ft_aggregate[1].clone(); match data { - FtAggregate::Node(node) => { + FtAggregate::Node(node) => return BytesReceived { node_public_key: node[1].clone(), era: node[3].clone(), - sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), - } - } + sum: node[5] + .parse::() + .expect("bytesReceivedSum must be convertable to u32"), + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } @@ -137,8 +139,8 @@ pub mod crypto { use frame_system::offchain::AppCrypto; use sp_core::sr25519::Signature as Sr25519Signature; use sp_runtime::{ - app_crypto::{app_crypto, sr25519}, - traits::Verify, + app_crypto::{app_crypto, sr25519}, + traits::Verify, }; app_crypto!(sr25519, KEY_TYPE); @@ -147,15 +149,15 @@ pub mod crypto { pub struct TestAuthId; impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; } impl AppCrypto for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; } } @@ -169,21 +171,21 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: + pub trait Config: frame_system::Config + pallet_contracts::Config - + pallet_session::Config::AccountId> + + pallet_session::Config::AccountId> + pallet_staking::Config + ddc_staking::Config + CreateSignedTransaction> - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { type Event: From> + IsType<::Event>; type Randomness: Randomness; type Call: From>; - type AuthorityId: AppCrypto; + type AuthorityId: AppCrypto; type TimeProvider: UnixTime; } @@ -202,28 +204,28 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn validation_results)] - pub(super) type ValidationResults = StorageValue<_, Vec>, ValueQuery>; + pub(super) type ValidationResults = + StorageValue<_, Vec>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event + pub enum Event where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - {} + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} #[pallet::error] pub enum Error {} #[pallet::hooks] - impl Hooks> for Pallet + impl Hooks> for Pallet where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { if block_number != 0u32.into() && block_number != 1u32.into() { - let era = Self::get_current_era(); + let era = Self::get_current_era(); match (era, >::get()) { (global_era_counter, Some(last_managed_era)) => { if last_managed_era >= global_era_counter { @@ -235,10 +237,11 @@ pub mod pallet { >::put(global_era_counter); }, }; - + let validators: Vec = >::iter_keys().collect(); let validators_count = validators.len() as u32; - let edges: Vec = >::iter_keys().collect(); + let edges: Vec = + >::iter_keys().collect(); log::info!( "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", block_number, @@ -248,7 +251,7 @@ pub mod pallet { validators, edges, ); - + // A naive approach assigns random validators for each edge. for edge in edges { let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = @@ -282,24 +285,25 @@ pub mod pallet { } #[pallet::call] - impl Pallet - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + impl Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { #[pallet::weight(10000)] - pub fn save_validated_data(origin: OriginFor, val_res: bool, cdn_node_pub_key: String, era: String) -> DispatchResult { + pub fn save_validated_data( + origin: OriginFor, + val_res: bool, + cdn_node_pub_key: String, + era: String, + ) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; info!("[DAC Validator] author: {:?}", signer); let mut v_results = ValidationResults::::get(); - let cur_validation = ValidationResult:: { - era, - val_res, - cdn_node_pub_key, - signer, - }; + let cur_validation = + ValidationResult:: { era, val_res, cdn_node_pub_key, signer }; v_results.push(cur_validation); @@ -330,24 +334,27 @@ pub mod pallet { } } - impl Pallet + impl Pallet where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - info!("[DAC Validator] Validation data stored onchain: {:?}", ValidationResults::::get()); + info!( + "[DAC Validator] Validation data stored onchain: {:?}", + ValidationResults::::get() + ); if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { - return Ok(()) + return Ok(()) } let signer = match Self::get_signer() { - Err(e) => { - warn!("{:?}", e); - return Ok(()); - } - Ok(signer) => signer, + Err(e) => { + warn!("{:?}", e); + return Ok(()) + }, + Ok(signer) => signer, }; info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); @@ -355,19 +362,17 @@ pub mod pallet { // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1u64; - let tx_res = signer.send_signed_transaction(|_acct| { - info!("[DAC Validator] Trigger proof of delivery"); + info!("[DAC Validator] Trigger proof of delivery"); - // This is the on-chain function - Call::proof_of_delivery { era: current_era } + // This is the on-chain function + Call::proof_of_delivery { era: current_era } }); match &tx_res { - None | Some((_, Err(()))) => { - return Err("Error while submitting proof of delivery TX") - } - Some((_, Ok(()))) => {} + None | Some((_, Err(()))) => + return Err("Error while submitting proof of delivery TX"), + Some((_, Ok(()))) => {}, } Ok(()) @@ -376,7 +381,7 @@ pub mod pallet { fn get_signer() -> ResultStr> { let signer = Signer::<_, _>::any_account(); if !signer.can_sign() { - return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); + return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); } Ok(signer) @@ -384,7 +389,9 @@ pub mod pallet { // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> u64 { - ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS).try_into().unwrap() + ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) + .try_into() + .unwrap() } fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { @@ -398,7 +405,7 @@ pub mod pallet { // Todo: handle the error let bytes_received_query = Self::get_bytes_received_query_url(era, cdn_node); let bytes_received_res: RedisFtAggregate = - Self::http_get_json(&bytes_received_query).unwrap(); + Self::http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::new(bytes_received_res); @@ -415,13 +422,13 @@ pub mod pallet { fn http_get_json(url: &str) -> ResultStr { let body = Self::http_get_request(url).map_err(|err| { - error!("[DAC Validator] Error while getting {}: {:?}", url, err); - "HTTP GET error" + error!("[DAC Validator] Error while getting {}: {:?}", url, err); + "HTTP GET error" })?; let parsed = serde_json::from_slice(&body).map_err(|err| { - warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); - "HTTP JSON parse error" + warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); + "HTTP JSON parse error" }); parsed @@ -438,23 +445,20 @@ pub mod pallet { let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + let response = + pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; if response.code != 200 { - warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); - return Err(http::Error::Unknown) + warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); + return Err(http::Error::Unknown) } // Next we fully read the response body and collect it to a vector of bytes. Ok(response.body().collect::>()) - } + } fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { - return if bytes_sent.sum == bytes_received.sum { - true - } else { - false - } + return if bytes_sent.sum == bytes_received.sum { true } else { false } } /// Fetch the tasks related to current validator @@ -490,7 +494,8 @@ pub mod pallet { } fn generate_random_number(seed: u32) -> u32 { - let (random_seed, _) = ::Randomness::random(&(b"ddc-validator", seed).encode()); + let (random_seed, _) = + ::Randomness::random(&(b"ddc-validator", seed).encode()); let random_number = ::decode(&mut random_seed.as_ref()) .expect("secure hashes should always be bigger than u32; qed"); From c37437e4f5ffbced9566a746b4e0708506f41252 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 24 Mar 2023 12:02:07 +0100 Subject: [PATCH 016/544] add filtering of requests --- Cargo.toml | 1 + src/lib.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af7a0108e..0e0fe0ea9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +array-bytes = "6.0.0" alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } diff --git a/src/lib.rs b/src/lib.rs index a2e6586a8..5a553ca1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,6 +107,27 @@ impl BytesSent { FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } + + pub fn get_all(aggregation: RedisFtAggregate) -> Vec { + let mut res: Vec = vec!(); + for i in 1..aggregation.ft_aggregate.len() { + let data = aggregation.ft_aggregate[i].clone(); + match data { + FtAggregate::Node(node) => { + let node = BytesSent { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + }; + + res.push(node); + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + return res; + } } #[derive(Clone)] @@ -132,6 +153,27 @@ impl BytesReceived { FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } + + pub fn get_all(aggregation: RedisFtAggregate) -> Vec { + let mut res: Vec = vec!(); + for i in 1..aggregation.ft_aggregate.len() { + let data = aggregation.ft_aggregate[i].clone(); + match data { + FtAggregate::Node(node) => { + let node = BytesReceived { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + }; + + res.push(node); + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + return res; + } } pub mod crypto { @@ -317,8 +359,9 @@ pub mod pallet { let signer: T::AccountId = ensure_signed(origin)?; let cdn_nodes_to_validate = Self::fetch_tasks(&signer); + let (s, r) = Self::fetch_data1(era); for cdn_node_id in cdn_nodes_to_validate { - let (bytes_sent, bytes_received) = Self::fetch_data(era, &cdn_node_id); + let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); let decisions_for_cdn = >::get(cdn_node_id); @@ -397,13 +440,13 @@ pub mod pallet { fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era, cdn_node); + let bytes_sent_query = Self::get_bytes_sent_query_url(era); let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era, cdn_node); + let bytes_received_query = Self::get_bytes_received_query_url(era); let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); @@ -412,12 +455,46 @@ pub mod pallet { (bytes_sent, bytes_received) } - fn get_bytes_sent_query_url(era: u64, cdn_node: &T::AccountId) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era, *cdn_node) + fn account_to_string(account: T::AccountId) -> String { + let to32 = T::AccountId::encode(&account); + let pub_key_str = array_bytes::bytes2hex("", to32); + + pub_key_str + } + + fn filter_data(s: &Vec, r: &Vec, a: &T::AccountId) -> (BytesSent, BytesReceived){ + let ac = Self::account_to_string(a.clone()); + + let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); + let filtered_r = &*r.into_iter().find(|br| br.node_public_key == ac).unwrap(); + + (filtered_s.clone(), filtered_r.clone()) + } + + fn fetch_data1(era: u64 ) -> (Vec, Vec){ + info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + // Todo: handle the error + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + let bytes_sent = BytesSent::get_all(bytes_sent_res); + + // Todo: handle the error + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = + Self::http_get_json(&bytes_received_query).unwrap(); + info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + let bytes_received = BytesReceived::get_all(bytes_received_res); + + (bytes_sent, bytes_received) + } + + fn get_bytes_sent_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) } - fn get_bytes_received_query_url(era: u64, cdn_node: &T::AccountId) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era, *cdn_node) + fn get_bytes_received_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) } fn http_get_json(url: &str) -> ResultStr { From 8de7826077b472f9378369829930e26a9cebd8a3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 27 Mar 2023 14:38:27 +0600 Subject: [PATCH 017/544] Refactor guard condition --- src/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5a553ca1d..dc5b4688c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,18 +268,12 @@ pub mod pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { if block_number != 0u32.into() && block_number != 1u32.into() { let era = Self::get_current_era(); - match (era, >::get()) { - (global_era_counter, Some(last_managed_era)) => { - if last_managed_era >= global_era_counter { - return 0 - } - >::put(global_era_counter); - }, - (global_era_counter, None) => { - >::put(global_era_counter); - }, - }; - + if let Some(last_managed_era) = >::get() { + if last_managed_era >= era { + return 0 + } + } + >::put(era); let validators: Vec = >::iter_keys().collect(); let validators_count = validators.len() as u32; let edges: Vec = From 5e8b0b01ebee7e2263b72311cb0a3e539f351b97 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 27 Mar 2023 15:30:57 +0600 Subject: [PATCH 018/544] Refactor a guard condition to decrease indentation --- src/lib.rs | 79 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dc5b4688c..cf4423173 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -266,48 +266,49 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - if block_number != 0u32.into() && block_number != 1u32.into() { - let era = Self::get_current_era(); - if let Some(last_managed_era) = >::get() { - if last_managed_era >= era { - return 0 - } + if block_number < 1u32.into() { + return 0 + } + + let era = Self::get_current_era(); + if let Some(last_managed_era) = >::get() { + if last_managed_era >= era { + return 0 } - >::put(era); - let validators: Vec = >::iter_keys().collect(); - let validators_count = validators.len() as u32; - let edges: Vec = - >::iter_keys().collect(); - log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", - block_number, - era, - >::get(), - validators_count, - validators, - edges, - ); - - // A naive approach assigns random validators for each edge. - for edge in edges { - let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = - Default::default(); - while !decisions.is_full() { - let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - let validator: T::AccountId = validators[validator_idx].clone(); - let assignment = Decision { - validator, - method: ValidationMethodKind::ProofOfDelivery, - decision: None, - }; - decisions.try_push(assignment).unwrap(); - } - Tasks::::insert(edge, decisions); + } + >::put(era); + + let validators: Vec = >::iter_keys().collect(); + let validators_count = validators.len() as u32; + let edges: Vec = >::iter_keys().collect(); + log::info!( + "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", + block_number, + era, + >::get(), + validators_count, + validators, + edges, + ); + + // A naive approach assigns random validators for each edge. + for edge in edges { + let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + Default::default(); + while !decisions.is_full() { + let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + let validator: T::AccountId = validators[validator_idx].clone(); + let assignment = Decision { + validator, + method: ValidationMethodKind::ProofOfDelivery, + decision: None, + }; + decisions.try_push(assignment).unwrap(); } - 0 - } else { - 0 + Tasks::::insert(edge, decisions); } + + 0 } fn offchain_worker(block_number: T::BlockNumber) { From 25b9c673b50953a89a5780ce8dbc4ba46c60bb8d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 27 Mar 2023 20:04:43 +0600 Subject: [PATCH 019/544] Use era type from staking primitives --- src/lib.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cf4423173..1de5200c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; pub use sp_runtime::offchain::{http, Duration, Timestamp}; +pub use sp_staking::EraIndex; pub use sp_std::prelude::*; extern crate alloc; @@ -64,7 +65,7 @@ pub struct Decision { #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] pub struct ValidationResult { - era: String, + era: EraIndex, signer: AccountId, val_res: bool, cdn_node_pub_key: String, @@ -89,7 +90,7 @@ pub enum FtAggregate { #[derive(Clone)] struct BytesSent { node_public_key: String, - era: String, + era: EraIndex, sum: u32, } @@ -101,7 +102,8 @@ impl BytesSent { FtAggregate::Node(node) => return BytesSent { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), @@ -116,7 +118,8 @@ impl BytesSent { FtAggregate::Node(node) => { let node = BytesSent { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), }; @@ -133,7 +136,7 @@ impl BytesSent { #[derive(Clone)] struct BytesReceived { node_public_key: String, - era: String, + era: EraIndex, sum: u32, } @@ -145,7 +148,8 @@ impl BytesReceived { FtAggregate::Node(node) => return BytesReceived { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5] .parse::() .expect("bytesReceivedSum must be convertable to u32"), @@ -162,7 +166,8 @@ impl BytesReceived { FtAggregate::Node(node) => { let node = BytesReceived { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), }; @@ -242,7 +247,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn last_managed_era)] - pub type LastManagedEra = StorageValue<_, u64>; + pub type LastManagedEra = StorageValue<_, EraIndex>; #[pallet::storage] #[pallet::getter(fn validation_results)] @@ -332,7 +337,7 @@ pub mod pallet { origin: OriginFor, val_res: bool, cdn_node_pub_key: String, - era: String, + era: EraIndex, ) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; @@ -350,7 +355,7 @@ pub mod pallet { } #[pallet::weight(10000)] - pub fn proof_of_delivery(origin: OriginFor, era: u64) -> DispatchResult { + pub fn proof_of_delivery(origin: OriginFor, era: EraIndex) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; let cdn_nodes_to_validate = Self::fetch_tasks(&signer); @@ -398,7 +403,7 @@ pub mod pallet { info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1u64; + let current_era = Self::get_current_era() - 1; let tx_res = signer.send_signed_transaction(|_acct| { info!("[DAC Validator] Trigger proof of delivery"); @@ -426,13 +431,13 @@ pub mod pallet { } // Get the current era; Shall we start era count from 0 or from 1? - fn get_current_era() -> u64 { + fn get_current_era() -> EraIndex { ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) .try_into() .unwrap() } - fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { + fn fetch_data(era: EraIndex, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = Self::get_bytes_sent_query_url(era); @@ -466,7 +471,7 @@ pub mod pallet { (filtered_s.clone(), filtered_r.clone()) } - fn fetch_data1(era: u64 ) -> (Vec, Vec){ + fn fetch_data1(era: EraIndex) -> (Vec, Vec){ info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = Self::get_bytes_sent_query_url(era); @@ -484,11 +489,11 @@ pub mod pallet { (bytes_sent, bytes_received) } - fn get_bytes_sent_query_url(era: u64) -> String { + fn get_bytes_sent_query_url(era: EraIndex) -> String { format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) } - fn get_bytes_received_query_url(era: u64) -> String { + fn get_bytes_received_query_url(era: EraIndex) -> String { format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) } From cf1383999d599f27de5d545901fc00f401af371e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 12:46:36 +0600 Subject: [PATCH 020/544] Fix faulty hook on block initialization --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1de5200c6..edbaba17d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,7 +271,7 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - if block_number < 1u32.into() { + if block_number <= 1u32.into() { return 0 } From ff9b3a50e4c88183537ce0a007d38326a34fce61 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 12:52:12 +0600 Subject: [PATCH 021/544] Autoformat DAC Validator files --- src/lib.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index edbaba17d..c0fe9def0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,7 +111,7 @@ impl BytesSent { } pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec!(); + let mut res: Vec = vec![]; for i in 1..aggregation.ft_aggregate.len() { let data = aggregation.ft_aggregate[i].clone(); match data { @@ -120,16 +120,18 @@ impl BytesSent { node_public_key: node[1].clone(), era: node[3].clone().parse::().expect("era must be convertible u32") as EraIndex, - sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + sum: node[5] + .parse::() + .expect("bytesSentSum must be convertable to u32"), }; res.push(node); - } + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } - return res; + return res } } @@ -159,7 +161,7 @@ impl BytesReceived { } pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec!(); + let mut res: Vec = vec![]; for i in 1..aggregation.ft_aggregate.len() { let data = aggregation.ft_aggregate[i].clone(); match data { @@ -168,16 +170,18 @@ impl BytesReceived { node_public_key: node[1].clone(), era: node[3].clone().parse::().expect("era must be convertible u32") as EraIndex, - sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + sum: node[5] + .parse::() + .expect("bytesReceivedSum must be convertable to u32"), }; res.push(node); - } + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } - return res; + return res } } @@ -462,7 +466,11 @@ pub mod pallet { pub_key_str } - fn filter_data(s: &Vec, r: &Vec, a: &T::AccountId) -> (BytesSent, BytesReceived){ + fn filter_data( + s: &Vec, + r: &Vec, + a: &T::AccountId, + ) -> (BytesSent, BytesReceived) { let ac = Self::account_to_string(a.clone()); let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); @@ -471,7 +479,7 @@ pub mod pallet { (filtered_s.clone(), filtered_r.clone()) } - fn fetch_data1(era: EraIndex) -> (Vec, Vec){ + fn fetch_data1(era: EraIndex) -> (Vec, Vec) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = Self::get_bytes_sent_query_url(era); From ccd5f7d10e94a4123d22938b2374ca440f44ba92 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 12:53:59 +0600 Subject: [PATCH 022/544] Typo fix --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c0fe9def0..a30027c7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,7 +104,7 @@ impl BytesSent { node_public_key: node[1].clone(), era: node[3].clone().parse::().expect("era must be convertible u32") as EraIndex, - sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + sum: node[5].parse::().expect("bytesSentSum must be convertible to u32"), }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } @@ -122,7 +122,7 @@ impl BytesSent { as EraIndex, sum: node[5] .parse::() - .expect("bytesSentSum must be convertable to u32"), + .expect("bytesSentSum must be convertible to u32"), }; res.push(node); @@ -154,7 +154,7 @@ impl BytesReceived { as EraIndex, sum: node[5] .parse::() - .expect("bytesReceivedSum must be convertable to u32"), + .expect("bytesReceivedSum must be convertible to u32"), }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } @@ -172,7 +172,7 @@ impl BytesReceived { as EraIndex, sum: node[5] .parse::() - .expect("bytesReceivedSum must be convertable to u32"), + .expect("bytesReceivedSum must be convertible to u32"), }; res.push(node); From 043f42c2edb6f3202da5dfe9f937b83523c3d142 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 13:45:04 +0600 Subject: [PATCH 023/544] Introduce era key for DAC validator tasks --- src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a30027c7d..32354fa19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,9 +242,11 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn tasks)] - pub type Tasks = StorageMap< + pub type Tasks = StorageDoubleMap< _, Twox64Concat, + EraIndex, + Twox64Concat, T::AccountId, BoundedVec, DdcValidatorsQuorumSize>, >; @@ -314,7 +316,7 @@ pub mod pallet { }; decisions.try_push(assignment).unwrap(); } - Tasks::::insert(edge, decisions); + Tasks::::insert(era, edge, decisions); } 0 @@ -361,14 +363,14 @@ pub mod pallet { #[pallet::weight(10000)] pub fn proof_of_delivery(origin: OriginFor, era: EraIndex) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; - - let cdn_nodes_to_validate = Self::fetch_tasks(&signer); + let era = Self::get_current_era(); + let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); let (s, r) = Self::fetch_data1(era); for cdn_node_id in cdn_nodes_to_validate { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - let decisions_for_cdn = >::get(cdn_node_id); + let decisions_for_cdn = >::get(era, cdn_node_id); for decision in decisions_for_cdn.unwrap().iter_mut() { if decision.validator == signer { decision.decision = Some(val_res); @@ -547,9 +549,9 @@ pub mod pallet { } /// Fetch the tasks related to current validator - fn fetch_tasks(validator: &T::AccountId) -> Vec { + fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; - for (cdn_id, cdn_tasks) in >::iter() { + for (cdn_id, cdn_tasks) in >::iter_prefix(era) { for decision in cdn_tasks.iter() { if decision.validator == *validator { cdn_nodes.push(cdn_id); From 6213789372ed31ad7ec747ab8e9f95a766f0f4ca Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 13:02:18 +0600 Subject: [PATCH 024/544] Set DAC Validators quorum size in runtime crate --- src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 32354fa19..eb284d97a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,10 +31,6 @@ pub use sp_std::prelude::*; extern crate alloc; -parameter_types! { - pub DdcValidatorsQuorumSize: u32 = 3; -} - type BalanceOf = <::Currency as Currency< ::AccountId, >>::Balance; @@ -238,6 +234,9 @@ pub mod pallet { type Call: From>; type AuthorityId: AppCrypto; type TimeProvider: UnixTime; + + #[pallet::constant] + type DdcValidatorsQuorumSize: Get; } #[pallet::storage] @@ -248,7 +247,7 @@ pub mod pallet { EraIndex, Twox64Concat, T::AccountId, - BoundedVec, DdcValidatorsQuorumSize>, + BoundedVec, T::DdcValidatorsQuorumSize>, >; #[pallet::storage] @@ -304,7 +303,7 @@ pub mod pallet { // A naive approach assigns random validators for each edge. for edge in edges { - let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = Default::default(); while !decisions.is_full() { let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; From d49120c295dd3cf2f288d6ca52fc6431742d129f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 15:26:38 +0600 Subject: [PATCH 025/544] Print pubkeys available to offchain worker --- src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index eb284d97a..6c06457a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ pub use pallet_session as session; pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; +pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, Duration, Timestamp}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; @@ -322,6 +323,16 @@ pub mod pallet { } fn offchain_worker(block_number: T::BlockNumber) { + let pubkeys = sr25519_public_keys(KEY_TYPE); + if pubkeys.is_empty() { + log::info!("No local sr25519 accounts available to offchain worker."); + return + } + log::info!( + "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", + pubkeys, pubkeys.first().unwrap() + ); + let res = Self::offchain_worker_main(block_number); match res { From c208087ebde61a0066a7f79c1c210866cda8ee70 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Mar 2023 12:46:42 +0200 Subject: [PATCH 026/544] merge with latest commit --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6c06457a1..229e01f05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,10 @@ pub use sp_std::prelude::*; extern crate alloc; +parameter_types! { + pub const ValidationThreshold: f32 = 5.0; +} + type BalanceOf = <::Currency as Currency< ::AccountId, >>::Balance; @@ -555,7 +559,9 @@ pub mod pallet { } fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { - return if bytes_sent.sum == bytes_received.sum { true } else { false } + let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); + + return if percentage_difference > 0.0 && (ValidationThreshold::get() - percentage_difference) > 0.0 { true } else { false } } /// Fetch the tasks related to current validator From 50b237a620e0a7dbe09149088d6ac54fe1ee2c94 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Mar 2023 12:49:55 +0200 Subject: [PATCH 027/544] fix merge --- src/lib.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 229e01f05..b39e00548 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,8 +88,8 @@ pub enum FtAggregate { Node(Vec), } -#[derive(Clone)] -struct BytesSent { +#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] +pub struct BytesSent { node_public_key: String, era: EraIndex, sum: u32, @@ -136,8 +136,8 @@ impl BytesSent { } } -#[derive(Clone)] -struct BytesReceived { +#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] +pub struct BytesReceived { node_public_key: String, era: EraIndex, sum: u32, @@ -375,8 +375,9 @@ pub mod pallet { } #[pallet::weight(10000)] - pub fn proof_of_delivery(origin: OriginFor, era: EraIndex) -> DispatchResult { + pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; + let era = Self::get_current_era(); let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); let (s, r) = Self::fetch_data1(era); @@ -423,15 +424,12 @@ pub mod pallet { info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1; + let current_era = Self::get_current_era() - 1u64; + let (s, r) = Self::fetch_data1(current_era); let tx_res = signer.send_signed_transaction(|_acct| { - info!("[DAC Validator] Trigger proof of delivery"); - - // This is the on-chain function - Call::proof_of_delivery { era: current_era } + Call::proof_of_delivery { s: s.clone(), r: r.clone() } }); - match &tx_res { None | Some((_, Err(()))) => return Err("Error while submitting proof of delivery TX"), From 589da9a9cbe410d6c3f3589c757a4ba714567145 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Mar 2023 12:52:33 +0200 Subject: [PATCH 028/544] fix typo --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b39e00548..af78c5be6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -424,7 +424,7 @@ pub mod pallet { info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1u64; + let current_era = Self::get_current_era() - 1; let (s, r) = Self::fetch_data1(current_era); let tx_res = signer.send_signed_transaction(|_acct| { From c7a15da9ef84d39fd54780fb6189489860c0ff96 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 16:35:22 +0600 Subject: [PATCH 029/544] Add doc comments --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index af78c5be6..eb28a1d59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ parameter_types! { pub const ValidationThreshold: f32 = 5.0; } +/// The balance type of this pallet. type BalanceOf = <::Currency as Currency< ::AccountId, >>::Balance; @@ -52,15 +53,22 @@ const ERA_IN_BLOCKS: u8 = 20; const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; +/// DAC Validation methods. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { + /// Compare amount of served content with amount of content consumed. ProofOfDelivery, } +/// Associates validation decision with the validator and the method used to produce it. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct Decision { + /// Individual validator's decision. Can be `None` if the validator did not produce a decision + /// (yet). pub decision: Option, + /// The method used to produce the decision. pub method: ValidationMethodKind, + /// The validator who produced the decision. pub validator: AccountId, } @@ -234,16 +242,27 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { + /// The overarching event type. type Event: From> + IsType<::Event>; + + /// Something that provides randomness in the runtime. Required by the tasks assignment + /// procedure. type Randomness: Randomness; + + /// A dispatchable call. type Call: From>; + type AuthorityId: AppCrypto; type TimeProvider: UnixTime; + /// Number of validators expected to produce an individual validation decision to form a + /// consensus. Tasks assignment procedure use this value to determine the number of + /// validators are getting the same task. Must be an odd number. #[pallet::constant] type DdcValidatorsQuorumSize: Get; } + /// The map from the era and CDN participant stash key to the validation decisions related. #[pallet::storage] #[pallet::getter(fn tasks)] pub type Tasks = StorageDoubleMap< @@ -255,6 +274,7 @@ pub mod pallet { BoundedVec, T::DdcValidatorsQuorumSize>, >; + /// The last era for which the tasks assignment produced. #[pallet::storage] #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, EraIndex>; @@ -576,6 +596,9 @@ pub mod pallet { cdn_nodes } + /// Randomly choose a number in range `[0, total)`. + /// Returns `None` for zero input. + /// Modification of `choose_ticket` from `pallet-lottery` version `4.0.0-dev`. fn choose(total: u32) -> Option { if total == 0 { return None @@ -594,6 +617,11 @@ pub mod pallet { Some(random_number % total) } + /// Generate a random number from a given seed. + /// Note that there is potential bias introduced by using modulus operator. + /// You should call this function with different seed values until the random + /// number lies within `u32::MAX - u32::MAX % n`. + /// Modification of `generate_random_number` from `pallet-lottery` version `4.0.0-dev`. fn generate_random_number(seed: u32) -> u32 { let (random_seed, _) = ::Randomness::random(&(b"ddc-validator", seed).encode()); From 051e95632afdb6c35100ed53b99a1ead583689b7 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 18:00:40 +0600 Subject: [PATCH 030/544] Module level docs --- src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index eb28a1d59..6402d9f24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,37 @@ +//! # DDC Validator pallet +//! +//! The DDC Validator pallet is responsible for producing validation decisions based on activity +//! data from DAC DataModel. It is expected to work on validators nodes only. +//! +//! - [`Config`] +//! - [`Call`] +//! - [`Pallet`] +//! - [`Hooks`] +//! +//! ## Responsibility +//! +//! 1. Assign validation tasks on DAC Validators in the beginning of each era, +//! 2. Spin the offchain worker which tries to execute the validation tasks each era, +//! 3. Fetch the data required for validation from DAC DataModel, +//! 4. Execute validation method on this data, +//! 5. Produce validation decision and submit it to the chain. +//! +//! ## Usage +//! +//! 1. Run the node with `--validator` flag, +//! 2. Setup validator key with `author_insertKey` RPC call. Use `dacv` validator key type and the +//! same private key as the one used to generate the validator's session keys, +//! 3. Proceed a regular validator setup, +//! 4. Tasks assignment will assign you a task in the beginning of the era which has your account in +//! validators set. +//! +//! ## Notes +//! +//! - Era definition in this pallet is different than in the `pallet-staking`. In this pallet era is +//! a period of time during which the validator is expected to produce a validation decision. +//! Means staking era and DAC era are different and are not related to each other, +//! - You can set DAC Validators quorum size by specifying `DdcValidatorsQuorumSize` parameter, + #![cfg_attr(not(feature = "std"), no_std)] pub use alloc::{format, string::String}; From 11747c29b7d6caa3547a1591106ba63c8b6389a0 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Wed, 29 Mar 2023 22:51:19 +0200 Subject: [PATCH 031/544] Remove http request from tx --- src/lib.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6402d9f24..0be9e9454 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -430,22 +430,32 @@ pub mod pallet { #[pallet::weight(10000)] pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { + info!("[DAC Validator] processing proof_of_delivery"); let signer: T::AccountId = ensure_signed(origin)?; + info!("signer: {:?}", Self::account_to_string(signer.clone())); + let era = Self::get_current_era(); let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); - let (s, r) = Self::fetch_data1(era); + + info!("[DAC Validator] cdn_nodes_to_validate: {:?}", cdn_nodes_to_validate); + for cdn_node_id in cdn_nodes_to_validate { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); let decisions_for_cdn = >::get(era, cdn_node_id); - for decision in decisions_for_cdn.unwrap().iter_mut() { + for decision in decisions_for_cdn.clone().unwrap().iter_mut() { if decision.validator == signer { decision.decision = Some(val_res); decision.method = ValidationMethodKind::ProofOfDelivery; } } + + info!( + "[DAC Validator] decisions_for_cdn: {:?}", + decisions_for_cdn + ); } Ok(()) @@ -458,11 +468,6 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - info!( - "[DAC Validator] Validation data stored onchain: {:?}", - ValidationResults::::get() - ); - if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { return Ok(()) } @@ -475,8 +480,6 @@ pub mod pallet { Ok(signer) => signer, }; - info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); - // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1; let (s, r) = Self::fetch_data1(current_era); @@ -484,9 +487,13 @@ pub mod pallet { let tx_res = signer.send_signed_transaction(|_acct| { Call::proof_of_delivery { s: s.clone(), r: r.clone() } }); + match &tx_res { - None | Some((_, Err(()))) => - return Err("Error while submitting proof of delivery TX"), + None => return Err("Error while submitting proof of delivery TX"), + Some((_, Err(e))) => { + info!("Error while submitting proof of delivery TX: {:?}", e); + return Err("Error while submitting proof of delivery TX"); + }, Some((_, Ok(()))) => {}, } @@ -620,6 +627,8 @@ pub mod pallet { fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; for (cdn_id, cdn_tasks) in >::iter_prefix(era) { + info!("[DAC Validator] tasks assigned to {:?}: {:?}", cdn_id, cdn_tasks); + for decision in cdn_tasks.iter() { if decision.validator == *validator { cdn_nodes.push(cdn_id); From c0f2a7a67f4e88e6e32890c2526676ea4500d3e4 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 30 Mar 2023 14:51:59 +0600 Subject: [PATCH 032/544] Submit DAC Validation decision call --- src/lib.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0be9e9454..b456baf62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -323,10 +323,22 @@ pub mod pallet { pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + /// DAC Validator successfully published the validation decision. + ValidationDecisionSubmitted, + } #[pallet::error] - pub enum Error {} + pub enum Error { + /// Validation decision attempts to submit the result for the wrong era (not the current + /// one). + BadEra, + /// Can't submit the validation decision twice. + DecisionAlreadySubmitted, + /// Task does not exist for a given era, CDN participant, and DAC validator. + TaskNotFound, + } #[pallet::hooks] impl Hooks> for Pallet @@ -428,6 +440,40 @@ pub mod pallet { Ok(()) } + /// Set validation decision in tasks assignment. + /// + /// `origin` must be a DAC Validator assigned to the task. + /// `era` must be a current era, otherwise the decision will be rejected. + /// `subject` is a CDN participant stash. + /// + /// Emits `ValidationDecisionSubmitted` event. + #[pallet::weight(100_000)] + pub fn submit_validation_decision( + origin: OriginFor, + era: EraIndex, + subject: T::AccountId, + method: ValidationMethodKind, + decision: bool, + ) -> DispatchResult { + let account = ensure_signed(origin)?; + + ensure!(Self::get_current_era() == era, Error::::BadEra); + + Tasks::::try_mutate_exists(era, &subject, |maybe_tasks| { + let mut tasks = maybe_tasks.take().ok_or(Error::::TaskNotFound)?; + let mut task = tasks + .iter_mut() + .find(|task| task.validator == account && task.method == method) + .ok_or(Error::::TaskNotFound)?; + ensure!(task.decision.is_none(), Error::::DecisionAlreadySubmitted); + task.decision = Some(decision); + + Self::deposit_event(Event::ValidationDecisionSubmitted); + + Ok(()) + }) + } + #[pallet::weight(10000)] pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { info!("[DAC Validator] processing proof_of_delivery"); From 3828bdc8b4f98f9a26e50e3cbabe08b7f6938fdb Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 31 Mar 2023 17:16:21 +0600 Subject: [PATCH 033/544] Fix validation decision update --- src/lib.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b456baf62..1f10608c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -490,18 +490,17 @@ pub mod pallet { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - let decisions_for_cdn = >::get(era, cdn_node_id); - for decision in decisions_for_cdn.clone().unwrap().iter_mut() { - if decision.validator == signer { - decision.decision = Some(val_res); - decision.method = ValidationMethodKind::ProofOfDelivery; - } - } - - info!( - "[DAC Validator] decisions_for_cdn: {:?}", - decisions_for_cdn - ); + >::mutate(era, cdn_node_id, |decisions_for_cdn| { + let decisions = + decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); + let mut decision = decisions + .iter_mut() + .find(|decision| decision.validator == signer) + .expect("unexpected validators set in tasks assignment"); + decision.decision = Some(val_res); + }); + + info!("[DAC Validator] decisions_for_cdn: {:?}", >::get(era, cdn_node_id)); } Ok(()) From c5cfe53f045ad3e22879bd8d7d1037644c50a6ef Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 31 Mar 2023 17:33:09 +0600 Subject: [PATCH 034/544] Typo fix --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1f10608c9..71c81b97f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -490,7 +490,7 @@ pub mod pallet { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - >::mutate(era, cdn_node_id, |decisions_for_cdn| { + >::mutate(era, &cdn_node_id, |decisions_for_cdn| { let decisions = decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); let mut decision = decisions From a52cdbb26d8cb5c8467fedd24c5c1c1b102dca4e Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 11 Apr 2023 17:09:53 +0200 Subject: [PATCH 035/544] Try integrate unit tests --- Cargo.toml | 6 ++ src/lib.rs | 6 ++ src/mock.rs | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/tests.rs | 0 4 files changed, 288 insertions(+) create mode 100644 src/mock.rs create mode 100644 src/tests.rs diff --git a/Cargo.toml b/Cargo.toml index 0e0fe0ea9..203e032e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,9 @@ std = [ "sp-staking/std", "sp-std/std", ] + +[dev-dependencies] +pallet-balances = { version = "4.0.0-dev", path = "../balances" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", path = "../randomness-collective-flip" } +pallet-timestamp = { version = "4.0.0-dev", path = "../timestamp" } +pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 71c81b97f..f1f64ad5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,12 @@ #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(test)] +mod mock; + +#[cfg(test)] +mod tests; + pub use alloc::{format, string::String}; pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; diff --git a/src/mock.rs b/src/mock.rs new file mode 100644 index 000000000..b40c3a1c0 --- /dev/null +++ b/src/mock.rs @@ -0,0 +1,276 @@ +use crate::{*, self as pallet_ddc_validator}; +use frame_support::{ + parameter_types, + weights::Weight, + traits::{ConstU16, ConstU64, Currency, Everything, Nothing} +}; +use frame_system::EnsureRoot; +use frame_system::offchain::SendTransactionTypes; +use sp_core::H256; +use sp_runtime::{ curve::PiecewiseLinear, generic, testing::{Header, TestXt}, traits::{BlakeTwo256, IdentityLookup, Verify, Extrinsic as ExtrinsicT, IdentifyAccount}, Perbill, MultiSignature, curve}; +use pallet_contracts as contracts; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; +type Balance = u128; +// type AccountId = u64; + +pub type Signature = MultiSignature; +pub type AccountId = <::Signer as IdentifyAccount>::AccountId; +// pub type Balance = u128; +pub type BlockNumber = u32; +pub type Moment = u64; + +// Configure a mock runtime to test the pallet. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system, + Balances: pallet_balances, + Contracts: contracts, + Session: pallet_session, + Timestamp: pallet_timestamp, + RandomnessCollectiveFlip: pallet_randomness_collective_flip, + DdcStaking: pallet_ddc_staking, + DdcValidator: pallet_ddc_validator, + } +); + +parameter_types! { + pub const BlockHashCount: BlockNumber = 250; + pub const MaximumBlockWeight: Weight = 1024; + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::one(); +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type Origin = Origin; + type Index = u64; + type BlockNumber = BlockNumber; + type Hash = H256; + type Call = Call; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + // u64; // sp_core::sr25519::Public; + type Lookup = IdentityLookup; + type Header = generic::Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub const SignedClaimHandicap: BlockNumber = 2; + pub const TombstoneDeposit: Balance = 16; + pub const StorageSizeOffset: u32 = 8; + pub const RentByteFee: Balance = 4; + pub const RentDepositOffset: Balance = 10_000; + pub const SurchargeReward: Balance = 150; + pub const MaxDepth: u32 = 100; + pub const MaxValueSize: u32 = 16_384; + pub Schedule: pallet_contracts::Schedule = Default::default(); +} + +use contracts::{Config as contractsConfig}; + +type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; + +impl contracts::Config for Test { + type Time = Timestamp; + type Randomness = RandomnessCollectiveFlip; + type Currency = Balances; + type Event = Event; + type CallStack = [pallet_contracts::Frame; 31]; + type WeightPrice = Self; //pallet_transaction_payment::Module; + type WeightInfo = (); + type ChainExtension = (); + type DeletionQueueDepth = (); + type DeletionWeightLimit = (); + type Schedule = Schedule; + type Call = Call; + type CallFilter = Nothing; + type DepositPerByte = DepositPerByte; + type DepositPerItem = DepositPerItem; + type AddressGenerator = pallet_contracts::DefaultAddressGenerator; +} + +parameter_types! { + pub const TransactionByteFee: u64 = 0; + pub const DepositPerItem: Balance = 0; + pub const DepositPerByte: Balance = 0; +} + +parameter_types! { + pub const MinimumPeriod: u64 = 1; +} + +impl pallet_timestamp::Config for Test { + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +impl pallet_randomness_collective_flip::Config for Test {} + +parameter_types! { + pub const DdcValidatorsQuorumSize: u32 = 3; +} + +impl pallet_session::Config for Test { + type Event = (); + type ValidatorId = AccountId; + type ValidatorIdOf = (); + type ShouldEndSession = (); + type NextSessionRotation = (); + type SessionManager = (); + type SessionHandler = (); + type Keys = (); + type WeightInfo = (); +} + +pallet_staking_reward_curve::build! { + const REWARD_CURVE: PiecewiseLinear<'static> = curve!( + min_inflation: 0_000_100, + max_inflation: 0_050_000, + ideal_stake: 0_200_000, + falloff: 0_050_000, + max_piece_count: 100, + test_precision: 0_050_000, + ); +} + +parameter_types! { + pub const SessionsPerEra: sp_staking::SessionIndex = 6; + pub const BondingDuration: sp_staking::EraIndex = 3; + pub const SlashDeferDuration: sp_staking::EraIndex = 2; + pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; + pub const MaxNominatorRewardedPerValidator: u32 = 256; + pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); + pub OffchainRepeat: BlockNumber = 5; +} + +impl pallet_staking::Config for Test { + type MaxNominations = (); + type Currency = Balances; + type UnixTime = Timestamp; + type CurrencyToVote = (); + type RewardRemainder = (); + type Event = Event; + type Slash = (); // send the slashed funds to the treasury. + type Reward = (); // rewards are minted from the void + type SessionsPerEra = SessionsPerEra; + type BondingDuration = BondingDuration; + type SlashDeferDuration = SlashDeferDuration; + /// A super-majority of the council can cancel the slash. + type SlashCancelOrigin = (); + type SessionInterface = Self; + type EraPayout = pallet_staking::ConvertCurve; + type NextNewSession = Session; + type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; + type OffendingValidatorsThreshold = OffendingValidatorsThreshold; + type ElectionProvider = (); + type GenesisElectionProvider = (); + type VoterList = (); + type MaxUnlockingChunks = ConstU32<32>; + type WeightInfo = pallet_staking::weights::SubstrateWeight; + type BenchmarkingConfig = (); +} + +impl pallet_ddc_staking::Config for Test { + type BondingDuration = BondingDuration; + type Currency = Balances; + type Event = Event; + type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; +} + +impl pallet_ddc_validator::Config for Test { + type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; + type Event = Event; + type Randomness = RandomnessCollectiveFlip; + type Call = Call; + type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; + type TimeProvider = pallet_timestamp::Pallet; +} + +impl SendTransactionTypes for Test + where + Call: From, +{ + type OverarchingCall = Call; + type Extrinsic = Extrinsic; +} + +parameter_types! { + pub const ExistentialDeposit: u64 = 1; + pub const MaxLocks: u32 = 10; +} + +impl pallet_balances::Config for Test { + type Balance = Balance; + type DustRemoval = (); + type Event = Event; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = (); +} + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + frame_system::GenesisConfig::default().build_storage::().unwrap().into() +} + +pub type Extrinsic = TestXt; + +impl SigningTypes for Test { + type Public = ::Signer; + type Signature = Signature; +} + +// impl frame_system::offchain::SendTransactionTypes for Test +// where +// Call: From, +// { +// type OverarchingCall = Call; +// type Extrinsic = TestXt; +// } + +// impl SendTransactionTypes for Test +// where +// Call: From, +// { +// type OverarchingCall = Call; +// type Extrinsic = Extrinsic; +// } + +impl CreateSignedTransaction for Test + where + Call: From, +{ + fn create_transaction>( + call: Call, + _public: ::Signer, + _account: AccountId, + nonce: u64, + ) -> Option<(Call, ::SignaturePayload)> { + Some((call, (nonce, ()))) + } +} \ No newline at end of file diff --git a/src/tests.rs b/src/tests.rs new file mode 100644 index 000000000..e69de29bb From 8b6ac905cc5d16bcf9c0eb590d0855c1ad6fe8d3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 16 Mar 2023 20:22:00 +0600 Subject: [PATCH 036/544] An empty DAC Validator pallet crate --- Cargo.toml | 19 +++++++++++++++++++ README.md | 1 + src/lib.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..d9525b4df --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "pallet-ddc-validator" +version = "0.1.0" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } +frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } +scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", +] diff --git a/README.md b/README.md new file mode 100644 index 000000000..3a21d9d6c --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# DDC Validator diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..0cecc036b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,26 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +pub use frame_support::pallet_prelude::*; +pub use frame_system::pallet_prelude::*; +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type Event: From> + IsType<::Event>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event {} + + #[pallet::error] + pub enum Error {} +} From ff1928da8eccfe61d48465a2beb5c29be8030805 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 17 Mar 2023 16:38:15 +0600 Subject: [PATCH 037/544] Era counter with privileged inc for DAC Validator --- src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0cecc036b..a9b774968 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,10 +17,29 @@ pub mod pallet { type Event: From> + IsType<::Event>; } + #[pallet::storage] + #[pallet::getter(fn global_era_counter)] + pub type GlobalEraCounter = StorageValue<_, u32>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event {} #[pallet::error] pub enum Error {} + + #[pallet::call] + impl Pallet { + #[pallet::weight(100_000)] + pub fn inc_era(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + if let Some(era) = >::get() { + let new_era = era.checked_add(1).unwrap_or_default(); + >::put(new_era); + } else { + >::put(1); + } + Ok(()) + } + } } From de4be86d9bbbdeccdedfb26f8c6440cf0264261f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 17 Mar 2023 17:15:04 +0600 Subject: [PATCH 038/544] Hooks and storage items for DAC Validator --- Cargo.toml | 13 +++++++++++++ src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9525b4df..057a274a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,14 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } +log = { version = "0.4.17", default-features = false } +pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } +pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } +sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } [features] default = ["std"] @@ -15,5 +22,11 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "pallet-ddc-staking/std", + "pallet-staking/std", "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", ] diff --git a/src/lib.rs b/src/lib.rs index a9b774968..df766e369 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,27 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use frame_support::pallet_prelude::*; +pub use frame_support::{pallet_prelude::*, parameter_types, weights::Weight, BoundedVec}; pub use frame_system::pallet_prelude::*; +pub use pallet_ddc_staking::{self as ddc_staking}; +pub use pallet_staking::{self as staking}; pub use pallet::*; +pub use sp_std::prelude::*; + +parameter_types! { + pub DdcValidatorsQuorumSize: u32 = 3; +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub enum ValidationMethodKind { + ProofOfDelivery, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct Decision { + pub decision: Option, + pub method: ValidationMethodKind, + pub validator: AccountId, +} #[frame_support::pallet] pub mod pallet { @@ -13,14 +32,27 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + pallet_staking::Config + ddc_staking::Config { type Event: From> + IsType<::Event>; } + #[pallet::storage] + #[pallet::getter(fn tasks)] + pub type Tasks = StorageMap< + _, + Twox64Concat, + T::AccountId, + BoundedVec, DdcValidatorsQuorumSize>, + >; + #[pallet::storage] #[pallet::getter(fn global_era_counter)] pub type GlobalEraCounter = StorageValue<_, u32>; + #[pallet::storage] + #[pallet::getter(fn last_managed_era)] + pub type LastManagedEra = StorageValue<_, u32>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event {} @@ -42,4 +74,24 @@ pub mod pallet { Ok(()) } } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(block_number: T::BlockNumber) -> Weight { + let validators: Vec = >::iter_keys().collect(); + let edges: Vec = >::iter_keys().collect(); + log::info!( + "Block number: {:?}, global era: {:?}, last era: {:?}, validators: {:?}, edges: {:?}", + block_number, + >::get(), + >::get(), + validators, + edges, + ); + 0 + } + fn offchain_worker(block_number: T::BlockNumber) { + log::info!("Off-chain worker at block {:?}", block_number); + } + } } From c551411ed758ef06c70e59ea79125b3074012613 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 17 Mar 2023 14:25:39 +0100 Subject: [PATCH 039/544] add function fetch_tasks --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index df766e369..77d1d894b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,4 +94,20 @@ pub mod pallet { log::info!("Off-chain worker at block {:?}", block_number); } } + + impl Pallet { + /// Fetch the tasks related to current validator + fn fetch_tasks(validator: T::AccountId) -> Vec { + let mut cdn_nodes: Vec = vec![]; + for (cdn_id, cdn_tasks) in >::iter() { + for decision in cdn_tasks.iter() { + if decision.validator == validator { + cdn_nodes.push(cdn_id); + break; + } + } + } + cdn_nodes + } + } } From cb3c966d695da2ca9f9525d518b571adb402ab6b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 20 Mar 2023 11:54:31 +0600 Subject: [PATCH 040/544] Assign a random DAC validator for each edge --- src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 77d1d894b..bb2dd7641 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use frame_support::{pallet_prelude::*, parameter_types, weights::Weight, BoundedVec}; +pub use frame_support::{ + pallet_prelude::*, parameter_types, traits::Randomness, weights::Weight, BoundedVec, +}; pub use frame_system::pallet_prelude::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; @@ -34,6 +36,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_staking::Config + ddc_staking::Config { type Event: From> + IsType<::Event>; + type Randomness: Randomness; } #[pallet::storage] @@ -79,15 +82,34 @@ pub mod pallet { impl Hooks> for Pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { let validators: Vec = >::iter_keys().collect(); + let validators_count = validators.len() as u32; let edges: Vec = >::iter_keys().collect(); log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators: {:?}, edges: {:?}", + "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", block_number, >::get(), >::get(), + validators_count, validators, edges, ); + + // A naive approach assigns random validators for each edge. + for edge in edges { + let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + Default::default(); + while !decisions.is_full() { + let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + let validator: T::AccountId = validators[validator_idx].clone(); + let assignment = Decision { + validator, + method: ValidationMethodKind::ProofOfDelivery, + decision: None, + }; + decisions.try_push(assignment).unwrap(); + } + Tasks::::insert(edge, decisions); + } 0 } fn offchain_worker(block_number: T::BlockNumber) { @@ -109,5 +131,31 @@ pub mod pallet { } cdn_nodes } + + fn choose(total: u32) -> Option { + if total == 0 { + return None + } + let mut random_number = Self::generate_random_number(0); + + // Best effort attempt to remove bias from modulus operator. + for i in 1..128 { + if random_number < u32::MAX - u32::MAX % total { + break + } + + random_number = Self::generate_random_number(i); + } + + Some(random_number % total) + } + + fn generate_random_number(seed: u32) -> u32 { + let (random_seed, _) = T::Randomness::random(&(b"ddc-validator", seed).encode()); + let random_number = ::decode(&mut random_seed.as_ref()) + .expect("secure hashes should always be bigger than u32; qed"); + + random_number + } } } From eb02ac07ab2262ffd6f451371cdb06196e78c7b8 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 20 Mar 2023 14:27:15 +0600 Subject: [PATCH 041/544] Assign DAC validation tasks on era increment --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bb2dd7641..a88d229d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,6 +81,19 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { + match (>::get(), >::get()) { + (Some(global_era_counter), Some(last_managed_era)) => { + if last_managed_era >= global_era_counter { + return 0 + } + >::put(global_era_counter); + }, + (Some(global_era_counter), None) => { + >::put(global_era_counter); + }, + _ => { return 0 }, + }; + let validators: Vec = >::iter_keys().collect(); let validators_count = validators.len() as u32; let edges: Vec = >::iter_keys().collect(); From 86d2174f8e08892cbb7a46b38880b1ba441b4627 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 20 Mar 2023 14:54:08 +0600 Subject: [PATCH 042/544] Format DAC Validator files --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a88d229d4..344048de9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,9 @@ pub use frame_support::{ pallet_prelude::*, parameter_types, traits::Randomness, weights::Weight, BoundedVec, }; pub use frame_system::pallet_prelude::*; +pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; -pub use pallet::*; pub use sp_std::prelude::*; parameter_types! { @@ -91,7 +91,7 @@ pub mod pallet { (Some(global_era_counter), None) => { >::put(global_era_counter); }, - _ => { return 0 }, + _ => return 0, }; let validators: Vec = >::iter_keys().collect(); @@ -125,6 +125,7 @@ pub mod pallet { } 0 } + fn offchain_worker(block_number: T::BlockNumber) { log::info!("Off-chain worker at block {:?}", block_number); } @@ -138,7 +139,7 @@ pub mod pallet { for decision in cdn_tasks.iter() { if decision.validator == validator { cdn_nodes.push(cdn_id); - break; + break } } } From 6a330d76946cfc6c3f79e517d0d24b3621845ae4 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 21 Mar 2023 15:15:39 +0100 Subject: [PATCH 043/544] adjust era --- src/lib.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 344048de9..10f72a1ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,16 @@ pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; pub use sp_std::prelude::*; +pub use sp_io::offchain::timestamp; parameter_types! { pub DdcValidatorsQuorumSize: u32 = 3; } +const TIME_START_MS: u64 = 1_672_531_200_000; +const ERA_DURATION_MS: u64 = 120_000; +const ERA_IN_BLOCKS: u8 = 20; + #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { ProofOfDelivery, @@ -48,10 +53,6 @@ pub mod pallet { BoundedVec, DdcValidatorsQuorumSize>, >; - #[pallet::storage] - #[pallet::getter(fn global_era_counter)] - pub type GlobalEraCounter = StorageValue<_, u32>; - #[pallet::storage] #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, u32>; @@ -63,21 +64,6 @@ pub mod pallet { #[pallet::error] pub enum Error {} - #[pallet::call] - impl Pallet { - #[pallet::weight(100_000)] - pub fn inc_era(origin: OriginFor) -> DispatchResult { - ensure_root(origin)?; - if let Some(era) = >::get() { - let new_era = era.checked_add(1).unwrap_or_default(); - >::put(new_era); - } else { - >::put(1); - } - Ok(()) - } - } - #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { @@ -100,7 +86,7 @@ pub mod pallet { log::info!( "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", block_number, - >::get(), + Self::get_current_era(), >::get(), validators_count, validators, @@ -170,6 +156,9 @@ pub mod pallet { .expect("secure hashes should always be bigger than u32; qed"); random_number + // Get the current era; Shall we start era count from 0 or from 1? + fn get_current_era() -> u64 { + (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS } } } From a9ed277ab846645e7293750bd820175dff17ca18 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 21 Mar 2023 15:40:37 +0100 Subject: [PATCH 044/544] fix era --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 10f72a1ac..3d708a0a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -156,6 +156,8 @@ pub mod pallet { .expect("secure hashes should always be bigger than u32; qed"); random_number + } + // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> u64 { (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS From 3b6a21bf91bd7b0be09ffc0c60615d36426878cd Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 22 Mar 2023 11:32:21 +0100 Subject: [PATCH 045/544] merge offchain worker with ddc validator --- Cargo.toml | 12 ++ src/lib.rs | 322 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 317 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 057a274a2..55172f684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,20 @@ version = "0.1.0" edition = "2021" [dependencies] +alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } log = { version = "0.4.17", default-features = false } +pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } +pallet-session = { version = "4.0.0-dev", path = "../session", default-features = false } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } +serde = { version = "1.0.101", optional = true } +serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } +sp-keystore = { version = "0.12.0", default-features = false, path = "../../primitives/keystore", optional = true } +sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } @@ -22,9 +29,14 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "pallet-contracts/std", "pallet-ddc-staking/std", "pallet-staking/std", + "pallet-session/std", "scale-info/std", + "serde", + "sp-keystore", + "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-staking/std", diff --git a/src/lib.rs b/src/lib.rs index 3d708a0a1..9cab6656c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,53 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub use alloc::{format, string::String}; +pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; +pub use codec::{Encode, Decode, MaxEncodedLen, HasCompact}; +pub use core::fmt::Debug; pub use frame_support::{ - pallet_prelude::*, parameter_types, traits::Randomness, weights::Weight, BoundedVec, + decl_event, decl_module, decl_storage, + log::{error, info, warn}, + pallet_prelude::*, + traits::{Randomness, Currency}, + weights::Weight, + dispatch::DispatchResult, + RuntimeDebug, + BoundedVec, + parameter_types, }; -pub use frame_system::pallet_prelude::*; +pub use frame_system::{ensure_signed, pallet_prelude::*, offchain::{CreateSignedTransaction, Signer, SigningTypes, AppCrypto, SendSignedTransaction}}; pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_staking::{self as staking}; +pub use pallet_session as session; +pub use scale_info::TypeInfo; +pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; +pub use sp_runtime::offchain::{http, Duration}; pub use sp_std::prelude::*; pub use sp_io::offchain::timestamp; +extern crate alloc; parameter_types! { pub DdcValidatorsQuorumSize: u32 = 3; } +type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +type ResultStr = Result; + + +pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); + +pub const HTTP_TIMEOUT_MS: u64 = 30_000; + const TIME_START_MS: u64 = 1_672_531_200_000; const ERA_DURATION_MS: u64 = 120_000; const ERA_IN_BLOCKS: u8 = 20; +const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; + #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { ProofOfDelivery, @@ -30,18 +60,112 @@ pub struct Decision { pub validator: AccountId, } +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] +pub struct ValidationResult { + era: String, + signer: AccountId, + val_res: bool, + cdn_node_pub_key: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct RedisFtAggregate { + #[serde(rename = "FT.AGGREGATE")] + pub ft_aggregate: (u32, Vec, Vec), +} + +#[derive(Clone)] +struct BytesSent { + node_public_key: String, + era: String, + sum: u32, +} + +impl BytesSent { + pub fn new(aggregate: RedisFtAggregate) -> BytesSent { + let (_, values, values2) = aggregate.ft_aggregate; + + BytesSent { + node_public_key: values[1].clone(), + era: values[3].clone(), + sum: values[5].parse::().expect("bytesSentSum must be convertable to u32"), + } + } +} + +#[derive(Clone)] +struct BytesReceived { + node_public_key: String, + era: String, + sum: u32, +} + +impl BytesReceived { + pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { + let (_, values, values2) = aggregate.ft_aggregate; + + BytesReceived { + node_public_key: values[1].clone(), + era: values[3].clone(), + sum: values[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + } + } +} + +pub mod crypto { + use super::KEY_TYPE; + use frame_system::offchain::AppCrypto; + use sp_core::sr25519::Signature as Sr25519Signature; + use sp_runtime::{ + app_crypto::{app_crypto, sr25519}, + traits::Verify, + }; + app_crypto!(sr25519, KEY_TYPE); + + use sp_runtime::{MultiSignature, MultiSigner}; + + pub struct TestAuthId; + + impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; + } + + impl AppCrypto for TestAuthId { + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; + } +} + #[frame_support::pallet] pub mod pallet { use super::*; #[pallet::pallet] + #[pallet::without_storage_info] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_staking::Config + ddc_staking::Config { + pub trait Config: + frame_system::Config + + pallet_contracts::Config + + pallet_session::Config::AccountId> + + pallet_staking::Config + + ddc_staking::Config + + CreateSignedTransaction> + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { type Event: From> + IsType<::Event>; type Randomness: Randomness; + type Call: From>; + type AuthorityId: AppCrypto; } #[pallet::storage] @@ -55,26 +179,34 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn last_managed_era)] - pub type LastManagedEra = StorageValue<_, u32>; + pub type LastManagedEra = StorageValue<_, u64>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event {} + pub enum Event + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + {} #[pallet::error] pub enum Error {} #[pallet::hooks] - impl Hooks> for Pallet { + impl Hooks> for Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { fn on_initialize(block_number: T::BlockNumber) -> Weight { - match (>::get(), >::get()) { - (Some(global_era_counter), Some(last_managed_era)) => { + match (Self::get_current_era(), >::get()) { + (global_era_counter, Some(last_managed_era)) => { if last_managed_era >= global_era_counter { return 0 } >::put(global_era_counter); }, - (Some(global_era_counter), None) => { + (global_era_counter, None) => { >::put(global_era_counter); }, _ => return 0, @@ -113,11 +245,172 @@ pub mod pallet { } fn offchain_worker(block_number: T::BlockNumber) { - log::info!("Off-chain worker at block {:?}", block_number); + let res = Self::offchain_worker_main(block_number); + + match res { + Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), + Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), + }; } } - impl Pallet { + #[pallet::call] + impl Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + #[pallet::weight(10000)] + pub fn save_validated_data(origin: OriginFor, val_res: bool, cdn_node_pub_key: String, era: String) -> DispatchResult { + let signer: T::AccountId = ensure_signed(origin)?; + + info!("[DAC Validator] author: {:?}", signer); + let mut v_results = ValidationResults::::get(); + + let cur_validation = ValidationResult:: { + era, + val_res, + cdn_node_pub_key, + signer, + }; + + v_results.push(cur_validation); + + ValidationResults::::set(v_results); + + Ok(()) + } + } + + impl Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { + info!("[DAC Validator] Validation data stored onchain: {:?}", ValidationResults::::get()); + + if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { + return Ok(()) + } + + let signer = match Self::get_signer() { + Err(e) => { + warn!("{:?}", e); + return Ok(()); + } + Ok(signer) => signer, + }; + + info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); + + // Read data from DataModel and do dumb validation + let current_era = Self::get_current_era() - 1u64; + let (bytes_sent, bytes_received) = Self::fetch_data(current_era); + let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + + let cdn_node_pub_key = bytes_sent.node_public_key.clone(); + let tx_res = signer.send_signed_transaction(|_acct| { + info!("[DAC Validator] Sending save_validated_data tx"); + + // This is the on-chain function + Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } + }); + + match &tx_res { + None | Some((_, Err(()))) => { + return Err("Error while submitting save_validated_data TX") + } + Some((_, Ok(()))) => {} + } + + Ok(()) + } + + fn get_signer() -> ResultStr> { + let signer = Signer::<_, _>::any_account(); + if !signer.can_sign() { + return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); + } + + Ok(signer) + } + + // Get the current era; Shall we start era count from 0 or from 1? + fn get_current_era() -> u64 { + (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS + } + + fn fetch_data(era: u64 ) -> (BytesSent, BytesReceived){ + info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + // Todo: handle the error + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + let bytes_sent = BytesSent::new(bytes_sent_res); + + // Todo: handle the error + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = + Self::http_get_json(&bytes_received_query).unwrap(); + info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + let bytes_received = BytesReceived::new(bytes_received_res); + + (bytes_sent, bytes_received) + } + + fn get_bytes_sent_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) + } + + fn get_bytes_received_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) + } + + fn http_get_json(url: &str) -> ResultStr { + let body = Self::http_get_request(url).map_err(|err| { + error!("[DAC Validator] Error while getting {}: {:?}", url, err); + "HTTP GET error" + })?; + + let parsed = serde_json::from_slice(&body).map_err(|err| { + warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); + "HTTP JSON parse error" + }); + + parsed + } + + fn http_get_request(http_url: &str) -> Result, http::Error> { + info!("[DAC Validator] Sending request to: {:?}", http_url); + + // Initiate an external HTTP GET request. This is using high-level wrappers from + // `sp_runtime`. + let request = http::Request::get(http_url); + + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + + let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + + let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + + if response.code != 200 { + warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + + // Next we fully read the response body and collect it to a vector of bytes. + Ok(response.body().collect::>()) + } + + fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { + return if bytes_sent.sum == bytes_received.sum { + true + } else { + false + } + } + /// Fetch the tasks related to current validator fn fetch_tasks(validator: T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; @@ -151,16 +444,11 @@ pub mod pallet { } fn generate_random_number(seed: u32) -> u32 { - let (random_seed, _) = T::Randomness::random(&(b"ddc-validator", seed).encode()); + let (random_seed, _) = ::Randomness::random(&(b"ddc-validator", seed).encode()); let random_number = ::decode(&mut random_seed.as_ref()) .expect("secure hashes should always be bigger than u32; qed"); random_number } - - // Get the current era; Shall we start era count from 0 or from 1? - fn get_current_era() -> u64 { - (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS - } } } From f50b16da0e394c5ceecca6ad1e243245b4201491 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 22 Mar 2023 14:43:26 +0100 Subject: [PATCH 046/544] add proof of delivery --- src/lib.rs | 75 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9cab6656c..52219d6dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -181,6 +181,10 @@ pub mod pallet { #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, u64>; + #[pallet::storage] + #[pallet::getter(fn validation_results)] + pub(super) type ValidationResults = StorageValue<_, Vec>, ValueQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event @@ -209,7 +213,6 @@ pub mod pallet { (global_era_counter, None) => { >::put(global_era_counter); }, - _ => return 0, }; let validators: Vec = >::iter_keys().collect(); @@ -280,6 +283,27 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(10000)] + pub fn proof_of_delivery(origin: OriginFor, era: u64) -> DispatchResult { + let signer: T::AccountId = ensure_signed(origin)?; + + let cdn_nodes_to_validate = Self::fetch_tasks(&signer); + for cdn_node_id in cdn_nodes_to_validate { + let (bytes_sent, bytes_received) = Self::fetch_data(era, &cdn_node_id); + let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + + let decisions_for_cdn = >::get(cdn_node_id); + for decision in decisions_for_cdn.unwrap().iter_mut() { + if decision.validator == signer { + decision.decision = Some(val_res); + decision.method = ValidationMethodKind::ProofOfDelivery; + } + } + } + + Ok(()) + } } impl Pallet @@ -306,23 +330,26 @@ pub mod pallet { // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1u64; - let (bytes_sent, bytes_received) = Self::fetch_data(current_era); - let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - let cdn_node_pub_key = bytes_sent.node_public_key.clone(); - let tx_res = signer.send_signed_transaction(|_acct| { - info!("[DAC Validator] Sending save_validated_data tx"); + // for decision in &mut cdn_nodes_to_validate { - // This is the on-chain function - Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } - }); + // } + // let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + // let cdn_node_pub_key = bytes_sent.node_public_key.clone(); - match &tx_res { - None | Some((_, Err(()))) => { - return Err("Error while submitting save_validated_data TX") - } - Some((_, Ok(()))) => {} - } + // let tx_res = signer.send_signed_transaction(|_acct| { + // info!("[DAC Validator] Sending save_validated_data tx"); + + // // This is the on-chain function + // Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } + // }); + + // match &tx_res { + // None | Some((_, Err(()))) => { + // return Err("Error while submitting save_validated_data TX") + // } + // Some((_, Ok(()))) => {} + // } Ok(()) } @@ -341,16 +368,16 @@ pub mod pallet { (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS } - fn fetch_data(era: u64 ) -> (BytesSent, BytesReceived){ + fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_query = Self::get_bytes_sent_query_url(era, cdn_node); let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_query = Self::get_bytes_received_query_url(era, cdn_node); let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); @@ -359,12 +386,12 @@ pub mod pallet { (bytes_sent, bytes_received) } - fn get_bytes_sent_query_url(era: u64) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) + fn get_bytes_sent_query_url(era: u64, cdn_node: &T::AccountId) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era, *cdn_node) } - fn get_bytes_received_query_url(era: u64) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) + fn get_bytes_received_query_url(era: u64, cdn_node: &T::AccountId) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era, *cdn_node) } fn http_get_json(url: &str) -> ResultStr { @@ -412,11 +439,11 @@ pub mod pallet { } /// Fetch the tasks related to current validator - fn fetch_tasks(validator: T::AccountId) -> Vec { + fn fetch_tasks(validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; for (cdn_id, cdn_tasks) in >::iter() { for decision in cdn_tasks.iter() { - if decision.validator == validator { + if decision.validator == *validator { cdn_nodes.push(cdn_id); break } From b906084a0eb6f18dae06bb2d6ef5752a5ff90fbc Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 22 Mar 2023 14:45:48 +0100 Subject: [PATCH 047/544] add PoD trigger in offchain worker --- src/lib.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 52219d6dc..d599567be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -331,25 +331,20 @@ pub mod pallet { // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1u64; - // for decision in &mut cdn_nodes_to_validate { + + let tx_res = signer.send_signed_transaction(|_acct| { + info!("[DAC Validator] Trigger proof of delivery"); - // } - // let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - // let cdn_node_pub_key = bytes_sent.node_public_key.clone(); - - // let tx_res = signer.send_signed_transaction(|_acct| { - // info!("[DAC Validator] Sending save_validated_data tx"); - - // // This is the on-chain function - // Call::save_validated_data { val_res, cdn_node_pub_key: cdn_node_pub_key.clone(), era: bytes_sent.era.clone() } - // }); + // This is the on-chain function + Call::proof_of_delivery { era: current_era } + }); - // match &tx_res { - // None | Some((_, Err(()))) => { - // return Err("Error while submitting save_validated_data TX") - // } - // Some((_, Ok(()))) => {} - // } + match &tx_res { + None | Some((_, Err(()))) => { + return Err("Error while submitting proof of delivery TX") + } + Some((_, Ok(()))) => {} + } Ok(()) } From f9dd9a0de6264af4ccb522163500de6b83552d72 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 23 Mar 2023 11:47:35 +0100 Subject: [PATCH 048/544] Move JSON parsing fix to ddc-validator --- src/lib.rs | 58 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d599567be..2b1d5245e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,8 +72,16 @@ pub struct ValidationResult { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct RedisFtAggregate { - #[serde(rename = "FT.AGGREGATE")] - pub ft_aggregate: (u32, Vec, Vec), + #[serde(rename = "FT.AGGREGATE")] + pub ft_aggregate: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(crate = "alt_serde")] +#[serde(untagged)] +pub enum FtAggregate { + Length(u32), + Node(Vec), } #[derive(Clone)] @@ -84,15 +92,20 @@ struct BytesSent { } impl BytesSent { - pub fn new(aggregate: RedisFtAggregate) -> BytesSent { - let (_, values, values2) = aggregate.ft_aggregate; - - BytesSent { - node_public_key: values[1].clone(), - era: values[3].clone(), - sum: values[5].parse::().expect("bytesSentSum must be convertable to u32"), - } - } + pub fn new(aggregate: RedisFtAggregate) -> BytesSent { + let data = aggregate.ft_aggregate[1].clone(); + + match data { + FtAggregate::Node(node) => { + return BytesSent { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + } + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } } #[derive(Clone)] @@ -103,15 +116,20 @@ struct BytesReceived { } impl BytesReceived { - pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { - let (_, values, values2) = aggregate.ft_aggregate; - - BytesReceived { - node_public_key: values[1].clone(), - era: values[3].clone(), - sum: values[5].parse::().expect("bytesReceivedSum must be convertable to u32"), - } - } + pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { + let data = aggregate.ft_aggregate[1].clone(); + + match data { + FtAggregate::Node(node) => { + return BytesReceived { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + } + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } } pub mod crypto { From 0cbef5016c24e9161e47f040a0af40a26d974a4a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 23 Mar 2023 15:23:09 +0100 Subject: [PATCH 049/544] fix timestamp bug --- src/lib.rs | 96 +++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b1d5245e..e7481fe6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ pub use frame_support::{ decl_event, decl_module, decl_storage, log::{error, info, warn}, pallet_prelude::*, - traits::{Randomness, Currency}, + traits::{Randomness, Currency, UnixTime}, weights::Weight, dispatch::DispatchResult, RuntimeDebug, @@ -22,9 +22,9 @@ pub use pallet_staking::{self as staking}; pub use pallet_session as session; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; -pub use sp_runtime::offchain::{http, Duration}; +pub use sp_runtime::offchain::{http, Duration, Timestamp}; pub use sp_std::prelude::*; -pub use sp_io::offchain::timestamp; + extern crate alloc; parameter_types! { @@ -42,8 +42,8 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const HTTP_TIMEOUT_MS: u64 = 30_000; -const TIME_START_MS: u64 = 1_672_531_200_000; -const ERA_DURATION_MS: u64 = 120_000; +const TIME_START_MS: u128 = 1_672_531_200_000; +const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; @@ -184,6 +184,7 @@ pub mod pallet { type Randomness: Randomness; type Call: From>; type AuthorityId: AppCrypto; + type TimeProvider: UnixTime; } #[pallet::storage] @@ -221,48 +222,53 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - match (Self::get_current_era(), >::get()) { - (global_era_counter, Some(last_managed_era)) => { - if last_managed_era >= global_era_counter { - return 0 + if block_number != 0u32.into() && block_number != 1u32.into() { + let era = Self::get_current_era(); + match (era, >::get()) { + (global_era_counter, Some(last_managed_era)) => { + if last_managed_era >= global_era_counter { + return 0 + } + >::put(global_era_counter); + }, + (global_era_counter, None) => { + >::put(global_era_counter); + }, + }; + + let validators: Vec = >::iter_keys().collect(); + let validators_count = validators.len() as u32; + let edges: Vec = >::iter_keys().collect(); + log::info!( + "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", + block_number, + era, + >::get(), + validators_count, + validators, + edges, + ); + + // A naive approach assigns random validators for each edge. + for edge in edges { + let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + Default::default(); + while !decisions.is_full() { + let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + let validator: T::AccountId = validators[validator_idx].clone(); + let assignment = Decision { + validator, + method: ValidationMethodKind::ProofOfDelivery, + decision: None, + }; + decisions.try_push(assignment).unwrap(); } - >::put(global_era_counter); - }, - (global_era_counter, None) => { - >::put(global_era_counter); - }, - }; - - let validators: Vec = >::iter_keys().collect(); - let validators_count = validators.len() as u32; - let edges: Vec = >::iter_keys().collect(); - log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", - block_number, - Self::get_current_era(), - >::get(), - validators_count, - validators, - edges, - ); - - // A naive approach assigns random validators for each edge. - for edge in edges { - let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = - Default::default(); - while !decisions.is_full() { - let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - let validator: T::AccountId = validators[validator_idx].clone(); - let assignment = Decision { - validator, - method: ValidationMethodKind::ProofOfDelivery, - decision: None, - }; - decisions.try_push(assignment).unwrap(); + Tasks::::insert(edge, decisions); } - Tasks::::insert(edge, decisions); + 0 + } else { + 0 } - 0 } fn offchain_worker(block_number: T::BlockNumber) { @@ -378,7 +384,7 @@ pub mod pallet { // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> u64 { - (timestamp().unix_millis() - TIME_START_MS) / ERA_DURATION_MS + ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS).try_into().unwrap() } fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { From 427f79ec813e9a7a3bfd9ab84de1b3a60ce766fd Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 24 Mar 2023 11:17:31 +0600 Subject: [PATCH 050/544] Autoformat DAC Validator files --- Cargo.toml | 8 +-- src/lib.rs | 205 +++++++++++++++++++++++++++-------------------------- 2 files changed, 109 insertions(+), 104 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55172f684..af7a0108e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,14 @@ frame-system = { version = "4.0.0-dev", default-features = false, path = "../sys log = { version = "0.4.17", default-features = false } pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } -pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } pallet-session = { version = "4.0.0-dev", path = "../session", default-features = false } +pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../staking" } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -sp-keystore = { version = "0.12.0", default-features = false, path = "../../primitives/keystore", optional = true } sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } +sp-keystore = { version = "0.12.0", default-features = false, path = "../../primitives/keystore", optional = true } sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } @@ -31,13 +31,13 @@ std = [ "frame-system/std", "pallet-contracts/std", "pallet-ddc-staking/std", - "pallet-staking/std", "pallet-session/std", + "pallet-staking/std", "scale-info/std", "serde", - "sp-keystore", "sp-core/std", "sp-io/std", + "sp-keystore", "sp-runtime/std", "sp-staking/std", "sp-std/std", diff --git a/src/lib.rs b/src/lib.rs index e7481fe6e..a2e6586a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,24 +2,27 @@ pub use alloc::{format, string::String}; pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; -pub use codec::{Encode, Decode, MaxEncodedLen, HasCompact}; +pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; pub use core::fmt::Debug; pub use frame_support::{ decl_event, decl_module, decl_storage, - log::{error, info, warn}, - pallet_prelude::*, - traits::{Randomness, Currency, UnixTime}, - weights::Weight, dispatch::DispatchResult, - RuntimeDebug, - BoundedVec, + log::{error, info, warn}, + pallet_prelude::*, parameter_types, + traits::{Currency, Randomness, UnixTime}, + weights::Weight, + BoundedVec, RuntimeDebug, +}; +pub use frame_system::{ + ensure_signed, + offchain::{AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes}, + pallet_prelude::*, }; -pub use frame_system::{ensure_signed, pallet_prelude::*, offchain::{CreateSignedTransaction, Signer, SigningTypes, AppCrypto, SendSignedTransaction}}; pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; -pub use pallet_staking::{self as staking}; pub use pallet_session as session; +pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; pub use sp_runtime::offchain::{http, Duration, Timestamp}; @@ -32,12 +35,11 @@ parameter_types! { } type BalanceOf = <::Currency as Currency< - ::AccountId, + ::AccountId, >>::Balance; type ResultStr = Result; - pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const HTTP_TIMEOUT_MS: u64 = 30_000; @@ -62,10 +64,10 @@ pub struct Decision { #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] pub struct ValidationResult { - era: String, - signer: AccountId, - val_res: bool, - cdn_node_pub_key: String, + era: String, + signer: AccountId, + val_res: bool, + cdn_node_pub_key: String, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -86,9 +88,9 @@ pub enum FtAggregate { #[derive(Clone)] struct BytesSent { - node_public_key: String, - era: String, - sum: u32, + node_public_key: String, + era: String, + sum: u32, } impl BytesSent { @@ -96,13 +98,12 @@ impl BytesSent { let data = aggregate.ft_aggregate[1].clone(); match data { - FtAggregate::Node(node) => { + FtAggregate::Node(node) => return BytesSent { node_public_key: node[1].clone(), era: node[3].clone(), sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), - } - } + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } @@ -110,9 +111,9 @@ impl BytesSent { #[derive(Clone)] struct BytesReceived { - node_public_key: String, - era: String, - sum: u32, + node_public_key: String, + era: String, + sum: u32, } impl BytesReceived { @@ -120,13 +121,14 @@ impl BytesReceived { let data = aggregate.ft_aggregate[1].clone(); match data { - FtAggregate::Node(node) => { + FtAggregate::Node(node) => return BytesReceived { node_public_key: node[1].clone(), era: node[3].clone(), - sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), - } - } + sum: node[5] + .parse::() + .expect("bytesReceivedSum must be convertable to u32"), + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } @@ -137,8 +139,8 @@ pub mod crypto { use frame_system::offchain::AppCrypto; use sp_core::sr25519::Signature as Sr25519Signature; use sp_runtime::{ - app_crypto::{app_crypto, sr25519}, - traits::Verify, + app_crypto::{app_crypto, sr25519}, + traits::Verify, }; app_crypto!(sr25519, KEY_TYPE); @@ -147,15 +149,15 @@ pub mod crypto { pub struct TestAuthId; impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; } impl AppCrypto for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; } } @@ -169,21 +171,21 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: + pub trait Config: frame_system::Config + pallet_contracts::Config - + pallet_session::Config::AccountId> + + pallet_session::Config::AccountId> + pallet_staking::Config + ddc_staking::Config + CreateSignedTransaction> - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { type Event: From> + IsType<::Event>; type Randomness: Randomness; type Call: From>; - type AuthorityId: AppCrypto; + type AuthorityId: AppCrypto; type TimeProvider: UnixTime; } @@ -202,28 +204,28 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn validation_results)] - pub(super) type ValidationResults = StorageValue<_, Vec>, ValueQuery>; + pub(super) type ValidationResults = + StorageValue<_, Vec>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event + pub enum Event where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - {} + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} #[pallet::error] pub enum Error {} #[pallet::hooks] - impl Hooks> for Pallet + impl Hooks> for Pallet where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { if block_number != 0u32.into() && block_number != 1u32.into() { - let era = Self::get_current_era(); + let era = Self::get_current_era(); match (era, >::get()) { (global_era_counter, Some(last_managed_era)) => { if last_managed_era >= global_era_counter { @@ -235,10 +237,11 @@ pub mod pallet { >::put(global_era_counter); }, }; - + let validators: Vec = >::iter_keys().collect(); let validators_count = validators.len() as u32; - let edges: Vec = >::iter_keys().collect(); + let edges: Vec = + >::iter_keys().collect(); log::info!( "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", block_number, @@ -248,7 +251,7 @@ pub mod pallet { validators, edges, ); - + // A naive approach assigns random validators for each edge. for edge in edges { let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = @@ -282,24 +285,25 @@ pub mod pallet { } #[pallet::call] - impl Pallet - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + impl Pallet + where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { #[pallet::weight(10000)] - pub fn save_validated_data(origin: OriginFor, val_res: bool, cdn_node_pub_key: String, era: String) -> DispatchResult { + pub fn save_validated_data( + origin: OriginFor, + val_res: bool, + cdn_node_pub_key: String, + era: String, + ) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; info!("[DAC Validator] author: {:?}", signer); let mut v_results = ValidationResults::::get(); - let cur_validation = ValidationResult:: { - era, - val_res, - cdn_node_pub_key, - signer, - }; + let cur_validation = + ValidationResult:: { era, val_res, cdn_node_pub_key, signer }; v_results.push(cur_validation); @@ -330,24 +334,27 @@ pub mod pallet { } } - impl Pallet + impl Pallet where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - info!("[DAC Validator] Validation data stored onchain: {:?}", ValidationResults::::get()); + info!( + "[DAC Validator] Validation data stored onchain: {:?}", + ValidationResults::::get() + ); if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { - return Ok(()) + return Ok(()) } let signer = match Self::get_signer() { - Err(e) => { - warn!("{:?}", e); - return Ok(()); - } - Ok(signer) => signer, + Err(e) => { + warn!("{:?}", e); + return Ok(()) + }, + Ok(signer) => signer, }; info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); @@ -355,19 +362,17 @@ pub mod pallet { // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1u64; - let tx_res = signer.send_signed_transaction(|_acct| { - info!("[DAC Validator] Trigger proof of delivery"); + info!("[DAC Validator] Trigger proof of delivery"); - // This is the on-chain function - Call::proof_of_delivery { era: current_era } + // This is the on-chain function + Call::proof_of_delivery { era: current_era } }); match &tx_res { - None | Some((_, Err(()))) => { - return Err("Error while submitting proof of delivery TX") - } - Some((_, Ok(()))) => {} + None | Some((_, Err(()))) => + return Err("Error while submitting proof of delivery TX"), + Some((_, Ok(()))) => {}, } Ok(()) @@ -376,7 +381,7 @@ pub mod pallet { fn get_signer() -> ResultStr> { let signer = Signer::<_, _>::any_account(); if !signer.can_sign() { - return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); + return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); } Ok(signer) @@ -384,7 +389,9 @@ pub mod pallet { // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> u64 { - ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS).try_into().unwrap() + ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) + .try_into() + .unwrap() } fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { @@ -398,7 +405,7 @@ pub mod pallet { // Todo: handle the error let bytes_received_query = Self::get_bytes_received_query_url(era, cdn_node); let bytes_received_res: RedisFtAggregate = - Self::http_get_json(&bytes_received_query).unwrap(); + Self::http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::new(bytes_received_res); @@ -415,13 +422,13 @@ pub mod pallet { fn http_get_json(url: &str) -> ResultStr { let body = Self::http_get_request(url).map_err(|err| { - error!("[DAC Validator] Error while getting {}: {:?}", url, err); - "HTTP GET error" + error!("[DAC Validator] Error while getting {}: {:?}", url, err); + "HTTP GET error" })?; let parsed = serde_json::from_slice(&body).map_err(|err| { - warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); - "HTTP JSON parse error" + warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); + "HTTP JSON parse error" }); parsed @@ -438,23 +445,20 @@ pub mod pallet { let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + let response = + pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; if response.code != 200 { - warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); - return Err(http::Error::Unknown) + warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); + return Err(http::Error::Unknown) } // Next we fully read the response body and collect it to a vector of bytes. Ok(response.body().collect::>()) - } + } fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { - return if bytes_sent.sum == bytes_received.sum { - true - } else { - false - } + return if bytes_sent.sum == bytes_received.sum { true } else { false } } /// Fetch the tasks related to current validator @@ -490,7 +494,8 @@ pub mod pallet { } fn generate_random_number(seed: u32) -> u32 { - let (random_seed, _) = ::Randomness::random(&(b"ddc-validator", seed).encode()); + let (random_seed, _) = + ::Randomness::random(&(b"ddc-validator", seed).encode()); let random_number = ::decode(&mut random_seed.as_ref()) .expect("secure hashes should always be bigger than u32; qed"); From 673cd9312048da38a2aaaf8636688581e0ffc5d8 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 24 Mar 2023 12:02:07 +0100 Subject: [PATCH 051/544] add filtering of requests --- Cargo.toml | 1 + src/lib.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af7a0108e..0e0fe0ea9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +array-bytes = "6.0.0" alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } diff --git a/src/lib.rs b/src/lib.rs index a2e6586a8..5a553ca1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,6 +107,27 @@ impl BytesSent { FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } + + pub fn get_all(aggregation: RedisFtAggregate) -> Vec { + let mut res: Vec = vec!(); + for i in 1..aggregation.ft_aggregate.len() { + let data = aggregation.ft_aggregate[i].clone(); + match data { + FtAggregate::Node(node) => { + let node = BytesSent { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + }; + + res.push(node); + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + return res; + } } #[derive(Clone)] @@ -132,6 +153,27 @@ impl BytesReceived { FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } + + pub fn get_all(aggregation: RedisFtAggregate) -> Vec { + let mut res: Vec = vec!(); + for i in 1..aggregation.ft_aggregate.len() { + let data = aggregation.ft_aggregate[i].clone(); + match data { + FtAggregate::Node(node) => { + let node = BytesReceived { + node_public_key: node[1].clone(), + era: node[3].clone(), + sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + }; + + res.push(node); + } + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + return res; + } } pub mod crypto { @@ -317,8 +359,9 @@ pub mod pallet { let signer: T::AccountId = ensure_signed(origin)?; let cdn_nodes_to_validate = Self::fetch_tasks(&signer); + let (s, r) = Self::fetch_data1(era); for cdn_node_id in cdn_nodes_to_validate { - let (bytes_sent, bytes_received) = Self::fetch_data(era, &cdn_node_id); + let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); let decisions_for_cdn = >::get(cdn_node_id); @@ -397,13 +440,13 @@ pub mod pallet { fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era, cdn_node); + let bytes_sent_query = Self::get_bytes_sent_query_url(era); let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era, cdn_node); + let bytes_received_query = Self::get_bytes_received_query_url(era); let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); @@ -412,12 +455,46 @@ pub mod pallet { (bytes_sent, bytes_received) } - fn get_bytes_sent_query_url(era: u64, cdn_node: &T::AccountId) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era, *cdn_node) + fn account_to_string(account: T::AccountId) -> String { + let to32 = T::AccountId::encode(&account); + let pub_key_str = array_bytes::bytes2hex("", to32); + + pub_key_str + } + + fn filter_data(s: &Vec, r: &Vec, a: &T::AccountId) -> (BytesSent, BytesReceived){ + let ac = Self::account_to_string(a.clone()); + + let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); + let filtered_r = &*r.into_iter().find(|br| br.node_public_key == ac).unwrap(); + + (filtered_s.clone(), filtered_r.clone()) + } + + fn fetch_data1(era: u64 ) -> (Vec, Vec){ + info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + // Todo: handle the error + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + let bytes_sent = BytesSent::get_all(bytes_sent_res); + + // Todo: handle the error + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = + Self::http_get_json(&bytes_received_query).unwrap(); + info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + let bytes_received = BytesReceived::get_all(bytes_received_res); + + (bytes_sent, bytes_received) + } + + fn get_bytes_sent_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) } - fn get_bytes_received_query_url(era: u64, cdn_node: &T::AccountId) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/{:?}/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era, *cdn_node) + fn get_bytes_received_query_url(era: u64) -> String { + format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) } fn http_get_json(url: &str) -> ResultStr { From b12511fdb4d6237c1f99414a783c86b7ac8bc789 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 27 Mar 2023 14:38:27 +0600 Subject: [PATCH 052/544] Refactor guard condition --- src/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5a553ca1d..dc5b4688c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,18 +268,12 @@ pub mod pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { if block_number != 0u32.into() && block_number != 1u32.into() { let era = Self::get_current_era(); - match (era, >::get()) { - (global_era_counter, Some(last_managed_era)) => { - if last_managed_era >= global_era_counter { - return 0 - } - >::put(global_era_counter); - }, - (global_era_counter, None) => { - >::put(global_era_counter); - }, - }; - + if let Some(last_managed_era) = >::get() { + if last_managed_era >= era { + return 0 + } + } + >::put(era); let validators: Vec = >::iter_keys().collect(); let validators_count = validators.len() as u32; let edges: Vec = From 3853a50bd35dae6405587f7bc010b1131b1eb1da Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 27 Mar 2023 15:30:57 +0600 Subject: [PATCH 053/544] Refactor a guard condition to decrease indentation --- src/lib.rs | 79 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dc5b4688c..cf4423173 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -266,48 +266,49 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - if block_number != 0u32.into() && block_number != 1u32.into() { - let era = Self::get_current_era(); - if let Some(last_managed_era) = >::get() { - if last_managed_era >= era { - return 0 - } + if block_number < 1u32.into() { + return 0 + } + + let era = Self::get_current_era(); + if let Some(last_managed_era) = >::get() { + if last_managed_era >= era { + return 0 } - >::put(era); - let validators: Vec = >::iter_keys().collect(); - let validators_count = validators.len() as u32; - let edges: Vec = - >::iter_keys().collect(); - log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", - block_number, - era, - >::get(), - validators_count, - validators, - edges, - ); - - // A naive approach assigns random validators for each edge. - for edge in edges { - let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = - Default::default(); - while !decisions.is_full() { - let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - let validator: T::AccountId = validators[validator_idx].clone(); - let assignment = Decision { - validator, - method: ValidationMethodKind::ProofOfDelivery, - decision: None, - }; - decisions.try_push(assignment).unwrap(); - } - Tasks::::insert(edge, decisions); + } + >::put(era); + + let validators: Vec = >::iter_keys().collect(); + let validators_count = validators.len() as u32; + let edges: Vec = >::iter_keys().collect(); + log::info!( + "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", + block_number, + era, + >::get(), + validators_count, + validators, + edges, + ); + + // A naive approach assigns random validators for each edge. + for edge in edges { + let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + Default::default(); + while !decisions.is_full() { + let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + let validator: T::AccountId = validators[validator_idx].clone(); + let assignment = Decision { + validator, + method: ValidationMethodKind::ProofOfDelivery, + decision: None, + }; + decisions.try_push(assignment).unwrap(); } - 0 - } else { - 0 + Tasks::::insert(edge, decisions); } + + 0 } fn offchain_worker(block_number: T::BlockNumber) { From fb88c8a7b01ed65a36cd95f6cdef6a4d964db646 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 27 Mar 2023 20:04:43 +0600 Subject: [PATCH 054/544] Use era type from staking primitives --- src/lib.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cf4423173..1de5200c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; pub use sp_runtime::offchain::{http, Duration, Timestamp}; +pub use sp_staking::EraIndex; pub use sp_std::prelude::*; extern crate alloc; @@ -64,7 +65,7 @@ pub struct Decision { #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] pub struct ValidationResult { - era: String, + era: EraIndex, signer: AccountId, val_res: bool, cdn_node_pub_key: String, @@ -89,7 +90,7 @@ pub enum FtAggregate { #[derive(Clone)] struct BytesSent { node_public_key: String, - era: String, + era: EraIndex, sum: u32, } @@ -101,7 +102,8 @@ impl BytesSent { FtAggregate::Node(node) => return BytesSent { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), @@ -116,7 +118,8 @@ impl BytesSent { FtAggregate::Node(node) => { let node = BytesSent { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), }; @@ -133,7 +136,7 @@ impl BytesSent { #[derive(Clone)] struct BytesReceived { node_public_key: String, - era: String, + era: EraIndex, sum: u32, } @@ -145,7 +148,8 @@ impl BytesReceived { FtAggregate::Node(node) => return BytesReceived { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5] .parse::() .expect("bytesReceivedSum must be convertable to u32"), @@ -162,7 +166,8 @@ impl BytesReceived { FtAggregate::Node(node) => { let node = BytesReceived { node_public_key: node[1].clone(), - era: node[3].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), }; @@ -242,7 +247,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn last_managed_era)] - pub type LastManagedEra = StorageValue<_, u64>; + pub type LastManagedEra = StorageValue<_, EraIndex>; #[pallet::storage] #[pallet::getter(fn validation_results)] @@ -332,7 +337,7 @@ pub mod pallet { origin: OriginFor, val_res: bool, cdn_node_pub_key: String, - era: String, + era: EraIndex, ) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; @@ -350,7 +355,7 @@ pub mod pallet { } #[pallet::weight(10000)] - pub fn proof_of_delivery(origin: OriginFor, era: u64) -> DispatchResult { + pub fn proof_of_delivery(origin: OriginFor, era: EraIndex) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; let cdn_nodes_to_validate = Self::fetch_tasks(&signer); @@ -398,7 +403,7 @@ pub mod pallet { info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1u64; + let current_era = Self::get_current_era() - 1; let tx_res = signer.send_signed_transaction(|_acct| { info!("[DAC Validator] Trigger proof of delivery"); @@ -426,13 +431,13 @@ pub mod pallet { } // Get the current era; Shall we start era count from 0 or from 1? - fn get_current_era() -> u64 { + fn get_current_era() -> EraIndex { ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) .try_into() .unwrap() } - fn fetch_data(era: u64, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { + fn fetch_data(era: EraIndex, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = Self::get_bytes_sent_query_url(era); @@ -466,7 +471,7 @@ pub mod pallet { (filtered_s.clone(), filtered_r.clone()) } - fn fetch_data1(era: u64 ) -> (Vec, Vec){ + fn fetch_data1(era: EraIndex) -> (Vec, Vec){ info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = Self::get_bytes_sent_query_url(era); @@ -484,11 +489,11 @@ pub mod pallet { (bytes_sent, bytes_received) } - fn get_bytes_sent_query_url(era: u64) -> String { + fn get_bytes_sent_query_url(era: EraIndex) -> String { format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) } - fn get_bytes_received_query_url(era: u64) -> String { + fn get_bytes_received_query_url(era: EraIndex) -> String { format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) } From 8e47f4a1750e297202216c75f97b09ca32f8c80f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 12:46:36 +0600 Subject: [PATCH 055/544] Fix faulty hook on block initialization --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1de5200c6..edbaba17d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,7 +271,7 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - if block_number < 1u32.into() { + if block_number <= 1u32.into() { return 0 } From 2f290ae466ceb38b545f6292e17ec8c496838f90 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 12:52:12 +0600 Subject: [PATCH 056/544] Autoformat DAC Validator files --- src/lib.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index edbaba17d..c0fe9def0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,7 +111,7 @@ impl BytesSent { } pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec!(); + let mut res: Vec = vec![]; for i in 1..aggregation.ft_aggregate.len() { let data = aggregation.ft_aggregate[i].clone(); match data { @@ -120,16 +120,18 @@ impl BytesSent { node_public_key: node[1].clone(), era: node[3].clone().parse::().expect("era must be convertible u32") as EraIndex, - sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + sum: node[5] + .parse::() + .expect("bytesSentSum must be convertable to u32"), }; res.push(node); - } + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } - return res; + return res } } @@ -159,7 +161,7 @@ impl BytesReceived { } pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec!(); + let mut res: Vec = vec![]; for i in 1..aggregation.ft_aggregate.len() { let data = aggregation.ft_aggregate[i].clone(); match data { @@ -168,16 +170,18 @@ impl BytesReceived { node_public_key: node[1].clone(), era: node[3].clone().parse::().expect("era must be convertible u32") as EraIndex, - sum: node[5].parse::().expect("bytesReceivedSum must be convertable to u32"), + sum: node[5] + .parse::() + .expect("bytesReceivedSum must be convertable to u32"), }; res.push(node); - } + }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } } - return res; + return res } } @@ -462,7 +466,11 @@ pub mod pallet { pub_key_str } - fn filter_data(s: &Vec, r: &Vec, a: &T::AccountId) -> (BytesSent, BytesReceived){ + fn filter_data( + s: &Vec, + r: &Vec, + a: &T::AccountId, + ) -> (BytesSent, BytesReceived) { let ac = Self::account_to_string(a.clone()); let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); @@ -471,7 +479,7 @@ pub mod pallet { (filtered_s.clone(), filtered_r.clone()) } - fn fetch_data1(era: EraIndex) -> (Vec, Vec){ + fn fetch_data1(era: EraIndex) -> (Vec, Vec) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = Self::get_bytes_sent_query_url(era); From 416c2c6d52fb59d2a3a1a93de0bffedd9638a685 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 12:53:59 +0600 Subject: [PATCH 057/544] Typo fix --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c0fe9def0..a30027c7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,7 +104,7 @@ impl BytesSent { node_public_key: node[1].clone(), era: node[3].clone().parse::().expect("era must be convertible u32") as EraIndex, - sum: node[5].parse::().expect("bytesSentSum must be convertable to u32"), + sum: node[5].parse::().expect("bytesSentSum must be convertible to u32"), }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } @@ -122,7 +122,7 @@ impl BytesSent { as EraIndex, sum: node[5] .parse::() - .expect("bytesSentSum must be convertable to u32"), + .expect("bytesSentSum must be convertible to u32"), }; res.push(node); @@ -154,7 +154,7 @@ impl BytesReceived { as EraIndex, sum: node[5] .parse::() - .expect("bytesReceivedSum must be convertable to u32"), + .expect("bytesReceivedSum must be convertible to u32"), }, FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), } @@ -172,7 +172,7 @@ impl BytesReceived { as EraIndex, sum: node[5] .parse::() - .expect("bytesReceivedSum must be convertable to u32"), + .expect("bytesReceivedSum must be convertible to u32"), }; res.push(node); From 1b75a63d0d4b5b63b2892b0d2cebf7f7d9e4f3bc Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 28 Mar 2023 13:45:04 +0600 Subject: [PATCH 058/544] Introduce era key for DAC validator tasks --- src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a30027c7d..32354fa19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,9 +242,11 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn tasks)] - pub type Tasks = StorageMap< + pub type Tasks = StorageDoubleMap< _, Twox64Concat, + EraIndex, + Twox64Concat, T::AccountId, BoundedVec, DdcValidatorsQuorumSize>, >; @@ -314,7 +316,7 @@ pub mod pallet { }; decisions.try_push(assignment).unwrap(); } - Tasks::::insert(edge, decisions); + Tasks::::insert(era, edge, decisions); } 0 @@ -361,14 +363,14 @@ pub mod pallet { #[pallet::weight(10000)] pub fn proof_of_delivery(origin: OriginFor, era: EraIndex) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; - - let cdn_nodes_to_validate = Self::fetch_tasks(&signer); + let era = Self::get_current_era(); + let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); let (s, r) = Self::fetch_data1(era); for cdn_node_id in cdn_nodes_to_validate { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - let decisions_for_cdn = >::get(cdn_node_id); + let decisions_for_cdn = >::get(era, cdn_node_id); for decision in decisions_for_cdn.unwrap().iter_mut() { if decision.validator == signer { decision.decision = Some(val_res); @@ -547,9 +549,9 @@ pub mod pallet { } /// Fetch the tasks related to current validator - fn fetch_tasks(validator: &T::AccountId) -> Vec { + fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; - for (cdn_id, cdn_tasks) in >::iter() { + for (cdn_id, cdn_tasks) in >::iter_prefix(era) { for decision in cdn_tasks.iter() { if decision.validator == *validator { cdn_nodes.push(cdn_id); From 1b9ec07f6e4ad8eae3b2182e9584e04aeea562f3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 13:02:18 +0600 Subject: [PATCH 059/544] Set DAC Validators quorum size in runtime crate --- src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 32354fa19..eb284d97a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,10 +31,6 @@ pub use sp_std::prelude::*; extern crate alloc; -parameter_types! { - pub DdcValidatorsQuorumSize: u32 = 3; -} - type BalanceOf = <::Currency as Currency< ::AccountId, >>::Balance; @@ -238,6 +234,9 @@ pub mod pallet { type Call: From>; type AuthorityId: AppCrypto; type TimeProvider: UnixTime; + + #[pallet::constant] + type DdcValidatorsQuorumSize: Get; } #[pallet::storage] @@ -248,7 +247,7 @@ pub mod pallet { EraIndex, Twox64Concat, T::AccountId, - BoundedVec, DdcValidatorsQuorumSize>, + BoundedVec, T::DdcValidatorsQuorumSize>, >; #[pallet::storage] @@ -304,7 +303,7 @@ pub mod pallet { // A naive approach assigns random validators for each edge. for edge in edges { - let mut decisions: BoundedVec, DdcValidatorsQuorumSize> = + let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = Default::default(); while !decisions.is_full() { let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; From 3dac8e82845c89e992d26d97c198cc678739f071 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 15:26:38 +0600 Subject: [PATCH 060/544] Print pubkeys available to offchain worker --- src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index eb284d97a..6c06457a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ pub use pallet_session as session; pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; +pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, Duration, Timestamp}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; @@ -322,6 +323,16 @@ pub mod pallet { } fn offchain_worker(block_number: T::BlockNumber) { + let pubkeys = sr25519_public_keys(KEY_TYPE); + if pubkeys.is_empty() { + log::info!("No local sr25519 accounts available to offchain worker."); + return + } + log::info!( + "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", + pubkeys, pubkeys.first().unwrap() + ); + let res = Self::offchain_worker_main(block_number); match res { From 9a473c4f6e999bc390faabf1c755f77d9bd8b5c1 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Mar 2023 12:46:42 +0200 Subject: [PATCH 061/544] merge with latest commit --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6c06457a1..229e01f05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,10 @@ pub use sp_std::prelude::*; extern crate alloc; +parameter_types! { + pub const ValidationThreshold: f32 = 5.0; +} + type BalanceOf = <::Currency as Currency< ::AccountId, >>::Balance; @@ -555,7 +559,9 @@ pub mod pallet { } fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { - return if bytes_sent.sum == bytes_received.sum { true } else { false } + let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); + + return if percentage_difference > 0.0 && (ValidationThreshold::get() - percentage_difference) > 0.0 { true } else { false } } /// Fetch the tasks related to current validator From 669dded6f19b8fe6b1dde9cf9b258ff3f54608a4 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Mar 2023 12:49:55 +0200 Subject: [PATCH 062/544] fix merge --- src/lib.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 229e01f05..b39e00548 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,8 +88,8 @@ pub enum FtAggregate { Node(Vec), } -#[derive(Clone)] -struct BytesSent { +#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] +pub struct BytesSent { node_public_key: String, era: EraIndex, sum: u32, @@ -136,8 +136,8 @@ impl BytesSent { } } -#[derive(Clone)] -struct BytesReceived { +#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] +pub struct BytesReceived { node_public_key: String, era: EraIndex, sum: u32, @@ -375,8 +375,9 @@ pub mod pallet { } #[pallet::weight(10000)] - pub fn proof_of_delivery(origin: OriginFor, era: EraIndex) -> DispatchResult { + pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { let signer: T::AccountId = ensure_signed(origin)?; + let era = Self::get_current_era(); let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); let (s, r) = Self::fetch_data1(era); @@ -423,15 +424,12 @@ pub mod pallet { info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1; + let current_era = Self::get_current_era() - 1u64; + let (s, r) = Self::fetch_data1(current_era); let tx_res = signer.send_signed_transaction(|_acct| { - info!("[DAC Validator] Trigger proof of delivery"); - - // This is the on-chain function - Call::proof_of_delivery { era: current_era } + Call::proof_of_delivery { s: s.clone(), r: r.clone() } }); - match &tx_res { None | Some((_, Err(()))) => return Err("Error while submitting proof of delivery TX"), From 48a130d22dc1963be5527bc1ae5ac41ccc73ce91 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Mar 2023 12:52:33 +0200 Subject: [PATCH 063/544] fix typo --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b39e00548..af78c5be6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -424,7 +424,7 @@ pub mod pallet { info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1u64; + let current_era = Self::get_current_era() - 1; let (s, r) = Self::fetch_data1(current_era); let tx_res = signer.send_signed_transaction(|_acct| { From c9986fab435cbd0824cced892c296114e7595ecb Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 16:35:22 +0600 Subject: [PATCH 064/544] Add doc comments --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index af78c5be6..eb28a1d59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ parameter_types! { pub const ValidationThreshold: f32 = 5.0; } +/// The balance type of this pallet. type BalanceOf = <::Currency as Currency< ::AccountId, >>::Balance; @@ -52,15 +53,22 @@ const ERA_IN_BLOCKS: u8 = 20; const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; +/// DAC Validation methods. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { + /// Compare amount of served content with amount of content consumed. ProofOfDelivery, } +/// Associates validation decision with the validator and the method used to produce it. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct Decision { + /// Individual validator's decision. Can be `None` if the validator did not produce a decision + /// (yet). pub decision: Option, + /// The method used to produce the decision. pub method: ValidationMethodKind, + /// The validator who produced the decision. pub validator: AccountId, } @@ -234,16 +242,27 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { + /// The overarching event type. type Event: From> + IsType<::Event>; + + /// Something that provides randomness in the runtime. Required by the tasks assignment + /// procedure. type Randomness: Randomness; + + /// A dispatchable call. type Call: From>; + type AuthorityId: AppCrypto; type TimeProvider: UnixTime; + /// Number of validators expected to produce an individual validation decision to form a + /// consensus. Tasks assignment procedure use this value to determine the number of + /// validators are getting the same task. Must be an odd number. #[pallet::constant] type DdcValidatorsQuorumSize: Get; } + /// The map from the era and CDN participant stash key to the validation decisions related. #[pallet::storage] #[pallet::getter(fn tasks)] pub type Tasks = StorageDoubleMap< @@ -255,6 +274,7 @@ pub mod pallet { BoundedVec, T::DdcValidatorsQuorumSize>, >; + /// The last era for which the tasks assignment produced. #[pallet::storage] #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, EraIndex>; @@ -576,6 +596,9 @@ pub mod pallet { cdn_nodes } + /// Randomly choose a number in range `[0, total)`. + /// Returns `None` for zero input. + /// Modification of `choose_ticket` from `pallet-lottery` version `4.0.0-dev`. fn choose(total: u32) -> Option { if total == 0 { return None @@ -594,6 +617,11 @@ pub mod pallet { Some(random_number % total) } + /// Generate a random number from a given seed. + /// Note that there is potential bias introduced by using modulus operator. + /// You should call this function with different seed values until the random + /// number lies within `u32::MAX - u32::MAX % n`. + /// Modification of `generate_random_number` from `pallet-lottery` version `4.0.0-dev`. fn generate_random_number(seed: u32) -> u32 { let (random_seed, _) = ::Randomness::random(&(b"ddc-validator", seed).encode()); From 9c77216cac535380f01cbb44e97d056e2169d5d7 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 29 Mar 2023 18:00:40 +0600 Subject: [PATCH 065/544] Module level docs --- src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index eb28a1d59..6402d9f24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,37 @@ +//! # DDC Validator pallet +//! +//! The DDC Validator pallet is responsible for producing validation decisions based on activity +//! data from DAC DataModel. It is expected to work on validators nodes only. +//! +//! - [`Config`] +//! - [`Call`] +//! - [`Pallet`] +//! - [`Hooks`] +//! +//! ## Responsibility +//! +//! 1. Assign validation tasks on DAC Validators in the beginning of each era, +//! 2. Spin the offchain worker which tries to execute the validation tasks each era, +//! 3. Fetch the data required for validation from DAC DataModel, +//! 4. Execute validation method on this data, +//! 5. Produce validation decision and submit it to the chain. +//! +//! ## Usage +//! +//! 1. Run the node with `--validator` flag, +//! 2. Setup validator key with `author_insertKey` RPC call. Use `dacv` validator key type and the +//! same private key as the one used to generate the validator's session keys, +//! 3. Proceed a regular validator setup, +//! 4. Tasks assignment will assign you a task in the beginning of the era which has your account in +//! validators set. +//! +//! ## Notes +//! +//! - Era definition in this pallet is different than in the `pallet-staking`. In this pallet era is +//! a period of time during which the validator is expected to produce a validation decision. +//! Means staking era and DAC era are different and are not related to each other, +//! - You can set DAC Validators quorum size by specifying `DdcValidatorsQuorumSize` parameter, + #![cfg_attr(not(feature = "std"), no_std)] pub use alloc::{format, string::String}; From 65ff73d2e90909f730d0f97da2dc0ab1828816e9 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Wed, 29 Mar 2023 22:51:19 +0200 Subject: [PATCH 066/544] Remove http request from tx --- src/lib.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6402d9f24..0be9e9454 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -430,22 +430,32 @@ pub mod pallet { #[pallet::weight(10000)] pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { + info!("[DAC Validator] processing proof_of_delivery"); let signer: T::AccountId = ensure_signed(origin)?; + info!("signer: {:?}", Self::account_to_string(signer.clone())); + let era = Self::get_current_era(); let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); - let (s, r) = Self::fetch_data1(era); + + info!("[DAC Validator] cdn_nodes_to_validate: {:?}", cdn_nodes_to_validate); + for cdn_node_id in cdn_nodes_to_validate { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); let decisions_for_cdn = >::get(era, cdn_node_id); - for decision in decisions_for_cdn.unwrap().iter_mut() { + for decision in decisions_for_cdn.clone().unwrap().iter_mut() { if decision.validator == signer { decision.decision = Some(val_res); decision.method = ValidationMethodKind::ProofOfDelivery; } } + + info!( + "[DAC Validator] decisions_for_cdn: {:?}", + decisions_for_cdn + ); } Ok(()) @@ -458,11 +468,6 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - info!( - "[DAC Validator] Validation data stored onchain: {:?}", - ValidationResults::::get() - ); - if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { return Ok(()) } @@ -475,8 +480,6 @@ pub mod pallet { Ok(signer) => signer, }; - info!("[DAC Validator] ValidationResults: {:?}", ValidationResults::::get()); - // Read data from DataModel and do dumb validation let current_era = Self::get_current_era() - 1; let (s, r) = Self::fetch_data1(current_era); @@ -484,9 +487,13 @@ pub mod pallet { let tx_res = signer.send_signed_transaction(|_acct| { Call::proof_of_delivery { s: s.clone(), r: r.clone() } }); + match &tx_res { - None | Some((_, Err(()))) => - return Err("Error while submitting proof of delivery TX"), + None => return Err("Error while submitting proof of delivery TX"), + Some((_, Err(e))) => { + info!("Error while submitting proof of delivery TX: {:?}", e); + return Err("Error while submitting proof of delivery TX"); + }, Some((_, Ok(()))) => {}, } @@ -620,6 +627,8 @@ pub mod pallet { fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; for (cdn_id, cdn_tasks) in >::iter_prefix(era) { + info!("[DAC Validator] tasks assigned to {:?}: {:?}", cdn_id, cdn_tasks); + for decision in cdn_tasks.iter() { if decision.validator == *validator { cdn_nodes.push(cdn_id); From 4f0495d0e3a9a6dc579f03d078ca8f6d6c1220ea Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 30 Mar 2023 14:51:59 +0600 Subject: [PATCH 067/544] Submit DAC Validation decision call --- src/lib.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0be9e9454..b456baf62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -323,10 +323,22 @@ pub mod pallet { pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + /// DAC Validator successfully published the validation decision. + ValidationDecisionSubmitted, + } #[pallet::error] - pub enum Error {} + pub enum Error { + /// Validation decision attempts to submit the result for the wrong era (not the current + /// one). + BadEra, + /// Can't submit the validation decision twice. + DecisionAlreadySubmitted, + /// Task does not exist for a given era, CDN participant, and DAC validator. + TaskNotFound, + } #[pallet::hooks] impl Hooks> for Pallet @@ -428,6 +440,40 @@ pub mod pallet { Ok(()) } + /// Set validation decision in tasks assignment. + /// + /// `origin` must be a DAC Validator assigned to the task. + /// `era` must be a current era, otherwise the decision will be rejected. + /// `subject` is a CDN participant stash. + /// + /// Emits `ValidationDecisionSubmitted` event. + #[pallet::weight(100_000)] + pub fn submit_validation_decision( + origin: OriginFor, + era: EraIndex, + subject: T::AccountId, + method: ValidationMethodKind, + decision: bool, + ) -> DispatchResult { + let account = ensure_signed(origin)?; + + ensure!(Self::get_current_era() == era, Error::::BadEra); + + Tasks::::try_mutate_exists(era, &subject, |maybe_tasks| { + let mut tasks = maybe_tasks.take().ok_or(Error::::TaskNotFound)?; + let mut task = tasks + .iter_mut() + .find(|task| task.validator == account && task.method == method) + .ok_or(Error::::TaskNotFound)?; + ensure!(task.decision.is_none(), Error::::DecisionAlreadySubmitted); + task.decision = Some(decision); + + Self::deposit_event(Event::ValidationDecisionSubmitted); + + Ok(()) + }) + } + #[pallet::weight(10000)] pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { info!("[DAC Validator] processing proof_of_delivery"); From 419abd0be976a4c8ecf6925d28afc69cadcd1b69 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 31 Mar 2023 17:16:21 +0600 Subject: [PATCH 068/544] Fix validation decision update --- src/lib.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b456baf62..1f10608c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -490,18 +490,17 @@ pub mod pallet { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - let decisions_for_cdn = >::get(era, cdn_node_id); - for decision in decisions_for_cdn.clone().unwrap().iter_mut() { - if decision.validator == signer { - decision.decision = Some(val_res); - decision.method = ValidationMethodKind::ProofOfDelivery; - } - } - - info!( - "[DAC Validator] decisions_for_cdn: {:?}", - decisions_for_cdn - ); + >::mutate(era, cdn_node_id, |decisions_for_cdn| { + let decisions = + decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); + let mut decision = decisions + .iter_mut() + .find(|decision| decision.validator == signer) + .expect("unexpected validators set in tasks assignment"); + decision.decision = Some(val_res); + }); + + info!("[DAC Validator] decisions_for_cdn: {:?}", >::get(era, cdn_node_id)); } Ok(()) From 1977ef70bbba64cff75b92fc806dc911f0c48e38 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 31 Mar 2023 17:33:09 +0600 Subject: [PATCH 069/544] Typo fix --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1f10608c9..71c81b97f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -490,7 +490,7 @@ pub mod pallet { let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - >::mutate(era, cdn_node_id, |decisions_for_cdn| { + >::mutate(era, &cdn_node_id, |decisions_for_cdn| { let decisions = decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); let mut decision = decisions From f4c46ea4b0237b0baf3a8c5f18b707a1464f0a44 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 10 Apr 2023 12:24:52 +0600 Subject: [PATCH 070/544] Integer type ValidationThreshold --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 71c81b97f..b1c65fe41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub use sp_std::prelude::*; extern crate alloc; parameter_types! { - pub const ValidationThreshold: f32 = 5.0; + pub const ValidationThreshold: u32 = 5; } /// The balance type of this pallet. @@ -665,7 +665,13 @@ pub mod pallet { fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); - return if percentage_difference > 0.0 && (ValidationThreshold::get() - percentage_difference) > 0.0 { true } else { false } + return if percentage_difference > 0.0 && + (ValidationThreshold::get() as f32 - percentage_difference) > 0.0 + { + true + } else { + false + } } /// Fetch the tasks related to current validator From 095718f199bb0f3004f8e17bccee1b959813bc66 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 10 Apr 2023 12:27:05 +0600 Subject: [PATCH 071/544] Autoformat DAC Validator files --- src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b1c65fe41..976a5131f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -400,7 +400,8 @@ pub mod pallet { } log::info!( "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", - pubkeys, pubkeys.first().unwrap() + pubkeys, + pubkeys.first().unwrap() ); let res = Self::offchain_worker_main(block_number); @@ -475,7 +476,11 @@ pub mod pallet { } #[pallet::weight(10000)] - pub fn proof_of_delivery(origin: OriginFor, s: Vec, r: Vec) -> DispatchResult { + pub fn proof_of_delivery( + origin: OriginFor, + s: Vec, + r: Vec, + ) -> DispatchResult { info!("[DAC Validator] processing proof_of_delivery"); let signer: T::AccountId = ensure_signed(origin)?; @@ -529,15 +534,16 @@ pub mod pallet { let current_era = Self::get_current_era() - 1; let (s, r) = Self::fetch_data1(current_era); - let tx_res = signer.send_signed_transaction(|_acct| { - Call::proof_of_delivery { s: s.clone(), r: r.clone() } + let tx_res = signer.send_signed_transaction(|_acct| Call::proof_of_delivery { + s: s.clone(), + r: r.clone(), }); match &tx_res { None => return Err("Error while submitting proof of delivery TX"), Some((_, Err(e))) => { info!("Error while submitting proof of delivery TX: {:?}", e); - return Err("Error while submitting proof of delivery TX"); + return Err("Error while submitting proof of delivery TX") }, Some((_, Ok(()))) => {}, } From 7244a13bf3a6764cd5cedd1f9296f920e0908571 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 10 Apr 2023 13:20:16 +0600 Subject: [PATCH 072/544] Set PoD allowed deviation in runtime crate --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 976a5131f..157d6fa0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,10 +66,6 @@ pub use sp_std::prelude::*; extern crate alloc; -parameter_types! { - pub const ValidationThreshold: u32 = 5; -} - /// The balance type of this pallet. type BalanceOf = <::Currency as Currency< ::AccountId, @@ -294,6 +290,13 @@ pub mod pallet { /// validators are getting the same task. Must be an odd number. #[pallet::constant] type DdcValidatorsQuorumSize: Get; + + /// Proof-of-Delivery parameter specifies an allowed deviation between bytes sent and bytes + /// received. The deviation is expressed as a percentage. For example, if the value is 10, + /// then the difference between bytes sent and bytes received is allowed to be up to 10%. + /// The value must be in range [0, 100]. + #[pallet::constant] + type ValidationThreshold: Get; } /// The map from the era and CDN participant stash key to the validation decisions related. @@ -672,7 +675,7 @@ pub mod pallet { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); return if percentage_difference > 0.0 && - (ValidationThreshold::get() as f32 - percentage_difference) > 0.0 + (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 { true } else { From fa83b3c275d3f7d0e20ec9697a209aebcd8ec06a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 14 Apr 2023 18:35:48 +0600 Subject: [PATCH 073/544] DAC Validators run a process by signal --- src/lib.rs | 183 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 130 insertions(+), 53 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 157d6fa0b..0ebd3f3f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,7 +81,8 @@ const TIME_START_MS: u128 = 1_672_531_200_000; const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; -const DATA_PROVIDER_URL: &str = "http://localhost:7379/"; +/// Webdis in experimental cluster connected to Redis in dev. +const DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379/"; /// DAC Validation methods. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] @@ -299,6 +300,11 @@ pub mod pallet { type ValidationThreshold: Get; } + /// A signal to start a process on all the validators. + #[pallet::storage] + #[pallet::getter(fn signal)] + pub(super) type Signal = StorageValue<_, bool>; + /// The map from the era and CDN participant stash key to the validation decisions related. #[pallet::storage] #[pallet::getter(fn tasks)] @@ -350,69 +356,108 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - if block_number <= 1u32.into() { - return 0 - } - - let era = Self::get_current_era(); - if let Some(last_managed_era) = >::get() { - if last_managed_era >= era { - return 0 - } + // Reset the signal in the beginning of the block to keep it reset until an incoming + // transaction sets it to true. + if Signal::::get().unwrap_or(false) { + Signal::::set(Some(false)); } - >::put(era); - let validators: Vec = >::iter_keys().collect(); - let validators_count = validators.len() as u32; - let edges: Vec = >::iter_keys().collect(); - log::info!( - "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, validators: {:?}, edges: {:?}", - block_number, - era, - >::get(), - validators_count, - validators, - edges, - ); - - // A naive approach assigns random validators for each edge. - for edge in edges { - let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = - Default::default(); - while !decisions.is_full() { - let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - let validator: T::AccountId = validators[validator_idx].clone(); - let assignment = Decision { - validator, - method: ValidationMethodKind::ProofOfDelivery, - decision: None, - }; - decisions.try_push(assignment).unwrap(); - } - Tasks::::insert(era, edge, decisions); - } + // Old task manager. + // + // if block_number <= 1u32.into() { + // return 0 + // } + + // let era = Self::get_current_era(); + // if let Some(last_managed_era) = >::get() { + // if last_managed_era >= era { + // return 0 + // } + // } + // >::put(era); + + // let validators: Vec = >::iter_keys().collect(); + // let validators_count = validators.len() as u32; + // let edges: Vec = + // >::iter_keys().collect(); log::info!( + // "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, + // validators: {:?}, edges: {:?}", block_number, + // era, + // >::get(), + // validators_count, + // validators, + // edges, + // ); + + // // A naive approach assigns random validators for each edge. + // for edge in edges { + // let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = + // Default::default(); + // while !decisions.is_full() { + // let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + // let validator: T::AccountId = validators[validator_idx].clone(); + // let assignment = Decision { + // validator, + // method: ValidationMethodKind::ProofOfDelivery, + // decision: None, + // }; + // decisions.try_push(assignment).unwrap(); + // } + // Tasks::::insert(era, edge, decisions); + // } 0 } + /// Offchain worker entry point. + /// + /// 1. Listen to a signal, + /// 2. Run a process at the same time, + /// 3. Read data from DAC. fn offchain_worker(block_number: T::BlockNumber) { - let pubkeys = sr25519_public_keys(KEY_TYPE); - if pubkeys.is_empty() { - log::info!("No local sr25519 accounts available to offchain worker."); + // Skip if not a validator. + if !sp_io::offchain::is_validator() { + return + } + + // Wait for signal. + let signal = Signal::::get().unwrap_or(false); + if !signal { + log::info!("🔎 DAC Validator is idle at block {:?}, waiting for a signal, signal state is {:?}", block_number, signal); return } + + // Read from DAC. + let current_era = Self::get_current_era(); + let (sent_query, sent, received_query, received) = Self::fetch_data2(current_era - 1); log::info!( - "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", - pubkeys, - pubkeys.first().unwrap() + "🔎 DAC Validator is fetching data from DAC, current era: {:?}, bytes sent query: {:?}, bytes sent response: {:?}, bytes received query: {:?}, bytes received response: {:?}", + current_era, + sent_query, + sent, + received_query, + received, ); - let res = Self::offchain_worker_main(block_number); - - match res { - Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), - Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), - }; + // Old off-chain worker. + // + // let pubkeys = sr25519_public_keys(KEY_TYPE); + // if pubkeys.is_empty() { + // log::info!("No local sr25519 accounts available to offchain worker."); + // return + // } + // log::info!( + // "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", + // pubkeys, + // pubkeys.first().unwrap() + // ); + + // let res = Self::offchain_worker_main(block_number); + + // match res { + // Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), + // Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), + // }; } } @@ -422,6 +467,25 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { + /// Run a process at the same time on all the validators. + #[pallet::weight(10_000)] + pub fn send_signal(origin: OriginFor) -> DispatchResult { + ensure_signed(origin)?; + + Signal::::set(Some(true)); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn reset_signal(origin: OriginFor) -> DispatchResult { + ensure_signed(origin)?; + + Signal::::set(Some(false)); + + Ok(()) + } + #[pallet::weight(10000)] pub fn save_validated_data( origin: OriginFor, @@ -626,6 +690,19 @@ pub mod pallet { (bytes_sent, bytes_received) } + fn fetch_data2(era: EraIndex) -> (String, Vec, String, Vec) { + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + let bytes_sent = BytesSent::get_all(bytes_sent_res); + + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = + Self::http_get_json(&bytes_received_query).unwrap(); + let bytes_received = BytesReceived::get_all(bytes_received_res); + + (bytes_sent_query, bytes_sent, bytes_received_query, bytes_received) + } + fn get_bytes_sent_query_url(era: EraIndex) -> String { format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) } @@ -649,7 +726,7 @@ pub mod pallet { } fn http_get_request(http_url: &str) -> Result, http::Error> { - info!("[DAC Validator] Sending request to: {:?}", http_url); + // info!("[DAC Validator] Sending request to: {:?}", http_url); // Initiate an external HTTP GET request. This is using high-level wrappers from // `sp_runtime`. From de1c21b36243fa39baa7d2b0c2b821a68304c682 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 15 Apr 2023 02:34:51 +0200 Subject: [PATCH 074/544] fix(ddc-validator): compilation error is fixed --- Cargo.toml | 3 ++ src/mock.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 203e032e1..eeaa05436 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } +frame-election-provider-support = { version = "4.0.0-dev", path = "../election-provider-support" } + log = { version = "0.4.17", default-features = false } pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } @@ -30,6 +32,7 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "frame-election-provider-support/std", "pallet-contracts/std", "pallet-ddc-staking/std", "pallet-session/std", diff --git a/src/mock.rs b/src/mock.rs index b40c3a1c0..76cde6fff 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -10,6 +10,22 @@ use sp_core::H256; use sp_runtime::{ curve::PiecewiseLinear, generic, testing::{Header, TestXt}, traits::{BlakeTwo256, IdentityLookup, Verify, Extrinsic as ExtrinsicT, IdentifyAccount}, Perbill, MultiSignature, curve}; use pallet_contracts as contracts; +use sp_runtime::traits::Convert; +use pallet_session::ShouldEndSession; +use sp_runtime::{ + impl_opaque_keys, + testing::{UintAuthorityId}, +}; +use sp_staking::SessionIndex; +use frame_support::{ + traits::{U128CurrencyToVote} +}; + +use frame_election_provider_support::{ + onchain, SequentialPhragmen +}; + + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; type Balance = u128; @@ -32,6 +48,7 @@ frame_support::construct_runtime!( Balances: pallet_balances, Contracts: contracts, Session: pallet_session, + Staking: pallet_staking, Timestamp: pallet_timestamp, RandomnessCollectiveFlip: pallet_randomness_collective_flip, DdcStaking: pallet_ddc_staking, @@ -90,13 +107,20 @@ use contracts::{Config as contractsConfig}; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +pub struct TestWeightToFee; +impl Convert for TestWeightToFee { + fn convert(weight: u64) -> u128 { + weight as u128 + } +} + impl contracts::Config for Test { type Time = Timestamp; type Randomness = RandomnessCollectiveFlip; type Currency = Balances; type Event = Event; type CallStack = [pallet_contracts::Frame; 31]; - type WeightPrice = Self; //pallet_transaction_payment::Module; + type WeightPrice = TestWeightToFee; //pallet_transaction_payment::Module; type WeightInfo = (); type ChainExtension = (); type DeletionQueueDepth = (); @@ -132,15 +156,34 @@ parameter_types! { pub const DdcValidatorsQuorumSize: u32 = 3; } +pub struct TestShouldEndSession; +impl ShouldEndSession for TestShouldEndSession { + fn should_end_session(now: u32) -> bool { + now % 10 == 0 // every 10 blocks + } +} + +impl_opaque_keys! { + pub struct MockSessionKeys { + pub dummy: UintAuthorityId, + } +} + +impl From for MockSessionKeys { + fn from(dummy: UintAuthorityId) -> Self { + Self { dummy } + } +} + impl pallet_session::Config for Test { - type Event = (); + type Event = Event; type ValidatorId = AccountId; type ValidatorIdOf = (); - type ShouldEndSession = (); + type ShouldEndSession = TestShouldEndSession; type NextSessionRotation = (); type SessionManager = (); - type SessionHandler = (); - type Keys = (); + type SessionHandler = pallet_session::TestSessionHandler; + type Keys = MockSessionKeys; type WeightInfo = (); } @@ -165,11 +208,24 @@ parameter_types! { pub OffchainRepeat: BlockNumber = 5; } + +pub struct OnChainSeqPhragmen; +impl onchain::ExecutionConfig for OnChainSeqPhragmen { + type System = Test; + type Solver = SequentialPhragmen; + type DataProvider = Staking; +} + +impl pallet_session::historical::Config for Test { + type FullIdentification = pallet_staking::Exposure; + type FullIdentificationOf = pallet_staking::ExposureOf; +} + impl pallet_staking::Config for Test { type MaxNominations = (); type Currency = Balances; type UnixTime = Timestamp; - type CurrencyToVote = (); + type CurrencyToVote = U128CurrencyToVote; type RewardRemainder = (); type Event = Event; type Slash = (); // send the slashed funds to the treasury. @@ -177,19 +233,18 @@ impl pallet_staking::Config for Test { type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; - /// A super-majority of the council can cancel the slash. - type SlashCancelOrigin = (); + type SlashCancelOrigin = frame_system::EnsureRoot; type SessionInterface = Self; type EraPayout = pallet_staking::ConvertCurve; type NextNewSession = Session; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; type OffendingValidatorsThreshold = OffendingValidatorsThreshold; - type ElectionProvider = (); - type GenesisElectionProvider = (); - type VoterList = (); + type ElectionProvider = onchain::UnboundedExecution; + type GenesisElectionProvider = Self::ElectionProvider; + type VoterList = pallet_staking::UseNominatorsAndValidatorsMap; type MaxUnlockingChunks = ConstU32<32>; type WeightInfo = pallet_staking::weights::SubstrateWeight; - type BenchmarkingConfig = (); + type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; } impl pallet_ddc_staking::Config for Test { From eb7da5928789a63813768ecd0098908185c46f97 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 17 Apr 2023 11:50:38 +0200 Subject: [PATCH 075/544] Fix MaxNominations config --- src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mock.rs b/src/mock.rs index 76cde6fff..d897eca04 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -222,7 +222,7 @@ impl pallet_session::historical::Config for Test { } impl pallet_staking::Config for Test { - type MaxNominations = (); + type MaxNominations = ConstU32<16>; type Currency = Balances; type UnixTime = Timestamp; type CurrencyToVote = U128CurrencyToVote; From dce39730b9df1c261f7bcfeb709bf07c3721c5eb Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 17 Apr 2023 11:55:47 +0200 Subject: [PATCH 076/544] Reorder imps block according to construct_runtime! --- src/mock.rs | 53 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/src/mock.rs b/src/mock.rs index d897eca04..2180867f8 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -9,7 +9,6 @@ use frame_system::offchain::SendTransactionTypes; use sp_core::H256; use sp_runtime::{ curve::PiecewiseLinear, generic, testing::{Header, TestXt}, traits::{BlakeTwo256, IdentityLookup, Verify, Extrinsic as ExtrinsicT, IdentifyAccount}, Perbill, MultiSignature, curve}; use pallet_contracts as contracts; - use sp_runtime::traits::Convert; use pallet_session::ShouldEndSession; use sp_runtime::{ @@ -20,24 +19,17 @@ use sp_staking::SessionIndex; use frame_support::{ traits::{U128CurrencyToVote} }; - use frame_election_provider_support::{ onchain, SequentialPhragmen }; - - type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; type Balance = u128; -// type AccountId = u64; - pub type Signature = MultiSignature; pub type AccountId = <::Signer as IdentifyAccount>::AccountId; -// pub type Balance = u128; pub type BlockNumber = u32; pub type Moment = u64; -// Configure a mock runtime to test the pallet. frame_support::construct_runtime!( pub enum Test where Block = Block, @@ -47,11 +39,11 @@ frame_support::construct_runtime!( System: frame_system, Balances: pallet_balances, Contracts: contracts, + Timestamp: pallet_timestamp, Session: pallet_session, Staking: pallet_staking, - Timestamp: pallet_timestamp, - RandomnessCollectiveFlip: pallet_randomness_collective_flip, DdcStaking: pallet_ddc_staking, + RandomnessCollectiveFlip: pallet_randomness_collective_flip, DdcValidator: pallet_ddc_validator, } ); @@ -187,6 +179,11 @@ impl pallet_session::Config for Test { type WeightInfo = (); } +impl pallet_session::historical::Config for Test { + type FullIdentification = pallet_staking::Exposure; + type FullIdentificationOf = pallet_staking::ExposureOf; +} + pallet_staking_reward_curve::build! { const REWARD_CURVE: PiecewiseLinear<'static> = curve!( min_inflation: 0_000_100, @@ -198,6 +195,13 @@ pallet_staking_reward_curve::build! { ); } +pub struct OnChainSeqPhragmen; +impl onchain::ExecutionConfig for OnChainSeqPhragmen { + type System = Test; + type Solver = SequentialPhragmen; + type DataProvider = Staking; +} + parameter_types! { pub const SessionsPerEra: sp_staking::SessionIndex = 6; pub const BondingDuration: sp_staking::EraIndex = 3; @@ -208,19 +212,6 @@ parameter_types! { pub OffchainRepeat: BlockNumber = 5; } - -pub struct OnChainSeqPhragmen; -impl onchain::ExecutionConfig for OnChainSeqPhragmen { - type System = Test; - type Solver = SequentialPhragmen; - type DataProvider = Staking; -} - -impl pallet_session::historical::Config for Test { - type FullIdentification = pallet_staking::Exposure; - type FullIdentificationOf = pallet_staking::ExposureOf; -} - impl pallet_staking::Config for Test { type MaxNominations = ConstU32<16>; type Currency = Balances; @@ -300,22 +291,6 @@ impl SigningTypes for Test { type Signature = Signature; } -// impl frame_system::offchain::SendTransactionTypes for Test -// where -// Call: From, -// { -// type OverarchingCall = Call; -// type Extrinsic = TestXt; -// } - -// impl SendTransactionTypes for Test -// where -// Call: From, -// { -// type OverarchingCall = Call; -// type Extrinsic = Extrinsic; -// } - impl CreateSignedTransaction for Test where Call: From, From 2835f5695e26edf4672ab83f2b9b70f10e8669ff Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 17 Apr 2023 12:41:49 +0200 Subject: [PATCH 077/544] Fix compilation errors after merge --- src/mock.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mock.rs b/src/mock.rs index 2180867f8..5e4ada7f3 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -144,10 +144,6 @@ impl pallet_timestamp::Config for Test { impl pallet_randomness_collective_flip::Config for Test {} -parameter_types! { - pub const DdcValidatorsQuorumSize: u32 = 3; -} - pub struct TestShouldEndSession; impl ShouldEndSession for TestShouldEndSession { fn should_end_session(now: u32) -> bool { @@ -196,10 +192,12 @@ pallet_staking_reward_curve::build! { } pub struct OnChainSeqPhragmen; -impl onchain::ExecutionConfig for OnChainSeqPhragmen { +impl onchain::Config for OnChainSeqPhragmen { type System = Test; type Solver = SequentialPhragmen; type DataProvider = Staking; + type WeightInfo = frame_election_provider_support::weights::SubstrateWeight; + } parameter_types! { @@ -236,6 +234,8 @@ impl pallet_staking::Config for Test { type MaxUnlockingChunks = ConstU32<32>; type WeightInfo = pallet_staking::weights::SubstrateWeight; type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; + type CurrencyBalance = Balance; + type OnStakerSlash = (); } impl pallet_ddc_staking::Config for Test { @@ -245,6 +245,11 @@ impl pallet_ddc_staking::Config for Test { type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } +parameter_types! { + pub const DdcValidatorsQuorumSize: u32 = 3; + pub const ValidationThreshold: u32 = 5; +} + impl pallet_ddc_validator::Config for Test { type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; type Event = Event; @@ -252,6 +257,7 @@ impl pallet_ddc_validator::Config for Test { type Call = Call; type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; type TimeProvider = pallet_timestamp::Pallet; + type ValidationThreshold = ValidationThreshold; } impl SendTransactionTypes for Test From 4c0817a3e79f4faa22af9de235a06e6b8d93fd0a Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 17 Apr 2023 14:58:29 +0200 Subject: [PATCH 078/544] Add unit test example --- src/tests.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index e69de29bb..cc0df5512 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -0,0 +1,15 @@ +use crate::{mock::*}; +use frame_support::{assert_ok}; +use sp_core::crypto::AccountId32; + +#[test] +fn save_validated_data_works() { + new_test_ext().execute_with(|| { + assert_ok!(DdcValidator::save_validated_data( + Origin::signed(AccountId32::from([1; 32])), + true, + String::from("0xab1"), + 1, + )); + }); +} \ No newline at end of file From b4c5a68748aea5acba87b31eef1740bc7c1e7852 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 18 Apr 2023 10:30:22 +0200 Subject: [PATCH 079/544] Fix build --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index eeaa05436..2c9fe6bc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } -frame-election-provider-support = { version = "4.0.0-dev", path = "../election-provider-support" } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" } log = { version = "0.4.17", default-features = false } pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } From d7da3133b3b08270c60fdc7a95b662c1b35edb1b Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Wed, 19 Apr 2023 11:46:03 +0200 Subject: [PATCH 080/544] Make data provider url configurable via rpc --- src/lib.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fef99bd08..2d565566c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,7 @@ pub use frame_support::{ traits::{Currency, Randomness, UnixTime}, weights::Weight, BoundedVec, RuntimeDebug, + storage, }; pub use frame_system::{ ensure_signed, @@ -66,7 +67,7 @@ pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; pub use sp_io::crypto::sr25519_public_keys; -pub use sp_runtime::offchain::{http, Duration, Timestamp}; +pub use sp_runtime::offchain::{http, Duration, Timestamp, storage::StorageValueRef}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; @@ -92,7 +93,9 @@ const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; /// Webdis in experimental cluster connected to Redis in dev. -const DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379/"; +// const DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379/"; +const DEFAULT_DATA_PROVIDER_URL: &str = "localhost:7379/"; +const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; /// DAC Validation methods. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] @@ -425,6 +428,10 @@ pub mod pallet { /// 2. Run a process at the same time, /// 3. Read data from DAC. fn offchain_worker(block_number: T::BlockNumber) { + let data_provider_url = Self::get_data_provider_url(); + + info!("data_provider_url: {:?}", data_provider_url.unwrap_or(String::from("no url"))); + // Skip if not a validator. if !sp_io::offchain::is_validator() { return @@ -628,6 +635,26 @@ pub mod pallet { Ok(()) } + fn get_data_provider_url() -> Option { + let url_ref = StorageValueRef::persistent(DATA_PROVIDER_URL_KEY).get::>(); + info!("url_ref: {:?}", url_ref); + match url_ref { + Ok(None) => { + let url_key = String::from_utf8(DATA_PROVIDER_URL_KEY.to_vec()).unwrap(); + let msg = format!("[DAC Validator] Data provider URL is not configured. Please configure it using offchain_localStorageSet with key {:?}", url_key); + warn!("{}", msg); + None + } + Ok(Some(url)) => { + Some(String::from_utf8(url).unwrap()) + }, + Err(_) => { + error!("[OCW] Data provider URL is configured but the value could not be decoded"); + None + } + } + } + fn get_signer() -> ResultStr> { let signer = Signer::<_, _>::any_account(); if !signer.can_sign() { @@ -714,11 +741,29 @@ pub mod pallet { } fn get_bytes_sent_query_url(era: EraIndex) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DATA_PROVIDER_URL, era, era) + let data_provider_url = Self::get_data_provider_url(); + + match data_provider_url { + Some(url) => { + return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); + } + None => { + return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); + } + } } fn get_bytes_received_query_url(era: EraIndex) -> String { - format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DATA_PROVIDER_URL, era, era) + let data_provider_url = Self::get_data_provider_url(); + + match data_provider_url { + Some(url) => { + return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); + } + None => { + return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); + } + } } fn http_get_json(url: &str) -> ResultStr { From c7f928b3cae46087ee4c589ac987d6ef7f3ea71e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 19 Apr 2023 20:24:41 +0600 Subject: [PATCH 081/544] Fix local storage reading --- src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2d565566c..4d4d88f32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -636,22 +636,19 @@ pub mod pallet { } fn get_data_provider_url() -> Option { - let url_ref = StorageValueRef::persistent(DATA_PROVIDER_URL_KEY).get::>(); + let url_ref = sp_io::offchain::local_storage_get( + sp_core::offchain::StorageKind::PERSISTENT, + DATA_PROVIDER_URL_KEY, + ); info!("url_ref: {:?}", url_ref); match url_ref { - Ok(None) => { + None => { let url_key = String::from_utf8(DATA_PROVIDER_URL_KEY.to_vec()).unwrap(); let msg = format!("[DAC Validator] Data provider URL is not configured. Please configure it using offchain_localStorageSet with key {:?}", url_key); warn!("{}", msg); None - } - Ok(Some(url)) => { - Some(String::from_utf8(url).unwrap()) }, - Err(_) => { - error!("[OCW] Data provider URL is configured but the value could not be decoded"); - None - } + Some(url) => Some(String::from_utf8(url).unwrap()), } } From a4a9f8cb88673a4373dbf12fa876ab06293b050b Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Wed, 19 Apr 2023 16:53:00 +0200 Subject: [PATCH 082/544] Clean up --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4d4d88f32..ec2769b01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,7 +93,6 @@ const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; /// Webdis in experimental cluster connected to Redis in dev. -// const DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379/"; const DEFAULT_DATA_PROVIDER_URL: &str = "localhost:7379/"; const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; @@ -640,7 +639,7 @@ pub mod pallet { sp_core::offchain::StorageKind::PERSISTENT, DATA_PROVIDER_URL_KEY, ); - info!("url_ref: {:?}", url_ref); + match url_ref { None => { let url_key = String::from_utf8(DATA_PROVIDER_URL_KEY.to_vec()).unwrap(); From a9f264aee0596a011b1a647bf8eff48d5318fe69 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 20 Apr 2023 13:00:01 +0600 Subject: [PATCH 083/544] Remove duplicate parameter --- src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ec2769b01..f1c58a4ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,10 +73,6 @@ pub use sp_std::prelude::*; extern crate alloc; -parameter_types! { - pub const ValidationThreshold: f32 = 5.0; -} - /// The balance type of this pallet. type BalanceOf = <::Currency as Currency< ::AccountId, From bae3c9e706aba2ccc8648287e122a03aa9b56b05 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 20 Apr 2023 13:10:24 +0600 Subject: [PATCH 084/544] Autoformat DAC Validator files --- src/lib.rs | 13 +- src/mock.rs | 340 +++++++++++++++++++++++++-------------------------- src/tests.rs | 22 ++-- 3 files changed, 186 insertions(+), 189 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1c58a4ba..f64bc4ae0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,11 +49,10 @@ pub use frame_support::{ dispatch::DispatchResult, log::{error, info, warn}, pallet_prelude::*, - parameter_types, + parameter_types, storage, traits::{Currency, Randomness, UnixTime}, weights::Weight, BoundedVec, RuntimeDebug, - storage, }; pub use frame_system::{ ensure_signed, @@ -67,7 +66,7 @@ pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; pub use sp_io::crypto::sr25519_public_keys; -pub use sp_runtime::offchain::{http, Duration, Timestamp, storage::StorageValueRef}; +pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; @@ -738,10 +737,10 @@ pub mod pallet { match data_provider_url { Some(url) => { return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); - } + }, None => { return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); - } + }, } } @@ -751,10 +750,10 @@ pub mod pallet { match data_provider_url { Some(url) => { return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); - } + }, None => { return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); - } + }, } } diff --git a/src/mock.rs b/src/mock.rs index 5e4ada7f3..bc057705c 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -1,27 +1,25 @@ -use crate::{*, self as pallet_ddc_validator}; +use crate::{self as pallet_ddc_validator, *}; +use frame_election_provider_support::{onchain, SequentialPhragmen}; use frame_support::{ - parameter_types, - weights::Weight, - traits::{ConstU16, ConstU64, Currency, Everything, Nothing} + parameter_types, + traits::{ConstU16, ConstU64, Currency, Everything, Nothing, U128CurrencyToVote}, + weights::Weight, }; -use frame_system::EnsureRoot; -use frame_system::offchain::SendTransactionTypes; -use sp_core::H256; -use sp_runtime::{ curve::PiecewiseLinear, generic, testing::{Header, TestXt}, traits::{BlakeTwo256, IdentityLookup, Verify, Extrinsic as ExtrinsicT, IdentifyAccount}, Perbill, MultiSignature, curve}; +use frame_system::{offchain::SendTransactionTypes, EnsureRoot}; use pallet_contracts as contracts; -use sp_runtime::traits::Convert; use pallet_session::ShouldEndSession; +use sp_core::H256; use sp_runtime::{ - impl_opaque_keys, - testing::{UintAuthorityId}, + curve, + curve::PiecewiseLinear, + generic, impl_opaque_keys, + testing::{Header, TestXt, UintAuthorityId}, + traits::{ + BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, + }, + MultiSignature, Perbill, }; use sp_staking::SessionIndex; -use frame_support::{ - traits::{U128CurrencyToVote} -}; -use frame_election_provider_support::{ - onchain, SequentialPhragmen -}; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; type Balance = u128; @@ -38,117 +36,118 @@ frame_support::construct_runtime!( { System: frame_system, Balances: pallet_balances, - Contracts: contracts, - Timestamp: pallet_timestamp, - Session: pallet_session, - Staking: pallet_staking, - DdcStaking: pallet_ddc_staking, - RandomnessCollectiveFlip: pallet_randomness_collective_flip, - DdcValidator: pallet_ddc_validator, + Contracts: contracts, + Timestamp: pallet_timestamp, + Session: pallet_session, + Staking: pallet_staking, + DdcStaking: pallet_ddc_staking, + RandomnessCollectiveFlip: pallet_randomness_collective_flip, + DdcValidator: pallet_ddc_validator, } ); parameter_types! { - pub const BlockHashCount: BlockNumber = 250; - pub const MaximumBlockWeight: Weight = 1024; - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); + pub const BlockHashCount: BlockNumber = 250; + pub const MaximumBlockWeight: Weight = 1024; + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::one(); } impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type Origin = Origin; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Call = Call; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - // u64; // sp_core::sr25519::Public; - type Lookup = IdentityLookup; - type Header = generic::Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type Origin = Origin; + type Index = u64; + type BlockNumber = BlockNumber; + type Hash = H256; + type Call = Call; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + // u64; // sp_core::sr25519::Public; + type Lookup = IdentityLookup; + type Header = generic::Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { - pub const SignedClaimHandicap: BlockNumber = 2; - pub const TombstoneDeposit: Balance = 16; - pub const StorageSizeOffset: u32 = 8; - pub const RentByteFee: Balance = 4; - pub const RentDepositOffset: Balance = 10_000; - pub const SurchargeReward: Balance = 150; - pub const MaxDepth: u32 = 100; - pub const MaxValueSize: u32 = 16_384; - pub Schedule: pallet_contracts::Schedule = Default::default(); + pub const SignedClaimHandicap: BlockNumber = 2; + pub const TombstoneDeposit: Balance = 16; + pub const StorageSizeOffset: u32 = 8; + pub const RentByteFee: Balance = 4; + pub const RentDepositOffset: Balance = 10_000; + pub const SurchargeReward: Balance = 150; + pub const MaxDepth: u32 = 100; + pub const MaxValueSize: u32 = 16_384; + pub Schedule: pallet_contracts::Schedule = Default::default(); } -use contracts::{Config as contractsConfig}; +use contracts::Config as contractsConfig; -type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; pub struct TestWeightToFee; impl Convert for TestWeightToFee { - fn convert(weight: u64) -> u128 { - weight as u128 - } + fn convert(weight: u64) -> u128 { + weight as u128 + } } impl contracts::Config for Test { - type Time = Timestamp; - type Randomness = RandomnessCollectiveFlip; - type Currency = Balances; - type Event = Event; - type CallStack = [pallet_contracts::Frame; 31]; - type WeightPrice = TestWeightToFee; //pallet_transaction_payment::Module; - type WeightInfo = (); - type ChainExtension = (); - type DeletionQueueDepth = (); - type DeletionWeightLimit = (); - type Schedule = Schedule; - type Call = Call; - type CallFilter = Nothing; - type DepositPerByte = DepositPerByte; - type DepositPerItem = DepositPerItem; - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; + type Time = Timestamp; + type Randomness = RandomnessCollectiveFlip; + type Currency = Balances; + type Event = Event; + type CallStack = [pallet_contracts::Frame; 31]; + type WeightPrice = TestWeightToFee; //pallet_transaction_payment::Module; + type WeightInfo = (); + type ChainExtension = (); + type DeletionQueueDepth = (); + type DeletionWeightLimit = (); + type Schedule = Schedule; + type Call = Call; + type CallFilter = Nothing; + type DepositPerByte = DepositPerByte; + type DepositPerItem = DepositPerItem; + type AddressGenerator = pallet_contracts::DefaultAddressGenerator; } parameter_types! { - pub const TransactionByteFee: u64 = 0; - pub const DepositPerItem: Balance = 0; + pub const TransactionByteFee: u64 = 0; + pub const DepositPerItem: Balance = 0; pub const DepositPerByte: Balance = 0; } parameter_types! { - pub const MinimumPeriod: u64 = 1; + pub const MinimumPeriod: u64 = 1; } impl pallet_timestamp::Config for Test { - type Moment = Moment; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); } impl pallet_randomness_collective_flip::Config for Test {} pub struct TestShouldEndSession; impl ShouldEndSession for TestShouldEndSession { - fn should_end_session(now: u32) -> bool { - now % 10 == 0 // every 10 blocks - } + fn should_end_session(now: u32) -> bool { + now % 10 == 0 // every 10 blocks + } } impl_opaque_keys! { @@ -164,15 +163,15 @@ impl From for MockSessionKeys { } impl pallet_session::Config for Test { - type Event = Event; - type ValidatorId = AccountId; - type ValidatorIdOf = (); - type ShouldEndSession = TestShouldEndSession; - type NextSessionRotation = (); - type SessionManager = (); - type SessionHandler = pallet_session::TestSessionHandler; - type Keys = MockSessionKeys; - type WeightInfo = (); + type Event = Event; + type ValidatorId = AccountId; + type ValidatorIdOf = (); + type ShouldEndSession = TestShouldEndSession; + type NextSessionRotation = (); + type SessionManager = (); + type SessionHandler = pallet_session::TestSessionHandler; + type Keys = MockSessionKeys; + type WeightInfo = (); } impl pallet_session::historical::Config for Test { @@ -193,11 +192,10 @@ pallet_staking_reward_curve::build! { pub struct OnChainSeqPhragmen; impl onchain::Config for OnChainSeqPhragmen { - type System = Test; - type Solver = SequentialPhragmen; - type DataProvider = Staking; - type WeightInfo = frame_election_provider_support::weights::SubstrateWeight; - + type System = Test; + type Solver = SequentialPhragmen; + type DataProvider = Staking; + type WeightInfo = frame_election_provider_support::weights::SubstrateWeight; } parameter_types! { @@ -211,61 +209,61 @@ parameter_types! { } impl pallet_staking::Config for Test { - type MaxNominations = ConstU32<16>; - type Currency = Balances; - type UnixTime = Timestamp; - type CurrencyToVote = U128CurrencyToVote; - type RewardRemainder = (); - type Event = Event; - type Slash = (); // send the slashed funds to the treasury. - type Reward = (); // rewards are minted from the void - type SessionsPerEra = SessionsPerEra; - type BondingDuration = BondingDuration; - type SlashDeferDuration = SlashDeferDuration; - type SlashCancelOrigin = frame_system::EnsureRoot; - type SessionInterface = Self; - type EraPayout = pallet_staking::ConvertCurve; - type NextNewSession = Session; - type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; - type OffendingValidatorsThreshold = OffendingValidatorsThreshold; - type ElectionProvider = onchain::UnboundedExecution; - type GenesisElectionProvider = Self::ElectionProvider; - type VoterList = pallet_staking::UseNominatorsAndValidatorsMap; - type MaxUnlockingChunks = ConstU32<32>; - type WeightInfo = pallet_staking::weights::SubstrateWeight; - type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; - type CurrencyBalance = Balance; - type OnStakerSlash = (); + type MaxNominations = ConstU32<16>; + type Currency = Balances; + type UnixTime = Timestamp; + type CurrencyToVote = U128CurrencyToVote; + type RewardRemainder = (); + type Event = Event; + type Slash = (); // send the slashed funds to the treasury. + type Reward = (); // rewards are minted from the void + type SessionsPerEra = SessionsPerEra; + type BondingDuration = BondingDuration; + type SlashDeferDuration = SlashDeferDuration; + type SlashCancelOrigin = frame_system::EnsureRoot; + type SessionInterface = Self; + type EraPayout = pallet_staking::ConvertCurve; + type NextNewSession = Session; + type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; + type OffendingValidatorsThreshold = OffendingValidatorsThreshold; + type ElectionProvider = onchain::UnboundedExecution; + type GenesisElectionProvider = Self::ElectionProvider; + type VoterList = pallet_staking::UseNominatorsAndValidatorsMap; + type MaxUnlockingChunks = ConstU32<32>; + type WeightInfo = pallet_staking::weights::SubstrateWeight; + type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; + type CurrencyBalance = Balance; + type OnStakerSlash = (); } impl pallet_ddc_staking::Config for Test { - type BondingDuration = BondingDuration; - type Currency = Balances; - type Event = Event; - type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; + type BondingDuration = BondingDuration; + type Currency = Balances; + type Event = Event; + type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } parameter_types! { pub const DdcValidatorsQuorumSize: u32 = 3; - pub const ValidationThreshold: u32 = 5; + pub const ValidationThreshold: u32 = 5; } impl pallet_ddc_validator::Config for Test { - type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; - type Event = Event; - type Randomness = RandomnessCollectiveFlip; - type Call = Call; - type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; - type TimeProvider = pallet_timestamp::Pallet; - type ValidationThreshold = ValidationThreshold; + type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; + type Event = Event; + type Randomness = RandomnessCollectiveFlip; + type Call = Call; + type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; + type TimeProvider = pallet_timestamp::Pallet; + type ValidationThreshold = ValidationThreshold; } impl SendTransactionTypes for Test - where - Call: From, +where + Call: From, { - type OverarchingCall = Call; - type Extrinsic = Extrinsic; + type OverarchingCall = Call; + type Extrinsic = Extrinsic; } parameter_types! { @@ -274,39 +272,39 @@ parameter_types! { } impl pallet_balances::Config for Test { - type Balance = Balance; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = (); + type Balance = Balance; + type DustRemoval = (); + type Event = Event; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = (); } // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::default().build_storage::().unwrap().into() + frame_system::GenesisConfig::default().build_storage::().unwrap().into() } pub type Extrinsic = TestXt; impl SigningTypes for Test { - type Public = ::Signer; - type Signature = Signature; + type Public = ::Signer; + type Signature = Signature; } impl CreateSignedTransaction for Test - where - Call: From, +where + Call: From, { - fn create_transaction>( - call: Call, - _public: ::Signer, - _account: AccountId, - nonce: u64, - ) -> Option<(Call, ::SignaturePayload)> { - Some((call, (nonce, ()))) - } -} \ No newline at end of file + fn create_transaction>( + call: Call, + _public: ::Signer, + _account: AccountId, + nonce: u64, + ) -> Option<(Call, ::SignaturePayload)> { + Some((call, (nonce, ()))) + } +} diff --git a/src/tests.rs b/src/tests.rs index cc0df5512..2baeb76c0 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,15 +1,15 @@ -use crate::{mock::*}; -use frame_support::{assert_ok}; +use crate::mock::*; +use frame_support::assert_ok; use sp_core::crypto::AccountId32; #[test] fn save_validated_data_works() { - new_test_ext().execute_with(|| { - assert_ok!(DdcValidator::save_validated_data( - Origin::signed(AccountId32::from([1; 32])), - true, - String::from("0xab1"), - 1, - )); - }); -} \ No newline at end of file + new_test_ext().execute_with(|| { + assert_ok!(DdcValidator::save_validated_data( + Origin::signed(AccountId32::from([1; 32])), + true, + String::from("0xab1"), + 1, + )); + }); +} From 201db368de4ab02388f6ed62b9f042abff471390 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 20 Apr 2023 14:13:45 +0600 Subject: [PATCH 085/544] Separate modules for validation and DAC client --- src/dac.rs | 1 + src/lib.rs | 3 +++ src/validation.rs | 1 + 3 files changed, 5 insertions(+) create mode 100644 src/dac.rs create mode 100644 src/validation.rs diff --git a/src/dac.rs b/src/dac.rs new file mode 100644 index 000000000..b24eb0cc5 --- /dev/null +++ b/src/dac.rs @@ -0,0 +1 @@ +//! A module with Data Activity Capture (DAC) interaction. diff --git a/src/lib.rs b/src/lib.rs index f64bc4ae0..fec14bdb0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,9 @@ #![cfg_attr(not(feature = "std"), no_std)] +mod dac; +mod validation; + #[cfg(test)] mod mock; diff --git a/src/validation.rs b/src/validation.rs new file mode 100644 index 000000000..017d90782 --- /dev/null +++ b/src/validation.rs @@ -0,0 +1 @@ +//! DAC Validation implementation. From 553f375e59eee95d34dbda6d2801c3ac49fe8e2d Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 20 Apr 2023 16:04:01 +0200 Subject: [PATCH 086/544] Implement job assignment --- Cargo.toml | 2 +- src/lib.rs | 110 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 84 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c9fe6bc2..26477e7c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" } - log = { version = "0.4.17", default-features = false } pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } @@ -25,6 +24,7 @@ sp-keystore = { version = "0.12.0", default-features = false, path = "../../prim sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } +rand = { version = "0.8", default-features = false } [features] default = ["std"] diff --git a/src/lib.rs b/src/lib.rs index ec2769b01..3d58f37d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ mod mock; #[cfg(test)] mod tests; +use std::collections::{HashMap}; pub use alloc::{format, string::String}; pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; @@ -70,6 +71,7 @@ pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, Duration, Timestamp, storage::StorageValueRef}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; +use rand::seq::SliceRandom; extern crate alloc; @@ -304,6 +306,8 @@ pub mod pallet { #[pallet::constant] type DdcValidatorsQuorumSize: Get; + type ValidatorsMax: Get; + /// Proof-of-Delivery parameter specifies an allowed deviation between bytes sent and bytes /// received. The deviation is expressed as a percentage. For example, if the value is 10, /// then the difference between bytes sent and bytes received is allowed to be up to 10%. @@ -312,6 +316,17 @@ pub mod pallet { type ValidationThreshold: Get; } + #[pallet::storage] + #[pallet::getter(fn assignments)] + pub(super) type Assignments = StorageDoubleMap< + _, + Twox64Concat, + EraIndex, + Twox64Concat, + String, + Vec, + >; + /// A signal to start a process on all the validators. #[pallet::storage] #[pallet::getter(fn signal)] @@ -370,36 +385,23 @@ pub mod pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { // Reset the signal in the beginning of the block to keep it reset until an incoming // transaction sets it to true. - if Signal::::get().unwrap_or(false) { - Signal::::set(Some(false)); - } + // if Signal::::get().unwrap_or(false) { + // Signal::::set(Some(false)); + // } // Old task manager. - // - // if block_number <= 1u32.into() { - // return 0 - // } - // let era = Self::get_current_era(); - // if let Some(last_managed_era) = >::get() { - // if last_managed_era >= era { - // return 0 - // } - // } - // >::put(era); - - // let validators: Vec = >::iter_keys().collect(); - // let validators_count = validators.len() as u32; - // let edges: Vec = - // >::iter_keys().collect(); log::info!( - // "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, - // validators: {:?}, edges: {:?}", block_number, - // era, - // >::get(), - // validators_count, - // validators, - // edges, - // ); + if block_number <= 1u32.into() { + return 0 + } + + let era = Self::get_current_era(); + if let Some(last_managed_era) = >::get() { + if last_managed_era >= era { + return 0 + } + } + >::put(era); // // A naive approach assigns random validators for each edge. // for edge in edges { @@ -811,6 +813,60 @@ pub mod pallet { } } + fn shuffle(mut list: Vec) -> Vec { + list.shuffle(&mut rand::thread_rng()); + + list + } + + fn split(list: Vec, segment_len: usize) -> Vec> { + list.chunks(segment_len).map(|chunk| chunk.to_vec()).collect() + } + + fn assign(quorum_size: usize) -> HashMap> { + let validators: Vec = >::iter_keys().collect(); + let edges: Vec = >::iter_keys().collect(); + + let shuffled_validators = Self::shuffle(validators); + let shuffled_edges = Self::shuffle(edges); + + let validators_keys: Vec = shuffled_validators.iter().map( |v| { + Self::account_to_string(v.clone()) + }).collect(); + + let edges_keys: Vec = shuffled_edges.iter().map( |e| { + Self::account_to_string(e.clone()) + }).collect(); + + let quorums = Self::split(validators_keys, quorum_size); + let edges_groups = Self::split(edges_keys, quorums.len()); + + Self::map_validators_to_edges(quorums, edges_groups) + } + + fn map_validators_to_edges(quorums: Vec>, edges_groups: Vec>) -> HashMap> { + let mut validators_to_edges: HashMap> = HashMap::new(); + + for (i, quorum) in quorums.iter().enumerate() { + let edges_group = &edges_groups[i]; + for validator in quorum { + validators_to_edges.insert(validator.clone(), edges_group.clone()); + } + } + + validators_to_edges + } + + fn save_assignments(era: EraIndex, assignments: HashMap>) -> DispatchResult { + let era = Self::get_current_era(); + + for (validator, edges) in assignments { + Assignments::::insert(era, validator, edges); + } + + Ok(()) + } + /// Fetch the tasks related to current validator fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { let mut cdn_nodes: Vec = vec![]; From 72c0c283be7523421b36b55a2b7aae1ba68d7a71 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 20 Apr 2023 18:57:39 +0200 Subject: [PATCH 087/544] Compilation fixes --- Cargo.toml | 1 - src/lib.rs | 39 +++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 26477e7c6..ff6dbd53b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ sp-keystore = { version = "0.12.0", default-features = false, path = "../../prim sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } -rand = { version = "0.8", default-features = false } [features] default = ["std"] diff --git a/src/lib.rs b/src/lib.rs index 3d58f37d1..050aa7267 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,6 @@ mod mock; #[cfg(test)] mod tests; -use std::collections::{HashMap}; pub use alloc::{format, string::String}; pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; @@ -71,7 +70,6 @@ pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, Duration, Timestamp, storage::StorageValueRef}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; -use rand::seq::SliceRandom; extern crate alloc; @@ -396,13 +394,18 @@ pub mod pallet { } let era = Self::get_current_era(); + info!("current era: {:?}", era); + if let Some(last_managed_era) = >::get() { + info!("last_managed_era: {:?}", last_managed_era); if last_managed_era >= era { return 0 } } >::put(era); + Self::assign(3usize); + // // A naive approach assigns random validators for each edge. // for edge in edges { // let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = @@ -814,7 +817,11 @@ pub mod pallet { } fn shuffle(mut list: Vec) -> Vec { - list.shuffle(&mut rand::thread_rng()); + let len = list.len(); + for i in 1..len { + let random_index = Self::choose(len as u32).unwrap() as usize; + list.swap(i, random_index) + } list } @@ -823,10 +830,14 @@ pub mod pallet { list.chunks(segment_len).map(|chunk| chunk.to_vec()).collect() } - fn assign(quorum_size: usize) -> HashMap> { + fn assign(quorum_size: usize) { let validators: Vec = >::iter_keys().collect(); let edges: Vec = >::iter_keys().collect(); + if edges.len() == 0 { + return; + } + let shuffled_validators = Self::shuffle(validators); let shuffled_edges = Self::shuffle(edges); @@ -841,30 +852,14 @@ pub mod pallet { let quorums = Self::split(validators_keys, quorum_size); let edges_groups = Self::split(edges_keys, quorums.len()); - Self::map_validators_to_edges(quorums, edges_groups) - } - - fn map_validators_to_edges(quorums: Vec>, edges_groups: Vec>) -> HashMap> { - let mut validators_to_edges: HashMap> = HashMap::new(); + let era = Self::get_current_era(); for (i, quorum) in quorums.iter().enumerate() { let edges_group = &edges_groups[i]; for validator in quorum { - validators_to_edges.insert(validator.clone(), edges_group.clone()); + Assignments::::insert(era, validator, edges_group); } } - - validators_to_edges - } - - fn save_assignments(era: EraIndex, assignments: HashMap>) -> DispatchResult { - let era = Self::get_current_era(); - - for (validator, edges) in assignments { - Assignments::::insert(era, validator, edges); - } - - Ok(()) } /// Fetch the tasks related to current validator From 8eca54ec7711b2e7861f6715a70bba6f91cf5d6f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Apr 2023 13:30:15 +0600 Subject: [PATCH 088/544] Validation results with aggregates from DAC --- src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fec14bdb0..b8b296e7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,30 @@ const ERA_IN_BLOCKS: u8 = 20; const DEFAULT_DATA_PROVIDER_URL: &str = "localhost:7379/"; const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; +/// Aggregated values from DAC that describe CDN node's activity during a certain era. +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct DacTotalAggregates { + /// Total bytes received by the client. + pub received: u64, + /// Total bytes sent by the CDN node. + pub sent: u64, + /// Total bytes sent by the CDN node to the client which interrupts the connection. + pub failed_by_client: u64, + /// ToDo: explain. + pub failure_rate: u64, +} + +/// Final DAC Validation decision. +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct ValidationDecision { + /// Validation result. + pub result: bool, + /// A hash of the data used to produce validation result. + pub payload: [u8; 256], + /// Values aggregated from the payload. + pub totals: DacTotalAggregates, +} + /// DAC Validation methods. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum ValidationMethodKind { @@ -315,6 +339,12 @@ pub mod pallet { #[pallet::getter(fn signal)] pub(super) type Signal = StorageValue<_, bool>; + /// The map from the era and CDN participant stash key to the validation decision related. + #[pallet::storage] + #[pallet::getter(fn validation_decisions)] + pub type ValidationDecisions = + StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; + /// The map from the era and CDN participant stash key to the validation decisions related. #[pallet::storage] #[pallet::getter(fn tasks)] @@ -591,6 +621,28 @@ pub mod pallet { Ok(()) } + + /// Set validation decision for a given CDN node in an era. + #[pallet::weight(10_000)] + pub fn set_validation_decision( + origin: OriginFor, + era: EraIndex, + cdn_node: T::AccountId, + validation_decision: ValidationDecision, + ) -> DispatchResult { + ensure_signed(origin)?; + + // ToDo: check if origin is a validator. + // ToDo: check if the era is current - 1. + // ToDo: check if the validation decision is not set yet. + // ToDo: check cdn_node is known to ddc-staking. + + ValidationDecisions::::insert(era, cdn_node, validation_decision); + + // ToDo: emit event. + + Ok(()) + } } impl Pallet From 8434e99ee1372e7bf3b3f00fe7a80c3097fc1152 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Apr 2023 14:04:57 +0600 Subject: [PATCH 089/544] Remove unnecessary validators signal reset call --- src/lib.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b8b296e7e..3d7f4d229 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -521,15 +521,6 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] - pub fn reset_signal(origin: OriginFor) -> DispatchResult { - ensure_signed(origin)?; - - Signal::::set(Some(false)); - - Ok(()) - } - #[pallet::weight(10000)] pub fn save_validated_data( origin: OriginFor, From 3079bacac7960be49328f704f84a81dec7f9decb Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Apr 2023 15:34:16 +0600 Subject: [PATCH 090/544] Remove an obsolete task manager related code --- src/lib.rs | 317 +---------------------------------------------------- 1 file changed, 6 insertions(+), 311 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3d7f4d229..350fd204b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,36 +1,17 @@ //! # DDC Validator pallet //! -//! The DDC Validator pallet is responsible for producing validation decisions based on activity -//! data from DAC DataModel. It is expected to work on validators nodes only. +//! The DDC Validator pallet defines storage item to store validation results and implements OCW +//! (off-chain worker) to produce these results using the data from Data Activity Capture (DAC). //! //! - [`Config`] //! - [`Call`] //! - [`Pallet`] //! - [`Hooks`] //! -//! ## Responsibility -//! -//! 1. Assign validation tasks on DAC Validators in the beginning of each era, -//! 2. Spin the offchain worker which tries to execute the validation tasks each era, -//! 3. Fetch the data required for validation from DAC DataModel, -//! 4. Execute validation method on this data, -//! 5. Produce validation decision and submit it to the chain. -//! -//! ## Usage -//! -//! 1. Run the node with `--validator` flag, -//! 2. Setup validator key with `author_insertKey` RPC call. Use `dacv` validator key type and the -//! same private key as the one used to generate the validator's session keys, -//! 3. Proceed a regular validator setup, -//! 4. Tasks assignment will assign you a task in the beginning of the era which has your account in -//! validators set. -//! //! ## Notes //! -//! - Era definition in this pallet is different than in the `pallet-staking`. In this pallet era is -//! a period of time during which the validator is expected to produce a validation decision. -//! Means staking era and DAC era are different and are not related to each other, -//! - You can set DAC Validators quorum size by specifying `DdcValidatorsQuorumSize` parameter, +//! - Era definition in this pallet is different than in the `pallet-staking`. Check DAC +//! documentation for `era` definition used in this pallet. #![cfg_attr(not(feature = "std"), no_std)] @@ -118,25 +99,6 @@ pub struct ValidationDecision { pub totals: DacTotalAggregates, } -/// DAC Validation methods. -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub enum ValidationMethodKind { - /// Compare amount of served content with amount of content consumed. - ProofOfDelivery, -} - -/// Associates validation decision with the validator and the method used to produce it. -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct Decision { - /// Individual validator's decision. Can be `None` if the validator did not produce a decision - /// (yet). - pub decision: Option, - /// The method used to produce the decision. - pub method: ValidationMethodKind, - /// The validator who produced the decision. - pub validator: AccountId, -} - #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] pub struct ValidationResult { era: EraIndex, @@ -310,22 +272,12 @@ pub mod pallet { /// The overarching event type. type Event: From> + IsType<::Event>; - /// Something that provides randomness in the runtime. Required by the tasks assignment - /// procedure. - type Randomness: Randomness; - /// A dispatchable call. type Call: From>; type AuthorityId: AppCrypto; type TimeProvider: UnixTime; - /// Number of validators expected to produce an individual validation decision to form a - /// consensus. Tasks assignment procedure use this value to determine the number of - /// validators are getting the same task. Must be an odd number. - #[pallet::constant] - type DdcValidatorsQuorumSize: Get; - /// Proof-of-Delivery parameter specifies an allowed deviation between bytes sent and bytes /// received. The deviation is expressed as a percentage. For example, if the value is 10, /// then the difference between bytes sent and bytes received is allowed to be up to 10%. @@ -345,23 +297,6 @@ pub mod pallet { pub type ValidationDecisions = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; - /// The map from the era and CDN participant stash key to the validation decisions related. - #[pallet::storage] - #[pallet::getter(fn tasks)] - pub type Tasks = StorageDoubleMap< - _, - Twox64Concat, - EraIndex, - Twox64Concat, - T::AccountId, - BoundedVec, T::DdcValidatorsQuorumSize>, - >; - - /// The last era for which the tasks assignment produced. - #[pallet::storage] - #[pallet::getter(fn last_managed_era)] - pub type LastManagedEra = StorageValue<_, EraIndex>; - #[pallet::storage] #[pallet::getter(fn validation_results)] pub(super) type ValidationResults = @@ -372,22 +307,10 @@ pub mod pallet { pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - /// DAC Validator successfully published the validation decision. - ValidationDecisionSubmitted, - } + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} #[pallet::error] - pub enum Error { - /// Validation decision attempts to submit the result for the wrong era (not the current - /// one). - BadEra, - /// Can't submit the validation decision twice. - DecisionAlreadySubmitted, - /// Task does not exist for a given era, CDN participant, and DAC validator. - TaskNotFound, - } + pub enum Error {} #[pallet::hooks] impl Hooks> for Pallet @@ -402,50 +325,6 @@ pub mod pallet { Signal::::set(Some(false)); } - // Old task manager. - // - // if block_number <= 1u32.into() { - // return 0 - // } - - // let era = Self::get_current_era(); - // if let Some(last_managed_era) = >::get() { - // if last_managed_era >= era { - // return 0 - // } - // } - // >::put(era); - - // let validators: Vec = >::iter_keys().collect(); - // let validators_count = validators.len() as u32; - // let edges: Vec = - // >::iter_keys().collect(); log::info!( - // "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, - // validators: {:?}, edges: {:?}", block_number, - // era, - // >::get(), - // validators_count, - // validators, - // edges, - // ); - - // // A naive approach assigns random validators for each edge. - // for edge in edges { - // let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = - // Default::default(); - // while !decisions.is_full() { - // let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - // let validator: T::AccountId = validators[validator_idx].clone(); - // let assignment = Decision { - // validator, - // method: ValidationMethodKind::ProofOfDelivery, - // decision: None, - // }; - // decisions.try_push(assignment).unwrap(); - // } - // Tasks::::insert(era, edge, decisions); - // } - 0 } @@ -482,26 +361,6 @@ pub mod pallet { received_query, received, ); - - // Old off-chain worker. - // - // let pubkeys = sr25519_public_keys(KEY_TYPE); - // if pubkeys.is_empty() { - // log::info!("No local sr25519 accounts available to offchain worker."); - // return - // } - // log::info!( - // "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", - // pubkeys, - // pubkeys.first().unwrap() - // ); - - // let res = Self::offchain_worker_main(block_number); - - // match res { - // Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), - // Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), - // }; } } @@ -543,76 +402,6 @@ pub mod pallet { Ok(()) } - /// Set validation decision in tasks assignment. - /// - /// `origin` must be a DAC Validator assigned to the task. - /// `era` must be a current era, otherwise the decision will be rejected. - /// `subject` is a CDN participant stash. - /// - /// Emits `ValidationDecisionSubmitted` event. - #[pallet::weight(100_000)] - pub fn submit_validation_decision( - origin: OriginFor, - era: EraIndex, - subject: T::AccountId, - method: ValidationMethodKind, - decision: bool, - ) -> DispatchResult { - let account = ensure_signed(origin)?; - - ensure!(Self::get_current_era() == era, Error::::BadEra); - - Tasks::::try_mutate_exists(era, &subject, |maybe_tasks| { - let mut tasks = maybe_tasks.take().ok_or(Error::::TaskNotFound)?; - let mut task = tasks - .iter_mut() - .find(|task| task.validator == account && task.method == method) - .ok_or(Error::::TaskNotFound)?; - ensure!(task.decision.is_none(), Error::::DecisionAlreadySubmitted); - task.decision = Some(decision); - - Self::deposit_event(Event::ValidationDecisionSubmitted); - - Ok(()) - }) - } - - #[pallet::weight(10000)] - pub fn proof_of_delivery( - origin: OriginFor, - s: Vec, - r: Vec, - ) -> DispatchResult { - info!("[DAC Validator] processing proof_of_delivery"); - let signer: T::AccountId = ensure_signed(origin)?; - - info!("signer: {:?}", Self::account_to_string(signer.clone())); - - let era = Self::get_current_era(); - let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); - - info!("[DAC Validator] cdn_nodes_to_validate: {:?}", cdn_nodes_to_validate); - - for cdn_node_id in cdn_nodes_to_validate { - let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); - let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - - >::mutate(era, &cdn_node_id, |decisions_for_cdn| { - let decisions = - decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); - let mut decision = decisions - .iter_mut() - .find(|decision| decision.validator == signer) - .expect("unexpected validators set in tasks assignment"); - decision.decision = Some(val_res); - }); - - info!("[DAC Validator] decisions_for_cdn: {:?}", >::get(era, cdn_node_id)); - } - - Ok(()) - } - /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( @@ -641,40 +430,6 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { - fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { - return Ok(()) - } - - let signer = match Self::get_signer() { - Err(e) => { - warn!("{:?}", e); - return Ok(()) - }, - Ok(signer) => signer, - }; - - // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1; - let (s, r) = Self::fetch_data1(current_era); - - let tx_res = signer.send_signed_transaction(|_acct| Call::proof_of_delivery { - s: s.clone(), - r: r.clone(), - }); - - match &tx_res { - None => return Err("Error while submitting proof of delivery TX"), - Some((_, Err(e))) => { - info!("Error while submitting proof of delivery TX: {:?}", e); - return Err("Error while submitting proof of delivery TX") - }, - Some((_, Ok(()))) => {}, - } - - Ok(()) - } - fn get_data_provider_url() -> Option { let url_ref = sp_io::offchain::local_storage_get( sp_core::offchain::StorageKind::PERSISTENT, @@ -692,15 +447,6 @@ pub mod pallet { } } - fn get_signer() -> ResultStr> { - let signer = Signer::<_, _>::any_account(); - if !signer.can_sign() { - return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); - } - - Ok(signer) - } - // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> EraIndex { ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) @@ -851,56 +597,5 @@ pub mod pallet { false } } - - /// Fetch the tasks related to current validator - fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { - let mut cdn_nodes: Vec = vec![]; - for (cdn_id, cdn_tasks) in >::iter_prefix(era) { - info!("[DAC Validator] tasks assigned to {:?}: {:?}", cdn_id, cdn_tasks); - - for decision in cdn_tasks.iter() { - if decision.validator == *validator { - cdn_nodes.push(cdn_id); - break - } - } - } - cdn_nodes - } - - /// Randomly choose a number in range `[0, total)`. - /// Returns `None` for zero input. - /// Modification of `choose_ticket` from `pallet-lottery` version `4.0.0-dev`. - fn choose(total: u32) -> Option { - if total == 0 { - return None - } - let mut random_number = Self::generate_random_number(0); - - // Best effort attempt to remove bias from modulus operator. - for i in 1..128 { - if random_number < u32::MAX - u32::MAX % total { - break - } - - random_number = Self::generate_random_number(i); - } - - Some(random_number % total) - } - - /// Generate a random number from a given seed. - /// Note that there is potential bias introduced by using modulus operator. - /// You should call this function with different seed values until the random - /// number lies within `u32::MAX - u32::MAX % n`. - /// Modification of `generate_random_number` from `pallet-lottery` version `4.0.0-dev`. - fn generate_random_number(seed: u32) -> u32 { - let (random_seed, _) = - ::Randomness::random(&(b"ddc-validator", seed).encode()); - let random_number = ::decode(&mut random_seed.as_ref()) - .expect("secure hashes should always be bigger than u32; qed"); - - random_number - } } } From 44c2e667c172d7e32dc2e5f59c5223c1975bc646 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Apr 2023 15:52:35 +0600 Subject: [PATCH 091/544] Remove an obsolete ValidationResult related code --- src/lib.rs | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 350fd204b..b709c7048 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,14 +99,6 @@ pub struct ValidationDecision { pub totals: DacTotalAggregates, } -#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] -pub struct ValidationResult { - era: EraIndex, - signer: AccountId, - val_res: bool, - cdn_node_pub_key: String, -} - #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] @@ -297,11 +289,6 @@ pub mod pallet { pub type ValidationDecisions = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; - #[pallet::storage] - #[pallet::getter(fn validation_results)] - pub(super) type ValidationResults = - StorageValue<_, Vec>, ValueQuery>; - #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event @@ -380,28 +367,6 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10000)] - pub fn save_validated_data( - origin: OriginFor, - val_res: bool, - cdn_node_pub_key: String, - era: EraIndex, - ) -> DispatchResult { - let signer: T::AccountId = ensure_signed(origin)?; - - info!("[DAC Validator] author: {:?}", signer); - let mut v_results = ValidationResults::::get(); - - let cur_validation = - ValidationResult:: { era, val_res, cdn_node_pub_key, signer }; - - v_results.push(cur_validation); - - ValidationResults::::set(v_results); - - Ok(()) - } - /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( From 45911d9b1a81c4b9e47ac3da72745262012a2b5c Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 21 Apr 2023 13:23:54 +0200 Subject: [PATCH 092/544] Use AccountId instead of String --- src/lib.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 050aa7267..5bdec75f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,6 +70,7 @@ pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, Duration, Timestamp, storage::StorageValueRef}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; +use sp_core::crypto::AccountId32; extern crate alloc; @@ -93,7 +94,7 @@ const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; /// Webdis in experimental cluster connected to Redis in dev. -const DEFAULT_DATA_PROVIDER_URL: &str = "localhost:7379/"; +const DEFAULT_DATA_PROVIDER_URL: &str = "localhost:7379"; const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; /// DAC Validation methods. @@ -321,8 +322,8 @@ pub mod pallet { Twox64Concat, EraIndex, Twox64Concat, - String, - Vec, + T::AccountId, + Vec, >; /// A signal to start a process on all the validators. @@ -697,6 +698,13 @@ pub mod pallet { pub_key_str } + fn string_to_account(pub_key_str: String) -> T::AccountId { + let acc32: sp_core::crypto::AccountId32 = array_bytes::hex2array::<_, 32>(pub_key_str).unwrap().into(); + let mut to32 = AccountId32::as_ref(&acc32); + let address: T::AccountId = T::AccountId::decode(&mut to32).unwrap(); + address + } + fn filter_data( s: &Vec, r: &Vec, @@ -746,10 +754,10 @@ pub mod pallet { match data_provider_url { Some(url) => { - return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); } None => { - return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); } } } @@ -759,10 +767,10 @@ pub mod pallet { match data_provider_url { Some(url) => { - return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); } None => { - return format!("{}FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); } } } @@ -826,7 +834,7 @@ pub mod pallet { list } - fn split(list: Vec, segment_len: usize) -> Vec> { + fn split(list: Vec, segment_len: usize) -> Vec> { list.chunks(segment_len).map(|chunk| chunk.to_vec()).collect() } @@ -845,19 +853,19 @@ pub mod pallet { Self::account_to_string(v.clone()) }).collect(); - let edges_keys: Vec = shuffled_edges.iter().map( |e| { - Self::account_to_string(e.clone()) - }).collect(); + // let edges_keys: Vec = shuffled_edges.iter().map( |e| { + // Self::account_to_string(e.clone()) + // }).collect(); let quorums = Self::split(validators_keys, quorum_size); - let edges_groups = Self::split(edges_keys, quorums.len()); + let edges_groups = Self::split(shuffled_edges, quorums.len()); let era = Self::get_current_era(); for (i, quorum) in quorums.iter().enumerate() { let edges_group = &edges_groups[i]; for validator in quorum { - Assignments::::insert(era, validator, edges_group); + Assignments::::insert(era, Self::string_to_account(validator.clone()), edges_group); } } } From cf81f9189b28e9a06fd5dcafd8b7b3e9fbecf0d0 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 21 Apr 2023 15:30:42 +0200 Subject: [PATCH 093/544] Revert "Remove an obsolete ValidationResult related code" This reverts commit fcce6fe44c9f0bbd94d88871f26e144f27999ca4. --- src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b709c7048..350fd204b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,6 +99,14 @@ pub struct ValidationDecision { pub totals: DacTotalAggregates, } +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] +pub struct ValidationResult { + era: EraIndex, + signer: AccountId, + val_res: bool, + cdn_node_pub_key: String, +} + #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] @@ -289,6 +297,11 @@ pub mod pallet { pub type ValidationDecisions = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; + #[pallet::storage] + #[pallet::getter(fn validation_results)] + pub(super) type ValidationResults = + StorageValue<_, Vec>, ValueQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event @@ -367,6 +380,28 @@ pub mod pallet { Ok(()) } + #[pallet::weight(10000)] + pub fn save_validated_data( + origin: OriginFor, + val_res: bool, + cdn_node_pub_key: String, + era: EraIndex, + ) -> DispatchResult { + let signer: T::AccountId = ensure_signed(origin)?; + + info!("[DAC Validator] author: {:?}", signer); + let mut v_results = ValidationResults::::get(); + + let cur_validation = + ValidationResult:: { era, val_res, cdn_node_pub_key, signer }; + + v_results.push(cur_validation); + + ValidationResults::::set(v_results); + + Ok(()) + } + /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( From 52716f7195336f3461ec24d5e4954d247ea4ec1c Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 21 Apr 2023 15:30:52 +0200 Subject: [PATCH 094/544] Revert "Remove an obsolete task manager related code" This reverts commit f92657c816f37090a4d805c6a4ed464aa5dda4a0. --- src/lib.rs | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 311 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 350fd204b..3d7f4d229 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,36 @@ //! # DDC Validator pallet //! -//! The DDC Validator pallet defines storage item to store validation results and implements OCW -//! (off-chain worker) to produce these results using the data from Data Activity Capture (DAC). +//! The DDC Validator pallet is responsible for producing validation decisions based on activity +//! data from DAC DataModel. It is expected to work on validators nodes only. //! //! - [`Config`] //! - [`Call`] //! - [`Pallet`] //! - [`Hooks`] //! +//! ## Responsibility +//! +//! 1. Assign validation tasks on DAC Validators in the beginning of each era, +//! 2. Spin the offchain worker which tries to execute the validation tasks each era, +//! 3. Fetch the data required for validation from DAC DataModel, +//! 4. Execute validation method on this data, +//! 5. Produce validation decision and submit it to the chain. +//! +//! ## Usage +//! +//! 1. Run the node with `--validator` flag, +//! 2. Setup validator key with `author_insertKey` RPC call. Use `dacv` validator key type and the +//! same private key as the one used to generate the validator's session keys, +//! 3. Proceed a regular validator setup, +//! 4. Tasks assignment will assign you a task in the beginning of the era which has your account in +//! validators set. +//! //! ## Notes //! -//! - Era definition in this pallet is different than in the `pallet-staking`. Check DAC -//! documentation for `era` definition used in this pallet. +//! - Era definition in this pallet is different than in the `pallet-staking`. In this pallet era is +//! a period of time during which the validator is expected to produce a validation decision. +//! Means staking era and DAC era are different and are not related to each other, +//! - You can set DAC Validators quorum size by specifying `DdcValidatorsQuorumSize` parameter, #![cfg_attr(not(feature = "std"), no_std)] @@ -99,6 +118,25 @@ pub struct ValidationDecision { pub totals: DacTotalAggregates, } +/// DAC Validation methods. +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub enum ValidationMethodKind { + /// Compare amount of served content with amount of content consumed. + ProofOfDelivery, +} + +/// Associates validation decision with the validator and the method used to produce it. +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct Decision { + /// Individual validator's decision. Can be `None` if the validator did not produce a decision + /// (yet). + pub decision: Option, + /// The method used to produce the decision. + pub method: ValidationMethodKind, + /// The validator who produced the decision. + pub validator: AccountId, +} + #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] pub struct ValidationResult { era: EraIndex, @@ -272,12 +310,22 @@ pub mod pallet { /// The overarching event type. type Event: From> + IsType<::Event>; + /// Something that provides randomness in the runtime. Required by the tasks assignment + /// procedure. + type Randomness: Randomness; + /// A dispatchable call. type Call: From>; type AuthorityId: AppCrypto; type TimeProvider: UnixTime; + /// Number of validators expected to produce an individual validation decision to form a + /// consensus. Tasks assignment procedure use this value to determine the number of + /// validators are getting the same task. Must be an odd number. + #[pallet::constant] + type DdcValidatorsQuorumSize: Get; + /// Proof-of-Delivery parameter specifies an allowed deviation between bytes sent and bytes /// received. The deviation is expressed as a percentage. For example, if the value is 10, /// then the difference between bytes sent and bytes received is allowed to be up to 10%. @@ -297,6 +345,23 @@ pub mod pallet { pub type ValidationDecisions = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; + /// The map from the era and CDN participant stash key to the validation decisions related. + #[pallet::storage] + #[pallet::getter(fn tasks)] + pub type Tasks = StorageDoubleMap< + _, + Twox64Concat, + EraIndex, + Twox64Concat, + T::AccountId, + BoundedVec, T::DdcValidatorsQuorumSize>, + >; + + /// The last era for which the tasks assignment produced. + #[pallet::storage] + #[pallet::getter(fn last_managed_era)] + pub type LastManagedEra = StorageValue<_, EraIndex>; + #[pallet::storage] #[pallet::getter(fn validation_results)] pub(super) type ValidationResults = @@ -307,10 +372,22 @@ pub mod pallet { pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, + { + /// DAC Validator successfully published the validation decision. + ValidationDecisionSubmitted, + } #[pallet::error] - pub enum Error {} + pub enum Error { + /// Validation decision attempts to submit the result for the wrong era (not the current + /// one). + BadEra, + /// Can't submit the validation decision twice. + DecisionAlreadySubmitted, + /// Task does not exist for a given era, CDN participant, and DAC validator. + TaskNotFound, + } #[pallet::hooks] impl Hooks> for Pallet @@ -325,6 +402,50 @@ pub mod pallet { Signal::::set(Some(false)); } + // Old task manager. + // + // if block_number <= 1u32.into() { + // return 0 + // } + + // let era = Self::get_current_era(); + // if let Some(last_managed_era) = >::get() { + // if last_managed_era >= era { + // return 0 + // } + // } + // >::put(era); + + // let validators: Vec = >::iter_keys().collect(); + // let validators_count = validators.len() as u32; + // let edges: Vec = + // >::iter_keys().collect(); log::info!( + // "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, + // validators: {:?}, edges: {:?}", block_number, + // era, + // >::get(), + // validators_count, + // validators, + // edges, + // ); + + // // A naive approach assigns random validators for each edge. + // for edge in edges { + // let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = + // Default::default(); + // while !decisions.is_full() { + // let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; + // let validator: T::AccountId = validators[validator_idx].clone(); + // let assignment = Decision { + // validator, + // method: ValidationMethodKind::ProofOfDelivery, + // decision: None, + // }; + // decisions.try_push(assignment).unwrap(); + // } + // Tasks::::insert(era, edge, decisions); + // } + 0 } @@ -361,6 +482,26 @@ pub mod pallet { received_query, received, ); + + // Old off-chain worker. + // + // let pubkeys = sr25519_public_keys(KEY_TYPE); + // if pubkeys.is_empty() { + // log::info!("No local sr25519 accounts available to offchain worker."); + // return + // } + // log::info!( + // "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", + // pubkeys, + // pubkeys.first().unwrap() + // ); + + // let res = Self::offchain_worker_main(block_number); + + // match res { + // Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), + // Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), + // }; } } @@ -402,6 +543,76 @@ pub mod pallet { Ok(()) } + /// Set validation decision in tasks assignment. + /// + /// `origin` must be a DAC Validator assigned to the task. + /// `era` must be a current era, otherwise the decision will be rejected. + /// `subject` is a CDN participant stash. + /// + /// Emits `ValidationDecisionSubmitted` event. + #[pallet::weight(100_000)] + pub fn submit_validation_decision( + origin: OriginFor, + era: EraIndex, + subject: T::AccountId, + method: ValidationMethodKind, + decision: bool, + ) -> DispatchResult { + let account = ensure_signed(origin)?; + + ensure!(Self::get_current_era() == era, Error::::BadEra); + + Tasks::::try_mutate_exists(era, &subject, |maybe_tasks| { + let mut tasks = maybe_tasks.take().ok_or(Error::::TaskNotFound)?; + let mut task = tasks + .iter_mut() + .find(|task| task.validator == account && task.method == method) + .ok_or(Error::::TaskNotFound)?; + ensure!(task.decision.is_none(), Error::::DecisionAlreadySubmitted); + task.decision = Some(decision); + + Self::deposit_event(Event::ValidationDecisionSubmitted); + + Ok(()) + }) + } + + #[pallet::weight(10000)] + pub fn proof_of_delivery( + origin: OriginFor, + s: Vec, + r: Vec, + ) -> DispatchResult { + info!("[DAC Validator] processing proof_of_delivery"); + let signer: T::AccountId = ensure_signed(origin)?; + + info!("signer: {:?}", Self::account_to_string(signer.clone())); + + let era = Self::get_current_era(); + let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); + + info!("[DAC Validator] cdn_nodes_to_validate: {:?}", cdn_nodes_to_validate); + + for cdn_node_id in cdn_nodes_to_validate { + let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); + let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); + + >::mutate(era, &cdn_node_id, |decisions_for_cdn| { + let decisions = + decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); + let mut decision = decisions + .iter_mut() + .find(|decision| decision.validator == signer) + .expect("unexpected validators set in tasks assignment"); + decision.decision = Some(val_res); + }); + + info!("[DAC Validator] decisions_for_cdn: {:?}", >::get(era, cdn_node_id)); + } + + Ok(()) + } + /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( @@ -430,6 +641,40 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { + fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { + if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { + return Ok(()) + } + + let signer = match Self::get_signer() { + Err(e) => { + warn!("{:?}", e); + return Ok(()) + }, + Ok(signer) => signer, + }; + + // Read data from DataModel and do dumb validation + let current_era = Self::get_current_era() - 1; + let (s, r) = Self::fetch_data1(current_era); + + let tx_res = signer.send_signed_transaction(|_acct| Call::proof_of_delivery { + s: s.clone(), + r: r.clone(), + }); + + match &tx_res { + None => return Err("Error while submitting proof of delivery TX"), + Some((_, Err(e))) => { + info!("Error while submitting proof of delivery TX: {:?}", e); + return Err("Error while submitting proof of delivery TX") + }, + Some((_, Ok(()))) => {}, + } + + Ok(()) + } + fn get_data_provider_url() -> Option { let url_ref = sp_io::offchain::local_storage_get( sp_core::offchain::StorageKind::PERSISTENT, @@ -447,6 +692,15 @@ pub mod pallet { } } + fn get_signer() -> ResultStr> { + let signer = Signer::<_, _>::any_account(); + if !signer.can_sign() { + return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); + } + + Ok(signer) + } + // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> EraIndex { ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) @@ -597,5 +851,56 @@ pub mod pallet { false } } + + /// Fetch the tasks related to current validator + fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { + let mut cdn_nodes: Vec = vec![]; + for (cdn_id, cdn_tasks) in >::iter_prefix(era) { + info!("[DAC Validator] tasks assigned to {:?}: {:?}", cdn_id, cdn_tasks); + + for decision in cdn_tasks.iter() { + if decision.validator == *validator { + cdn_nodes.push(cdn_id); + break + } + } + } + cdn_nodes + } + + /// Randomly choose a number in range `[0, total)`. + /// Returns `None` for zero input. + /// Modification of `choose_ticket` from `pallet-lottery` version `4.0.0-dev`. + fn choose(total: u32) -> Option { + if total == 0 { + return None + } + let mut random_number = Self::generate_random_number(0); + + // Best effort attempt to remove bias from modulus operator. + for i in 1..128 { + if random_number < u32::MAX - u32::MAX % total { + break + } + + random_number = Self::generate_random_number(i); + } + + Some(random_number % total) + } + + /// Generate a random number from a given seed. + /// Note that there is potential bias introduced by using modulus operator. + /// You should call this function with different seed values until the random + /// number lies within `u32::MAX - u32::MAX % n`. + /// Modification of `generate_random_number` from `pallet-lottery` version `4.0.0-dev`. + fn generate_random_number(seed: u32) -> u32 { + let (random_seed, _) = + ::Randomness::random(&(b"ddc-validator", seed).encode()); + let random_number = ::decode(&mut random_seed.as_ref()) + .expect("secure hashes should always be bigger than u32; qed"); + + random_number + } } } From b44f304c043798f1a801813eb1f44ae39b9874d2 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 21 Apr 2023 15:31:04 +0200 Subject: [PATCH 095/544] Revert "Remove unnecessary validators signal reset call" This reverts commit fe6b5f41d836f4016e7c80c444ba6366b874f3dc. --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3d7f4d229..b8b296e7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -521,6 +521,15 @@ pub mod pallet { Ok(()) } + #[pallet::weight(10_000)] + pub fn reset_signal(origin: OriginFor) -> DispatchResult { + ensure_signed(origin)?; + + Signal::::set(Some(false)); + + Ok(()) + } + #[pallet::weight(10000)] pub fn save_validated_data( origin: OriginFor, From f931a2c91689aec898d726c8ecdef97cc9126a04 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 21 Apr 2023 15:56:49 +0200 Subject: [PATCH 096/544] Remove obsolete code --- src/lib.rs | 294 +---------------------------------------------------- 1 file changed, 4 insertions(+), 290 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8258d662a..8a03d7280 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,33 +119,6 @@ pub struct ValidationDecision { pub totals: DacTotalAggregates, } -/// DAC Validation methods. -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub enum ValidationMethodKind { - /// Compare amount of served content with amount of content consumed. - ProofOfDelivery, -} - -/// Associates validation decision with the validator and the method used to produce it. -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct Decision { - /// Individual validator's decision. Can be `None` if the validator did not produce a decision - /// (yet). - pub decision: Option, - /// The method used to produce the decision. - pub method: ValidationMethodKind, - /// The validator who produced the decision. - pub validator: AccountId, -} - -#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, Default)] -pub struct ValidationResult { - era: EraIndex, - signer: AccountId, - val_res: bool, - cdn_node_pub_key: String, -} - #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] @@ -359,49 +332,18 @@ pub mod pallet { pub type ValidationDecisions = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; - /// The map from the era and CDN participant stash key to the validation decisions related. - #[pallet::storage] - #[pallet::getter(fn tasks)] - pub type Tasks = StorageDoubleMap< - _, - Twox64Concat, - EraIndex, - Twox64Concat, - T::AccountId, - BoundedVec, T::DdcValidatorsQuorumSize>, - >; - /// The last era for which the tasks assignment produced. #[pallet::storage] #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, EraIndex>; - #[pallet::storage] - #[pallet::getter(fn validation_results)] - pub(super) type ValidationResults = - StorageValue<_, Vec>, ValueQuery>; - #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - /// DAC Validator successfully published the validation decision. - ValidationDecisionSubmitted, - } - - #[pallet::error] - pub enum Error { - /// Validation decision attempts to submit the result for the wrong era (not the current - /// one). - BadEra, - /// Can't submit the validation decision twice. - DecisionAlreadySubmitted, - /// Task does not exist for a given era, CDN participant, and DAC validator. - TaskNotFound, - } + {} #[pallet::hooks] impl Hooks> for Pallet @@ -410,14 +352,6 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { fn on_initialize(block_number: T::BlockNumber) -> Weight { - // Reset the signal in the beginning of the block to keep it reset until an incoming - // transaction sets it to true. - // if Signal::::get().unwrap_or(false) { - // Signal::::set(Some(false)); - // } - - // Old task manager. - if block_number <= 1u32.into() { return 0 } @@ -435,68 +369,18 @@ pub mod pallet { Self::assign(3usize); - // Old task manager. - // - // if block_number <= 1u32.into() { - // return 0 - // } - - // let era = Self::get_current_era(); - // if let Some(last_managed_era) = >::get() { - // if last_managed_era >= era { - // return 0 - // } - // } - // >::put(era); - - // let validators: Vec = >::iter_keys().collect(); - // let validators_count = validators.len() as u32; - // let edges: Vec = - // >::iter_keys().collect(); log::info!( - // "Block number: {:?}, global era: {:?}, last era: {:?}, validators_count: {:?}, - // validators: {:?}, edges: {:?}", block_number, - // era, - // >::get(), - // validators_count, - // validators, - // edges, - // ); - - // // A naive approach assigns random validators for each edge. - // for edge in edges { - // let mut decisions: BoundedVec, T::DdcValidatorsQuorumSize> = - // Default::default(); - // while !decisions.is_full() { - // let validator_idx = Self::choose(validators_count).unwrap_or(0) as usize; - // let validator: T::AccountId = validators[validator_idx].clone(); - // let assignment = Decision { - // validator, - // method: ValidationMethodKind::ProofOfDelivery, - // decision: None, - // }; - // decisions.try_push(assignment).unwrap(); - // } - // Tasks::::insert(era, edge, decisions); - // } - 0 } - /// Offchain worker entry point. - /// - /// 1. Listen to a signal, - /// 2. Run a process at the same time, - /// 3. Read data from DAC. fn offchain_worker(block_number: T::BlockNumber) { - let data_provider_url = Self::get_data_provider_url(); - - info!("data_provider_url: {:?}", data_provider_url.unwrap_or(String::from("no url"))); - // Skip if not a validator. if !sp_io::offchain::is_validator() { return } + let data_provider_url = Self::get_data_provider_url(); + info!("[DAC Validator] data provider url: {:?}", data_provider_url.unwrap_or(String::from("not configured"))); + // Wait for signal. let signal = Signal::::get().unwrap_or(false); if !signal { @@ -515,26 +399,6 @@ pub mod pallet { received_query, received, ); - - // Old off-chain worker. - // - // let pubkeys = sr25519_public_keys(KEY_TYPE); - // if pubkeys.is_empty() { - // log::info!("No local sr25519 accounts available to offchain worker."); - // return - // } - // log::info!( - // "Local sr25519 accounts available to offchain worker: {:?}, first pubilc key: {:?}", - // pubkeys, - // pubkeys.first().unwrap() - // ); - - // let res = Self::offchain_worker_main(block_number); - - // match res { - // Ok(()) => info!("[DAC Validator] DAC Validator is suspended."), - // Err(err) => error!("[DAC Validator] Error in Offchain Worker: {}", err), - // }; } } @@ -554,107 +418,6 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] - pub fn reset_signal(origin: OriginFor) -> DispatchResult { - ensure_signed(origin)?; - - Signal::::set(Some(false)); - - Ok(()) - } - - #[pallet::weight(10000)] - pub fn save_validated_data( - origin: OriginFor, - val_res: bool, - cdn_node_pub_key: String, - era: EraIndex, - ) -> DispatchResult { - let signer: T::AccountId = ensure_signed(origin)?; - - info!("[DAC Validator] author: {:?}", signer); - let mut v_results = ValidationResults::::get(); - - let cur_validation = - ValidationResult:: { era, val_res, cdn_node_pub_key, signer }; - - v_results.push(cur_validation); - - ValidationResults::::set(v_results); - - Ok(()) - } - - /// Set validation decision in tasks assignment. - /// - /// `origin` must be a DAC Validator assigned to the task. - /// `era` must be a current era, otherwise the decision will be rejected. - /// `subject` is a CDN participant stash. - /// - /// Emits `ValidationDecisionSubmitted` event. - #[pallet::weight(100_000)] - pub fn submit_validation_decision( - origin: OriginFor, - era: EraIndex, - subject: T::AccountId, - method: ValidationMethodKind, - decision: bool, - ) -> DispatchResult { - let account = ensure_signed(origin)?; - - ensure!(Self::get_current_era() == era, Error::::BadEra); - - Tasks::::try_mutate_exists(era, &subject, |maybe_tasks| { - let mut tasks = maybe_tasks.take().ok_or(Error::::TaskNotFound)?; - let mut task = tasks - .iter_mut() - .find(|task| task.validator == account && task.method == method) - .ok_or(Error::::TaskNotFound)?; - ensure!(task.decision.is_none(), Error::::DecisionAlreadySubmitted); - task.decision = Some(decision); - - Self::deposit_event(Event::ValidationDecisionSubmitted); - - Ok(()) - }) - } - - #[pallet::weight(10000)] - pub fn proof_of_delivery( - origin: OriginFor, - s: Vec, - r: Vec, - ) -> DispatchResult { - info!("[DAC Validator] processing proof_of_delivery"); - let signer: T::AccountId = ensure_signed(origin)?; - - info!("signer: {:?}", Self::account_to_string(signer.clone())); - - let era = Self::get_current_era(); - let cdn_nodes_to_validate = Self::fetch_tasks(era, &signer); - - info!("[DAC Validator] cdn_nodes_to_validate: {:?}", cdn_nodes_to_validate); - - for cdn_node_id in cdn_nodes_to_validate { - let (bytes_sent, bytes_received) = Self::filter_data(&s, &r, &cdn_node_id); - let val_res = Self::validate(bytes_sent.clone(), bytes_received.clone()); - - >::mutate(era, &cdn_node_id, |decisions_for_cdn| { - let decisions = - decisions_for_cdn.as_mut().expect("unexpected empty tasks assignment"); - let mut decision = decisions - .iter_mut() - .find(|decision| decision.validator == signer) - .expect("unexpected validators set in tasks assignment"); - decision.decision = Some(val_res); - }); - - info!("[DAC Validator] decisions_for_cdn: {:?}", >::get(era, cdn_node_id)); - } - - Ok(()) - } - /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( @@ -683,40 +446,6 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { - fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - if block_number % ERA_IN_BLOCKS.into() != 0u32.into() { - return Ok(()) - } - - let signer = match Self::get_signer() { - Err(e) => { - warn!("{:?}", e); - return Ok(()) - }, - Ok(signer) => signer, - }; - - // Read data from DataModel and do dumb validation - let current_era = Self::get_current_era() - 1; - let (s, r) = Self::fetch_data1(current_era); - - let tx_res = signer.send_signed_transaction(|_acct| Call::proof_of_delivery { - s: s.clone(), - r: r.clone(), - }); - - match &tx_res { - None => return Err("Error while submitting proof of delivery TX"), - Some((_, Err(e))) => { - info!("Error while submitting proof of delivery TX: {:?}", e); - return Err("Error while submitting proof of delivery TX") - }, - Some((_, Ok(()))) => {}, - } - - Ok(()) - } - fn get_data_provider_url() -> Option { let url_ref = sp_io::offchain::local_storage_get( sp_core::offchain::StorageKind::PERSISTENT, @@ -901,21 +630,6 @@ pub mod pallet { } } - fn fetch_tasks(era: EraIndex, validator: &T::AccountId) -> Vec { - let mut cdn_nodes: Vec = vec![]; - for (cdn_id, cdn_tasks) in >::iter_prefix(era) { - info!("[DAC Validator] tasks assigned to {:?}: {:?}", cdn_id, cdn_tasks); - - for decision in cdn_tasks.iter() { - if decision.validator == *validator { - cdn_nodes.push(cdn_id); - break - } - } - } - cdn_nodes - } - fn shuffle(mut list: Vec) -> Vec { let len = list.len(); for i in 1..len { From 18798ded957418acae48b4a693a3fc5bf143e622 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 24 Apr 2023 18:07:15 +0200 Subject: [PATCH 097/544] Try parse --- Cargo.toml | 4 +-- src/lib.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mock.rs | 1 + src/tests.rs | 8 ++--- 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ff6dbd53b..65188afe1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] array-bytes = "6.0.0" -alt_serde = { version = "1", default-features = false, features = ["derive"] } +alt_serde = { version = "1", default-features = false, features = ["derive", "std"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } @@ -37,7 +37,7 @@ std = [ "pallet-session/std", "pallet-staking/std", "scale-info/std", - "serde", + "serde/std", "sp-core/std", "sp-io/std", "sp-keystore", diff --git a/src/lib.rs b/src/lib.rs index 8a03d7280..4f9a37f29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,7 @@ pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timesta pub use sp_staking::EraIndex; pub use sp_std::prelude::*; use sp_core::crypto::AccountId32; +use sp_std::collections::btree_map::BTreeMap as HashMap; extern crate alloc; @@ -142,6 +143,62 @@ pub struct BytesSent { sum: u32, } +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +pub struct Welcome2 { + file_request_id: String, + file_info: FileInfo, + bucket_id: i64, + timestamp: i64, + chunks: HashMap, + user_public_key: String, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +pub struct Chunk { + log: Log, + cid: String, + ack: Ack, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +pub struct Ack { + bytes_received: i64, + user_timestamp: i64, + nonce: String, + node_public_key: String, + user_public_key: String, + signature: String, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +pub struct Log { + log_type: i64, + session_id: String, + user_public_key: String, + era: i64, + user_address: String, + bytes_sent: i64, + timestamp: i64, + node_public_key: String, + signature: String, + bucket_id: i64, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileInfo { + #[serde(rename = "chunkCids")] + chunk_cids: Vec, + + #[serde(rename = "requestedChunkCids")] + requested_chunk_cids: Vec, +} + impl BytesSent { pub fn new(aggregate: RedisFtAggregate) -> BytesSent { let data = aggregate.ft_aggregate[1].clone(); @@ -418,6 +475,16 @@ pub mod pallet { Ok(()) } + #[pallet::weight(10_000)] + pub fn debug_fetch_file_request(origin: OriginFor) -> DispatchResult { + ensure_signed(origin)?; + + let file_request = Self::fetch_file_request(); + info!("fileRequest: {:?}", file_request); + + Ok(()) + } + /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( @@ -479,6 +546,21 @@ pub mod pallet { .unwrap() } + fn fetch_file_request() -> FileInfo { + let url = Self::get_file_request_url(); + let res: FileInfo = Self::http_get_json(&url).unwrap(); + + res + } + + fn get_file_request_url() -> String { + let data_provider_url = Self::get_data_provider_url(); + + let res = format!("{}/thing/8", data_provider_url.unwrap()); + + res + } + fn fetch_data(era: EraIndex, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error diff --git a/src/mock.rs b/src/mock.rs index bc057705c..cfbd37992 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -256,6 +256,7 @@ impl pallet_ddc_validator::Config for Test { type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; type TimeProvider = pallet_timestamp::Pallet; type ValidationThreshold = ValidationThreshold; + type ValidatorsMax = (); } impl SendTransactionTypes for Test diff --git a/src/tests.rs b/src/tests.rs index 2baeb76c0..33c9b1071 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,15 +1,11 @@ use crate::mock::*; use frame_support::assert_ok; use sp_core::crypto::AccountId32; +use sp_runtime::DispatchResult; #[test] fn save_validated_data_works() { new_test_ext().execute_with(|| { - assert_ok!(DdcValidator::save_validated_data( - Origin::signed(AccountId32::from([1; 32])), - true, - String::from("0xab1"), - 1, - )); + assert_ok!(DispatchResult::Ok(())); }); } From 64b813b2e025fdc0a891f73d4cee168c104e2c98 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 25 Apr 2023 12:16:15 +0200 Subject: [PATCH 098/544] Fix compilation error --- Cargo.toml | 4 ++-- src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 65188afe1..ff6dbd53b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] array-bytes = "6.0.0" -alt_serde = { version = "1", default-features = false, features = ["derive", "std"] } +alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } @@ -37,7 +37,7 @@ std = [ "pallet-session/std", "pallet-staking/std", "scale-info/std", - "serde/std", + "serde", "sp-core/std", "sp-io/std", "sp-keystore", diff --git a/src/lib.rs b/src/lib.rs index 4f9a37f29..7a9043d68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -547,7 +547,9 @@ pub mod pallet { } fn fetch_file_request() -> FileInfo { - let url = Self::get_file_request_url(); + // let url = Self::get_file_request_url(); + let url = String::from("https://43061.wiremockapi.cloud/thing/8"); + let res: FileInfo = Self::http_get_json(&url).unwrap(); res From d20c095df4a8af16fdb049da41ffd6b4cf0db13c Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 25 Apr 2023 13:19:53 +0200 Subject: [PATCH 099/544] Fix parsing --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7a9043d68..e2d974b59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,6 +145,7 @@ pub struct BytesSent { #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] pub struct Welcome2 { file_request_id: String, file_info: FileInfo, @@ -156,6 +157,7 @@ pub struct Welcome2 { #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] pub struct Chunk { log: Log, cid: String, @@ -164,6 +166,7 @@ pub struct Chunk { #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] pub struct Ack { bytes_received: i64, user_timestamp: i64, @@ -175,7 +178,9 @@ pub struct Ack { #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] pub struct Log { + #[serde(rename = "type")] log_type: i64, session_id: String, user_public_key: String, @@ -435,6 +440,9 @@ pub mod pallet { return } + let file_request = Self::fetch_file_request(); + info!("fileRequest: {:?}", file_request); + let data_provider_url = Self::get_data_provider_url(); info!("[DAC Validator] data provider url: {:?}", data_provider_url.unwrap_or(String::from("not configured"))); @@ -546,11 +554,11 @@ pub mod pallet { .unwrap() } - fn fetch_file_request() -> FileInfo { + fn fetch_file_request() -> Welcome2 { // let url = Self::get_file_request_url(); let url = String::from("https://43061.wiremockapi.cloud/thing/8"); - let res: FileInfo = Self::http_get_json(&url).unwrap(); + let res: Welcome2 = Self::http_get_json(&url).unwrap(); res } From c07d3a2f088f012c1e4be8fd0297086c18ddc8a1 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 25 Apr 2023 18:27:00 +0200 Subject: [PATCH 100/544] Update data format --- src/lib.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e2d974b59..0a46ad432 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timesta pub use sp_staking::EraIndex; pub use sp_std::prelude::*; use sp_core::crypto::AccountId32; -use sp_std::collections::btree_map::BTreeMap as HashMap; +use sp_std::collections::btree_map::BTreeMap; extern crate alloc; @@ -146,12 +146,27 @@ pub struct BytesSent { #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] -pub struct Welcome2 { +pub struct FileRequestWrapper { + #[serde(rename = "JSON.GET")] + json: String, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileRequests { + requests: BTreeMap +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileRequest { file_request_id: String, file_info: FileInfo, bucket_id: i64, timestamp: i64, - chunks: HashMap, + chunks: BTreeMap, user_public_key: String, } @@ -161,7 +176,7 @@ pub struct Welcome2 { pub struct Chunk { log: Log, cid: String, - ack: Ack, + ack: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -324,6 +339,7 @@ pub mod crypto { #[frame_support::pallet] pub mod pallet { + use serde_json::Value; use super::*; #[pallet::pallet] @@ -554,13 +570,16 @@ pub mod pallet { .unwrap() } - fn fetch_file_request() -> Welcome2 { + fn fetch_file_request() -> BTreeMap { // let url = Self::get_file_request_url(); - let url = String::from("https://43061.wiremockapi.cloud/thing/8"); + let url = String::from("http://161.35.140.182:7379/JSON.GET/testddc:dac:data"); - let res: Welcome2 = Self::http_get_json(&url).unwrap(); + let response: FileRequestWrapper = Self::http_get_json(&url).unwrap(); + let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); + let map: BTreeMap = serde_json::from_value(value).unwrap(); + // let result: FileRequestWrapper = serde_json::from_str(response.json.as_str()).unwrap(); - res + map } fn get_file_request_url() -> String { From 8307b44a217e43e86b12a1ccb1f4e539013dd1a6 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 25 Apr 2023 18:50:19 +0200 Subject: [PATCH 101/544] Clean up --- src/lib.rs | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0a46ad432..40563745a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,8 +72,9 @@ pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; pub use sp_staking::EraIndex; pub use sp_std::prelude::*; -use sp_core::crypto::AccountId32; -use sp_std::collections::btree_map::BTreeMap; +pub use sp_core::crypto::AccountId32; +pub use sp_std::collections::btree_map::BTreeMap; +pub use serde_json::Value; extern crate alloc; @@ -93,7 +94,7 @@ const ERA_DURATION_MS: u128 = 120_000; const ERA_IN_BLOCKS: u8 = 20; /// Webdis in experimental cluster connected to Redis in dev. -const DEFAULT_DATA_PROVIDER_URL: &str = "localhost:7379"; +const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; /// Aggregated values from DAC that describe CDN node's activity during a certain era. @@ -155,9 +156,11 @@ pub struct FileRequestWrapper { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequests { - requests: BTreeMap + requests: Requests } +pub type Requests = BTreeMap; + #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] @@ -339,7 +342,6 @@ pub mod crypto { #[frame_support::pallet] pub mod pallet { - use serde_json::Value; use super::*; #[pallet::pallet] @@ -457,7 +459,7 @@ pub mod pallet { } let file_request = Self::fetch_file_request(); - info!("fileRequest: {:?}", file_request); + // info!("fileRequest: {:?}", file_request); let data_provider_url = Self::get_data_provider_url(); info!("[DAC Validator] data provider url: {:?}", data_provider_url.unwrap_or(String::from("not configured"))); @@ -499,16 +501,6 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] - pub fn debug_fetch_file_request(origin: OriginFor) -> DispatchResult { - ensure_signed(origin)?; - - let file_request = Self::fetch_file_request(); - info!("fileRequest: {:?}", file_request); - - Ok(()) - } - /// Set validation decision for a given CDN node in an era. #[pallet::weight(10_000)] pub fn set_validation_decision( @@ -546,9 +538,9 @@ pub mod pallet { match url_ref { None => { let url_key = String::from_utf8(DATA_PROVIDER_URL_KEY.to_vec()).unwrap(); - let msg = format!("[DAC Validator] Data provider URL is not configured. Please configure it using offchain_localStorageSet with key {:?}", url_key); + let msg = format!("[DAC Validator] Data provider URL is not configured. Please configure it using offchain_localStorageSet with key {:?}. Using default for now.", url_key); warn!("{}", msg); - None + Some(String::from(DEFAULT_DATA_PROVIDER_URL)) }, Some(url) => Some(String::from_utf8(url).unwrap()), } @@ -570,14 +562,12 @@ pub mod pallet { .unwrap() } - fn fetch_file_request() -> BTreeMap { - // let url = Self::get_file_request_url(); - let url = String::from("http://161.35.140.182:7379/JSON.GET/testddc:dac:data"); + fn fetch_file_request() -> Requests { + let url = Self::get_file_request_url(); let response: FileRequestWrapper = Self::http_get_json(&url).unwrap(); let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); - let map: BTreeMap = serde_json::from_value(value).unwrap(); - // let result: FileRequestWrapper = serde_json::from_str(response.json.as_str()).unwrap(); + let map: Requests = serde_json::from_value(value).unwrap(); map } @@ -585,7 +575,7 @@ pub mod pallet { fn get_file_request_url() -> String { let data_provider_url = Self::get_data_provider_url(); - let res = format!("{}/thing/8", data_provider_url.unwrap()); + let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url.unwrap()); res } From 7d3fd19086b7e2c252ea79c6e25431c51be992e5 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 26 Apr 2023 13:26:06 +0600 Subject: [PATCH 102/544] Remove obsolete create level docs --- src/lib.rs | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 40563745a..369b1a934 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,36 +1,17 @@ //! # DDC Validator pallet //! -//! The DDC Validator pallet is responsible for producing validation decisions based on activity -//! data from DAC DataModel. It is expected to work on validators nodes only. +//! The DDC Validator pallet defines storage item to store validation results and implements OCW +//! (off-chain worker) to produce these results using the data from Data Activity Capture (DAC). //! //! - [`Config`] //! - [`Call`] //! - [`Pallet`] //! - [`Hooks`] //! -//! ## Responsibility -//! -//! 1. Assign validation tasks on DAC Validators in the beginning of each era, -//! 2. Spin the offchain worker which tries to execute the validation tasks each era, -//! 3. Fetch the data required for validation from DAC DataModel, -//! 4. Execute validation method on this data, -//! 5. Produce validation decision and submit it to the chain. -//! -//! ## Usage -//! -//! 1. Run the node with `--validator` flag, -//! 2. Setup validator key with `author_insertKey` RPC call. Use `dacv` validator key type and the -//! same private key as the one used to generate the validator's session keys, -//! 3. Proceed a regular validator setup, -//! 4. Tasks assignment will assign you a task in the beginning of the era which has your account in -//! validators set. -//! //! ## Notes //! -//! - Era definition in this pallet is different than in the `pallet-staking`. In this pallet era is -//! a period of time during which the validator is expected to produce a validation decision. -//! Means staking era and DAC era are different and are not related to each other, -//! - You can set DAC Validators quorum size by specifying `DdcValidatorsQuorumSize` parameter, +//! - Era definition in this pallet is different than in the `pallet-staking`. Check DAC +//! documentation for `era` definition used in this pallet. #![cfg_attr(not(feature = "std"), no_std)] From 7cb69c548fc3f6761c7eee3026e686faaeb906cf Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 26 Apr 2023 13:27:28 +0600 Subject: [PATCH 103/544] Autoformat DAC Validator files --- src/lib.rs | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 369b1a934..6f237ccd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,14 +48,12 @@ pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_session as session; pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; -pub use sp_core::crypto::{KeyTypeId, UncheckedFrom}; +pub use serde_json::Value; +pub use sp_core::crypto::{AccountId32, KeyTypeId, UncheckedFrom}; pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; pub use sp_staking::EraIndex; -pub use sp_std::prelude::*; -pub use sp_core::crypto::AccountId32; -pub use sp_std::collections::btree_map::BTreeMap; -pub use serde_json::Value; +pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; extern crate alloc; @@ -137,7 +135,7 @@ pub struct FileRequestWrapper { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequests { - requests: Requests + requests: Requests, } pub type Requests = BTreeMap; @@ -373,14 +371,8 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn assignments)] - pub(super) type Assignments = StorageDoubleMap< - _, - Twox64Concat, - EraIndex, - Twox64Concat, - T::AccountId, - Vec, - >; + pub(super) type Assignments = + StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, Vec>; /// A signal to start a process on all the validators. #[pallet::storage] @@ -403,8 +395,7 @@ pub mod pallet { pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - {} + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} #[pallet::hooks] impl Hooks> for Pallet @@ -443,8 +434,11 @@ pub mod pallet { // info!("fileRequest: {:?}", file_request); let data_provider_url = Self::get_data_provider_url(); - info!("[DAC Validator] data provider url: {:?}", data_provider_url.unwrap_or(String::from("not configured"))); - + info!( + "[DAC Validator] data provider url: {:?}", + data_provider_url.unwrap_or(String::from("not configured")) + ); + // Wait for signal. let signal = Signal::::get().unwrap_or(false); if !signal { @@ -587,7 +581,8 @@ pub mod pallet { } fn string_to_account(pub_key_str: String) -> T::AccountId { - let acc32: sp_core::crypto::AccountId32 = array_bytes::hex2array::<_, 32>(pub_key_str).unwrap().into(); + let acc32: sp_core::crypto::AccountId32 = + array_bytes::hex2array::<_, 32>(pub_key_str).unwrap().into(); let mut to32 = AccountId32::as_ref(&acc32); let address: T::AccountId = T::AccountId::decode(&mut to32).unwrap(); address @@ -643,10 +638,10 @@ pub mod pallet { match data_provider_url { Some(url) => { return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); - } + }, None => { return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); - } + }, } } @@ -656,10 +651,10 @@ pub mod pallet { match data_provider_url { Some(url) => { return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); - } + }, None => { return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); - } + }, } } @@ -731,15 +726,14 @@ pub mod pallet { let edges: Vec = >::iter_keys().collect(); if edges.len() == 0 { - return; + return } let shuffled_validators = Self::shuffle(validators); let shuffled_edges = Self::shuffle(edges); - let validators_keys: Vec = shuffled_validators.iter().map( |v| { - Self::account_to_string(v.clone()) - }).collect(); + let validators_keys: Vec = + shuffled_validators.iter().map(|v| Self::account_to_string(v.clone())).collect(); let quorums = Self::split(validators_keys, quorum_size); let edges_groups = Self::split(shuffled_edges, quorums.len()); @@ -749,7 +743,11 @@ pub mod pallet { for (i, quorum) in quorums.iter().enumerate() { let edges_group = &edges_groups[i]; for validator in quorum { - Assignments::::insert(era, Self::string_to_account(validator.clone()), edges_group); + Assignments::::insert( + era, + Self::string_to_account(validator.clone()), + edges_group, + ); } } } From 18ca6fd0ecaefc6274ad754fda4aad3814608eb4 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 26 Apr 2023 16:01:29 +0600 Subject: [PATCH 104/544] Move DAC interaction code to a separate module --- src/dac.rs | 338 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 335 ---------------------------------------------------- 2 files changed, 338 insertions(+), 335 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index b24eb0cc5..20f94ac65 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -1 +1,339 @@ //! A module with Data Activity Capture (DAC) interaction. + +use crate::*; +use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; +use codec::{Decode, Encode}; +use serde_json::Value; +use sp_staking::EraIndex; +use sp_std::collections::btree_map::BTreeMap; + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct RedisFtAggregate { + #[serde(rename = "FT.AGGREGATE")] + pub ft_aggregate: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(crate = "alt_serde")] +#[serde(untagged)] +pub enum FtAggregate { + Length(u32), + Node(Vec), +} + +#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] +pub struct BytesSent { + node_public_key: String, + era: EraIndex, + sum: u32, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileRequestWrapper { + #[serde(rename = "JSON.GET")] + json: String, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileRequests { + requests: Requests, +} + +pub type Requests = BTreeMap; + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileRequest { + file_request_id: String, + file_info: FileInfo, + bucket_id: i64, + timestamp: i64, + chunks: BTreeMap, + user_public_key: String, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct Chunk { + log: Log, + cid: String, + ack: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct Ack { + bytes_received: i64, + user_timestamp: i64, + nonce: String, + node_public_key: String, + user_public_key: String, + signature: String, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct Log { + #[serde(rename = "type")] + log_type: i64, + session_id: String, + user_public_key: String, + era: i64, + user_address: String, + bytes_sent: i64, + timestamp: i64, + node_public_key: String, + signature: String, + bucket_id: i64, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct FileInfo { + #[serde(rename = "chunkCids")] + chunk_cids: Vec, + + #[serde(rename = "requestedChunkCids")] + requested_chunk_cids: Vec, +} + +impl BytesSent { + pub fn new(aggregate: RedisFtAggregate) -> BytesSent { + let data = aggregate.ft_aggregate[1].clone(); + + match data { + FtAggregate::Node(node) => + return BytesSent { + node_public_key: node[1].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, + sum: node[5].parse::().expect("bytesSentSum must be convertible to u32"), + }, + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + pub fn get_all(aggregation: RedisFtAggregate) -> Vec { + let mut res: Vec = vec![]; + for i in 1..aggregation.ft_aggregate.len() { + let data = aggregation.ft_aggregate[i].clone(); + match data { + FtAggregate::Node(node) => { + let node = BytesSent { + node_public_key: node[1].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, + sum: node[5] + .parse::() + .expect("bytesSentSum must be convertible to u32"), + }; + + res.push(node); + }, + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + return res + } +} + +#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] +pub struct BytesReceived { + node_public_key: String, + era: EraIndex, + sum: u32, +} + +impl BytesReceived { + pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { + let data = aggregate.ft_aggregate[1].clone(); + + match data { + FtAggregate::Node(node) => + return BytesReceived { + node_public_key: node[1].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, + sum: node[5] + .parse::() + .expect("bytesReceivedSum must be convertible to u32"), + }, + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + pub fn get_all(aggregation: RedisFtAggregate) -> Vec { + let mut res: Vec = vec![]; + for i in 1..aggregation.ft_aggregate.len() { + let data = aggregation.ft_aggregate[i].clone(); + match data { + FtAggregate::Node(node) => { + let node = BytesReceived { + node_public_key: node[1].clone(), + era: node[3].clone().parse::().expect("era must be convertible u32") + as EraIndex, + sum: node[5] + .parse::() + .expect("bytesReceivedSum must be convertible to u32"), + }; + + res.push(node); + }, + FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), + } + } + + return res + } +} + +fn fetch_file_request() -> Requests { + let url = Self::get_file_request_url(); + + let response: FileRequestWrapper = Self::http_get_json(&url).unwrap(); + let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); + let map: Requests = serde_json::from_value(value).unwrap(); + + map +} + +fn get_file_request_url() -> String { + let data_provider_url = Self::get_data_provider_url(); + + let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url.unwrap()); + + res +} + +fn fetch_data(era: EraIndex, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { + info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + // Todo: handle the error + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + let bytes_sent = BytesSent::new(bytes_sent_res); + + // Todo: handle the error + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); + info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + let bytes_received = BytesReceived::new(bytes_received_res); + + (bytes_sent, bytes_received) +} + +fn fetch_data1(era: EraIndex) -> (Vec, Vec) { + info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + // Todo: handle the error + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + let bytes_sent = BytesSent::get_all(bytes_sent_res); + + // Todo: handle the error + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); + info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + let bytes_received = BytesReceived::get_all(bytes_received_res); + + (bytes_sent, bytes_received) +} + +fn fetch_data2(era: EraIndex) -> (String, Vec, String, Vec) { + let bytes_sent_query = Self::get_bytes_sent_query_url(era); + let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + let bytes_sent = BytesSent::get_all(bytes_sent_res); + + let bytes_received_query = Self::get_bytes_received_query_url(era); + let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); + let bytes_received = BytesReceived::get_all(bytes_received_res); + + (bytes_sent_query, bytes_sent, bytes_received_query, bytes_received) +} + +fn get_bytes_received_query_url(era: EraIndex) -> String { + let data_provider_url = Self::get_data_provider_url(); + + match data_provider_url { + Some(url) => { + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); + }, + None => { + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); + }, + } +} + +fn http_get_json(url: &str) -> ResultStr { + let body = Self::http_get_request(url).map_err(|err| { + error!("[DAC Validator] Error while getting {}: {:?}", url, err); + "HTTP GET error" + })?; + + let parsed = serde_json::from_slice(&body).map_err(|err| { + warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); + "HTTP JSON parse error" + }); + + parsed +} + +fn http_get_request(http_url: &str) -> Result, http::Error> { + // info!("[DAC Validator] Sending request to: {:?}", http_url); + + // Initiate an external HTTP GET request. This is using high-level wrappers from + // `sp_runtime`. + let request = http::Request::get(http_url); + + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + + let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + + let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + + if response.code != 200 { + warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + + // Next we fully read the response body and collect it to a vector of bytes. + Ok(response.body().collect::>()) +} + +fn filter_data( + s: &Vec, + r: &Vec, + a: &T::AccountId, +) -> (BytesSent, BytesReceived) { + let ac = Self::account_to_string(a.clone()); + + let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); + let filtered_r = &*r.into_iter().find(|br| br.node_public_key == ac).unwrap(); + + (filtered_s.clone(), filtered_r.clone()) +} + +fn get_bytes_sent_query_url(era: EraIndex) -> String { + let data_provider_url = Self::get_data_provider_url(); + + match data_provider_url { + Some(url) => { + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); + }, + None => { + return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); + }, + } +} diff --git a/src/lib.rs b/src/lib.rs index 6f237ccd8..a4f3d5659 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,198 +100,6 @@ pub struct ValidationDecision { pub totals: DacTotalAggregates, } -#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct RedisFtAggregate { - #[serde(rename = "FT.AGGREGATE")] - pub ft_aggregate: Vec, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(crate = "alt_serde")] -#[serde(untagged)] -pub enum FtAggregate { - Length(u32), - Node(Vec), -} - -#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] -pub struct BytesSent { - node_public_key: String, - era: EraIndex, - sum: u32, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileRequestWrapper { - #[serde(rename = "JSON.GET")] - json: String, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileRequests { - requests: Requests, -} - -pub type Requests = BTreeMap; - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileRequest { - file_request_id: String, - file_info: FileInfo, - bucket_id: i64, - timestamp: i64, - chunks: BTreeMap, - user_public_key: String, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct Chunk { - log: Log, - cid: String, - ack: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct Ack { - bytes_received: i64, - user_timestamp: i64, - nonce: String, - node_public_key: String, - user_public_key: String, - signature: String, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct Log { - #[serde(rename = "type")] - log_type: i64, - session_id: String, - user_public_key: String, - era: i64, - user_address: String, - bytes_sent: i64, - timestamp: i64, - node_public_key: String, - signature: String, - bucket_id: i64, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileInfo { - #[serde(rename = "chunkCids")] - chunk_cids: Vec, - - #[serde(rename = "requestedChunkCids")] - requested_chunk_cids: Vec, -} - -impl BytesSent { - pub fn new(aggregate: RedisFtAggregate) -> BytesSent { - let data = aggregate.ft_aggregate[1].clone(); - - match data { - FtAggregate::Node(node) => - return BytesSent { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5].parse::().expect("bytesSentSum must be convertible to u32"), - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec![]; - for i in 1..aggregation.ft_aggregate.len() { - let data = aggregation.ft_aggregate[i].clone(); - match data { - FtAggregate::Node(node) => { - let node = BytesSent { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5] - .parse::() - .expect("bytesSentSum must be convertible to u32"), - }; - - res.push(node); - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - return res - } -} - -#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] -pub struct BytesReceived { - node_public_key: String, - era: EraIndex, - sum: u32, -} - -impl BytesReceived { - pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { - let data = aggregate.ft_aggregate[1].clone(); - - match data { - FtAggregate::Node(node) => - return BytesReceived { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5] - .parse::() - .expect("bytesReceivedSum must be convertible to u32"), - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec![]; - for i in 1..aggregation.ft_aggregate.len() { - let data = aggregation.ft_aggregate[i].clone(); - match data { - FtAggregate::Node(node) => { - let node = BytesReceived { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5] - .parse::() - .expect("bytesReceivedSum must be convertible to u32"), - }; - - res.push(node); - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - return res - } -} - pub mod crypto { use super::KEY_TYPE; use frame_system::offchain::AppCrypto; @@ -537,42 +345,6 @@ pub mod pallet { .unwrap() } - fn fetch_file_request() -> Requests { - let url = Self::get_file_request_url(); - - let response: FileRequestWrapper = Self::http_get_json(&url).unwrap(); - let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); - let map: Requests = serde_json::from_value(value).unwrap(); - - map - } - - fn get_file_request_url() -> String { - let data_provider_url = Self::get_data_provider_url(); - - let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url.unwrap()); - - res - } - - fn fetch_data(era: EraIndex, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { - info!("[DAC Validator] DAC Validator is running. Current era is {}", era); - // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era); - let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); - info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); - let bytes_sent = BytesSent::new(bytes_sent_res); - - // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era); - let bytes_received_res: RedisFtAggregate = - Self::http_get_json(&bytes_received_query).unwrap(); - info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); - let bytes_received = BytesReceived::new(bytes_received_res); - - (bytes_sent, bytes_received) - } - fn account_to_string(account: T::AccountId) -> String { let to32 = T::AccountId::encode(&account); let pub_key_str = array_bytes::bytes2hex("", to32); @@ -588,113 +360,6 @@ pub mod pallet { address } - fn filter_data( - s: &Vec, - r: &Vec, - a: &T::AccountId, - ) -> (BytesSent, BytesReceived) { - let ac = Self::account_to_string(a.clone()); - - let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); - let filtered_r = &*r.into_iter().find(|br| br.node_public_key == ac).unwrap(); - - (filtered_s.clone(), filtered_r.clone()) - } - - fn fetch_data1(era: EraIndex) -> (Vec, Vec) { - info!("[DAC Validator] DAC Validator is running. Current era is {}", era); - // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era); - let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); - info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); - let bytes_sent = BytesSent::get_all(bytes_sent_res); - - // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era); - let bytes_received_res: RedisFtAggregate = - Self::http_get_json(&bytes_received_query).unwrap(); - info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); - let bytes_received = BytesReceived::get_all(bytes_received_res); - - (bytes_sent, bytes_received) - } - - fn fetch_data2(era: EraIndex) -> (String, Vec, String, Vec) { - let bytes_sent_query = Self::get_bytes_sent_query_url(era); - let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); - let bytes_sent = BytesSent::get_all(bytes_sent_res); - - let bytes_received_query = Self::get_bytes_received_query_url(era); - let bytes_received_res: RedisFtAggregate = - Self::http_get_json(&bytes_received_query).unwrap(); - let bytes_received = BytesReceived::get_all(bytes_received_res); - - (bytes_sent_query, bytes_sent, bytes_received_query, bytes_received) - } - - fn get_bytes_sent_query_url(era: EraIndex) -> String { - let data_provider_url = Self::get_data_provider_url(); - - match data_provider_url { - Some(url) => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); - }, - None => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); - }, - } - } - - fn get_bytes_received_query_url(era: EraIndex) -> String { - let data_provider_url = Self::get_data_provider_url(); - - match data_provider_url { - Some(url) => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); - }, - None => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); - }, - } - } - - fn http_get_json(url: &str) -> ResultStr { - let body = Self::http_get_request(url).map_err(|err| { - error!("[DAC Validator] Error while getting {}: {:?}", url, err); - "HTTP GET error" - })?; - - let parsed = serde_json::from_slice(&body).map_err(|err| { - warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); - "HTTP JSON parse error" - }); - - parsed - } - - fn http_get_request(http_url: &str) -> Result, http::Error> { - // info!("[DAC Validator] Sending request to: {:?}", http_url); - - // Initiate an external HTTP GET request. This is using high-level wrappers from - // `sp_runtime`. - let request = http::Request::get(http_url); - - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - - let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - - let response = - pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - - if response.code != 200 { - warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - - // Next we fully read the response body and collect it to a vector of bytes. - Ok(response.body().collect::>()) - } - fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); From 47587227c3213e3e50b2f2c6363335711225a620 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 26 Apr 2023 19:12:06 +0600 Subject: [PATCH 105/544] Add DAC Validator utils module --- src/utils.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/utils.rs diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 000000000..5c8c5cf4f --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,18 @@ +use alloc::string::String; +use codec::{Decode, Encode}; +use sp_core::crypto::AccountId32; + +pub fn account_to_string(account: T::AccountId) -> String { + let to32 = T::AccountId::encode(&account); + let pub_key_str = array_bytes::bytes2hex("", to32); + + pub_key_str +} + +pub fn string_to_account(pub_key_str: String) -> T::AccountId { + let acc32: sp_core::crypto::AccountId32 = + array_bytes::hex2array::<_, 32>(pub_key_str).unwrap().into(); + let mut to32 = AccountId32::as_ref(&acc32); + let address: T::AccountId = T::AccountId::decode(&mut to32).unwrap(); + address +} From a2e6b918f80d1430e72bc353ba12c7f258a57c99 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 26 Apr 2023 19:13:49 +0600 Subject: [PATCH 106/544] Fix dac module usage in ddc-validator crate --- src/dac.rs | 106 +++++++++++++++++++++++++---------------------------- src/lib.rs | 53 ++++++++++----------------- 2 files changed, 69 insertions(+), 90 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 20f94ac65..32d1fd793 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -1,11 +1,17 @@ //! A module with Data Activity Capture (DAC) interaction. -use crate::*; +use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; +use frame_support::log::{error, info, warn}; use serde_json::Value; +use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; -use sp_std::collections::btree_map::BTreeMap; +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; + +use crate::utils; + +pub const HTTP_TIMEOUT_MS: u64 = 30_000; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(crate = "alt_serde")] @@ -27,7 +33,7 @@ pub enum FtAggregate { pub struct BytesSent { node_public_key: String, era: EraIndex, - sum: u32, + pub sum: u32, } #[derive(Serialize, Deserialize, Debug)] @@ -153,7 +159,7 @@ impl BytesSent { pub struct BytesReceived { node_public_key: String, era: EraIndex, - sum: u32, + pub sum: u32, } impl BytesReceived { @@ -199,85 +205,82 @@ impl BytesReceived { } } -fn fetch_file_request() -> Requests { - let url = Self::get_file_request_url(); +fn get_file_request_url(data_provider_url: &String) -> String { + let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url); + + res +} - let response: FileRequestWrapper = Self::http_get_json(&url).unwrap(); +pub(crate) fn fetch_file_request(url: &String) -> Requests { + let response: FileRequestWrapper = http_get_json(&url).unwrap(); let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); let map: Requests = serde_json::from_value(value).unwrap(); map } -fn get_file_request_url() -> String { - let data_provider_url = Self::get_data_provider_url(); - - let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url.unwrap()); - - res -} - -fn fetch_data(era: EraIndex, cdn_node: &T::AccountId) -> (BytesSent, BytesReceived) { +pub(crate) fn fetch_data( + data_provider_url: &String, + era: EraIndex, + cdn_node: &T::AccountId, +) -> (BytesSent, BytesReceived) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era); - let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); + let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era); - let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); + let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); + let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::new(bytes_received_res); (bytes_sent, bytes_received) } -fn fetch_data1(era: EraIndex) -> (Vec, Vec) { +pub(crate) fn fetch_data1( + data_provider_url: &String, + era: EraIndex, +) -> (Vec, Vec) { info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error - let bytes_sent_query = Self::get_bytes_sent_query_url(era); - let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); + let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); + let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::get_all(bytes_sent_res); // Todo: handle the error - let bytes_received_query = Self::get_bytes_received_query_url(era); - let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); + let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); + let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::get_all(bytes_received_res); (bytes_sent, bytes_received) } -fn fetch_data2(era: EraIndex) -> (String, Vec, String, Vec) { - let bytes_sent_query = Self::get_bytes_sent_query_url(era); - let bytes_sent_res: RedisFtAggregate = Self::http_get_json(&bytes_sent_query).unwrap(); +pub(crate) fn fetch_data2( + data_provider_url: &String, + era: EraIndex, +) -> (String, Vec, String, Vec) { + let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); + let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); let bytes_sent = BytesSent::get_all(bytes_sent_res); - let bytes_received_query = Self::get_bytes_received_query_url(era); - let bytes_received_res: RedisFtAggregate = Self::http_get_json(&bytes_received_query).unwrap(); + let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); + let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); let bytes_received = BytesReceived::get_all(bytes_received_res); (bytes_sent_query, bytes_sent, bytes_received_query, bytes_received) } -fn get_bytes_received_query_url(era: EraIndex) -> String { - let data_provider_url = Self::get_data_provider_url(); - - match data_provider_url { - Some(url) => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", url, era, era); - }, - None => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", DEFAULT_DATA_PROVIDER_URL, era, era); - }, - } +fn get_bytes_received_query_url(data_provider_url: &String, era: EraIndex) -> String { + format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", data_provider_url, era, era) } -fn http_get_json(url: &str) -> ResultStr { - let body = Self::http_get_request(url).map_err(|err| { +fn http_get_json(url: &str) -> crate::ResultStr { + let body = http_get_request(url).map_err(|err| { error!("[DAC Validator] Error while getting {}: {:?}", url, err); "HTTP GET error" })?; @@ -312,12 +315,12 @@ fn http_get_request(http_url: &str) -> Result, http::Error> { Ok(response.body().collect::>()) } -fn filter_data( +fn filter_data( s: &Vec, r: &Vec, a: &T::AccountId, ) -> (BytesSent, BytesReceived) { - let ac = Self::account_to_string(a.clone()); + let ac = utils::account_to_string::(a.clone()); let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); let filtered_r = &*r.into_iter().find(|br| br.node_public_key == ac).unwrap(); @@ -325,15 +328,6 @@ fn filter_data( (filtered_s.clone(), filtered_r.clone()) } -fn get_bytes_sent_query_url(era: EraIndex) -> String { - let data_provider_url = Self::get_data_provider_url(); - - match data_provider_url { - Some(url) => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", url, era, era); - }, - None => { - return format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", DEFAULT_DATA_PROVIDER_URL, era, era); - }, - } +fn get_bytes_sent_query_url(data_provider_url: &String, era: EraIndex) -> String { + format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", data_provider_url, era, era) } diff --git a/src/lib.rs b/src/lib.rs index a4f3d5659..cefd0da33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ #![cfg_attr(not(feature = "std"), no_std)] mod dac; +mod utils; mod validation; #[cfg(test)] @@ -66,15 +67,13 @@ type ResultStr = Result; pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); -pub const HTTP_TIMEOUT_MS: u64 = 30_000; - -const TIME_START_MS: u128 = 1_672_531_200_000; -const ERA_DURATION_MS: u128 = 120_000; -const ERA_IN_BLOCKS: u8 = 20; +pub const TIME_START_MS: u128 = 1_672_531_200_000; +pub const ERA_DURATION_MS: u128 = 120_000; +pub const ERA_IN_BLOCKS: u8 = 20; /// Webdis in experimental cluster connected to Redis in dev. -const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; -const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; +pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; /// Aggregated values from DAC that describe CDN node's activity during a certain era. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] @@ -238,14 +237,12 @@ pub mod pallet { return } - let file_request = Self::fetch_file_request(); - // info!("fileRequest: {:?}", file_request); + let data_provider_url = + Self::get_data_provider_url().unwrap_or(String::from(DEFAULT_DATA_PROVIDER_URL)); + info!("[DAC Validator] data provider url: {:?}", &data_provider_url,); - let data_provider_url = Self::get_data_provider_url(); - info!( - "[DAC Validator] data provider url: {:?}", - data_provider_url.unwrap_or(String::from("not configured")) - ); + let file_request = dac::fetch_file_request(&data_provider_url); + // info!("fileRequest: {:?}", file_request); // Wait for signal. let signal = Signal::::get().unwrap_or(false); @@ -256,7 +253,8 @@ pub mod pallet { // Read from DAC. let current_era = Self::get_current_era(); - let (sent_query, sent, received_query, received) = Self::fetch_data2(current_era - 1); + let (sent_query, sent, received_query, received) = + dac::fetch_data2(&data_provider_url, current_era - 1); log::info!( "🔎 DAC Validator is fetching data from DAC, current era: {:?}, bytes sent query: {:?}, bytes sent response: {:?}, bytes received query: {:?}, bytes received response: {:?}", current_era, @@ -345,22 +343,7 @@ pub mod pallet { .unwrap() } - fn account_to_string(account: T::AccountId) -> String { - let to32 = T::AccountId::encode(&account); - let pub_key_str = array_bytes::bytes2hex("", to32); - - pub_key_str - } - - fn string_to_account(pub_key_str: String) -> T::AccountId { - let acc32: sp_core::crypto::AccountId32 = - array_bytes::hex2array::<_, 32>(pub_key_str).unwrap().into(); - let mut to32 = AccountId32::as_ref(&acc32); - let address: T::AccountId = T::AccountId::decode(&mut to32).unwrap(); - address - } - - fn validate(bytes_sent: BytesSent, bytes_received: BytesReceived) -> bool { + fn validate(bytes_sent: dac::BytesSent, bytes_received: dac::BytesReceived) -> bool { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); return if percentage_difference > 0.0 && @@ -397,8 +380,10 @@ pub mod pallet { let shuffled_validators = Self::shuffle(validators); let shuffled_edges = Self::shuffle(edges); - let validators_keys: Vec = - shuffled_validators.iter().map(|v| Self::account_to_string(v.clone())).collect(); + let validators_keys: Vec = shuffled_validators + .iter() + .map(|v| utils::account_to_string::(v.clone())) + .collect(); let quorums = Self::split(validators_keys, quorum_size); let edges_groups = Self::split(shuffled_edges, quorums.len()); @@ -410,7 +395,7 @@ pub mod pallet { for validator in quorum { Assignments::::insert( era, - Self::string_to_account(validator.clone()), + utils::string_to_account::(validator.clone()), edges_group, ); } From 1c0abec2491e00af8be00fa152edf5a8ca84ecb8 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 27 Apr 2023 19:09:16 +0600 Subject: [PATCH 107/544] Use log crate directly --- src/dac.rs | 21 ++++++++++----------- src/lib.rs | 11 +++++------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 32d1fd793..a6e450219 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -3,7 +3,6 @@ use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; -use frame_support::log::{error, info, warn}; use serde_json::Value; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; @@ -224,17 +223,17 @@ pub(crate) fn fetch_data( era: EraIndex, cdn_node: &T::AccountId, ) -> (BytesSent, BytesReceived) { - info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + log::info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); - info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + log::info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); - info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + log::info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::new(bytes_received_res); (bytes_sent, bytes_received) @@ -244,17 +243,17 @@ pub(crate) fn fetch_data1( data_provider_url: &String, era: EraIndex, ) -> (Vec, Vec) { - info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + log::info!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); - info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + log::info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::get_all(bytes_sent_res); // Todo: handle the error let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); - info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + log::info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::get_all(bytes_received_res); (bytes_sent, bytes_received) @@ -281,12 +280,12 @@ fn get_bytes_received_query_url(data_provider_url: &String, era: EraIndex) -> St fn http_get_json(url: &str) -> crate::ResultStr { let body = http_get_request(url).map_err(|err| { - error!("[DAC Validator] Error while getting {}: {:?}", url, err); + log::error!("[DAC Validator] Error while getting {}: {:?}", url, err); "HTTP GET error" })?; let parsed = serde_json::from_slice(&body).map_err(|err| { - warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); + log::warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); "HTTP JSON parse error" }); @@ -294,7 +293,7 @@ fn http_get_json(url: &str) -> crate::ResultStr { } fn http_get_request(http_url: &str) -> Result, http::Error> { - // info!("[DAC Validator] Sending request to: {:?}", http_url); + // log::info!("[DAC Validator] Sending request to: {:?}", http_url); // Initiate an external HTTP GET request. This is using high-level wrappers from // `sp_runtime`. @@ -307,7 +306,7 @@ fn http_get_request(http_url: &str) -> Result, http::Error> { let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; if response.code != 200 { - warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); + log::warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); return Err(http::Error::Unknown) } diff --git a/src/lib.rs b/src/lib.rs index cefd0da33..78fd8ffe9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,6 @@ pub use core::fmt::Debug; pub use frame_support::{ decl_event, decl_module, decl_storage, dispatch::DispatchResult, - log::{error, info, warn}, pallet_prelude::*, parameter_types, storage, traits::{Currency, Randomness, UnixTime}, @@ -216,10 +215,10 @@ pub mod pallet { } let era = Self::get_current_era(); - info!("current era: {:?}", era); + log::info!("current era: {:?}", era); if let Some(last_managed_era) = >::get() { - info!("last_managed_era: {:?}", last_managed_era); + log::info!("last_managed_era: {:?}", last_managed_era); if last_managed_era >= era { return 0 } @@ -239,10 +238,10 @@ pub mod pallet { let data_provider_url = Self::get_data_provider_url().unwrap_or(String::from(DEFAULT_DATA_PROVIDER_URL)); - info!("[DAC Validator] data provider url: {:?}", &data_provider_url,); + log::info!("[DAC Validator] data provider url: {:?}", &data_provider_url); let file_request = dac::fetch_file_request(&data_provider_url); - // info!("fileRequest: {:?}", file_request); + // log::info!("fileRequest: {:?}", file_request); // Wait for signal. let signal = Signal::::get().unwrap_or(false); @@ -320,7 +319,7 @@ pub mod pallet { None => { let url_key = String::from_utf8(DATA_PROVIDER_URL_KEY.to_vec()).unwrap(); let msg = format!("[DAC Validator] Data provider URL is not configured. Please configure it using offchain_localStorageSet with key {:?}. Using default for now.", url_key); - warn!("{}", msg); + log::warn!("{}", msg); Some(String::from(DEFAULT_DATA_PROVIDER_URL)) }, Some(url) => Some(String::from_utf8(url).unwrap()), From 0f29c1cff27f87785e5ff2d71f8ee462cd6b2b92 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 27 Apr 2023 15:16:36 +0200 Subject: [PATCH 108/544] Implement bytes aggregation --- src/dac.rs | 98 ++++++++++++++++++++++++++++++++++++++++++++++++------ src/lib.rs | 8 +++-- 2 files changed, 94 insertions(+), 12 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index a6e450219..b3bfc8af2 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -6,10 +6,18 @@ use codec::{Decode, Encode}; use serde_json::Value; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +pub use sp_std::{ + collections::{ + btree_map::BTreeMap, + btree_set::BTreeSet, + }, + prelude::* +}; + use crate::utils; +pub type TimestampInSec = u64; pub const HTTP_TIMEOUT_MS: u64 = 30_000; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -58,8 +66,8 @@ pub type Requests = BTreeMap; pub struct FileRequest { file_request_id: String, file_info: FileInfo, - bucket_id: i64, - timestamp: i64, + bucket_id: u64, + timestamp: u64, chunks: BTreeMap, user_public_key: String, } @@ -77,8 +85,8 @@ pub struct Chunk { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Ack { - bytes_received: i64, - user_timestamp: i64, + bytes_received: u64, + user_timestamp: u64, nonce: String, node_public_key: String, user_public_key: String, @@ -90,16 +98,16 @@ pub struct Ack { #[serde(rename_all = "camelCase")] pub struct Log { #[serde(rename = "type")] - log_type: i64, + log_type: u64, session_id: String, user_public_key: String, - era: i64, + era: u64, user_address: String, - bytes_sent: i64, - timestamp: i64, + bytes_sent: u64, + timestamp: u64, node_public_key: String, signature: String, - bucket_id: i64, + bucket_id: u64, } #[derive(Serialize, Deserialize, Debug)] @@ -204,6 +212,76 @@ impl BytesReceived { } } +fn get_timestamps_with_ack(file_requests: &FileRequests) -> Vec { + let mut timestamps:Vec = Vec::new(); + + for (_, file_request) in &file_requests.requests { + for (_, chunk) in &file_request.chunks { + if let Some(ack) = &chunk.ack { + timestamps.push(chunk.log.timestamp); + } + } + } + + timestamps.sort(); + + timestamps +} + +pub fn get_proved_deliveried_bytes_sum(file_requests: &FileRequests) -> u64 { + let ack_timestamps= get_timestamps_with_ack(file_requests); + let mut total_bytes_received = 0u64; + + for (_, file_request) in &file_requests.requests { + for (_, chunk) in &file_request.chunks { + if let Some(ack) = &chunk.ack { + total_bytes_received += ack.bytes_received; + } else { + total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + } + } + } + + total_bytes_received +} + +fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> u64 { + let log_timestamp = chunk.log.timestamp; + let neighbors = get_closer_neighbors(log_timestamp, &ack_timestamps); + let is_proved = is_lies_within_threshold(log_timestamp, neighbors, 42); + + if is_proved { + return chunk.log.bytes_sent; + } else { + 0 + } +} + +fn get_closer_neighbors(timestamp: TimestampInSec, timestamps: &Vec) -> (TimestampInSec, TimestampInSec) { + let mut before = 0; + let mut after = TimestampInSec::MAX; + for ts in timestamps { + if ts < ×tamp { + before = before.max(*ts); + } else if ts > ×tamp { + after = after.min(*ts); + } + } + + (before, after) +} + +fn is_lies_within_threshold(timestamp: TimestampInSec, borders: (TimestampInSec, TimestampInSec), threshold: TimestampInSec) -> bool { + let left_distance = timestamp - borders.0; + let right_distance = borders.1 - timestamp; + + if left_distance < threshold || right_distance < threshold { + return true; + } + + false +} + fn get_file_request_url(data_provider_url: &String) -> String { let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url); diff --git a/src/lib.rs b/src/lib.rs index 78fd8ffe9..b075b5eca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,12 @@ pub use sp_core::crypto::{AccountId32, KeyTypeId, UncheckedFrom}; pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; pub use sp_staking::EraIndex; -pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +pub use sp_std::{ + collections::{ + btree_map::BTreeMap, + }, + prelude::* +}; extern crate alloc; @@ -241,7 +246,6 @@ pub mod pallet { log::info!("[DAC Validator] data provider url: {:?}", &data_provider_url); let file_request = dac::fetch_file_request(&data_provider_url); - // log::info!("fileRequest: {:?}", file_request); // Wait for signal. let signal = Signal::::get().unwrap_or(false); From 11c219cc2577f3e9c4cba2b27206eca6254d946d Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 27 Apr 2023 20:02:17 +0200 Subject: [PATCH 109/544] Clean up code --- src/dac.rs | 8 ++++---- src/lib.rs | 34 ++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index b3bfc8af2..dc160db84 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -212,10 +212,10 @@ impl BytesReceived { } } -fn get_timestamps_with_ack(file_requests: &FileRequests) -> Vec { +fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { let mut timestamps:Vec = Vec::new(); - for (_, file_request) in &file_requests.requests { + for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { if let Some(ack) = &chunk.ack { timestamps.push(chunk.log.timestamp); @@ -228,11 +228,11 @@ fn get_timestamps_with_ack(file_requests: &FileRequests) -> Vec timestamps } -pub fn get_proved_deliveried_bytes_sum(file_requests: &FileRequests) -> u64 { +pub fn get_proved_deliveried_bytes_sum(file_requests: &Requests) -> u64 { let ack_timestamps= get_timestamps_with_ack(file_requests); let mut total_bytes_received = 0u64; - for (_, file_request) in &file_requests.requests { + for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { if let Some(ack) = &chunk.ack { total_bytes_received += ack.bytes_received; diff --git a/src/lib.rs b/src/lib.rs index b075b5eca..6848ad3e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,6 +76,7 @@ pub const ERA_DURATION_MS: u128 = 120_000; pub const ERA_IN_BLOCKS: u8 = 20; /// Webdis in experimental cluster connected to Redis in dev. +// pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; @@ -201,6 +202,11 @@ pub mod pallet { #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, EraIndex>; + #[pallet::error] + pub enum Error { + // TBA + } + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event @@ -241,11 +247,14 @@ pub mod pallet { return } - let data_provider_url = - Self::get_data_provider_url().unwrap_or(String::from(DEFAULT_DATA_PROVIDER_URL)); - log::info!("[DAC Validator] data provider url: {:?}", &data_provider_url); + let data_provider_url = Self::get_data_provider_url(); + info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); + + let mock_data_url = Self::get_mock_data_url(); - let file_request = dac::fetch_file_request(&data_provider_url); + let file_request = dac::fetch_file_request(&mock_data_url); + let bytes_sum = dac::get_proved_deliveried_bytes_sum(&file_request); + info!("Proved bytes sum: {:?}", bytes_sum); // Wait for signal. let signal = Signal::::get().unwrap_or(false); @@ -313,23 +322,28 @@ pub mod pallet { ::AccountId: AsRef<[u8]> + UncheckedFrom, as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { - fn get_data_provider_url() -> Option { + fn get_data_provider_url() -> String { let url_ref = sp_io::offchain::local_storage_get( sp_core::offchain::StorageKind::PERSISTENT, DATA_PROVIDER_URL_KEY, ); match url_ref { + Some(url) => String::from_utf8(url).expect("Data provider URL should be valid UTF-8 string"), None => { - let url_key = String::from_utf8(DATA_PROVIDER_URL_KEY.to_vec()).unwrap(); - let msg = format!("[DAC Validator] Data provider URL is not configured. Please configure it using offchain_localStorageSet with key {:?}. Using default for now.", url_key); - log::warn!("{}", msg); - Some(String::from(DEFAULT_DATA_PROVIDER_URL)) + String::from(DEFAULT_DATA_PROVIDER_URL) }, - Some(url) => Some(String::from_utf8(url).unwrap()), } } + fn get_mock_data_url() -> String { + let data_url = Self::get_data_provider_url(); + let mock_url = "/JSON.GET/testddc:dac:data/INDENT/0"; + let url = format!("{}{}", data_url, mock_url); + + url + } + fn get_signer() -> ResultStr> { let signer = Signer::<_, _>::any_account(); if !signer.can_sign() { From 1f458ae8a702e9cce9fd54b80dcddf07c78458cc Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 28 Apr 2023 13:18:40 +0200 Subject: [PATCH 110/544] Fix mock data url --- src/dac.rs | 4 ++-- src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index dc160db84..11c8c8802 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -228,14 +228,14 @@ fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { timestamps } -pub fn get_proved_deliveried_bytes_sum(file_requests: &Requests) -> u64 { +pub fn get_proved_delivered_bytes_sum(file_requests: &Requests) -> u64 { let ack_timestamps= get_timestamps_with_ack(file_requests); let mut total_bytes_received = 0u64; for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { if let Some(ack) = &chunk.ack { - total_bytes_received += ack.bytes_received; + total_bytes_received += &chunk.log.bytes_sent; } else { total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); } diff --git a/src/lib.rs b/src/lib.rs index 6848ad3e1..51aa4ac88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -253,7 +253,7 @@ pub mod pallet { let mock_data_url = Self::get_mock_data_url(); let file_request = dac::fetch_file_request(&mock_data_url); - let bytes_sum = dac::get_proved_deliveried_bytes_sum(&file_request); + let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); info!("Proved bytes sum: {:?}", bytes_sum); // Wait for signal. @@ -338,7 +338,7 @@ pub mod pallet { fn get_mock_data_url() -> String { let data_url = Self::get_data_provider_url(); - let mock_url = "/JSON.GET/testddc:dac:data/INDENT/0"; + let mock_url = "/JSON.GET/testddc:dac:data"; let url = format!("{}{}", data_url, mock_url); url From 652fd81dd0f40a078120cc874fe62839f8f3a3fc Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 28 Apr 2023 13:29:03 +0200 Subject: [PATCH 111/544] Fix info macro --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 51aa4ac88..40d52dcd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,13 +248,13 @@ pub mod pallet { } let data_provider_url = Self::get_data_provider_url(); - info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); + log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); let mock_data_url = Self::get_mock_data_url(); let file_request = dac::fetch_file_request(&mock_data_url); let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); - info!("Proved bytes sum: {:?}", bytes_sum); + log::info!("Proved bytes sum: {:?}", bytes_sum); // Wait for signal. let signal = Signal::::get().unwrap_or(false); From f5bb023ef7594caa10315ab70c6536e9f173880b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 28 Apr 2023 19:48:28 +0600 Subject: [PATCH 112/544] DAC aggregates reading function --- Cargo.toml | 2 ++ src/dac.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ff6dbd53b..0657d768f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../su frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" } log = { version = "0.4.17", default-features = false } +lite-json = { version = "0.2.0", default-features = false } pallet-contracts = { version = '4.0.0-dev', default-features = false, path = "../contracts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } pallet-session = { version = "4.0.0-dev", path = "../session", default-features = false } @@ -32,6 +33,7 @@ std = [ "frame-support/std", "frame-system/std", "frame-election-provider-support/std", + "lite-json/std", "pallet-contracts/std", "pallet-ddc-staking/std", "pallet-session/std", diff --git a/src/dac.rs b/src/dac.rs index 11c8c8802..2ab312b14 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -3,6 +3,7 @@ use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; +use lite_json::json::JsonValue; use serde_json::Value; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; @@ -408,3 +409,29 @@ fn filter_data( fn get_bytes_sent_query_url(data_provider_url: &String, era: EraIndex) -> String { format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", data_provider_url, era, era) } + +pub(crate) fn fetch_aggregates( + data_provider_url: &String, + era: EraIndex, +) -> Result { + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + let url = + format!("{}/JSON.GET/ddc:dac:aggregation:nodes:{}?type=query", data_provider_url, era); + let request = http::Request::get(url.as_str()); + let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + if response.code != 200 { + log::warn!("Unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + let body = response.body().collect::>(); + let body_str = sp_std::str::from_utf8(&body).map_err(|_| { + log::warn!("No UTF-8 body"); + http::Error::Unknown + })?; + let json = lite_json::parse_json(body_str).map_err(|_| { + log::warn!("No JSON body"); + http::Error::Unknown + })?; + Ok(json) +} From 4fa175b2e2f2973e47f489762b503b8377009114 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 28 Apr 2023 19:50:11 +0600 Subject: [PATCH 113/544] Print the number of broken sessions by CDN node --- src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 40d52dcd8..0661efb66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,7 @@ pub use frame_system::{ offchain::{AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes}, pallet_prelude::*, }; +pub use lite_json::json::JsonValue; pub use pallet::*; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_session as session; @@ -256,6 +257,34 @@ pub mod pallet { let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); log::info!("Proved bytes sum: {:?}", bytes_sum); + // Print the number of broken sessions per CDN node. + let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data + let aggregates_obj = aggregates_value.as_object().unwrap(); + aggregates_obj + .into_iter() + .for_each(|(cdn_node_pubkey, cdn_node_aggregates_value)| { + // iterate over aggregates for each node + let cdn_node_aggregates_obj = cdn_node_aggregates_value.as_object().unwrap(); + // Extract `nodeInterruptedSessions` field + let (_, cdn_node_interrupted_sessions_value) = cdn_node_aggregates_obj + .into_iter() + .find(|(key, _)| key.iter().copied().eq("nodeInterruptedSessions".chars())) + .unwrap(); + let cdn_node_interrupted_sessions_obj = + cdn_node_interrupted_sessions_value.as_object().unwrap(); + // Prepare CDN pubkey without heap allocated string + let cdn_node_pubkey_vecu8: Vec = + cdn_node_pubkey.iter().map(|c| *c as u8).collect(); + let cdn_node_pubkey_str = + sp_std::str::from_utf8(&cdn_node_pubkey_vecu8).unwrap(); + log::info!( + "Broken sessions per CDN node | Node {}: {} sessions broken", + cdn_node_pubkey_str, + cdn_node_interrupted_sessions_obj.len(), /* count sessions broken by the + * node */ + ); + }); + // Wait for signal. let signal = Signal::::get().unwrap_or(false); if !signal { From c2e46564f50b50f3810cb86e366586e8c5d0182f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 28 Apr 2023 19:51:25 +0600 Subject: [PATCH 114/544] Autoformat DAC Validator files --- Cargo.toml | 2 +- src/dac.rs | 27 +++++++++++++++------------ src/lib.rs | 14 ++++---------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0657d768f..66b8deec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,4 +52,4 @@ std = [ pallet-balances = { version = "4.0.0-dev", path = "../balances" } pallet-randomness-collective-flip = { version = "4.0.0-dev", path = "../randomness-collective-flip" } pallet-timestamp = { version = "4.0.0-dev", path = "../timestamp" } -pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" } \ No newline at end of file +pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" } diff --git a/src/dac.rs b/src/dac.rs index 2ab312b14..9f0c0f5ac 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -8,14 +8,10 @@ use serde_json::Value; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; pub use sp_std::{ - collections::{ - btree_map::BTreeMap, - btree_set::BTreeSet, - }, - prelude::* + collections::{btree_map::BTreeMap, btree_set::BTreeSet}, + prelude::*, }; - use crate::utils; pub type TimestampInSec = u64; @@ -214,7 +210,7 @@ impl BytesReceived { } fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { - let mut timestamps:Vec = Vec::new(); + let mut timestamps: Vec = Vec::new(); for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { @@ -230,7 +226,7 @@ fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { } pub fn get_proved_delivered_bytes_sum(file_requests: &Requests) -> u64 { - let ack_timestamps= get_timestamps_with_ack(file_requests); + let ack_timestamps = get_timestamps_with_ack(file_requests); let mut total_bytes_received = 0u64; for (_, file_request) in file_requests { @@ -252,13 +248,16 @@ fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> (TimestampInSec, TimestampInSec) { +fn get_closer_neighbors( + timestamp: TimestampInSec, + timestamps: &Vec, +) -> (TimestampInSec, TimestampInSec) { let mut before = 0; let mut after = TimestampInSec::MAX; for ts in timestamps { @@ -272,12 +271,16 @@ fn get_closer_neighbors(timestamp: TimestampInSec, timestamps: &Vec bool { +fn is_lies_within_threshold( + timestamp: TimestampInSec, + borders: (TimestampInSec, TimestampInSec), + threshold: TimestampInSec, +) -> bool { let left_distance = timestamp - borders.0; let right_distance = borders.1 - timestamp; if left_distance < threshold || right_distance < threshold { - return true; + return true } false diff --git a/src/lib.rs b/src/lib.rs index 0661efb66..0aeaf7778 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,12 +54,7 @@ pub use sp_core::crypto::{AccountId32, KeyTypeId, UncheckedFrom}; pub use sp_io::crypto::sr25519_public_keys; pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; pub use sp_staking::EraIndex; -pub use sp_std::{ - collections::{ - btree_map::BTreeMap, - }, - prelude::* -}; +pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; extern crate alloc; @@ -358,10 +353,9 @@ pub mod pallet { ); match url_ref { - Some(url) => String::from_utf8(url).expect("Data provider URL should be valid UTF-8 string"), - None => { - String::from(DEFAULT_DATA_PROVIDER_URL) - }, + Some(url) => + String::from_utf8(url).expect("Data provider URL should be valid UTF-8 string"), + None => String::from(DEFAULT_DATA_PROVIDER_URL), } } From 33651929b3dfd89e4aad3bebe2ff862b98b7652d Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 28 Apr 2023 16:45:59 +0200 Subject: [PATCH 115/544] Add const for threshold configuration --- src/dac.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dac.rs b/src/dac.rs index 9f0c0f5ac..52497eed5 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -16,6 +16,7 @@ use crate::utils; pub type TimestampInSec = u64; pub const HTTP_TIMEOUT_MS: u64 = 30_000; +pub const FAILED_CONTENT_CONSUMER_THRESHOLD: TimestampInSec = 100; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(crate = "alt_serde")] @@ -245,7 +246,7 @@ pub fn get_proved_delivered_bytes_sum(file_requests: &Requests) -> u64 { fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> u64 { let log_timestamp = chunk.log.timestamp; let neighbors = get_closer_neighbors(log_timestamp, &ack_timestamps); - let is_proved = is_lies_within_threshold(log_timestamp, neighbors, 42); + let is_proved = is_lies_within_threshold(log_timestamp, neighbors, FAILED_CONTENT_CONSUMER_THRESHOLD); if is_proved { return chunk.log.bytes_sent From 6298c5d091127f1e1a81ec1cd95b3d80b3d17363 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 3 May 2023 13:52:53 +0600 Subject: [PATCH 116/544] DAC Validators' "shared memory" module --- src/lib.rs | 1 + src/shm.rs | 1 + 2 files changed, 2 insertions(+) create mode 100644 src/shm.rs diff --git a/src/lib.rs b/src/lib.rs index 0aeaf7778..e0c481342 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ #![cfg_attr(not(feature = "std"), no_std)] mod dac; +mod shm; mod utils; mod validation; diff --git a/src/shm.rs b/src/shm.rs new file mode 100644 index 000000000..baad0fa83 --- /dev/null +++ b/src/shm.rs @@ -0,0 +1 @@ +//! Validators' "shared memory" module. From f18fe685685896d8421bfb6ef6aac61847057034 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 4 May 2023 15:27:37 +0600 Subject: [PATCH 117/544] Borrow DAC data for validation, remove ownership --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e0c481342..11a082deb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -384,7 +384,7 @@ pub mod pallet { .unwrap() } - fn validate(bytes_sent: dac::BytesSent, bytes_received: dac::BytesReceived) -> bool { + fn validate(bytes_sent: &dac::BytesSent, bytes_received: &dac::BytesReceived) -> bool { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); return if percentage_difference > 0.0 && From c6007274ea8c4278d7212b9161cd6273e9d7adb1 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 4 May 2023 17:53:48 +0600 Subject: [PATCH 118/544] Make all DAC data types fields public --- src/dac.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 52497eed5..2bf6cde85 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -36,8 +36,8 @@ pub enum FtAggregate { #[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] pub struct BytesSent { - node_public_key: String, - era: EraIndex, + pub node_public_key: String, + pub era: EraIndex, pub sum: u32, } @@ -162,8 +162,8 @@ impl BytesSent { #[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] pub struct BytesReceived { - node_public_key: String, - era: EraIndex, + pub node_public_key: String, + pub era: EraIndex, pub sum: u32, } From 247995397be2d105e1a21a3ce24b9a2b2b18acf0 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 4 May 2023 17:56:38 +0600 Subject: [PATCH 119/544] Create intermediate validation decisions --- src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 11a082deb..a6381e401 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -300,6 +300,45 @@ pub mod pallet { received_query, received, ); + + // Create intermediate validation decisions + // ======================================== + + // All validators validate all CDN nodes. + let edges: Vec = >::iter_keys().collect(); + for edge in edges.iter() { + // Get string type CDN node pubkey + let edge_pubkey: String = utils::account_to_string::(edge.clone()); + + // Get bytes sent and received for the CDN node + let Some(node_sent) = sent + .iter() + .find(|bytes_sent| bytes_sent.node_public_key == edge_pubkey) else { + log::warn!("No logs to validate {:?}", edge); + continue + }; + let Some(client_received) = received + .iter() + .find(|bytes_received| bytes_received.node_public_key == edge_pubkey) else { + log::warn!("No acks to validate {:?}", edge); + continue + }; + + // Proof-of-delivery validation + let validation_result = Self::validate(node_sent, client_received); + + // Prepare an intermediate validation decision + let _validation_decision = ValidationDecision { + result: validation_result, + payload: [0u8; 256], // ToDo: put a hash of the validated data here + totals: DacTotalAggregates { + sent: node_sent.sum as u64, + received: client_received.sum as u64, + failed_by_client: 0, // ToDo + failure_rate: 0, // ToDo + }, + }; + } } } From 2689bff4cd668fe7bb2ef7de98fb20c04625ee6f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 4 May 2023 18:54:53 +0600 Subject: [PATCH 120/544] Remove let...else unstable feature usage --- src/lib.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a6381e401..391804e9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -311,18 +311,26 @@ pub mod pallet { let edge_pubkey: String = utils::account_to_string::(edge.clone()); // Get bytes sent and received for the CDN node - let Some(node_sent) = sent + let node_sent: &dac::BytesSent = match sent .iter() - .find(|bytes_sent| bytes_sent.node_public_key == edge_pubkey) else { + .find(|bytes_sent| bytes_sent.node_public_key == edge_pubkey) + { + Some(node_sent) => node_sent, + None => { log::warn!("No logs to validate {:?}", edge); continue - }; - let Some(client_received) = received + }, + }; + let client_received: &dac::BytesReceived = match received .iter() - .find(|bytes_received| bytes_received.node_public_key == edge_pubkey) else { + .find(|bytes_received| bytes_received.node_public_key == edge_pubkey) + { + Some(client_received) => client_received, + None => { log::warn!("No acks to validate {:?}", edge); continue - }; + }, + }; // Proof-of-delivery validation let validation_result = Self::validate(node_sent, client_received); From bf748db920f2be6107a47aef16e26493891354a4 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 5 May 2023 18:34:18 +0600 Subject: [PATCH 121/544] Base64 encoding func for validators' shared memory --- Cargo.toml | 1 + src/shm.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 66b8deec8..7e2d7f563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] array-bytes = "6.0.0" alt_serde = { version = "1", default-features = false, features = ["derive"] } +base64 = { version = "0.21.0", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } diff --git a/src/shm.rs b/src/shm.rs index baad0fa83..ab8698d0d 100644 --- a/src/shm.rs +++ b/src/shm.rs @@ -1 +1,12 @@ //! Validators' "shared memory" module. + +use base64::prelude::*; +use sp_std::prelude::*; + +/// Encodes a vector of bytes into a vector of characters using base64 encoding. +pub fn base64_encode(input: &Vec) -> Vec { + let mut buf = Vec::with_capacity(1024); // ToDo: calculate capacity + buf.resize(1024, 0); + BASE64_STANDARD.encode_slice(input, &mut buf).unwrap(); // ToDo: handle error + buf.iter().map(|&byte| byte as char).collect() +} From e93cad5f2946ce0dfe4bc2837628897eed15ab48 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 5 May 2023 19:51:00 +0600 Subject: [PATCH 122/544] A func to publish intermediate validation result --- src/shm.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/shm.rs b/src/shm.rs index ab8698d0d..6ae033e77 100644 --- a/src/shm.rs +++ b/src/shm.rs @@ -1,8 +1,14 @@ //! Validators' "shared memory" module. +use alloc::{format, string::String}; // ToDo: remove String usage use base64::prelude::*; +use lite_json::json::JsonValue; +use sp_runtime::offchain::{http, Duration}; +use sp_staking::EraIndex; use sp_std::prelude::*; +const HTTP_TIMEOUT_MS: u64 = 30_000; + /// Encodes a vector of bytes into a vector of characters using base64 encoding. pub fn base64_encode(input: &Vec) -> Vec { let mut buf = Vec::with_capacity(1024); // ToDo: calculate capacity @@ -10,3 +16,43 @@ pub fn base64_encode(input: &Vec) -> Vec { BASE64_STANDARD.encode_slice(input, &mut buf).unwrap(); // ToDo: handle error buf.iter().map(|&byte| byte as char).collect() } + +/// Publish intermediate validation result to redis. +pub fn share_intermediate_validation_result( + shared_memory_webdis_url: &String, + era: EraIndex, + validator: &String, + cdn_node: &String, + validation_result: bool, + validation_decision_encoded: &String, +) -> Result { + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + let validation_result_string = String::from(if validation_result { "true" } else { "false" }); + let validation_decision_string = String::from(validation_decision_encoded); + let url = format!( + "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{{\"result\":{},\"data\":{}}}", + shared_memory_webdis_url, + validator, + cdn_node, + era, + validation_result_string, + validation_decision_string, + ); + let request = http::Request::get(url.as_str()); + let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + if response.code != 200 { + log::warn!("Unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + let body = response.body().collect::>(); + let body_str = sp_std::str::from_utf8(&body).map_err(|_| { + log::warn!("No UTF-8 body"); + http::Error::Unknown + })?; + let json = lite_json::parse_json(body_str).map_err(|_| { + log::warn!("No JSON body"); + http::Error::Unknown + })?; + Ok(json) +} From a81248a0ccf0dac1444ec4d35086480505677c3e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 5 May 2023 20:29:07 +0600 Subject: [PATCH 123/544] Reset validators launch signal each block --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 391804e9e..406250e97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -222,6 +222,8 @@ pub mod pallet { return 0 } + Signal::::set(Some(false)); + let era = Self::get_current_era(); log::info!("current era: {:?}", era); From 9ef60d6768680da48728a80e60a180a2cef8b49e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 5 May 2023 20:29:38 +0600 Subject: [PATCH 124/544] Publish intermediate validation results to shm --- src/lib.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 406250e97..4f4657115 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -338,7 +338,7 @@ pub mod pallet { let validation_result = Self::validate(node_sent, client_received); // Prepare an intermediate validation decision - let _validation_decision = ValidationDecision { + let validation_decision = ValidationDecision { result: validation_result, payload: [0u8; 256], // ToDo: put a hash of the validated data here totals: DacTotalAggregates { @@ -348,7 +348,38 @@ pub mod pallet { failure_rate: 0, // ToDo }, }; + + // Encode validation decision to base64 + let validation_decision_serialized: Vec = validation_decision.encode(); + let validation_decision_base64 = + shm::base64_encode(&validation_decision_serialized); + log::info!( + "Intermediate validation decision for CDN node {:?}: , base64 encoded: {:?}", + validation_decision, + validation_decision_base64, + ); + + // Prepare values to publish validation decision and publish it + let validator_id_string = String::from("validator1"); // ToDo: get validator ID + let edge_id_string = utils::account_to_string::(edge.clone()); + let validation_decision_base64_string = + validation_decision_base64.iter().cloned().collect::(); + let response = shm::share_intermediate_validation_result( + &data_provider_url, + current_era - 1, + &validator_id_string, + &edge_id_string, + validation_result, + &validation_decision_base64_string, + ); + let response_text = response.unwrap().to_string(); + log::info!("Redis response: {:?}", response_text) } + log::info!( + "Intermediate validation results published for {} CDN nodes in era {:?}", + edges.len(), + current_era - 1 + ); } } From 735668215f75f40855c2b7b503125a857d148e0a Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 4 May 2023 16:16:35 +0200 Subject: [PATCH 125/544] Implement validator decisions fetching Cargo fmt Post mocked final decision Parse intermediate decisions Adjust get_final_decisions according to new structs Fix input structures Remove unused code Replace Post with Put Run cargo fmt --- src/dac.rs | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/lib.rs | 5 ++ 2 files changed, 168 insertions(+), 2 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 2bf6cde85..36e5bd4ef 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -4,8 +4,13 @@ use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; use lite_json::json::JsonValue; +use log::info; use serde_json::Value; -use sp_runtime::offchain::{http, Duration}; +use sp_runtime::offchain::{ + http, + http::{Method, Request}, + Duration, +}; use sp_staking::EraIndex; pub use sp_std::{ collections::{btree_map::BTreeMap, btree_set::BTreeSet}, @@ -119,6 +124,52 @@ pub struct FileInfo { requested_chunk_cids: Vec, } +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct ValidationResult { + data: String, + result: bool, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct ValidationResults(BTreeMap); + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct Edges(BTreeMap); + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct Wrapper { + #[serde(rename = "HGET")] + decisions: String, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct ResultLog { + validator_id: String, + data: String, + result: bool, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct ResultsLog(Vec>); + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct FinalDecision { + data: String, + result: bool, + results_log: ResultsLog, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(crate = "alt_serde")] +pub(crate) struct FinalDecisions(BTreeMap); + impl BytesSent { pub fn new(aggregate: RedisFtAggregate) -> BytesSent { let data = aggregate.ft_aggregate[1].clone(); @@ -246,7 +297,8 @@ pub fn get_proved_delivered_bytes_sum(file_requests: &Requests) -> u64 { fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> u64 { let log_timestamp = chunk.log.timestamp; let neighbors = get_closer_neighbors(log_timestamp, &ack_timestamps); - let is_proved = is_lies_within_threshold(log_timestamp, neighbors, FAILED_CONTENT_CONSUMER_THRESHOLD); + let is_proved = + is_lies_within_threshold(log_timestamp, neighbors, FAILED_CONTENT_CONSUMER_THRESHOLD); if is_proved { return chunk.log.bytes_sent @@ -439,3 +491,112 @@ pub(crate) fn fetch_aggregates( })?; Ok(json) } + +pub(crate) fn make_http_put(url: &String, payload: &String) -> Result<(), http::Error> { + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + + let request = http::Request::new(url.as_str()) + .method(Method::Put) + .body(vec![payload.as_bytes()]); + + let pending_req = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + let response = pending_req.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + + if response.code != 200 { + log::warn!("Unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + + let body = response.body().collect::>(); + let body_str = sp_std::str::from_utf8(&body).map_err(|_| { + log::warn!("No UTF-8 body"); + http::Error::Unknown + })?; + + let json = lite_json::parse_json(body_str).map_err(|_| { + log::warn!("No JSON body"); + http::Error::Unknown + })?; + + Ok(()) +} + +pub(crate) fn fetch_validators_decisions( + data_provider_url: &String, + era: EraIndex, +) -> Result { + let url = format!("{}/HGET/mock:ddc:dac:decisions_to_eras/{}", data_provider_url, era); + let wrapper: Wrapper = http_get_json(&url).unwrap(); + + Ok(wrapper) +} + +pub(crate) fn post_final_decision( + data_provider_url: &String, + era: EraIndex, + decision: FinalDecision, +) -> Result<(), http::Error> { + let url = format!("{}/HSET/mock:ddc:dac:final_decision_to_era/{}", data_provider_url, era); + + let payload_str: String = serde_json::to_string(&decision).unwrap(); + let res = make_http_put(&url, &payload_str); + + res +} + +pub(crate) fn get_final_decision(decisions: &ValidationResults) -> FinalDecision { + let mut validators_on_edge = 0u32; + let mut positive_count = 0u32; + + let mut results_log: Vec> = Vec::new(); + for (validator_id, decision) in decisions.0.iter() { + let result = decision.result; + + if result == true { + positive_count += 1; + } + + let result_log_value = + ResultLog { validator_id: validator_id.clone(), data: String::from("Base64"), result }; + + let mut result_log: BTreeMap = BTreeMap::new(); + result_log.insert(validator_id.clone(), result_log_value); + results_log.push(result_log); + + validators_on_edge += 1; + } + + let threshold = validators_on_edge / 2; + + let mut validation_result = false; + if positive_count > threshold { + validation_result = true; + } + + let final_decision = FinalDecision { + data: String::from("Base64"), + result: validation_result, + results_log: ResultsLog(results_log), + }; + + final_decision +} + +pub(crate) fn finalize_decisions( + data_provider_url: &String, + era: EraIndex, + edge: &String, +) -> Result<(), http::Error> { + let wrapper = fetch_validators_decisions(data_provider_url, era).unwrap(); + let edges: Edges = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); + let result = edges.0.get(edge).unwrap(); + info!("decisions: {:?}", result); + + let final_decision = get_final_decision(&result); + + info!("final_decision: {:?}", final_decision); + + let res = post_final_decision(data_provider_url, era, final_decision); + + res +} diff --git a/src/lib.rs b/src/lib.rs index 4f4657115..a9ea535e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,6 +255,11 @@ pub mod pallet { let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); log::info!("Proved bytes sum: {:?}", bytes_sum); + let assigned_edge = + String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); + dac::finalize_decisions(&data_provider_url, 123345 as EraIndex, &assigned_edge) + .unwrap(); + // Print the number of broken sessions per CDN node. let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data let aggregates_obj = aggregates_value.as_object().unwrap(); From 118ead186dc74ac2e8fbb26fe517effad3a38b27 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 10 May 2023 11:19:09 +0600 Subject: [PATCH 126/544] Fix shm save_validation_result_by_node request arg --- src/shm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shm.rs b/src/shm.rs index 6ae033e77..d782f0c4b 100644 --- a/src/shm.rs +++ b/src/shm.rs @@ -30,7 +30,7 @@ pub fn share_intermediate_validation_result( let validation_result_string = String::from(if validation_result { "true" } else { "false" }); let validation_decision_string = String::from(validation_decision_encoded); let url = format!( - "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{{\"result\":{},\"data\":{}}}", + "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{{\"result\":{},\"data\":\"{}\"}}", shared_memory_webdis_url, validator, cdn_node, From 6a5e48f7dbe52a2f7182cb7230db0f4099cdf999 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 10 May 2023 11:43:56 +0600 Subject: [PATCH 127/544] Module docs for validators' shared memory mod --- src/shm.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shm.rs b/src/shm.rs index d782f0c4b..777f31d11 100644 --- a/src/shm.rs +++ b/src/shm.rs @@ -1,4 +1,9 @@ //! Validators' "shared memory" module. +//! +//! It implements a step of the DAC and Validation sequence when validators share their intermediate +//! validation results with each other. The design of the "shared memory" is expected to become like +//! transactions pool or peers list in the future, but for now it works on the centralized Redis +//! server which we maintain for DAC DataModel. use alloc::{format, string::String}; // ToDo: remove String usage use base64::prelude::*; From 5d54ce57c46f42073f1d1e450e46af97d89f1a08 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 10 May 2023 11:53:49 +0600 Subject: [PATCH 128/544] Payments module for DDC Validator pallet --- src/lib.rs | 1 + src/payments.rs | 1 + 2 files changed, 2 insertions(+) create mode 100644 src/payments.rs diff --git a/src/lib.rs b/src/lib.rs index a9ea535e1..820aaf5dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ #![cfg_attr(not(feature = "std"), no_std)] mod dac; +mod payments; mod shm; mod utils; mod validation; diff --git a/src/payments.rs b/src/payments.rs new file mode 100644 index 000000000..a1a26ade5 --- /dev/null +++ b/src/payments.rs @@ -0,0 +1 @@ +//! Payments module to calculate and store a withdrawal per content owner and a payout per CDN node. From 240f13f29e9cc3befd22d9cc72db6480ea45f1fa Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 11 May 2023 10:31:28 +0200 Subject: [PATCH 129/544] Get final decision --- src/dac.rs | 102 ++++++++++++++++++++++++++++++----------------------- src/lib.rs | 4 ++- 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 36e5bd4ef..e9253f051 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -6,6 +6,7 @@ use codec::{Decode, Encode}; use lite_json::json::JsonValue; use log::info; use serde_json::Value; +use sp_runtime::generic::Era; use sp_runtime::offchain::{ http, http::{Method, Request}, @@ -124,20 +125,16 @@ pub struct FileInfo { requested_chunk_cids: Vec, } -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct ValidationResult { - data: String, - result: bool, -} +type EdgeId = String; +type ValidatorId = String; -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct ValidationResults(BTreeMap); +// #[derive(Debug, Deserialize, Serialize)] +// #[serde(crate = "alt_serde")] +// pub(crate) struct ValidationResults(BTreeMap); #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "alt_serde")] -pub(crate) struct Edges(BTreeMap); +pub(crate) struct EdgesToResults(BTreeMap>); #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "alt_serde")] @@ -148,22 +145,28 @@ pub(crate) struct Wrapper { #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "alt_serde")] -pub(crate) struct ResultLog { - validator_id: String, - data: String, +pub(crate) struct ValidationResult { + validator_id: ValidatorId, + edge_id: EdgeId, result: bool, + received: u64, + sent: u64, + era: EraIndex, } -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct ResultsLog(Vec>); +// #[derive(Debug, Deserialize, Serialize)] +// #[serde(crate = "alt_serde")] +// pub(crate) struct ResultsLogs(Vec); #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "alt_serde")] pub(crate) struct FinalDecision { - data: String, result: bool, - results_log: ResultsLog, + edge_id: EdgeId, + era: EraIndex, + received: u64, + sent: u64, + results_logs: Vec, } #[derive(Debug, Deserialize, Serialize)] @@ -544,24 +547,17 @@ pub(crate) fn post_final_decision( res } -pub(crate) fn get_final_decision(decisions: &ValidationResults) -> FinalDecision { +pub(crate) fn get_final_decision(decisions: Vec) -> FinalDecision { let mut validators_on_edge = 0u32; let mut positive_count = 0u32; - let mut results_log: Vec> = Vec::new(); - for (validator_id, decision) in decisions.0.iter() { - let result = decision.result; - - if result == true { + let mut results_logs: Vec = Vec::new(); + for decision in decisions { + if decision.result == true { positive_count += 1; } - let result_log_value = - ResultLog { validator_id: validator_id.clone(), data: String::from("Base64"), result }; - - let mut result_log: BTreeMap = BTreeMap::new(); - result_log.insert(validator_id.clone(), result_log_value); - results_log.push(result_log); + results_logs.push(decision); validators_on_edge += 1; } @@ -574,29 +570,47 @@ pub(crate) fn get_final_decision(decisions: &ValidationResults) -> FinalDecision } let final_decision = FinalDecision { - data: String::from("Base64"), result: validation_result, - results_log: ResultsLog(results_log), + edge_id: results_logs[0].edge_id.clone(), + results_logs, + // Todo: Implement fn to get the values from intermediate decisions + received: 0, + sent: 0, + era: 0, }; final_decision } -pub(crate) fn finalize_decisions( +// pub(crate) fn finalize_decisions( +// data_provider_url: &String, +// era: EraIndex, +// edge: &String, +// ) -> Result<(), http::Error> { +// let wrapper = fetch_validators_decisions(data_provider_url, era).unwrap(); +// let edges: Edges = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); +// let result = edges.0.get(edge).unwrap(); +// info!("decisions: {:?}", result); +// +// let final_decision = get_final_decision(&result); +// +// info!("final_decision: {:?}", final_decision); +// +// let res = post_final_decision(data_provider_url, era, final_decision); +// +// res +// } + +pub(crate) fn get_validation_results( data_provider_url: &String, era: EraIndex, edge: &String, -) -> Result<(), http::Error> { +) -> Result, http::Error> { let wrapper = fetch_validators_decisions(data_provider_url, era).unwrap(); - let edges: Edges = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); - let result = edges.0.get(edge).unwrap(); - info!("decisions: {:?}", result); + let mut edges: EdgesToResults = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); + let results = edges.0.remove(edge).unwrap(); - let final_decision = get_final_decision(&result); - - info!("final_decision: {:?}", final_decision); - - let res = post_final_decision(data_provider_url, era, final_decision); - - res + Ok(results) } + +// pub(crate) fn save_final_decision(); diff --git a/src/lib.rs b/src/lib.rs index a9ea535e1..386b18efc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -257,8 +257,10 @@ pub mod pallet { let assigned_edge = String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); - dac::finalize_decisions(&data_provider_url, 123345 as EraIndex, &assigned_edge) + let validations_res = dac::get_validation_results(&data_provider_url, 5 as EraIndex, &assigned_edge) .unwrap(); + let final_res = dac::get_final_decision(validations_res); + log::info!("final_res: {:?}", final_res); // Print the number of broken sessions per CDN node. let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data From eb86761a033766f6ff0b8eae35cae3988eb0f8b7 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 11 May 2023 10:32:33 +0200 Subject: [PATCH 130/544] Run cargo fmt --- src/dac.rs | 12 +++++++----- src/lib.rs | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index e9253f051..da789361f 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -6,11 +6,13 @@ use codec::{Decode, Encode}; use lite_json::json::JsonValue; use log::info; use serde_json::Value; -use sp_runtime::generic::Era; -use sp_runtime::offchain::{ - http, - http::{Method, Request}, - Duration, +use sp_runtime::{ + generic::Era, + offchain::{ + http, + http::{Method, Request}, + Duration, + }, }; use sp_staking::EraIndex; pub use sp_std::{ diff --git a/src/lib.rs b/src/lib.rs index 386b18efc..10c359694 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -257,8 +257,9 @@ pub mod pallet { let assigned_edge = String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); - let validations_res = dac::get_validation_results(&data_provider_url, 5 as EraIndex, &assigned_edge) - .unwrap(); + let validations_res = + dac::get_validation_results(&data_provider_url, 5 as EraIndex, &assigned_edge) + .unwrap(); let final_res = dac::get_final_decision(validations_res); log::info!("final_res: {:?}", final_res); From 6f14608f7d348e816f05c5f94d12ebda65c18769 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 11 May 2023 12:48:34 +0200 Subject: [PATCH 131/544] Replace FinalDecision wiht ValidationDecision --- src/dac.rs | 41 ++++++++++------------------------------- src/utils.rs | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index da789361f..1ed5d217e 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -19,8 +19,7 @@ pub use sp_std::{ collections::{btree_map::BTreeMap, btree_set::BTreeSet}, prelude::*, }; - -use crate::utils; +use crate::{DacTotalAggregates, utils, ValidationDecision}; pub type TimestampInSec = u64; pub const HTTP_TIMEOUT_MS: u64 = 30_000; @@ -549,7 +548,7 @@ pub(crate) fn post_final_decision( res } -pub(crate) fn get_final_decision(decisions: Vec) -> FinalDecision { +pub(crate) fn get_final_decision(decisions: Vec) -> ValidationDecision { let mut validators_on_edge = 0u32; let mut positive_count = 0u32; @@ -571,38 +570,20 @@ pub(crate) fn get_final_decision(decisions: Vec) -> FinalDecis validation_result = true; } - let final_decision = FinalDecision { + let final_decision= ValidationDecision { result: validation_result, - edge_id: results_logs[0].edge_id.clone(), - results_logs, - // Todo: Implement fn to get the values from intermediate decisions - received: 0, - sent: 0, - era: 0, + payload: utils::get_hashed(&results_logs), + totals: DacTotalAggregates { + received: 0, + sent: 0, + failed_by_client: 0, + failure_rate: 0, + }, }; final_decision } -// pub(crate) fn finalize_decisions( -// data_provider_url: &String, -// era: EraIndex, -// edge: &String, -// ) -> Result<(), http::Error> { -// let wrapper = fetch_validators_decisions(data_provider_url, era).unwrap(); -// let edges: Edges = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); -// let result = edges.0.get(edge).unwrap(); -// info!("decisions: {:?}", result); -// -// let final_decision = get_final_decision(&result); -// -// info!("final_decision: {:?}", final_decision); -// -// let res = post_final_decision(data_provider_url, era, final_decision); -// -// res -// } - pub(crate) fn get_validation_results( data_provider_url: &String, era: EraIndex, @@ -614,5 +595,3 @@ pub(crate) fn get_validation_results( Ok(results) } - -// pub(crate) fn save_final_decision(); diff --git a/src/utils.rs b/src/utils.rs index 5c8c5cf4f..bf3ed3cc4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,11 @@ use alloc::string::String; use codec::{Decode, Encode}; use sp_core::crypto::AccountId32; +use sp_io::hashing::blake2_256; +use crate::dac::ValidationResult; +pub use sp_std::{ + prelude::*, +}; pub fn account_to_string(account: T::AccountId) -> String { let to32 = T::AccountId::encode(&account); @@ -16,3 +21,20 @@ pub fn string_to_account(pub_key_str: String) -> T::Acc let address: T::AccountId = T::AccountId::decode(&mut to32).unwrap(); address } + +pub(crate) fn hash(data: &String) -> [u8; 32] { + let hash = blake2_256(data.as_bytes()); + let mut result = [0u8; 32]; + result.copy_from_slice(&hash); + + result +} + +pub(crate) fn get_hashed(data: &Vec) -> [u8; 256] { + let results_log = serde_json::to_string(data).unwrap(); + let mut payload:[u8; 256] = [0; 256]; + let hashed_results = hash(&results_log); + payload[..32].copy_from_slice(&hashed_results); + + payload +} From d983ac8089ea0324d3d924bcf4089088d88bcd9f Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 11 May 2023 17:09:39 +0200 Subject: [PATCH 132/544] Implement find_largest_group --- src/dac.rs | 61 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 1ed5d217e..5bcb53ce8 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -144,7 +144,7 @@ pub(crate) struct Wrapper { decisions: String, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] #[serde(crate = "alt_serde")] pub(crate) struct ValidationResult { validator_id: ValidatorId, @@ -549,30 +549,12 @@ pub(crate) fn post_final_decision( } pub(crate) fn get_final_decision(decisions: Vec) -> ValidationDecision { - let mut validators_on_edge = 0u32; - let mut positive_count = 0u32; - - let mut results_logs: Vec = Vec::new(); - for decision in decisions { - if decision.result == true { - positive_count += 1; - } - - results_logs.push(decision); - - validators_on_edge += 1; - } - - let threshold = validators_on_edge / 2; - - let mut validation_result = false; - if positive_count > threshold { - validation_result = true; - } + let common_decisions = find_largest_group(decisions).unwrap(); + let decision_example = common_decisions.get(0).unwrap(); let final_decision= ValidationDecision { - result: validation_result, - payload: utils::get_hashed(&results_logs), + result: decision_example.result, + payload: utils::get_hashed(&common_decisions), totals: DacTotalAggregates { received: 0, sent: 0, @@ -595,3 +577,36 @@ pub(crate) fn get_validation_results( Ok(results) } + +fn find_largest_group(decisions: Vec) -> Option> { + let mut groups: Vec> = Vec::new(); + let half = decisions.len() / 2; + + for decision in decisions { + let mut found_group = false; + + for group in &mut groups { + if group.iter().all(|x| x.result == decision.result && x.received == decision.received && x.sent == decision.sent) { + group.push(decision.clone()); + found_group = true; + break; + } + } + + if !found_group { + groups.push(vec![decision]); + } + } + + let largest_group = groups + .into_iter() + .max_by_key(|group| group.len()) + .unwrap_or(Vec::new()); + + + if largest_group.len() > half { + Some(largest_group) + } else { + None + } +} From 9391f9ceec640b9574b4c0ac2cac6a3bea38da79 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 12 May 2023 09:51:22 +0200 Subject: [PATCH 133/544] Send tx --- src/dac.rs | 4 ++-- src/lib.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 5bcb53ce8..f964c5947 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -556,8 +556,8 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validation result: decision_example.result, payload: utils::get_hashed(&common_decisions), totals: DacTotalAggregates { - received: 0, - sent: 0, + received: decision_example.received, + sent: decision_example.sent, failed_by_client: 0, failure_rate: 0, }, diff --git a/src/lib.rs b/src/lib.rs index 10c359694..dfe80316e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -261,6 +261,17 @@ pub mod pallet { dac::get_validation_results(&data_provider_url, 5 as EraIndex, &assigned_edge) .unwrap(); let final_res = dac::get_final_decision(validations_res); + + let signer = Self::get_signer().unwrap(); + + let tx_res = signer.send_signed_transaction(|_acct| { + Call::set_validation_decision { + era: 5 as EraIndex, + cdn_node: utils::string_to_account::(assigned_edge.clone()), + validation_decision: final_res.clone(), + } + }); + log::info!("final_res: {:?}", final_res); // Print the number of broken sessions per CDN node. From b2a5309295bf95d51b99bed0fcc92e1a561a911a Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 12 May 2023 09:55:07 +0200 Subject: [PATCH 134/544] Cargo fmt --- src/dac.rs | 26 +++++++++----------------- src/lib.rs | 10 ++++------ src/utils.rs | 8 +++----- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index f964c5947..9f74e3093 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -1,5 +1,6 @@ //! A module with Data Activity Capture (DAC) interaction. +use crate::{utils, DacTotalAggregates, ValidationDecision}; use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; @@ -19,7 +20,6 @@ pub use sp_std::{ collections::{btree_map::BTreeMap, btree_set::BTreeSet}, prelude::*, }; -use crate::{DacTotalAggregates, utils, ValidationDecision}; pub type TimestampInSec = u64; pub const HTTP_TIMEOUT_MS: u64 = 30_000; @@ -129,10 +129,6 @@ pub struct FileInfo { type EdgeId = String; type ValidatorId = String; -// #[derive(Debug, Deserialize, Serialize)] -// #[serde(crate = "alt_serde")] -// pub(crate) struct ValidationResults(BTreeMap); - #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "alt_serde")] pub(crate) struct EdgesToResults(BTreeMap>); @@ -155,10 +151,6 @@ pub(crate) struct ValidationResult { era: EraIndex, } -// #[derive(Debug, Deserialize, Serialize)] -// #[serde(crate = "alt_serde")] -// pub(crate) struct ResultsLogs(Vec); - #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "alt_serde")] pub(crate) struct FinalDecision { @@ -552,7 +544,7 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validation let common_decisions = find_largest_group(decisions).unwrap(); let decision_example = common_decisions.get(0).unwrap(); - let final_decision= ValidationDecision { + let final_decision = ValidationDecision { result: decision_example.result, payload: utils::get_hashed(&common_decisions), totals: DacTotalAggregates { @@ -586,10 +578,14 @@ fn find_largest_group(decisions: Vec) -> Option) -> Option half { Some(largest_group) diff --git a/src/lib.rs b/src/lib.rs index dfe80316e..fad5faab2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -264,12 +264,10 @@ pub mod pallet { let signer = Self::get_signer().unwrap(); - let tx_res = signer.send_signed_transaction(|_acct| { - Call::set_validation_decision { - era: 5 as EraIndex, - cdn_node: utils::string_to_account::(assigned_edge.clone()), - validation_decision: final_res.clone(), - } + let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: 5 as EraIndex, + cdn_node: utils::string_to_account::(assigned_edge.clone()), + validation_decision: final_res.clone(), }); log::info!("final_res: {:?}", final_res); diff --git a/src/utils.rs b/src/utils.rs index bf3ed3cc4..3c5c90c80 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,11 +1,9 @@ +use crate::dac::ValidationResult; use alloc::string::String; use codec::{Decode, Encode}; use sp_core::crypto::AccountId32; use sp_io::hashing::blake2_256; -use crate::dac::ValidationResult; -pub use sp_std::{ - prelude::*, -}; +pub use sp_std::prelude::*; pub fn account_to_string(account: T::AccountId) -> String { let to32 = T::AccountId::encode(&account); @@ -32,7 +30,7 @@ pub(crate) fn hash(data: &String) -> [u8; 32] { pub(crate) fn get_hashed(data: &Vec) -> [u8; 256] { let results_log = serde_json::to_string(data).unwrap(); - let mut payload:[u8; 256] = [0; 256]; + let mut payload: [u8; 256] = [0; 256]; let hashed_results = hash(&results_log); payload[..32].copy_from_slice(&hashed_results); From 6d05d4935b1cde5eb543820dd0064cd8a7aefb03 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 12 May 2023 10:07:07 +0200 Subject: [PATCH 135/544] Put mocked era to get_validation_results --- src/dac.rs | 2 +- src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dac.rs b/src/dac.rs index 9f74e3093..68442f1b1 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -563,7 +563,7 @@ pub(crate) fn get_validation_results( era: EraIndex, edge: &String, ) -> Result, http::Error> { - let wrapper = fetch_validators_decisions(data_provider_url, era).unwrap(); + let wrapper = fetch_validators_decisions(data_provider_url, 5 as EraIndex).unwrap(); // Era is mocked for now let mut edges: EdgesToResults = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); let results = edges.0.remove(edge).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index fad5faab2..9bde10b40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,6 +246,7 @@ pub mod pallet { return } + let current_era = Self::get_current_era(); let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); @@ -258,14 +259,14 @@ pub mod pallet { let assigned_edge = String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); let validations_res = - dac::get_validation_results(&data_provider_url, 5 as EraIndex, &assigned_edge) + dac::get_validation_results(&data_provider_url, current_era, &assigned_edge) .unwrap(); let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: 5 as EraIndex, + era: current_era, cdn_node: utils::string_to_account::(assigned_edge.clone()), validation_decision: final_res.clone(), }); @@ -308,7 +309,6 @@ pub mod pallet { } // Read from DAC. - let current_era = Self::get_current_era(); let (sent_query, sent, received_query, received) = dac::fetch_data2(&data_provider_url, current_era - 1); log::info!( From 8cc34ae2dbb6728081982565ad93c5c0f725f2b1 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 12 May 2023 17:21:28 +0600 Subject: [PATCH 136/544] Add `set_era_reward_points` call to ddc-validator --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index dbf0f1c27..2b7b3236e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -438,6 +438,34 @@ pub mod pallet { Ok(()) } + + /// Set reward points for CDN participants at the given era. + /// + /// ToDo: remove it when the off-chain worker will be able to set reward points using the + /// same call defined in `pallet-ddc-staking`. + /// + /// `stakers_points` is a vector of (stash account ID, reward points) pairs. The rewards + /// distribution will be based on total reward points, with each CDN participant receiving a + /// proportionate reward based on their individual reward points. + /// + /// See also [`pallet_ddc_staking::ErasEdgesRewardPoints`]. + #[pallet::weight(100_000)] + pub fn set_era_reward_points( + origin: OriginFor, + era: EraIndex, + stakers_points: Vec<(T::AccountId, u64)>, + ) -> DispatchResult { + ensure_signed(origin)?; + + >::mutate(era, |era_rewards| { + for (staker, points) in stakers_points.into_iter() { + *era_rewards.individual.entry(staker).or_default() += points; + era_rewards.total += points; + } + }); + + Ok(()) + } } impl Pallet From a10a664823aa933879bc58509c2260a38153ba8c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 12 May 2023 19:55:54 +0600 Subject: [PATCH 137/544] Set era reward points from off-chain worker --- src/lib.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 2b7b3236e..9f9dbdd30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -398,6 +398,66 @@ pub mod pallet { edges.len(), current_era - 1 ); + + // Set CDN nodes' reward points + // ============================ + + // Let's use a mock data until we have a real final validation decisions for all the CDN + // nodes. + let mock_final_validation_decisions: Vec<(T::AccountId, ValidationDecision)> = vec![ + ( + utils::string_to_account::( + "0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1".into(), + ), + ValidationDecision { + result: true, + payload: [0u8; 256], + totals: DacTotalAggregates { + sent: 100, + received: 100, + failed_by_client: 0, + failure_rate: 0, + }, + }, + ), + ( + utils::string_to_account::( + "0xa2d14e71b52e5695e72c0567926bc68b68bda74df5c1ccf1d4ba612c153ff66b".into(), + ), + ValidationDecision { + result: true, + payload: [0u8; 256], + totals: DacTotalAggregates { + sent: 200, + received: 200, + failed_by_client: 0, + failure_rate: 0, + }, + }, + ), + ]; + + // Calculate CDN nodes reward points from validation decision aggregates + let cdn_nodes_reward_points: Vec<(T::AccountId, u64)> = mock_final_validation_decisions + .into_iter() + .filter(|(_, validation_decision)| validation_decision.result) // skip misbehaving + .map(|(cdn_node, validation_decision)| { + // ToDo: should we use `sent` or `received` or anything else as a reward point? + (cdn_node, validation_decision.totals.sent) + }) + .collect(); + + // Store CDN node reward points on-chain + let signer: Signer = Signer::<_, _>::any_account(); + if !signer.can_sign() { + log::warn!("No local accounts available to set era reward points. Consider adding one via `author_insertKey` RPC."); + return + } + // ToDo: replace local call by a call from `ddc-staking` pallet + let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { + era: current_era - 1, + stakers_points: cdn_nodes_reward_points.clone(), + }); } } From c63857813a6dab3c11f8dbe5d9889c3fd1ddf406 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 15 May 2023 14:05:53 +0600 Subject: [PATCH 138/544] Prevent panic on redis shared memory comm error --- src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9f9dbdd30..36a708d99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -390,8 +390,13 @@ pub mod pallet { validation_result, &validation_decision_base64_string, ); - let response_text = response.unwrap().to_string(); - log::info!("Redis response: {:?}", response_text) + match response { + Ok(response) => log::info!("Shared memory response: {:?}", response.to_string()), + Err(e) => { + log::error!("Shared memory error: {:?}", e); + continue + }, + } } log::info!( "Intermediate validation results published for {} CDN nodes in era {:?}", From ce1acf4546f322c3c41600015b4f47ca617640e6 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 12 May 2023 18:35:21 +0200 Subject: [PATCH 139/544] accounts first version --- Cargo.toml | 31 ++++ src/lib.rs | 416 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 447 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..38e73bde4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "pallet-ddc-accounts" +version = "0.1.0" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } +frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } +scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } +sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } +sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } +sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } +log = { version = "0.4.17", default-features = false } + +[dev-dependencies] +substrate-test-utils = { version = "4.0.0-dev", path = "../../test-utils" } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", +] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..2b0dca3eb --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,416 @@ +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +use codec::{Decode, Encode, HasCompact}; + +use frame_support::{ + parameter_types, + traits::{Currency, DefensiveSaturating, LockIdentifier, WithdrawReasons, ExistenceRequirement, UnixTime}, + BoundedVec, + PalletId +}; +use scale_info::TypeInfo; +use sp_runtime::{ + traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, + RuntimeDebug, +}; + +use sp_staking::EraIndex; +use sp_std::prelude::*; + +pub use pallet::*; + +pub const TIME_START_MS: u128 = 1_672_531_200_000; +pub const ERA_DURATION_MS: u128 = 120_000; +pub const ERA_IN_BLOCKS: u8 = 20; + +/// The balance type of this pallet. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +parameter_types! { + /// A limit to the number of pending unlocks an account may have in parallel. + pub MaxUnlockingChunks: u32 = 32; +} + +/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct UnlockChunk { + /// Amount of funds to be unlocked. + #[codec(compact)] + value: Balance, + /// Era number at which point it'll be unlocked. + #[codec(compact)] + era: EraIndex, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct AccountsLedger { + /// The stash account whose balance is actually locked and can be used for CDN usage. + pub stash: AccountId, + /// The total amount of the stash's balance that we are currently accounting for. + /// It's just `active` plus all the `unlocking` balances. + #[codec(compact)] + pub total: Balance, + /// The total amount of the stash's balance that will be accessible for CDN payments in any forthcoming + /// rounds. + #[codec(compact)] + pub active: Balance, + /// Any balance that is becoming free, which may eventually be transferred out of the stash + /// (assuming that the content owner has to pay for network usage). It is assumed that this will be treated as a first + /// in, first out queue where the new (higher value) eras get pushed on the back. + pub unlocking: BoundedVec, MaxUnlockingChunks>, +} + +impl + AccountsLedger +{ + /// Initializes the default object using the given stash. + pub fn default_from(stash: AccountId) -> Self { + Self { stash, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } + } + + /// Remove entries from `unlocking` that are sufficiently old and reduce the + /// total by the sum of their balances. + fn consolidate_unlocked(self, current_era: EraIndex) -> Self { + let mut total = self.total; + let unlocking: BoundedVec<_, _> = self + .unlocking + .into_iter() + .filter(|chunk| { + log::info!("Chunk era: {:?}", chunk.era); + if chunk.era > current_era { + true + } else { + total = total.saturating_sub(chunk.value); + false + } + }) + .collect::>() + .try_into() + .expect( + "filtering items from a bounded vec always leaves length less than bounds. qed", + ); + + Self { stash: self.stash, total, active: self.active, unlocking } + } +} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::{ + pallet_prelude::*, sp_runtime::traits::StaticLookup, traits::LockableCurrency, + Blake2_128Concat, + }; + use frame_system::pallet_prelude::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + /// The accounts's pallet id, used for deriving its sovereign account ID. + #[pallet::constant] + type PalletId: Get; + type Currency: LockableCurrency; + type Event: From> + IsType<::Event>; + /// Number of eras that staked funds must remain bonded for. + #[pallet::constant] + type BondingDuration: Get; + type TimeProvider: UnixTime; + } + + /// Map from all locked "stash" accounts to the controller account. + #[pallet::storage] + #[pallet::getter(fn bonded)] + pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + + /// Map from all (unlocked) "controller" accounts to the info regarding the staking. + #[pallet::storage] + #[pallet::getter(fn ledger)] + pub type Ledger = + StorageMap<_, Blake2_128Concat, T::AccountId, AccountsLedger>>; + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + /// An account has bonded this amount. \[stash, amount\] + /// + /// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably, + /// it will not be emitted for staking rewards when they are added to stake. + Deposited(T::AccountId, BalanceOf), + /// An account has unbonded this amount. \[stash, amount\] + Unbonded(T::AccountId, BalanceOf), + /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` + /// from the unlocking queue. \[stash, amount\] + Withdrawn(T::AccountId, BalanceOf), + } + + #[pallet::error] + pub enum Error { + /// Not a controller account. + NotController, + /// Not a stash account. + NotStash, + /// Controller is already paired. + AlreadyPaired, + /// Cannot deposit dust + InsufficientDeposit, + /// Can not schedule more unlock chunks. + NoMoreChunks, + /// Internal state has become somehow corrupted and the operation cannot continue. + BadState, + } + + #[pallet::call] + impl Pallet { + /// Take the origin account as a stash and lock up `value` of its balance. `controller` will + /// be the account that controls it. + /// + /// `value` must be more than the `minimum_balance` specified by `T::Currency`. + /// + /// The dispatch origin for this call must be _Signed_ by the stash account. + /// + /// Emits `Deposited`. + #[pallet::weight(10_000)] pub fn deposit( + origin: OriginFor, + controller: ::Source, + #[pallet::compact] value: BalanceOf, + ) -> DispatchResult { + let stash = ensure_signed(origin)?; + + let controller = T::Lookup::lookup(controller)?; + + if >::contains_key(&controller) { + Err(Error::::AlreadyPaired)? + } + + // Reject a deposit which is considered to be _dust_. + if value < T::Currency::minimum_balance() { + Err(Error::::InsufficientDeposit)? + } + + frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; + + let stash_balance = T::Currency::free_balance(&stash); + let value = value.min(stash_balance); + Self::deposit_event(Event::::Deposited(stash.clone(), value)); + let item = + AccountsLedger { stash: stash.clone(), total: value, active: value, unlocking: Default::default() }; + Self::update_ledger_and_deposit( &stash, &controller, &item); + Ok(()) + } + + /// Add some extra amount that have appeared in the stash `free_balance` into the balance up + /// for CDN payments. + /// + /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. + /// + /// Emits `Deposited`. + #[pallet::weight(10_000)] + pub fn deposit_extra( + origin: OriginFor, + #[pallet::compact] max_additional: BalanceOf, + ) -> DispatchResult { + let stash = ensure_signed(origin)?; + + let controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; + let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + + let stash_balance = T::Currency::free_balance(&stash); + let extra = stash_balance.min(max_additional); + ledger.total += extra; + ledger.active += extra; + // Last check: the new active amount of ledger must be more than ED. + ensure!( + ledger.active >= T::Currency::minimum_balance(), + Error::::InsufficientDeposit + ); + + Self::update_ledger_and_deposit(&stash, &controller, &ledger); + + Self::deposit_event(Event::::Deposited(stash.clone(), extra)); + + Ok(()) + } + + /// Schedule a portion of the stash to be unlocked ready for transfer out after the bond + /// period ends. If this leaves an amount actively bonded less than + /// T::Currency::minimum_balance(), then it is increased to the full amount. + /// + /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. + /// + /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move + /// the funds out of management ready for transfer. + /// + /// No more than a limited number of unlocking chunks (see `MaxUnlockingChunks`) + /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need + /// to be called first to remove some of the chunks (if possible). + /// + /// Emits `Unbonded`. + /// + /// See also [`Call::withdraw_unbonded`]. + #[pallet::weight(10_000)] + pub fn unbond( + origin: OriginFor, + #[pallet::compact] value: BalanceOf, + ) -> DispatchResult { + let controller = ensure_signed(origin)?; + let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + ensure!( + ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, + Error::::NoMoreChunks, + ); + + let mut value = value.min(ledger.active); + + if !value.is_zero() { + ledger.active -= value; + + // Avoid there being a dust balance left in the accounts system. + if ledger.active < T::Currency::minimum_balance() { + value += ledger.active; + ledger.active = Zero::zero(); + } + + // Note: bonding for extra era to allow for accounting + let era = Self::get_current_era() + T::BondingDuration::get(); + log::info!("Era for the unbond: {:?}", era); + + if let Some(mut chunk) = + ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) + { + // To keep the chunk count down, we only keep one chunk per era. Since + // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will + // be the last one. + chunk.value = chunk.value.defensive_saturating_add(value) + } else { + ledger + .unlocking + .try_push(UnlockChunk { value, era }) + .map_err(|_| Error::::NoMoreChunks)?; + }; + + Self::update_ledger(&controller, &ledger); + + Self::deposit_event(Event::::Unbonded(ledger.stash, value)); + } + Ok(()) + } + + + /// Remove any unlocked chunks from the `unlocking` queue from our management. + /// + /// This essentially frees up that balance to be used by the stash account to do + /// whatever it wants. + /// + /// The dispatch origin for this call must be _Signed_ by the controller. + /// + /// Emits `Withdrawn`. + /// + /// See also [`Call::unbond`]. + #[pallet::weight(10_000)] + pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { + let controller = ensure_signed(origin)?; + let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let (stash, old_total) = (ledger.stash.clone(), ledger.total); + let current_era = Self::get_current_era(); + ledger = ledger.consolidate_unlocked(current_era); + log::info!("Current era: {:?}", current_era); + + if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() { + log::info!("Killing stash"); + // This account must have called `unbond()` with some value that caused the active + // portion to fall below existential deposit + will have no more unlocking chunks + // left. We can now safely remove all accounts-related information. + Self::kill_stash(&stash)?; + } else { + log::info!("Updating ledger"); + // This was the consequence of a partial unbond. just update the ledger and move on. + Self::update_ledger(&controller, &ledger); + }; + + log::info!("Current total: {:?}", ledger.total); + log::info!("Old total: {:?}", old_total); + + // `old_total` should never be less than the new total because + // `consolidate_unlocked` strictly subtracts balance. + if ledger.total < old_total { + log::info!("Preparing for transfer"); + // Already checked that this won't overflow by entry condition. + let value = old_total - ledger.total; + + let account_id = Self::account_id(); + + T::Currency::transfer( + &account_id, + &stash, + value, + ExistenceRequirement::KeepAlive, + )?; + Self::deposit_event(Event::::Withdrawn(stash, value)); + } + + Ok(()) + } + } + + impl Pallet { + pub fn account_id() -> T::AccountId { + T::PalletId::get().into_account() + } + /// Update the ledger for a controller. + /// + /// This will also deposit the funds to pallet. + fn update_ledger_and_deposit( + stash: &T::AccountId, + controller: &T::AccountId, + ledger: &AccountsLedger>, + ) { + let account_id = Self::account_id(); + + T::Currency::transfer( + stash, + &account_id, + ledger.total, + ExistenceRequirement::KeepAlive, + )?; + >::insert(controller, ledger); + } + + /// Update the ledger for a controller. + fn update_ledger( + controller: &T::AccountId, + ledger: &AccountsLedger>, + ) { + >::insert(controller, ledger); + } + + /// Remove all associated data of a stash account from the accounts system. + /// + /// Assumes storage is upgraded before calling. + /// + /// This is called: + /// - after a `withdraw_unbonded()` call that frees all of a stash's bonded balance. + fn kill_stash(stash: &T::AccountId) -> DispatchResult { + let controller = >::get(stash).ok_or(Error::::NotStash)?; + + >::remove(stash); + >::remove(&controller); + + frame_system::Pallet::::dec_consumers(stash); + + Ok(()) + } + + // Get the current era. + fn get_current_era() -> EraIndex { + ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) + .try_into() + .unwrap() + } + } +} From 98077dc0b8b8ba922b6a607aa4d9edd1da80a9dd Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 12 May 2023 19:28:07 +0200 Subject: [PATCH 140/544] fix code quality --- src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b0dca3eb..78f07c525 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use codec::{Decode, Encode, HasCompact}; use frame_support::{ parameter_types, - traits::{Currency, DefensiveSaturating, LockIdentifier, WithdrawReasons, ExistenceRequirement, UnixTime}, + traits::{Currency, DefensiveSaturating, ExistenceRequirement, UnixTime}, BoundedVec, PalletId }; @@ -155,6 +155,8 @@ pub mod pallet { NotController, /// Not a stash account. NotStash, + /// Stash is already bonded. + AlreadyBonded, /// Controller is already paired. AlreadyPaired, /// Cannot deposit dust @@ -182,6 +184,10 @@ pub mod pallet { ) -> DispatchResult { let stash = ensure_signed(origin)?; + if >::contains_key(&stash) { + Err(Error::::AlreadyBonded)? + } + let controller = T::Lookup::lookup(controller)?; if >::contains_key(&controller) { @@ -195,12 +201,14 @@ pub mod pallet { frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; + >::insert(&stash, &controller); + let stash_balance = T::Currency::free_balance(&stash); let value = value.min(stash_balance); Self::deposit_event(Event::::Deposited(stash.clone(), value)); let item = AccountsLedger { stash: stash.clone(), total: value, active: value, unlocking: Default::default() }; - Self::update_ledger_and_deposit( &stash, &controller, &item); + Self::update_ledger_and_deposit( &stash, &controller, &item)?; Ok(()) } @@ -230,7 +238,7 @@ pub mod pallet { Error::::InsufficientDeposit ); - Self::update_ledger_and_deposit(&stash, &controller, &ledger); + Self::update_ledger_and_deposit(&stash, &controller, &ledger)?; Self::deposit_event(Event::::Deposited(stash.clone(), extra)); @@ -369,7 +377,7 @@ pub mod pallet { stash: &T::AccountId, controller: &T::AccountId, ledger: &AccountsLedger>, - ) { + ) -> DispatchResult { let account_id = Self::account_id(); T::Currency::transfer( @@ -379,6 +387,8 @@ pub mod pallet { ExistenceRequirement::KeepAlive, )?; >::insert(controller, ledger); + + Ok(()) } /// Update the ledger for a controller. From dacff9a1a820059c0191e03dba8c9aec555bbccf Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 15 May 2023 12:23:19 +0200 Subject: [PATCH 141/544] add existential balance for pallet accounts --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 78f07c525..62acb3a82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,6 +167,27 @@ pub mod pallet { BadState, } + #[pallet::genesis_config] + pub struct GenesisConfig; + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + let account_id = >::account_id(); + let min = T::Currency::minimum_balance(); + if T::Currency::free_balance(&account_id) < min { + let _ = T::Currency::make_free_balance_be(&account_id, min); + } + } + } + #[pallet::call] impl Pallet { /// Take the origin account as a stash and lock up `value` of its balance. `controller` will From 5b580da8ca2c9c535516433f39c4ab84a59ea3d2 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 15 May 2023 09:58:37 +0200 Subject: [PATCH 142/544] Validate once per era --- src/lib.rs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 36a708d99..bc10d8ea9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,31 +248,34 @@ pub mod pallet { } let current_era = Self::get_current_era(); + let last_managed_era = Self::last_managed_era().unwrap(); let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - let mock_data_url = Self::get_mock_data_url(); + if current_era > last_managed_era { + let mock_data_url = Self::get_mock_data_url(); - let file_request = dac::fetch_file_request(&mock_data_url); - let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); - log::info!("Proved bytes sum: {:?}", bytes_sum); + let file_request = dac::fetch_file_request(&mock_data_url); + let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); + log::info!("Proved bytes sum: {:?}", bytes_sum); - let assigned_edge = - String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); - let validations_res = - dac::get_validation_results(&data_provider_url, current_era, &assigned_edge) - .unwrap(); - let final_res = dac::get_final_decision(validations_res); + let assigned_edge = + String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); + let validations_res = + dac::get_validation_results(&data_provider_url, current_era, &assigned_edge) + .unwrap(); + let final_res = dac::get_final_decision(validations_res); - let signer = Self::get_signer().unwrap(); + let signer = Self::get_signer().unwrap(); - let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, - cdn_node: utils::string_to_account::(assigned_edge.clone()), - validation_decision: final_res.clone(), - }); + let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: current_era, + cdn_node: utils::string_to_account::(assigned_edge.clone()), + validation_decision: final_res.clone(), + }); - log::info!("final_res: {:?}", final_res); + log::info!("final_res: {:?}", final_res); + } // Print the number of broken sessions per CDN node. let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data From 03da8e215bdc96773f5207490b26ce95106f2f0d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 16 May 2023 16:06:00 +0600 Subject: [PATCH 143/544] Return early if no `dacv` key found, don't panic --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bc10d8ea9..671556d5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -266,7 +266,13 @@ pub mod pallet { .unwrap(); let final_res = dac::get_final_decision(validations_res); - let signer = Self::get_signer().unwrap(); + let signer = match Self::get_signer() { + Ok(signer) => signer, + Err(e) => { + log::info!("{}", e); + return + }, + }; let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { era: current_era, From 2e72f43fa1c65e36a8568735e7cbc659f0b70b65 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 18 May 2023 14:26:46 +0200 Subject: [PATCH 144/544] add charge payments to accounts --- pallets/ddc-accounts/src/lib.rs | 194 ++++++++++++++++++++++---------- 1 file changed, 136 insertions(+), 58 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 62acb3a82..7ec367d5c 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -6,8 +6,7 @@ use codec::{Decode, Encode, HasCompact}; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement, UnixTime}, - BoundedVec, - PalletId + BoundedVec, PalletId, }; use scale_info::TypeInfo; use sp_runtime::{ @@ -44,6 +43,26 @@ pub struct UnlockChunk { era: EraIndex, } +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct Bucket { + bucket_id: u128, + owner_id: AccountId, + public_availability: bool, + resources_reserved: u128, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct BucketsDetails { + bucket_id: u128, + amount: Balance, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct ReceiverDetails { + cdn_owner: AccountId, + amount: Balance, +} + #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct AccountsLedger { /// The stash account whose balance is actually locked and can be used for CDN usage. @@ -52,13 +71,14 @@ pub struct AccountsLedger { /// It's just `active` plus all the `unlocking` balances. #[codec(compact)] pub total: Balance, - /// The total amount of the stash's balance that will be accessible for CDN payments in any forthcoming - /// rounds. + /// The total amount of the stash's balance that will be accessible for CDN payments in any + /// forthcoming rounds. #[codec(compact)] pub active: Balance, /// Any balance that is becoming free, which may eventually be transferred out of the stash - /// (assuming that the content owner has to pay for network usage). It is assumed that this will be treated as a first - /// in, first out queue where the new (higher value) eras get pushed on the back. + /// (assuming that the content owner has to pay for network usage). It is assumed that this + /// will be treated as a first in, first out queue where the new (higher value) eras get pushed + /// on the back. pub unlocking: BoundedVec, MaxUnlockingChunks>, } @@ -78,7 +98,7 @@ impl current_era { true } else { @@ -112,7 +132,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - /// The accounts's pallet id, used for deriving its sovereign account ID. + /// The accounts's pallet id, used for deriving its sovereign account ID. #[pallet::constant] type PalletId: Get; type Currency: LockableCurrency; @@ -120,7 +140,7 @@ pub mod pallet { /// Number of eras that staked funds must remain bonded for. #[pallet::constant] type BondingDuration: Get; - type TimeProvider: UnixTime; + type TimeProvider: UnixTime; } /// Map from all locked "stash" accounts to the controller account. @@ -134,6 +154,21 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, AccountsLedger>>; + #[pallet::type_value] + pub fn DefaultBucketCount() -> u128 { + 0_u128 + } + #[pallet::storage] + #[pallet::getter(fn buckets_count)] + pub type BucketsCount = + StorageValue>; + + /// Map from all locked accounts and their buckets to the bucket structure + #[pallet::storage] + #[pallet::getter(fn buckets)] + pub type Buckets = + StorageMap<_, Twox64Concat, u128, Bucket, OptionQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { @@ -155,7 +190,7 @@ pub mod pallet { NotController, /// Not a stash account. NotStash, - /// Stash is already bonded. + /// Stash is already bonded. AlreadyBonded, /// Controller is already paired. AlreadyPaired, @@ -168,12 +203,12 @@ pub mod pallet { } #[pallet::genesis_config] - pub struct GenesisConfig; + pub struct GenesisConfig; #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - Self + Self } } @@ -190,6 +225,50 @@ pub mod pallet { #[pallet::call] impl Pallet { + #[pallet::weight(10_000)] + pub fn charge_payments( + origin: OriginFor, + paying_accounts: Vec>>, + ) -> DispatchResult { + let validator = ensure_signed(origin)?; + let account_id = Self::account_id(); + + for bucket_details in paying_accounts.iter() { + let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); + let content_owner = bucket.owner_id; + let amount = bucket_details.amount; + + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; + ledger.total -= amount; + ledger.active -= amount; + + Self::update_ledger(&content_owner, &ledger); + } + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn create_bucket( + origin: OriginFor, + public_availability: bool, + resources_reserved: u128, + ) -> DispatchResult { + let bucket_owner = ensure_signed(origin)?; + let cur_bucket_id = Self::buckets_count(); + + let bucket = Bucket { + bucket_id: cur_bucket_id + 1, + owner_id: bucket_owner, + public_availability, + resources_reserved, + }; + + >::set(cur_bucket_id + 1); + >::insert(cur_bucket_id + 1, bucket); + Ok(()) + } + /// Take the origin account as a stash and lock up `value` of its balance. `controller` will /// be the account that controls it. /// @@ -198,14 +277,15 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the stash account. /// /// Emits `Deposited`. - #[pallet::weight(10_000)] pub fn deposit( + #[pallet::weight(10_000)] + pub fn deposit( origin: OriginFor, controller: ::Source, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let stash = ensure_signed(origin)?; - if >::contains_key(&stash) { + if >::contains_key(&stash) { Err(Error::::AlreadyBonded)? } @@ -227,13 +307,17 @@ pub mod pallet { let stash_balance = T::Currency::free_balance(&stash); let value = value.min(stash_balance); Self::deposit_event(Event::::Deposited(stash.clone(), value)); - let item = - AccountsLedger { stash: stash.clone(), total: value, active: value, unlocking: Default::default() }; - Self::update_ledger_and_deposit( &stash, &controller, &item)?; + let item = AccountsLedger { + stash: stash.clone(), + total: value, + active: value, + unlocking: Default::default(), + }; + Self::update_ledger_and_deposit(&stash, &controller, &item)?; Ok(()) } - /// Add some extra amount that have appeared in the stash `free_balance` into the balance up + /// Add some extra amount that have appeared in the stash `free_balance` into the balance up /// for CDN payments. /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. @@ -250,23 +334,23 @@ pub mod pallet { let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; let stash_balance = T::Currency::free_balance(&stash); - let extra = stash_balance.min(max_additional); - ledger.total += extra; - ledger.active += extra; - // Last check: the new active amount of ledger must be more than ED. - ensure!( - ledger.active >= T::Currency::minimum_balance(), - Error::::InsufficientDeposit - ); - - Self::update_ledger_and_deposit(&stash, &controller, &ledger)?; - - Self::deposit_event(Event::::Deposited(stash.clone(), extra)); - + let extra = stash_balance.min(max_additional); + ledger.total += extra; + ledger.active += extra; + // Last check: the new active amount of ledger must be more than ED. + ensure!( + ledger.active >= T::Currency::minimum_balance(), + Error::::InsufficientDeposit + ); + + Self::update_ledger_and_deposit(&stash, &controller, &ledger)?; + + Self::deposit_event(Event::::Deposited(stash.clone(), extra)); + Ok(()) } - /// Schedule a portion of the stash to be unlocked ready for transfer out after the bond + /// Schedule a portion of the stash to be unlocked ready for transfer out after the bond /// period ends. If this leaves an amount actively bonded less than /// T::Currency::minimum_balance(), then it is increased to the full amount. /// @@ -307,7 +391,7 @@ pub mod pallet { // Note: bonding for extra era to allow for accounting let era = Self::get_current_era() + T::BondingDuration::get(); - log::info!("Era for the unbond: {:?}", era); + log::info!("Era for the unbond: {:?}", era); if let Some(mut chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) @@ -330,7 +414,6 @@ pub mod pallet { Ok(()) } - /// Remove any unlocked chunks from the `unlocking` queue from our management. /// /// This essentially frees up that balance to be used by the stash account to do @@ -346,40 +429,35 @@ pub mod pallet { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); - let current_era = Self::get_current_era(); + let current_era = Self::get_current_era(); ledger = ledger.consolidate_unlocked(current_era); - log::info!("Current era: {:?}", current_era); + log::info!("Current era: {:?}", current_era); if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() { - log::info!("Killing stash"); + log::info!("Killing stash"); // This account must have called `unbond()` with some value that caused the active // portion to fall below existential deposit + will have no more unlocking chunks // left. We can now safely remove all accounts-related information. Self::kill_stash(&stash)?; } else { - log::info!("Updating ledger"); + log::info!("Updating ledger"); // This was the consequence of a partial unbond. just update the ledger and move on. Self::update_ledger(&controller, &ledger); }; - - log::info!("Current total: {:?}", ledger.total); - log::info!("Old total: {:?}", old_total); + + log::info!("Current total: {:?}", ledger.total); + log::info!("Old total: {:?}", old_total); // `old_total` should never be less than the new total because // `consolidate_unlocked` strictly subtracts balance. if ledger.total < old_total { - log::info!("Preparing for transfer"); + log::info!("Preparing for transfer"); // Already checked that this won't overflow by entry condition. let value = old_total - ledger.total; - let account_id = Self::account_id(); + let account_id = Self::account_id(); - T::Currency::transfer( - &account_id, - &stash, - value, - ExistenceRequirement::KeepAlive, - )?; + T::Currency::transfer(&account_id, &stash, value, ExistenceRequirement::KeepAlive)?; Self::deposit_event(Event::::Withdrawn(stash, value)); } @@ -388,18 +466,18 @@ pub mod pallet { } impl Pallet { - pub fn account_id() -> T::AccountId { - T::PalletId::get().into_account() - } + pub fn account_id() -> T::AccountId { + T::PalletId::get().into_account() + } /// Update the ledger for a controller. /// /// This will also deposit the funds to pallet. fn update_ledger_and_deposit( - stash: &T::AccountId, + stash: &T::AccountId, controller: &T::AccountId, ledger: &AccountsLedger>, ) -> DispatchResult { - let account_id = Self::account_id(); + let account_id = Self::account_id(); T::Currency::transfer( stash, @@ -409,10 +487,10 @@ pub mod pallet { )?; >::insert(controller, ledger); - Ok(()) + Ok(()) } - /// Update the ledger for a controller. + /// Update the ledger for a controller. fn update_ledger( controller: &T::AccountId, ledger: &AccountsLedger>, @@ -420,7 +498,7 @@ pub mod pallet { >::insert(controller, ledger); } - /// Remove all associated data of a stash account from the accounts system. + /// Remove all associated data of a stash account from the accounts system. /// /// Assumes storage is upgraded before calling. /// @@ -437,7 +515,7 @@ pub mod pallet { Ok(()) } - // Get the current era. + // Get the current era. fn get_current_era() -> EraIndex { ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) .try_into() From 937ae3951e0530581856e5dd5be4ded64173a53e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 18 May 2023 18:45:17 +0600 Subject: [PATCH 145/544] Don't panic in absence of `LastManagedEra` value --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 671556d5f..e91596394 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -248,7 +248,7 @@ pub mod pallet { } let current_era = Self::get_current_era(); - let last_managed_era = Self::last_managed_era().unwrap(); + let last_managed_era = Self::last_managed_era().unwrap_or(0); let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); From d38fb2e10d6cecd5a30c4eedf9f1915fb3c00299 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 18 May 2023 18:47:04 +0600 Subject: [PATCH 146/544] Autoformat DAC Validator files --- pallets/ddc-validator/src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index e91596394..bc985f1f2 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -259,8 +259,9 @@ pub mod pallet { let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); log::info!("Proved bytes sum: {:?}", bytes_sum); - let assigned_edge = - String::from("0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1"); + let assigned_edge = String::from( + "0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1", + ); let validations_res = dac::get_validation_results(&data_provider_url, current_era, &assigned_edge) .unwrap(); @@ -274,11 +275,12 @@ pub mod pallet { }, }; - let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, - cdn_node: utils::string_to_account::(assigned_edge.clone()), - validation_decision: final_res.clone(), - }); + let tx_res = + signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: current_era, + cdn_node: utils::string_to_account::(assigned_edge.clone()), + validation_decision: final_res.clone(), + }); log::info!("final_res: {:?}", final_res); } @@ -400,7 +402,8 @@ pub mod pallet { &validation_decision_base64_string, ); match response { - Ok(response) => log::info!("Shared memory response: {:?}", response.to_string()), + Ok(response) => + log::info!("Shared memory response: {:?}", response.to_string()), Err(e) => { log::error!("Shared memory error: {:?}", e); continue From 2f8e1d895ce63304a2d829a0c5273df3d8e3678b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 12:18:29 +0600 Subject: [PATCH 147/544] Remove unwraps from bytes sent and received fetch --- pallets/ddc-validator/src/dac.rs | 8 ++++---- pallets/ddc-validator/src/lib.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 68442f1b1..442ab3661 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -393,16 +393,16 @@ pub(crate) fn fetch_data1( pub(crate) fn fetch_data2( data_provider_url: &String, era: EraIndex, -) -> (String, Vec, String, Vec) { +) -> Result<(String, Vec, String, Vec), ()> { let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); - let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); + let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).map_err(|_|())?; let bytes_sent = BytesSent::get_all(bytes_sent_res); let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); - let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); + let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).map_err(|_|())?; let bytes_received = BytesReceived::get_all(bytes_received_res); - (bytes_sent_query, bytes_sent, bytes_received_query, bytes_received) + Ok((bytes_sent_query, bytes_sent, bytes_received_query, bytes_received)) } fn get_bytes_received_query_url(data_provider_url: &String, era: EraIndex) -> String { diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index bc985f1f2..1dffcf5de 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -321,8 +321,14 @@ pub mod pallet { } // Read from DAC. - let (sent_query, sent, received_query, received) = - dac::fetch_data2(&data_provider_url, current_era - 1); + let response = dac::fetch_data2(&data_provider_url, current_era - 1); + let (sent_query, sent, received_query, received) = match response { + Ok(data) => data, + Err(_) => { + log::info!("🔎 DAC Validator failed to bytes sent and bytes received from DAC"); + return + }, + }; log::info!( "🔎 DAC Validator is fetching data from DAC, current era: {:?}, bytes sent query: {:?}, bytes sent response: {:?}, bytes received query: {:?}, bytes received response: {:?}", current_era, From 7b206d158f0981360a81be8e7d7bfbb0ef1e0b15 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 12:43:10 +0600 Subject: [PATCH 148/544] Print an account available to the off-chain worker --- pallets/ddc-validator/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 1dffcf5de..2bfbd334b 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -247,6 +247,13 @@ pub mod pallet { return } + if let Some(pubkey) = sr25519_public_keys(KEY_TYPE).first() { + // May not work with some kinds of AccountId. Check + // https://substrate.stackexchange.com/questions/1484. + let account = T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap(); + log::debug!("🔎 DAC Validator's local account {:?}", account); + } + let current_era = Self::get_current_era(); let last_managed_era = Self::last_managed_era().unwrap_or(0); let data_provider_url = Self::get_data_provider_url(); From ed5cee935217ea6a0bb941039b4b417d98bd6709 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 13:21:43 +0600 Subject: [PATCH 149/544] Typo fix --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 2bfbd334b..1cb6d0228 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -332,7 +332,7 @@ pub mod pallet { let (sent_query, sent, received_query, received) = match response { Ok(data) => data, Err(_) => { - log::info!("🔎 DAC Validator failed to bytes sent and bytes received from DAC"); + log::info!("🔎 DAC Validator failed to get bytes sent and received from DAC"); return }, }; From ca0b17d42bf95f9b08bc8a2f4b6350bb66899bac Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 14:54:21 +0600 Subject: [PATCH 150/544] Add ddc-accounts dependency to ddc-validator --- Cargo.lock | 1 + pallets/ddc-validator/Cargo.toml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8e63452b3..4e3536133 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4676,6 +4676,7 @@ dependencies = [ "log", "pallet-balances", "pallet-contracts", + "pallet-ddc-accounts", "pallet-ddc-staking", "pallet-randomness-collective-flip", "pallet-session", diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 3cf75a246..a1cfef98d 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -14,6 +14,7 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa log = { version = "0.4.17", default-features = false } lite-json = { version = "0.2.0", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" } +pallet-ddc-accounts = { version = "0.1.0", default-features = false, path = "../ddc-accounts" } pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" } @@ -36,6 +37,7 @@ std = [ "frame-election-provider-support/std", "lite-json/std", "pallet-contracts/std", + "pallet-ddc-accounts/std", "pallet-ddc-staking/std", "pallet-session/std", "pallet-staking/std", From 24efe5da4cd4ecc7667ac35b0ced16f9e9aa7c1b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 16:13:35 +0600 Subject: [PATCH 151/544] Price per byte storage item and a call to set it --- pallets/ddc-accounts/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 7ec367d5c..e70c60233 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -169,6 +169,11 @@ pub mod pallet { pub type Buckets = StorageMap<_, Twox64Concat, u128, Bucket, OptionQuery>; + /// Price per byte of the bucket traffic in smallest units of the currency. + #[pallet::storage] + #[pallet::getter(fn pricing)] + pub type Pricing = StorageValue<_, u128>; + #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { @@ -463,6 +468,16 @@ pub mod pallet { Ok(()) } + + /// Set price per byte of the bucket traffic in smallest units of the currency. + /// + /// The dispatch origin for this call must be _Root_. + #[pallet::weight(10_000)] + pub fn set_pricing(origin: OriginFor, price_per_byte: u128) -> DispatchResult { + ensure_root(origin)?; + >::set(Some(price_per_byte)); + Ok(()) + } } impl Pallet { From 740dce652fc8b3ebf11c5807a1b55913734fafad Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 16:23:49 +0600 Subject: [PATCH 152/544] Move pricing storage item and call to ddc-staking --- pallets/ddc-accounts/src/lib.rs | 15 --------------- pallets/ddc-staking/src/lib.rs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index e70c60233..7ec367d5c 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -169,11 +169,6 @@ pub mod pallet { pub type Buckets = StorageMap<_, Twox64Concat, u128, Bucket, OptionQuery>; - /// Price per byte of the bucket traffic in smallest units of the currency. - #[pallet::storage] - #[pallet::getter(fn pricing)] - pub type Pricing = StorageValue<_, u128>; - #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { @@ -468,16 +463,6 @@ pub mod pallet { Ok(()) } - - /// Set price per byte of the bucket traffic in smallest units of the currency. - /// - /// The dispatch origin for this call must be _Root_. - #[pallet::weight(10_000)] - pub fn set_pricing(origin: OriginFor, price_per_byte: u128) -> DispatchResult { - ensure_root(origin)?; - >::set(Some(price_per_byte)); - Ok(()) - } } impl Pallet { diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ced37c72a..0ac5652b7 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -211,6 +211,11 @@ pub mod pallet { pub type ErasEdgesRewardPoints = StorageMap<_, Twox64Concat, EraIndex, EraRewardPoints, ValueQuery>; + /// Price per byte of the bucket traffic in smallest units of the currency. + #[pallet::storage] + #[pallet::getter(fn pricing)] + pub type Pricing = StorageValue<_, u128>; + #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { @@ -579,6 +584,16 @@ pub mod pallet { Ok(()) } + + /// Set price per byte of the bucket traffic in smallest units of the currency. + /// + /// The dispatch origin for this call must be _Root_. + #[pallet::weight(10_000)] + pub fn set_pricing(origin: OriginFor, price_per_byte: u128) -> DispatchResult { + ensure_root(origin)?; + >::set(Some(price_per_byte)); + Ok(()) + } } impl Pallet { From 1cc29e031706b9d314e513a40742dd8faa0a23c3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 19 May 2023 17:43:59 +0600 Subject: [PATCH 153/544] Compute CDN payout using the price per byte --- pallets/ddc-staking/src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 0ac5652b7..d1e387b75 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -257,6 +257,10 @@ pub mod pallet { AlreadyInRole, /// Two or more occurrences of a staker account in rewards points list. DuplicateRewardPoints, + /// Price per byte of the traffic is unknown. + PricingNotSet, + /// Impossible budget value that overflows pallet's balance type. + BudgetOverflow, } #[pallet::call] @@ -601,19 +605,30 @@ pub mod pallet { // ToDo: check that the era is finished // ToDo: check reward points are set - // An account we withdraw the funds from and the amount of funds to withdraw. - let payout_source_account: T::AccountId = T::StakersPayoutSource::get().into_account(); - let payout_budget = T::Currency::free_balance(&payout_source_account); let era_reward_points: EraRewardPoints = >::get(&era); + + let price_per_byte: u128 = match Self::pricing() { + Some(pricing) => pricing, + None => Err(Error::::PricingNotSet)?, + }; + + // An account we withdraw the funds from and the amount of funds to withdraw. + let payout_source_account: T::AccountId = T::StakersPayoutSource::get().into_account(); + let payout_budget: BalanceOf = + match (price_per_byte * era_reward_points.total as u128).try_into() { + Ok(value) => value, + Err(_) => Err(Error::::BudgetOverflow)?, + }; log::debug!( "Will payout to DDC stakers for era {:?} from account {:?} with total budget {:?} \ - , there are {:?} stakers earned {:?} reward points", + , there are {:?} stakers earned {:?} reward points with price per byte {:?}", era, payout_source_account, payout_budget, era_reward_points.individual.len(), era_reward_points.total, + price_per_byte, ); // Transfer a part of the budget to each CDN participant rewarded this era. From a4663998d41e86aeb2b86ae7e6467025b8a2a67e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 19 May 2023 18:06:19 +0200 Subject: [PATCH 154/544] account for unlocking chunks for payments --- pallets/ddc-accounts/src/lib.rs | 67 ++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 7ec367d5c..e31f3d27b 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -114,6 +114,33 @@ impl (Self, Balance) { + let mut unlocking_balance = Balance::zero(); + + while let Some(last) = self.unlocking.last_mut() { + if unlocking_balance + last.value <= value { + unlocking_balance += last.value; + self.active -= last.value; + self.unlocking.pop(); + } else { + let diff = value - unlocking_balance; + + unlocking_balance += diff; + self.active -= diff; + last.value -= diff; + } + + if unlocking_balance >= value { + break + } + } + + (self, unlocking_balance) + } } #[frame_support::pallet] @@ -182,6 +209,8 @@ pub mod pallet { /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` /// from the unlocking queue. \[stash, amount\] Withdrawn(T::AccountId, BalanceOf), + /// Total amount charged from all accounts to pay CDN nodes + Charged(BalanceOf), } #[pallet::error] @@ -231,19 +260,31 @@ pub mod pallet { paying_accounts: Vec>>, ) -> DispatchResult { let validator = ensure_signed(origin)?; - let account_id = Self::account_id(); - - for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); - let content_owner = bucket.owner_id; - let amount = bucket_details.amount; - - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; - ledger.total -= amount; - ledger.active -= amount; - - Self::update_ledger(&content_owner, &ledger); - } + let mut total_charged = BalanceOf::::zero(); + + for bucket_details in paying_accounts.iter() { + let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); + let content_owner = bucket.owner_id; + let amount = bucket_details.amount; + + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; + if ledger.active >= amount { + ledger.total -= amount; + ledger.active -= amount; + total_charged += amount; + Self::update_ledger(&content_owner, &ledger); + } else { + let diff = amount - ledger.active; + total_charged += ledger.active; + ledger.total -= ledger.active; + ledger.active = BalanceOf::::zero(); + let (ledger, charged) = ledger.charge_unlocking(diff); + Self::update_ledger(&content_owner, &ledger); + total_charged += charged; + } + + } + Self::deposit_event(Event::::Charged(total_charged)); Ok(()) } From cce436f548ad3a1638b6bd52d24f0b398b5b4c99 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 22 May 2023 16:37:57 +0600 Subject: [PATCH 155/544] Autoformat DAC Validator files --- pallets/ddc-validator/src/dac.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 442ab3661..af871abe8 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -395,11 +395,12 @@ pub(crate) fn fetch_data2( era: EraIndex, ) -> Result<(String, Vec, String, Vec), ()> { let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); - let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).map_err(|_|())?; + let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).map_err(|_| ())?; let bytes_sent = BytesSent::get_all(bytes_sent_res); let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); - let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).map_err(|_|())?; + let bytes_received_res: RedisFtAggregate = + http_get_json(&bytes_received_query).map_err(|_| ())?; let bytes_received = BytesReceived::get_all(bytes_received_res); Ok((bytes_sent_query, bytes_sent, bytes_received_query, bytes_received)) From 9af794b105eb43d7234155130a3f714926800f71 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 22 May 2023 18:39:55 +0200 Subject: [PATCH 156/544] Move code form the old repo --- pallets/ddc-validator/src/dac.rs | 37 +++-- pallets/ddc-validator/src/lib.rs | 238 ++++++++++++++++++++--------- pallets/ddc-validator/src/shm.rs | 107 ++++++++++++- pallets/ddc-validator/src/utils.rs | 36 ++++- 4 files changed, 319 insertions(+), 99 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index af871abe8..9a0f27739 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -273,21 +273,24 @@ fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { timestamps } -pub fn get_proved_delivered_bytes_sum(file_requests: &Requests) -> u64 { +pub fn get_served_bytes_sum(file_requests: &Requests) -> (u64, u64) { let ack_timestamps = get_timestamps_with_ack(file_requests); let mut total_bytes_received = 0u64; + let mut total_bytes_sent = 0u64; for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { + total_bytes_sent += chunk.log.bytes_sent; + if let Some(ack) = &chunk.ack { - total_bytes_received += &chunk.log.bytes_sent; + total_bytes_received += ack.bytes_received; } else { total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); } } } - total_bytes_received + (total_bytes_sent, total_bytes_received) } fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> u64 { @@ -342,10 +345,13 @@ fn get_file_request_url(data_provider_url: &String) -> String { } pub(crate) fn fetch_file_request(url: &String) -> Requests { + log::info!("fetch_file_request | url: {:?}", url); let response: FileRequestWrapper = http_get_json(&url).unwrap(); let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); let map: Requests = serde_json::from_value(value).unwrap(); + log::info!("response.json: {:?}", response.json); + map } @@ -410,7 +416,7 @@ fn get_bytes_received_query_url(data_provider_url: &String, era: EraIndex) -> St format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", data_provider_url, era, era) } -fn http_get_json(url: &str) -> crate::ResultStr { +pub(crate) fn http_get_json(url: &str) -> crate::ResultStr { let body = http_get_request(url).map_err(|err| { log::error!("[DAC Validator] Error while getting {}: {:?}", url, err); "HTTP GET error" @@ -541,16 +547,19 @@ pub(crate) fn post_final_decision( res } -pub(crate) fn get_final_decision(decisions: Vec) -> ValidationDecision { +pub(crate) fn get_final_decision(decisions: Vec) -> ValidationDecision { let common_decisions = find_largest_group(decisions).unwrap(); let decision_example = common_decisions.get(0).unwrap(); + let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); + let final_decision = ValidationDecision { + edge: decision_example.edge.clone(), result: decision_example.result, - payload: utils::get_hashed(&common_decisions), + payload: utils::hash(&serialized_decisions), totals: DacTotalAggregates { - received: decision_example.received, - sent: decision_example.sent, + received: decision_example.totals.received, + sent: decision_example.totals.sent, failed_by_client: 0, failure_rate: 0, }, @@ -559,7 +568,7 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validation final_decision } -pub(crate) fn get_validation_results( +pub(crate) fn fetch_validation_results( data_provider_url: &String, era: EraIndex, edge: &String, @@ -571,8 +580,8 @@ pub(crate) fn get_validation_results( Ok(results) } -fn find_largest_group(decisions: Vec) -> Option> { - let mut groups: Vec> = Vec::new(); +fn find_largest_group(decisions: Vec) -> Option> { + let mut groups: Vec> = Vec::new(); let half = decisions.len() / 2; for decision in decisions { @@ -581,12 +590,12 @@ fn find_largest_group(decisions: Vec) -> Option last_managed_era { - let mock_data_url = Self::get_mock_data_url(); - - let file_request = dac::fetch_file_request(&mock_data_url); - let bytes_sum = dac::get_proved_delivered_bytes_sum(&file_request); - log::info!("Proved bytes sum: {:?}", bytes_sum); - - let assigned_edge = String::from( - "0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1", - ); - let validations_res = - dac::get_validation_results(&data_provider_url, current_era, &assigned_edge) - .unwrap(); - let final_res = dac::get_final_decision(validations_res); - - let signer = match Self::get_signer() { - Ok(signer) => signer, - Err(e) => { - log::info!("{}", e); - return - }, - }; - - let tx_res = - signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, - cdn_node: utils::string_to_account::(assigned_edge.clone()), - validation_decision: final_res.clone(), - }); - - log::info!("final_res: {:?}", final_res); - } + // `If` commented for testing purposes + // if current_era > last_managed_era { + Self::validate_edges(); + //} // Print the number of broken sessions per CDN node. - let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data - let aggregates_obj = aggregates_value.as_object().unwrap(); - aggregates_obj - .into_iter() - .for_each(|(cdn_node_pubkey, cdn_node_aggregates_value)| { - // iterate over aggregates for each node - let cdn_node_aggregates_obj = cdn_node_aggregates_value.as_object().unwrap(); - // Extract `nodeInterruptedSessions` field - let (_, cdn_node_interrupted_sessions_value) = cdn_node_aggregates_obj - .into_iter() - .find(|(key, _)| key.iter().copied().eq("nodeInterruptedSessions".chars())) - .unwrap(); - let cdn_node_interrupted_sessions_obj = - cdn_node_interrupted_sessions_value.as_object().unwrap(); - // Prepare CDN pubkey without heap allocated string - let cdn_node_pubkey_vecu8: Vec = - cdn_node_pubkey.iter().map(|c| *c as u8).collect(); - let cdn_node_pubkey_str = - sp_std::str::from_utf8(&cdn_node_pubkey_vecu8).unwrap(); - log::info!( - "Broken sessions per CDN node | Node {}: {} sessions broken", - cdn_node_pubkey_str, - cdn_node_interrupted_sessions_obj.len(), /* count sessions broken by the - * node */ - ); - }); + // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data + // let aggregates_obj = aggregates_value.as_object().unwrap(); + // aggregates_obj + // .into_iter() + // .for_each(|(cdn_node_pubkey, cdn_node_aggregates_value)| { + // // iterate over aggregates for each node + // let cdn_node_aggregates_obj = cdn_node_aggregates_value.as_object().unwrap(); + // // Extract `nodeInterruptedSessions` field + // let (_, cdn_node_interrupted_sessions_value) = cdn_node_aggregates_obj + // .into_iter() + // .find(|(key, _)| key.iter().copied().eq("nodeInterruptedSessions".chars())) + // .unwrap(); + // let cdn_node_interrupted_sessions_obj = + // cdn_node_interrupted_sessions_value.as_object().unwrap(); + // // Prepare CDN pubkey without heap allocated string + // let cdn_node_pubkey_vecu8: Vec = + // cdn_node_pubkey.iter().map(|c| *c as u8).collect(); + // let cdn_node_pubkey_str = + // sp_std::str::from_utf8(&cdn_node_pubkey_vecu8).unwrap(); + // log::info!( + // "Broken sessions per CDN node | Node {}: {} sessions broken", + // cdn_node_pubkey_str, + // cdn_node_interrupted_sessions_obj.len(), /* count sessions broken by the + // * node */ + // ); + // }); // Wait for signal. let signal = Signal::::get().unwrap_or(false); @@ -381,8 +352,9 @@ pub mod pallet { // Prepare an intermediate validation decision let validation_decision = ValidationDecision { + edge: utils::account_to_string::(edge.clone()), result: validation_result, - payload: [0u8; 256], // ToDo: put a hash of the validated data here + payload: [0u8; 32], // ToDo: put a hash of the validated data here totals: DacTotalAggregates { sent: node_sent.sum as u64, received: client_received.sum as u64, @@ -440,8 +412,9 @@ pub mod pallet { "0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1".into(), ), ValidationDecision { + edge: "test".into(), result: true, - payload: [0u8; 256], + payload: [0u8; 32], totals: DacTotalAggregates { sent: 100, received: 100, @@ -455,8 +428,9 @@ pub mod pallet { "0xa2d14e71b52e5695e72c0567926bc68b68bda74df5c1ccf1d4ba612c153ff66b".into(), ), ValidationDecision { + edge: "test".into(), result: true, - payload: [0u8; 256], + payload: [0u8; 32], totals: DacTotalAggregates { sent: 200, received: 200, @@ -612,6 +586,18 @@ pub mod pallet { } } + fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool { + let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); + + return if percentage_difference > 0.0 && + (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 + { + true + } else { + false + } + } + fn shuffle(mut list: Vec) -> Vec { let len = list.len(); for i in 1..len { @@ -645,6 +631,9 @@ pub mod pallet { let quorums = Self::split(validators_keys, quorum_size); let edges_groups = Self::split(shuffled_edges, quorums.len()); + info!("quorums: {:?}", quorums); + info!("edges_groups: {:?}", edges_groups); + let era = Self::get_current_era(); for (i, quorum) in quorums.iter().enumerate() { @@ -693,5 +682,112 @@ pub mod pallet { random_number } + + fn find_validators_from_quorum(validator_id: &T::AccountId, era: &EraIndex) -> Vec { + let validator_edges = Self::assignments(era, &validator_id).unwrap(); + let mut quorum_members: Vec = Vec::new(); + + >::iter_prefix(era).for_each(|(candidate_id, edges)| { + if validator_edges == edges { + let candidate_id_str = utils::account_to_string::(candidate_id); + quorum_members.push(candidate_id_str); + } + }); + + quorum_members + } + + fn get_public_key() -> Option { + match sr25519_public_keys(KEY_TYPE).first() { + Some(pubkey) => Some(T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()), + None => None + } + } + + fn validate_edges() { + let current_era = Self::get_current_era(); + let mock_data_url = Self::get_mock_data_url(); + let data_provider_url = Self::get_data_provider_url(); + + // let signer = Self::get_signer().unwrap(); + // let validator = signer.get_any_account().unwrap().id; + let validator = Self::get_public_key().unwrap(); + + info!("validator: {:?}", validator); + + let assigned_edges = Self::assignments(current_era - 1, validator.clone()).unwrap(); + + info!("assigned_edges: {:?}", assigned_edges); + + for assigned_edge in assigned_edges.iter() { + let file_request = dac::fetch_file_request(&mock_data_url); + let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&file_request); + let is_valid = Self::is_valid(bytes_sent, bytes_received); + + info!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); + + let payload = serde_json::to_string(&file_request).unwrap(); + let decision = ValidationDecision { + edge: utils::account_to_string::(assigned_edge.clone()), + result: is_valid, + payload: utils::hash(&payload), + totals: DacTotalAggregates { + received: bytes_received, + sent: bytes_sent, + failed_by_client: 0, + failure_rate: 0, + } + }; + + info!("decision: {:?}", decision); + + let serialized_decision = serde_json::to_string(&decision).unwrap(); + let encoded_decision = shm::base64_encode(&serialized_decision.as_bytes().to_vec()); + let validator_str = utils::account_to_string::(validator.clone()); + let edge_str = utils::account_to_string::(assigned_edge.clone()); + + let encoded_decision_str = encoded_decision.iter().cloned().collect::(); + + let response = shm::share_intermediate_validation_result( + &data_provider_url, + current_era - 1, + &validator_str, + &edge_str, + is_valid, + &encoded_decision_str, + ); + + if let Err(res) = response.clone() { + log::error!("share_intermediate_validation_result request failed: {:?}", res); + } + + if let Ok(res) = response.clone() { + info!("shm res: {:?}", res.to_string()); + } + + if let Ok(res) = response { + let edge = utils::account_to_string::(assigned_edge.clone()); + let prev_era = (current_era - 1) as EraIndex; + let quorum = Self::find_validators_from_quorum(&validator, &prev_era); + let validations_res = shm::get_intermediate_decisions(&data_provider_url, &edge_str, &prev_era, quorum); + + log::info!("get_intermediate_decisions result: {:?}", validations_res); + + if validations_res.len() == QUORUM_SIZE { + let final_res = dac::get_final_decision(validations_res); + + let signer = Self::get_signer().unwrap(); + + let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: current_era, + cdn_node: utils::string_to_account::(edge.clone()), + validation_decision: final_res.clone(), + }); + + log::info!("final_res: {:?}", final_res); + } + } + } + } } } diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 777f31d11..1fe38e1cc 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -5,19 +5,52 @@ //! transactions pool or peers list in the future, but for now it works on the centralized Redis //! server which we maintain for DAC DataModel. -use alloc::{format, string::String}; // ToDo: remove String usage +use alloc::{format, string::String}; +pub use sp_std::{collections::btree_map::BTreeMap}; +// ToDo: remove String usage use base64::prelude::*; use lite_json::json::JsonValue; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; use sp_std::prelude::*; +use crate::{dac, utils, ValidationDecision}; +use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; +use log::info; const HTTP_TIMEOUT_MS: u64 = 30_000; +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct IntermediateDecisionsWrapper { + #[serde(rename = "JSON.GET")] + json: String, +} + +#[derive(Debug, Deserialize, Serialize, Clone)] +#[serde(crate = "alt_serde")] +pub(crate) struct IntermediateDecisions { + validators_to_decisions: BTreeMap, +} + +#[derive(Debug, Deserialize, Serialize, Clone)] +#[serde(crate = "alt_serde")] +struct IntermediateDecision { + result: bool, + data: String, +} + +pub fn base64_decode(input: &String) -> Vec { + let mut buf = Vec::with_capacity(392); // ToDo: calculate capacity + buf.resize(392, 0); + BASE64_STANDARD.decode_slice(input, &mut buf).unwrap(); // ToDo: handle error + buf.iter().map(|&char| char as u8).collect() +} + /// Encodes a vector of bytes into a vector of characters using base64 encoding. pub fn base64_encode(input: &Vec) -> Vec { - let mut buf = Vec::with_capacity(1024); // ToDo: calculate capacity - buf.resize(1024, 0); + let mut buf = Vec::with_capacity(392); // ToDo: calculate capacity + buf.resize(392, 0); BASE64_STANDARD.encode_slice(input, &mut buf).unwrap(); // ToDo: handle error buf.iter().map(|&byte| byte as char).collect() } @@ -32,17 +65,27 @@ pub fn share_intermediate_validation_result( validation_decision_encoded: &String, ) -> Result { let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - let validation_result_string = String::from(if validation_result { "true" } else { "false" }); let validation_decision_string = String::from(validation_decision_encoded); + let json = serde_json::json!({ + "result": validation_result, + "data": validation_decision_string, + }); + let json_str = serde_json::to_string(&json).unwrap(); + let unescaped_json = utils::unescape(&json_str); + let url_encoded_json = utils::url_encode(&unescaped_json); + + log::info!("json_str: {:?}", json_str); + let url = format!( - "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{{\"result\":{},\"data\":\"{}\"}}", + "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", shared_memory_webdis_url, validator, cdn_node, era, - validation_result_string, - validation_decision_string, + url_encoded_json, ); + + log::info!("share_intermediate_validation_result url: {:?}", url); let request = http::Request::get(url.as_str()); let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; @@ -55,9 +98,59 @@ pub fn share_intermediate_validation_result( log::warn!("No UTF-8 body"); http::Error::Unknown })?; + + log::info!("body_str: {:?}", body_str); + let json = lite_json::parse_json(body_str).map_err(|_| { log::warn!("No JSON body"); http::Error::Unknown })?; Ok(json) } + +pub(crate) fn get_intermediate_decisions(data_provider_url: &String, edge: &str, era: &EraIndex, quorum: Vec) -> Vec { + let url = format!("{}/JSON.GET/ddc:dac:shared:nodes:{}", data_provider_url, era); + + let response: IntermediateDecisionsWrapper = dac::http_get_json(url.as_str()).unwrap(); + let mut edges_to_validators_decisions: BTreeMap> = serde_json::from_str(&response.json).unwrap(); + let decisions_for_edge = IntermediateDecisions { + validators_to_decisions: edges_to_validators_decisions.remove(edge).unwrap() + }; + + let quorum_decisions = find_quorum_decisions(decisions_for_edge, quorum); + let decoded_decisions = decode_intermediate_decisions(quorum_decisions); + + decoded_decisions +} + +pub(crate) fn decode_intermediate_decisions(decisions: IntermediateDecisions) -> Vec { + let mut decoded_decisions: Vec = Vec::new(); + + for (_, decision) in decisions.validators_to_decisions.iter() { + let data = base64_decode(&decision.data); + + let data_str = String::from_utf8_lossy(&data); + let data_trimmed = data_str.trim_end_matches('\0'); + + info!("data_str: {:?}", data_trimmed); + + let decoded_decision: ValidationDecision = serde_json::from_str(&data_trimmed).unwrap(); + + decoded_decisions.push(decoded_decision); + } + + decoded_decisions +} + +pub(crate) fn find_quorum_decisions(all_decisions: IntermediateDecisions, quorum: Vec) -> IntermediateDecisions { + let mut quorum_decisions: BTreeMap = BTreeMap::new(); + for (validator_id, decision) in all_decisions.validators_to_decisions.iter() { + if quorum.contains(validator_id) { + quorum_decisions.insert(validator_id.clone(), decision.clone()); + } + } + + IntermediateDecisions { + validators_to_decisions: quorum_decisions + } +} diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs index 3c5c90c80..36dc4492a 100644 --- a/pallets/ddc-validator/src/utils.rs +++ b/pallets/ddc-validator/src/utils.rs @@ -1,5 +1,5 @@ use crate::dac::ValidationResult; -use alloc::string::String; +use alloc::{format, string::String}; use codec::{Decode, Encode}; use sp_core::crypto::AccountId32; use sp_io::hashing::blake2_256; @@ -28,11 +28,33 @@ pub(crate) fn hash(data: &String) -> [u8; 32] { result } -pub(crate) fn get_hashed(data: &Vec) -> [u8; 256] { - let results_log = serde_json::to_string(data).unwrap(); - let mut payload: [u8; 256] = [0; 256]; - let hashed_results = hash(&results_log); - payload[..32].copy_from_slice(&hashed_results); +pub(crate) fn url_encode(input: &str) -> String { + let mut encoded = String::new(); - payload + for byte in input.bytes() { + match byte { + // Unreserved characters (alphanumeric and -_.~) + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { + encoded.push(byte as char); + } + _ => { + encoded.push('%'); + encoded.push_str(&format!("{:02X}", byte)); + } + } + } + + encoded } + +pub(crate) fn unescape(json: &str) -> String { + let mut result = String::new(); + + for ch in json.chars() { + if ch != '\\' { + result.push(ch); + } + } + + result +} \ No newline at end of file From 5768ed8f0c8928b2f6ffc51af9126d73d11e7239 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 23 May 2023 17:32:26 +0200 Subject: [PATCH 157/544] Fix job assignment --- pallets/ddc-validator/src/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 99c0a56b6..8c16b2393 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -78,7 +78,7 @@ pub const ERA_IN_BLOCKS: u8 = 20; // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; -pub const QUORUM_SIZE: usize = 1; +pub const QUORUM_SIZE: usize = 3; /// Aggregated values from DAC that describe CDN node's activity during a certain era. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize)] @@ -609,7 +609,19 @@ pub mod pallet { } fn split(list: Vec, segment_len: usize) -> Vec> { - list.chunks(segment_len).map(|chunk| chunk.to_vec()).collect() + let mut result: Vec> = Vec::new(); + + if segment_len == 0 { + return result; + } + + for i in (0..list.len()).step_by(segment_len) { + let end = usize::min(i + segment_len, list.len()); + let chunk = list[i..end].to_vec(); + result.push(chunk); + } + + result } fn assign(quorum_size: usize) { @@ -629,7 +641,7 @@ pub mod pallet { .collect(); let quorums = Self::split(validators_keys, quorum_size); - let edges_groups = Self::split(shuffled_edges, quorums.len()); + let edges_groups = Self::split(shuffled_edges, quorum_size); info!("quorums: {:?}", quorums); info!("edges_groups: {:?}", edges_groups); From a5054c989af904247f28e4e3aaf615c459f614f3 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Wed, 24 May 2023 18:04:15 +0200 Subject: [PATCH 158/544] Incerease spec_version --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index b764b42b5..60755e9fe 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 30700, + spec_version: 30800, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, From b0ad5a8f36ff74d4a14009b8e99e50c0e3387ef0 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 29 May 2023 14:22:21 +0600 Subject: [PATCH 159/544] Return result type from shm encode/decode funcs --- pallets/ddc-validator/src/shm.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 1fe38e1cc..120d60103 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -40,19 +40,19 @@ struct IntermediateDecision { data: String, } -pub fn base64_decode(input: &String) -> Vec { +pub fn base64_decode(input: &String) -> Result, ()> { let mut buf = Vec::with_capacity(392); // ToDo: calculate capacity buf.resize(392, 0); - BASE64_STANDARD.decode_slice(input, &mut buf).unwrap(); // ToDo: handle error - buf.iter().map(|&char| char as u8).collect() + BASE64_STANDARD.decode_slice(input, &mut buf).map_err(|_| ())?; + Ok(buf.iter().map(|&char| char as u8).collect()) } /// Encodes a vector of bytes into a vector of characters using base64 encoding. -pub fn base64_encode(input: &Vec) -> Vec { +pub fn base64_encode(input: &Vec) -> Result, ()> { let mut buf = Vec::with_capacity(392); // ToDo: calculate capacity buf.resize(392, 0); - BASE64_STANDARD.encode_slice(input, &mut buf).unwrap(); // ToDo: handle error - buf.iter().map(|&byte| byte as char).collect() + BASE64_STANDARD.encode_slice(input, &mut buf).map_err(|_| ())?; + Ok(buf.iter().map(|&byte| byte as char).collect()) } /// Publish intermediate validation result to redis. From 076e13cc3c08b8596ac90422dd431a15f28e4174 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 29 May 2023 14:49:37 +0600 Subject: [PATCH 160/544] Panic at higher level on shm coding errors --- pallets/ddc-validator/src/lib.rs | 7 ++++--- pallets/ddc-validator/src/shm.rs | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 8c16b2393..eb6dc2513 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -366,7 +366,7 @@ pub mod pallet { // Encode validation decision to base64 let validation_decision_serialized: Vec = validation_decision.encode(); let validation_decision_base64 = - shm::base64_encode(&validation_decision_serialized); + shm::base64_encode(&validation_decision_serialized).unwrap(); log::info!( "Intermediate validation decision for CDN node {:?}: , base64 encoded: {:?}", validation_decision, @@ -748,13 +748,14 @@ pub mod pallet { sent: bytes_sent, failed_by_client: 0, failure_rate: 0, - } + }, }; info!("decision: {:?}", decision); let serialized_decision = serde_json::to_string(&decision).unwrap(); - let encoded_decision = shm::base64_encode(&serialized_decision.as_bytes().to_vec()); + let encoded_decision = + shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); let validator_str = utils::account_to_string::(validator.clone()); let edge_str = utils::account_to_string::(assigned_edge.clone()); diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 120d60103..31477ad1d 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -123,11 +123,13 @@ pub(crate) fn get_intermediate_decisions(data_provider_url: &String, edge: &str, decoded_decisions } -pub(crate) fn decode_intermediate_decisions(decisions: IntermediateDecisions) -> Vec { +pub(crate) fn decode_intermediate_decisions( + decisions: IntermediateDecisions, +) -> Vec { let mut decoded_decisions: Vec = Vec::new(); for (_, decision) in decisions.validators_to_decisions.iter() { - let data = base64_decode(&decision.data); + let data = base64_decode(&decision.data).unwrap(); let data_str = String::from_utf8_lossy(&data); let data_trimmed = data_str.trim_end_matches('\0'); From d9c9bcc56900e67ae4272835bf80d2ebb31134cd Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 29 May 2023 17:37:31 +0200 Subject: [PATCH 161/544] Fix encoding/decoding --- pallets/ddc-validator/src/shm.rs | 8 ++++---- pallets/ddc-validator/src/utils.rs | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 31477ad1d..ad7990b7f 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -41,16 +41,16 @@ struct IntermediateDecision { } pub fn base64_decode(input: &String) -> Result, ()> { - let mut buf = Vec::with_capacity(392); // ToDo: calculate capacity - buf.resize(392, 0); + let mut buf = Vec::with_capacity(1000); // ToDo: calculate capacity + buf.resize(1000, 0); BASE64_STANDARD.decode_slice(input, &mut buf).map_err(|_| ())?; Ok(buf.iter().map(|&char| char as u8).collect()) } /// Encodes a vector of bytes into a vector of characters using base64 encoding. pub fn base64_encode(input: &Vec) -> Result, ()> { - let mut buf = Vec::with_capacity(392); // ToDo: calculate capacity - buf.resize(392, 0); + let mut buf = Vec::with_capacity(1000); // ToDo: calculate capacity + buf.resize(1000, 0); BASE64_STANDARD.encode_slice(input, &mut buf).map_err(|_| ())?; Ok(buf.iter().map(|&byte| byte as char).collect()) } diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs index 36dc4492a..93c282d03 100644 --- a/pallets/ddc-validator/src/utils.rs +++ b/pallets/ddc-validator/src/utils.rs @@ -49,12 +49,26 @@ pub(crate) fn url_encode(input: &str) -> String { pub(crate) fn unescape(json: &str) -> String { let mut result = String::new(); + let mut chars = json.chars().peekable(); - for ch in json.chars() { - if ch != '\\' { - result.push(ch); + while let Some(c) = chars.next() { + if c == '\\' { + match chars.peek() { + Some('u') => { + // Skip over the next 5 characters + for _ in 0..5 { + chars.next(); + } + } + _ => { + // Skip over the next character + chars.next(); + } + } + } else { + result.push(c); } } result -} \ No newline at end of file +} From bc90d78862b0b1ef88064438afd5b350f59ffc5e Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 29 May 2023 18:16:26 +0200 Subject: [PATCH 162/544] Assign job for current era if there is no assignment --- pallets/ddc-validator/src/lib.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index eb6dc2513..d3f70f904 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -234,15 +234,20 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); - if let Some(last_managed_era) = >::get() { - log::info!("last_managed_era: {:?}", last_managed_era); - if last_managed_era >= era { - return 0 + match >::get(){ + Some(last_managed_era) => { + if last_managed_era > era { + return 0 + } else { + Self::assign(3usize, era + 1); + >::put(era); + } + } + None => { + Self::assign(3usize, era); + >::put(era); } } - >::put(era); - - Self::assign(3usize); 0 } @@ -624,7 +629,7 @@ pub mod pallet { result } - fn assign(quorum_size: usize) { + fn assign(quorum_size: usize, era: EraIndex) { let validators: Vec = >::iter_keys().collect(); let edges: Vec = >::iter_keys().collect(); @@ -646,8 +651,6 @@ pub mod pallet { info!("quorums: {:?}", quorums); info!("edges_groups: {:?}", edges_groups); - let era = Self::get_current_era(); - for (i, quorum) in quorums.iter().enumerate() { let edges_group = &edges_groups[i]; for validator in quorum { @@ -727,7 +730,7 @@ pub mod pallet { info!("validator: {:?}", validator); - let assigned_edges = Self::assignments(current_era - 1, validator.clone()).unwrap(); + let assigned_edges = Self::assignments(current_era - 1, validator.clone()).expect("No assignments for the previous era"); info!("assigned_edges: {:?}", assigned_edges); From ee6a19ad94dfa58b7ea056c6c39bd224f0439263 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 12 Jun 2023 15:47:44 +0600 Subject: [PATCH 163/544] Fix `PalletId` to `AccountId` conversion --- pallets/ddc-accounts/src/lib.rs | 2 +- pallets/ddc-staking/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index e31f3d27b..300ae61d5 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -508,7 +508,7 @@ pub mod pallet { impl Pallet { pub fn account_id() -> T::AccountId { - T::PalletId::get().into_account() + T::PalletId::get().into_account_truncating() } /// Update the ledger for a controller. /// diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index f66411934..5e2ed1691 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -615,7 +615,8 @@ pub mod pallet { }; // An account we withdraw the funds from and the amount of funds to withdraw. - let payout_source_account: T::AccountId = T::StakersPayoutSource::get().into_account(); + let payout_source_account: T::AccountId = + T::StakersPayoutSource::get().into_account_truncating(); let payout_budget: BalanceOf = match (price_per_byte * era_reward_points.total as u128).try_into() { Ok(value) => value, From f67157af093aee3a86600359c8f0de9ffac039be Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 31 May 2023 10:10:32 +0200 Subject: [PATCH 164/544] link payments --- pallets/ddc-accounts/src/lib.rs | 37 ++++++++++++++++++++++++++++++-- pallets/ddc-validator/src/dac.rs | 24 +++++++++++++++++++-- pallets/ddc-validator/src/lib.rs | 25 +++++++++++++++++++-- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 300ae61d5..fca422dc4 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -53,8 +53,8 @@ pub struct Bucket { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct BucketsDetails { - bucket_id: u128, - amount: Balance, + pub bucket_id: u128, + pub amount: Balance, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -562,5 +562,38 @@ pub mod pallet { .try_into() .unwrap() } + + // Charge payments from content owners + pub fn charge_payments_new( + paying_accounts: Vec>>, + ) -> DispatchResult { + let mut total_charged = BalanceOf::::zero(); + + for bucket_details in paying_accounts.iter() { + let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); + let content_owner = bucket.owner_id; + let amount = bucket_details.amount; + + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; + if ledger.active >= amount { + ledger.total -= amount; + ledger.active -= amount; + total_charged += amount; + Self::update_ledger(&content_owner, &ledger); + } else { + let diff = amount - ledger.active; + total_charged += ledger.active; + ledger.total -= ledger.active; + ledger.active = BalanceOf::::zero(); + let (ledger, charged) = ledger.charge_unlocking(diff); + Self::update_ledger(&content_owner, &ledger); + total_charged += charged; + } + + } + Self::deposit_event(Event::::Charged(total_charged)); + + Ok(()) + } } } diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 9a0f27739..dd1ec370b 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -71,7 +71,7 @@ pub type Requests = BTreeMap; pub struct FileRequest { file_request_id: String, file_info: FileInfo, - bucket_id: u64, + bucket_id: u128, timestamp: u64, chunks: BTreeMap, user_public_key: String, @@ -112,7 +112,7 @@ pub struct Log { timestamp: u64, node_public_key: String, signature: String, - bucket_id: u64, + bucket_id: u128, } #[derive(Serialize, Deserialize, Debug)] @@ -273,6 +273,26 @@ fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { timestamps } +pub fn get_acknowledged_bytes_bucket<'a>(file_requests: &'a Requests, acknowledged_bytes_by_bucket: &'a mut Vec<(u128, u64)>) -> &'a Vec<(u128, u64)> { + let ack_timestamps = get_timestamps_with_ack(file_requests); + + for (_, file_request) in file_requests { + let mut total_bytes_received = 0u64; + let bucket_id = file_request.bucket_id; + for (_, chunk) in &file_request.chunks { + + if let Some(ack) = &chunk.ack { + total_bytes_received += ack.bytes_received; + } else { + total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + } + } + acknowledged_bytes_by_bucket.push((bucket_id, total_bytes_received)); + } + + acknowledged_bytes_by_bucket +} + pub fn get_served_bytes_sum(file_requests: &Requests) -> (u64, u64) { let ack_timestamps = get_timestamps_with_ack(file_requests); let mut total_bytes_received = 0u64; diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index d3f70f904..86bdeb6ad 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -47,6 +47,7 @@ pub use frame_system::{ }; pub use lite_json::json::JsonValue; pub use pallet::*; +pub use pallet_ddc_accounts::{self as ddc_accounts, BucketsDetails}; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_session as session; pub use pallet_staking::{self as staking}; @@ -73,12 +74,13 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const TIME_START_MS: u128 = 1_672_531_200_000; pub const ERA_DURATION_MS: u128 = 120_000; pub const ERA_IN_BLOCKS: u8 = 20; +pub const BYTES_TO_CERE: u64 = 1_000; /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; -pub const QUORUM_SIZE: usize = 3; +pub const QUORUM_SIZE: usize = 1; /// Aggregated values from DAC that describe CDN node's activity during a certain era. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize)] @@ -150,6 +152,7 @@ pub mod pallet { + pallet_contracts::Config + pallet_session::Config::AccountId> + pallet_staking::Config + + ddc_accounts::Config + ddc_staking::Config + CreateSignedTransaction> where @@ -574,7 +577,7 @@ pub mod pallet { // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> EraIndex { - ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) + ((::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) .try_into() .unwrap() } @@ -631,7 +634,10 @@ pub mod pallet { fn assign(quorum_size: usize, era: EraIndex) { let validators: Vec = >::iter_keys().collect(); + log::info!("current validators: {:?}", validators); + let edges: Vec = >::iter_keys().collect(); + log::info!("current edges: {:?}", edges); if edges.len() == 0 { return @@ -735,7 +741,10 @@ pub mod pallet { info!("assigned_edges: {:?}", assigned_edges); for assigned_edge in assigned_edges.iter() { + // Store bucket payments + let payments_per_bucket = &mut Vec::new(); let file_request = dac::fetch_file_request(&mock_data_url); + dac::get_acknowledged_bytes_bucket(&file_request, payments_per_bucket); let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&file_request); let is_valid = Self::is_valid(bytes_sent, bytes_received); @@ -790,6 +799,18 @@ pub mod pallet { log::info!("get_intermediate_decisions result: {:?}", validations_res); if validations_res.len() == QUORUM_SIZE { + log::info!("payments per bucket: {:?}", payments_per_bucket); + + let mut payments = vec![]; + for bucket in payments_per_bucket.into_iter() { + let cere_payment: u32 = (bucket.1 / BYTES_TO_CERE) as u32; + let bucket_info = BucketsDetails {bucket_id: bucket.0, amount: cere_payment.into()}; + payments.push(bucket_info); + } + log::info!("final payments: {:?}", payments); + + ddc_accounts::pallet::Pallet::::charge_payments_new(payments); + let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); From 2754f72862562358a4aaab87e171b548bf6b4a87 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Sat, 3 Jun 2023 10:19:07 +0200 Subject: [PATCH 165/544] fix entry point for call --- pallets/ddc-accounts/src/lib.rs | 6 +++++- pallets/ddc-validator/src/lib.rs | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index fca422dc4..d7e6e2560 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -579,6 +579,7 @@ pub mod pallet { ledger.total -= amount; ledger.active -= amount; total_charged += amount; + log::info!("Ledger updated state: {:?}", &ledger); Self::update_ledger(&content_owner, &ledger); } else { let diff = amount - ledger.active; @@ -586,12 +587,15 @@ pub mod pallet { ledger.total -= ledger.active; ledger.active = BalanceOf::::zero(); let (ledger, charged) = ledger.charge_unlocking(diff); + log::info!("Ledger updated state: {:?}", &ledger); Self::update_ledger(&content_owner, &ledger); total_charged += charged; } - } + log::info!("Total charged: {:?}", &total_charged); + Self::deposit_event(Event::::Charged(total_charged)); + log::info!("Deposit event executed"); Ok(()) } diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 86bdeb6ad..b45c59d41 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -74,7 +74,7 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const TIME_START_MS: u128 = 1_672_531_200_000; pub const ERA_DURATION_MS: u128 = 120_000; pub const ERA_IN_BLOCKS: u8 = 20; -pub const BYTES_TO_CERE: u64 = 1_000; +pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and adjusted /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; @@ -538,6 +538,18 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(100_000)] + pub fn charge_payments_cdn( + origin: OriginFor, + paying_accounts: Vec>>, + ) -> DispatchResult { + ensure_signed(origin)?; + + >::charge_payments_new(paying_accounts); + + Ok(()) + } } impl Pallet @@ -809,7 +821,16 @@ pub mod pallet { } log::info!("final payments: {:?}", payments); - ddc_accounts::pallet::Pallet::::charge_payments_new(payments); + // Store CDN node reward points on-chain + let signer: Signer = Signer::<_, _>::any_account(); + if !signer.can_sign() { + log::warn!("No local accounts available to charge payments for CDN. Consider adding one via `author_insertKey` RPC."); + return + } + // ToDo: replace local call by a call from `ddc-staking` pallet + let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_cdn { + paying_accounts: payments.clone(), + }); let final_res = dac::get_final_decision(validations_res); From 2e7543a828e2a9524a17db898a0f9983389e7490 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 23 Jun 2023 16:52:53 +0200 Subject: [PATCH 166/544] add OCWkeys --- pallets/ddc-validator/src/lib.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index b45c59d41..d76f5c495 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -209,9 +209,15 @@ pub mod pallet { #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, EraIndex>; + /// The mapping of controller accounts to OCW public keys + #[pallet::storage] + #[pallet::getter(fn ocw_keys)] + pub type OffchainWorkerKeys = + StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + #[pallet::error] pub enum Error { - // TBA + NotController } #[pallet::event] @@ -550,6 +556,21 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(100_000)] + pub fn set_ocw_key( + origin: OriginFor, + ocw_pub: T::AccountId, + ) -> DispatchResult { + let controller = ensure_signed(origin)?; + ensure!( + staking::Ledger::::contains_key(&controller), + Error::::NotController + ); + + OffchainWorkerKeys::::insert(controller, ocw_pub); + Ok(()) + } } impl Pallet From 584d4e498dcba414ccc6c26bb44e9e406842bb64 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 23 Jun 2023 16:54:36 +0200 Subject: [PATCH 167/544] add rewards structure for cluster manager --- pallets/ddc-staking/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 5e2ed1691..5363b40cc 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -191,6 +191,12 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger>>; + /// Map from all "stash" accounts to the paid out rewards + #[pallet::storage] + #[pallet::getter(fn rewards)] + pub type Rewards = + StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf>; + /// The map from (wannabe) storage network participant stash key to the preferences of that /// storage network participant. #[pallet::storage] @@ -652,6 +658,9 @@ pub mod pallet { reward, ExistenceRequirement::AllowDeath, )?; // ToDo: all success or noop + let mut total_rewards: BalanceOf = Self::rewards(&stash).unwrap(); + total_rewards += reward; + >::insert(&stash, total_rewards); } log::debug!( "Balance left on payout source account {:?}", From 0145f401c4b8bd1a3451adde51290a22884acb44 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 26 Jun 2023 17:41:04 +0200 Subject: [PATCH 168/544] update access control --- pallets/ddc-validator/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index d76f5c495..7953651e8 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -217,7 +217,8 @@ pub mod pallet { #[pallet::error] pub enum Error { - NotController + NotController, + OCWKeyNotRegistered, } #[pallet::event] @@ -550,7 +551,12 @@ pub mod pallet { origin: OriginFor, paying_accounts: Vec>>, ) -> DispatchResult { - ensure_signed(origin)?; + let controller = ensure_signed(origin)?; + ensure!( + OffchainWorkerKeys::::contains_key(&controller), + Error::::OCWKeyNotRegistered + ); + >::charge_payments_new(paying_accounts); @@ -563,11 +569,14 @@ pub mod pallet { ocw_pub: T::AccountId, ) -> DispatchResult { let controller = ensure_signed(origin)?; + let ledger = staking::Ledger::::get(&controller).ok_or(Error::::NotController)?; + let era = staking::Pallet::::current_era().unwrap(); + ensure!( - staking::Ledger::::contains_key(&controller), + staking::ErasStakers::::contains_key(era, &ledger.stash), Error::::NotController ); - + OffchainWorkerKeys::::insert(controller, ocw_pub); Ok(()) } From 6b30429006d43e7a196e80673f553c972b93ff21 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 30 Jun 2023 11:32:10 +0200 Subject: [PATCH 169/544] link payout to stakers --- pallets/ddc-validator/src/lib.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 7953651e8..cd92bcbf1 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -547,7 +547,7 @@ pub mod pallet { } #[pallet::weight(100_000)] - pub fn charge_payments_cdn( + pub fn charge_payments_content_owners( origin: OriginFor, paying_accounts: Vec>>, ) -> DispatchResult { @@ -557,12 +557,27 @@ pub mod pallet { Error::::OCWKeyNotRegistered ); - >::charge_payments_new(paying_accounts); Ok(()) } + #[pallet::weight(100_000)] + pub fn payout_cdn_owners( + origin: OriginFor, + era: EraIndex, + ) -> DispatchResult { + let controller = ensure_signed(origin)?; + ensure!( + OffchainWorkerKeys::::contains_key(&controller), + Error::::OCWKeyNotRegistered + ); + + >::do_payout_stakers(era); + + Ok(()) + } + #[pallet::weight(100_000)] pub fn set_ocw_key( origin: OriginFor, @@ -858,10 +873,14 @@ pub mod pallet { return } // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_cdn { + let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_content_owners { paying_accounts: payments.clone(), }); + let _payout_tx_res = signer.send_signed_transaction(|_account| Call::payout_cdn_owners { + era: current_era, + }); + let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); From 775e8c31386695f6426f127574c098f32735ac3e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 30 Jun 2023 12:50:34 +0200 Subject: [PATCH 170/544] update staking --- pallets/ddc-staking/src/lib.rs | 488 ++++++++++++++++++++++----------- runtime/cere-dev/src/lib.rs | 12 + 2 files changed, 342 insertions(+), 158 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 5363b40cc..fcbfb0dfa 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -14,15 +14,17 @@ use codec::{Decode, Encode, HasCompact}; use frame_support::{ dispatch::Codec, + pallet_prelude::*, parameter_types, traits::{ - Currency, DefensiveSaturating, ExistenceRequirement, LockIdentifier, WithdrawReasons, + Currency, DefensiveSaturating, ExistenceRequirement, LockIdentifier, LockableCurrency, UnixTime, WithdrawReasons, }, BoundedVec, PalletId, }; +use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ - traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedSub, Saturating, Zero}, + traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedSub, Saturating, StaticLookup, Zero}, Perbill, RuntimeDebug, }; @@ -34,6 +36,14 @@ use sp_std::{ pub use pallet::*; +/// Two minutes. +/// +/// If you are changing this, check `on_finalize` hook to ensure `CurrentEra` is capable to hold the +/// value with the new era duration. +const DDC_ERA_DURATION_MS: u128 = 120_000; + +/// 2023-01-01 00:00:00 UTC +const DDC_ERA_START_MS: u128 = 1_672_531_200_000; const DDC_STAKING_ID: LockIdentifier = *b"ddcstake"; // DDC maintainer's stake /// Counter for the number of "reward" points earned by a given staker. @@ -43,6 +53,8 @@ pub type RewardPoint = u64; pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +pub type ClusterId = u32; + parameter_types! { /// A limit to the number of pending unlocks an account may have in parallel. pub MaxUnlockingChunks: u32 = 32; @@ -86,6 +98,8 @@ pub struct StakingLedger { /// rounds. #[codec(compact)] pub active: Balance, + /// Era number at which chilling will be allowed. + pub chilling: Option, /// Any balance that is becoming free, which may eventually be transferred out of the stash /// (assuming it doesn't get slashed first). It is assumed that this will be treated as a first /// in, first out queue where the new (higher value) eras get pushed on the back. @@ -97,7 +111,13 @@ impl Self { - Self { stash, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } + Self { + stash, + total: Zero::zero(), + active: Zero::zero(), + chilling: Default::default(), + unlocking: Default::default(), + } } /// Remove entries from `unlocking` that are sufficiently old and reduce the @@ -121,7 +141,35 @@ impl { + /// The bond size required to become and maintain the role of a CDN participant. + #[codec(compact)] + pub edge_bond_size: BalanceOf, + /// Number of eras should pass before a CDN participant can chill. + pub edge_chill_delay: EraIndex, + /// The bond size required to become and maintain the role of a storage network participant. + #[codec(compact)] + pub storage_bond_size: BalanceOf, + /// Number of eras should pass before a storage network participant can chill. + pub storage_chill_delay: EraIndex, +} + +impl Default for ClusterSettings { + /// Default to the values specified in the runtime config. + fn default() -> Self { + Self { + edge_bond_size: T::DefaultEdgeBondSize::get(), + edge_chill_delay: T::DefaultEdgeChillDelay::get(), + storage_bond_size: T::DefaultStorageBondSize::get(), + storage_chill_delay: T::DefaultStorageChillDelay::get(), + } } } @@ -165,6 +213,23 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type Currency: LockableCurrency; + + /// Default bond size for a CDN participant. + #[pallet::constant] + type DefaultEdgeBondSize: Get>; + + /// Default number or DDC eras required to pass before a CDN participant can chill. + #[pallet::constant] + type DefaultEdgeChillDelay: Get; + + /// Default bond size for a storage network participant. + #[pallet::constant] + type DefaultStorageBondSize: Get>; + + /// Default number or DDC eras required to pass before a storage participant can chill. + #[pallet::constant] + type DefaultStorageChillDelay: Get; + type Event: From> + IsType<::Event>; /// Number of eras that staked funds must remain bonded for. #[pallet::constant] @@ -173,17 +238,23 @@ pub mod pallet { type StakersPayoutSource: Get; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + + /// Time used for computing era index. It is guaranteed to start being called from the first + /// `on_finalize`. + type UnixTime: UnixTime; } + /// Map from all locked "stash" accounts to the controller account. #[pallet::storage] #[pallet::getter(fn bonded)] pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; - /// The bond size required to become and maintain the role of a CDN or storage network - /// participant. + /// DDC clusters staking settings. #[pallet::storage] - pub type BondSize = StorageValue<_, BalanceOf, ValueQuery>; + #[pallet::getter(fn settings)] + pub type Settings = + StorageMap<_, Identity, ClusterId, ClusterSettings, ValueQuery>; /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] @@ -191,24 +262,23 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger>>; - /// Map from all "stash" accounts to the paid out rewards + /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to + /// participate into. #[pallet::storage] - #[pallet::getter(fn rewards)] - pub type Rewards = - StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf>; + #[pallet::getter(fn edges)] + pub type Edges = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// The map from (wannabe) storage network participant stash key to the preferences of that - /// storage network participant. + /// The map of (wannabe) storage network participants stash keys to the DDC cluster ID they wish + /// to participate into.. #[pallet::storage] #[pallet::getter(fn storages)] - pub type Storages = - CountedStorageMap<_, Twox64Concat, T::AccountId, StoragePrefs, ValueQuery>; + pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// The map from (wannabe) CDN participant stash key to the preferences of that CDN participant. + /// Map from all "stash" accounts to the paid out rewards #[pallet::storage] - #[pallet::getter(fn edges)] - pub type Edges = - CountedStorageMap<_, Twox64Concat, T::AccountId, EdgePrefs, ValueQuery>; + #[pallet::getter(fn rewards)] + pub type Rewards = + StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf>; /// The current era index. /// @@ -247,6 +317,9 @@ pub mod pallet { /// An account has stopped participating as either a storage network or CDN participant. /// \[stash\] Chilled(T::AccountId), + /// An account has declared desire to stop participating in CDN or storage network soon. + /// \[stash, cluster, era\] + ChillSoon(T::AccountId, ClusterId, EraIndex), } #[pallet::error] @@ -270,14 +343,28 @@ pub mod pallet { // An account already declared a desire to participate in the network with a certain role // and to take another role it should call `chill` first. AlreadyInRole, - /// Two or more occurrences of a staker account in rewards points list. + /// Action is allowed at some point of time in future not reached yet. + TooEarly, DuplicateRewardPoints, - /// Price per byte of the traffic is unknown. PricingNotSet, - /// Impossible budget value that overflows pallet's balance type. BudgetOverflow, } + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_finalize(_n: BlockNumberFor) { + // Check if we have a new era and if so bump the current era index. + let now_as_millis = T::UnixTime::now().as_millis(); + let computed_era: EraIndex = + ((now_as_millis - DDC_ERA_START_MS) / DDC_ERA_DURATION_MS) as u32; // saturated + if Self::current_era() >= Some(computed_era) { + return + } + CurrentEra::::put(computed_era); + // ToDo: add `on_initialize` hook to track `on_finalize` weight + } + } + #[pallet::call] impl Pallet { /// Take the origin account as a stash and lock up `value` of its balance. `controller` will @@ -292,6 +379,7 @@ pub mod pallet { pub fn bond( origin: OriginFor, controller: ::Source, + #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let stash = ensure_signed(origin)?; @@ -305,39 +393,34 @@ pub mod pallet { Err(Error::::AlreadyPaired)? } - let stash_free = T::Currency::free_balance(&stash); - // Reject a bond which is considered to be _dust_. - if stash_free < T::Currency::minimum_balance() { - Err(Error::::InsufficientBond)? - } - - let bond_size = BondSize::::get(); - - // Reject a bond which is lower then required. - if stash_free < bond_size { + if value < T::Currency::minimum_balance() { Err(Error::::InsufficientBond)? } frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; // You're auto-bonded forever, here. We might improve this by only bonding when - // you actually store/serve and remove once you unbond. + // you actually store/serve and remove once you unbond __everything__. >::insert(&stash, &controller); - Self::deposit_event(Event::::Bonded(stash.clone(), bond_size)); + let stash_balance = T::Currency::free_balance(&stash); + let value = value.min(stash_balance); + Self::deposit_event(Event::::Bonded(stash.clone(), value)); let item = StakingLedger { stash, - total: bond_size, - active: bond_size, + total: value, + active: value, + chilling: Default::default(), unlocking: Default::default(), }; Self::update_ledger(&controller, &item); Ok(()) } - /// Schedule a bond of the stash to be unlocked ready for transfer out after the bond - /// period ends. + /// Schedule a portion of the stash to be unlocked ready for transfer out after the bond + /// period ends. If this leaves an amount actively bonded less than + /// T::Currency::minimum_balance(), then it is increased to the full amount. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. /// @@ -346,10 +429,7 @@ pub mod pallet { /// /// No more than a limited number of unlocking chunks (see `MaxUnlockingChunks`) /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need - /// to be called first to remove some of the chunks (if possible). This feature is actually - /// not required because we unlock the whole bond at once, means it is impossible to have - /// more then one unlocking at time. But this is inherited from the `pallet-staking` and we - /// may remove in some future version. + /// to be called first to remove some of the chunks (if possible). /// /// If a user encounters the `InsufficientBond` error when calling this extrinsic, /// they should call `chill` first in order to free up their bonded funds. @@ -360,48 +440,58 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::unbond())] pub fn unbond( origin: OriginFor, + #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - - if ledger.active.is_zero() { - // Nothing to unbond. - return Ok(()) - } - ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, ); - // Make sure that the user maintains enough active bond for their role. - // If a user runs into this error, they should chill first. - ensure!(!Storages::::contains_key(&ledger.stash), Error::::InsufficientBond); - ensure!(!Edges::::contains_key(&ledger.stash), Error::::InsufficientBond); + let mut value = value.min(ledger.active); - let era = Self::current_era().unwrap_or(0) + T::BondingDuration::get(); + if !value.is_zero() { + ledger.active -= value; - // Unbond actual active stake instead of the current `BondSize` to allow users bond and - // unbond the same amount regardless of changes of the `BondSize`. - let unbond_value = ledger.active.clone(); - ledger.active = Zero::zero(); + // Avoid there being a dust balance left in the staking system. + if ledger.active < T::Currency::minimum_balance() { + value += ledger.active; + ledger.active = Zero::zero(); + } - if let Some(mut chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { - // To keep the chunk count down, we only keep one chunk per era. Since - // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will - // be the last one. - chunk.value = chunk.value.defensive_saturating_add(unbond_value) - } else { - ledger - .unlocking - .try_push(UnlockChunk { value: unbond_value, era }) - .map_err(|_| Error::::NoMoreChunks)?; - }; - // NOTE: ledger must be updated prior to calling `Self::weight_of`. - Self::update_ledger(&controller, &ledger); + let min_active_bond = if let Some(cluster_id) = Self::edges(&ledger.stash) { + Self::settings(cluster_id).edge_bond_size + } else if let Some(cluster_id) = Self::storages(&ledger.stash) { + Self::settings(cluster_id).storage_bond_size + } else { + Zero::zero() + }; - Self::deposit_event(Event::::Unbonded(ledger.stash, unbond_value)); + // Make sure that the user maintains enough active bond for their role in the + // cluster. If a user runs into this error, they should chill first. + ensure!(ledger.active >= min_active_bond, Error::::InsufficientBond); + + // Note: in case there is no current era it is fine to bond one era more. + let era = Self::current_era().unwrap_or(0) + T::BondingDuration::get(); + if let Some(mut chunk) = + ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) + { + // To keep the chunk count down, we only keep one chunk per era. Since + // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will + // be the last one. + chunk.value = chunk.value.defensive_saturating_add(value) + } else { + ledger + .unlocking + .try_push(UnlockChunk { value, era }) + .map_err(|_| Error::::NoMoreChunks)?; + }; + Self::update_ledger(&controller, &ledger); + + Self::deposit_event(Event::::Unbonded(ledger.stash, value)); + } Ok(()) } @@ -447,58 +537,136 @@ pub mod pallet { Ok(()) } - /// Declare the desire to participate in storage network for the origin controller. + /// Declare the desire to participate in CDN for the origin controller. Also works to cancel + /// a previous "chill". /// - /// Effects will be felt at the beginning of the next era. + /// `cluster` is the ID of the DDC cluster the participant wishes to join. /// - /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. - #[pallet::weight(T::WeightInfo::store())] - pub fn store(origin: OriginFor, prefs: StoragePrefs) -> DispatchResult { + /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The + /// bond size must be greater than or equal to the `EdgeBondSize`. + #[pallet::weight(T::WeightInfo::serve())] + pub fn serve(origin: OriginFor, cluster: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - - ensure!(ledger.active >= BondSize::::get(), Error::::InsufficientBond); + ensure!( + ledger.active >= Self::settings(cluster).edge_bond_size, + Error::::InsufficientBond + ); let stash = &ledger.stash; - // Can't participate in storage network if already participating in CDN. - ensure!(!Edges::::contains_key(&stash), Error::::AlreadyInRole); + // Can't participate in CDN if already participating in storage network. + ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); + + // Is it an attempt to cancel a previous "chill"? + if let Some(current_cluster) = Self::edges(&stash) { + // Switching the cluster is prohibited. The user should chill first. + ensure!(current_cluster == cluster, Error::::AlreadyInRole); + // Cancel previous "chill" attempts + Self::reset_chilling(&controller); + return Ok(()) + } - Self::do_add_storage(stash, prefs); + Self::do_add_edge(stash, cluster); Ok(()) } - /// Declare the desire to participate in CDN for the origin controller. + /// Declare the desire to participate in storage network for the origin controller. Also + /// works to cancel a previous "chill". /// - /// Effects will be felt at the beginning of the next era. + /// `cluster` is the ID of the DDC cluster the participant wishes to join. /// - /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. - #[pallet::weight(T::WeightInfo::serve())] - pub fn serve(origin: OriginFor, prefs: EdgePrefs) -> DispatchResult { + /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The + /// bond size must be greater than or equal to the `StorageBondSize`. + #[pallet::weight(T::WeightInfo::store())] + pub fn store(origin: OriginFor, cluster: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - - ensure!(ledger.active >= BondSize::::get(), Error::::InsufficientBond); + ensure!( + ledger.active >= Self::settings(cluster).storage_bond_size, + Error::::InsufficientBond + ); let stash = &ledger.stash; - // Can't participate in CDN if already participating in storage network. - ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); + // Can't participate in storage network if already participating in CDN. + ensure!(!Edges::::contains_key(&stash), Error::::AlreadyInRole); + + // Is it an attempt to cancel a previous "chill"? + if let Some(current_cluster) = Self::storages(&stash) { + // Switching the cluster is prohibited. The user should chill first. + ensure!(current_cluster == cluster, Error::::AlreadyInRole); + // Cancel previous "chill" attempts + Self::reset_chilling(&controller); + return Ok(()) + } + + Self::do_add_storage(stash, cluster); - Self::do_add_edge(stash, prefs); Ok(()) } /// Declare no desire to either participate in storage network or CDN. /// - /// Effects will be felt at the beginning of the next era. + /// Only in case the delay for the role _origin_ maintains in the cluster is set to zero in + /// cluster settings, it removes the participant immediately. Otherwise, it requires at + /// least two invocations to effectively remove the participant. The first invocation only + /// updates the [`Ledger`] to note the DDC era at which the participant may "chill" (current + /// era + the delay from the cluster settings). The second invocation made at the noted era + /// (or any further era) will remove the participant from the list of CDN or storage network + /// participants. If the cluster settings updated significantly decreasing the delay, one + /// may invoke it again to decrease the era at with the participant may "chill". But it + /// never increases the era at which the participant may "chill" even when the cluster + /// settings updated increasing the delay. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. + /// + /// Emits `ChillSoon`, `Chill`. #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let current_era = match Self::current_era() { + Some(era) => era, + None => Err(Error::::TooEarly)?, // can't chill before the first era + }; + + // Extract delay from the cluster settings. + let (cluster, delay) = if let Some(cluster) = Self::edges(&ledger.stash) { + (cluster, Self::settings(cluster).edge_chill_delay) + } else if let Some(cluster) = Self::storages(&ledger.stash) { + (cluster, Self::settings(cluster).storage_chill_delay) + } else { + return Ok(()) // already chilled + }; + + if delay == 0 { + // No delay is set, so we can chill right away. + Self::chill_stash(&ledger.stash); + return Ok(()) + } + + let can_chill_from = current_era.defensive_saturating_add(delay); + match ledger.chilling { + None => { + // No previous declarations of desire to chill. Note it to allow chilling soon. + Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from); + return Ok(()) + }, + Some(chilling) if can_chill_from < chilling => { + // Time to chill is not reached yet, but it is allowed to chill earlier. Update + // to allow chilling sooner. + Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from); + return Ok(()) + }, + Some(chilling) if chilling > current_era => Err(Error::::TooEarly)?, + Some(_) => (), + } + + // It's time to chill. Self::chill_stash(&ledger.stash); + Self::reset_chilling(&controller); // for future chilling + Ok(()) } @@ -527,6 +695,31 @@ pub mod pallet { Ok(()) } + /// Set custom DDC staking settings for a particular cluster. + /// + /// * `settings` - The new settings for the cluster. If `None`, the settings will be removed + /// from the storage and default settings will be used. + /// + /// RuntimeOrigin must be Root to call this function. + /// + /// NOTE: Existing CDN and storage network participants will not be affected by this + /// settings update. + #[pallet::weight(10_000)] + pub fn set_settings( + origin: OriginFor, + cluster: ClusterId, + settings: Option>, + ) -> DispatchResult { + ensure_root(origin)?; + + match settings { + None => Settings::::remove(cluster), + Some(settings) => Settings::::insert(cluster, settings), + } + + Ok(()) + } + /// Pay out all the stakers for a single era. #[pallet::weight(100_000)] pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { @@ -576,39 +769,10 @@ pub mod pallet { >::set(Some(price_per_byte)); Ok(()) } - - /// Update the DDC staking configurations . - /// - /// * `bond_size`: The active bond needed to be a Storage or Edge node. - /// - /// RuntimeOrigin must be Root to call this function. - /// - /// NOTE: Existing nominators and validators will not be affected by this update. - #[pallet::weight(10_000)] - pub fn set_staking_configs( - origin: OriginFor, - bond_size: ConfigOp>, - ) -> DispatchResult { - ensure_root(origin)?; - - macro_rules! config_op_exp { - ($storage:ty, $op:ident) => { - match $op { - ConfigOp::Noop => (), - ConfigOp::Set(v) => <$storage>::put(v), - ConfigOp::Remove => <$storage>::kill(), - } - }; - } - - config_op_exp!(BondSize, bond_size); - - Ok(()) - } } impl Pallet { - pub(super) fn do_payout_stakers(era: EraIndex) -> DispatchResult { + pub fn do_payout_stakers(era: EraIndex) -> DispatchResult { // ToDo: check that the era is finished // ToDo: check reward points are set @@ -695,6 +859,20 @@ pub mod pallet { } } + /// Note a desire of a stash account to chill soon. + fn chill_stash_soon( + stash: &T::AccountId, + controller: &T::AccountId, + cluster: ClusterId, + can_chill_from: EraIndex, + ) { + Ledger::::mutate(&controller, |maybe_ledger| { + if let Some(ref mut ledger) = maybe_ledger { + ledger.chilling = Some(can_chill_from) + } + }); + Self::deposit_event(Event::::ChillSoon(stash.clone(), cluster, can_chill_from)); + } /// Remove all associated data of a stash account from the staking system. /// /// Assumes storage is upgraded before calling. @@ -716,64 +894,58 @@ pub mod pallet { Ok(()) } - /// This function will add a storage network participant to the `Storages` storage map. + /// This function will add a CDN participant to the `Edges` storage map. /// - /// If the storage network participant already exists, their preferences will be updated. + /// If the CDN participant already exists, their cluster will be updated. /// - /// NOTE: you must ALWAYS use this function to add a storage network participant to the - /// system. Any access to `Storages` outside of this function is almost certainly + /// NOTE: you must ALWAYS use this function to add a CDN participant to the system. Any + /// access to `Edges` outside of this function is almost certainly /// wrong. - pub fn do_add_storage(who: &T::AccountId, prefs: StoragePrefs) { - Storages::::insert(who, prefs); + pub fn do_add_edge(who: &T::AccountId, cluster: ClusterId) { + Edges::::insert(who, cluster); } - /// This function will remove a storage network participant from the `Storages` storage map. + /// This function will remove a CDN participant from the `Edges` map. /// - /// Returns true if `who` was removed from `Storages`, otherwise false. + /// Returns true if `who` was removed from `Edges`, otherwise false. /// /// NOTE: you must ALWAYS use this function to remove a storage network participant from the - /// system. Any access to `Storages` outside of this function is almost certainly + /// system. Any access to `Edges` outside of this function is almost certainly /// wrong. - pub fn do_remove_storage(who: &T::AccountId) -> bool { - let outcome = if Storages::::contains_key(who) { - Storages::::remove(who); - true - } else { - false - }; - - outcome + pub fn do_remove_edge(who: &T::AccountId) -> bool { + Edges::::take(who).is_some() } - /// This function will add a CDN participant to the `Edges` storage map. + /// This function will add a storage network participant to the `Storages` storage map. /// - /// If the CDN participant already exists, their preferences will be updated. + /// If the storage network participant already exists, their cluster will be updated. /// - /// NOTE: you must ALWAYS use this function to add a CDN participant to the system. Any - /// access to `Edges` outside of this function is almost certainly + /// NOTE: you must ALWAYS use this function to add a storage network participant to the + /// system. Any access to `Storages` outside of this function is almost certainly /// wrong. - pub fn do_add_edge(who: &T::AccountId, prefs: EdgePrefs) { - Edges::::insert(who, prefs); + pub fn do_add_storage(who: &T::AccountId, cluster: ClusterId) { + Storages::::insert(who, cluster); } - /// This function will remove a CDN participant from the `Edges` storage map. + /// This function will remove a storage network participant from the `Storages` map. /// - /// Returns true if `who` was removed from `Edges`, otherwise false. + /// Returns true if `who` was removed from `Storages`, otherwise false. /// /// NOTE: you must ALWAYS use this function to remove a storage network participant from the - /// system. Any access to `Edges` outside of this function is almost certainly + /// system. Any access to `Storages` outside of this function is almost certainly /// wrong. - pub fn do_remove_edge(who: &T::AccountId) -> bool { - let outcome = if Edges::::contains_key(who) { - Storages::::remove(who); - true - } else { - false - }; - - outcome + pub fn do_remove_storage(who: &T::AccountId) -> bool { + Storages::::take(who).is_some() } + /// Reset the chilling era for a controller. + pub fn reset_chilling(controller: &T::AccountId) { + Ledger::::mutate(&controller, |maybe_ledger| { + if let Some(ref mut ledger) = maybe_ledger { + ledger.chilling = None + } + }); + } /// Add reward points to CDN participants using their stash account ID. pub fn reward_by_ids( era: EraIndex, diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 572b91a90..6e882828d 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -75,6 +75,7 @@ use sp_runtime::{ transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill, }; +use sp_staking::EraIndex; use sp_std::prelude::*; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -1254,10 +1255,21 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { type Call = Call; } +parameter_types! { + pub const DefaultEdgeBondSize: Balance = 100 * DOLLARS; + pub const DefaultEdgeChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era + pub const DefaultStorageBondSize: Balance = 100 * DOLLARS; + pub const DefaultStorageChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era +} impl pallet_ddc_staking::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; + type DefaultEdgeBondSize = DefaultEdgeBondSize; + type DefaultEdgeChillDelay = DefaultEdgeChillDelay; + type DefaultStorageBondSize = DefaultStorageBondSize; + type DefaultStorageChillDelay = DefaultStorageChillDelay; type Event = Event; + type UnixTime = Timestamp; type StakersPayoutSource = Ddc_Accounts_Pallet_Id; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } From 6b5b7c4bc28750565675df38ea00c3cc997ef878 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 4 Jul 2023 13:00:44 +0600 Subject: [PATCH 171/544] Update dependencies versions to fix build --- Cargo.lock | 58 ++++++++++++++++++++++++++++++++ pallets/ddc-accounts/Cargo.toml | 14 ++++---- pallets/ddc-validator/Cargo.toml | 34 +++++++++---------- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d4c9b4ca..d3b91b58f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,6 +168,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "array-bytes" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b1c5a481ec30a5abd8dfbd94ab5cf1bb4e9a66be7f1b3b322f2f1170c200fd" + [[package]] name = "arrayref" version = "0.3.7" @@ -794,8 +800,10 @@ dependencies = [ "pallet-contracts", "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", + "pallet-ddc-accounts", "pallet-ddc-metrics-offchain-worker", "pallet-ddc-staking", + "pallet-ddc-validator", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", @@ -4819,6 +4827,22 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-ddc-accounts" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "substrate-test-utils", +] + [[package]] name = "pallet-ddc-metrics-offchain-worker" version = "4.7.0" @@ -4852,6 +4876,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "log", "parity-scale-codec", "scale-info", "sp-io", @@ -4861,6 +4886,39 @@ dependencies = [ "substrate-test-utils", ] +[[package]] +name = "pallet-ddc-validator" +version = "0.1.0" +dependencies = [ + "alt_serde", + "array-bytes", + "base64 0.21.2", + "frame-election-provider-support", + "frame-support", + "frame-system", + "lite-json", + "log", + "pallet-balances", + "pallet-contracts", + "pallet-ddc-accounts", + "pallet-ddc-staking", + "pallet-randomness-collective-flip", + "pallet-session", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "serde", + "serde_json 1.0.44", + "sp-core", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-staking", + "sp-std", +] + [[package]] name = "pallet-democracy" version = "4.0.0-dev" diff --git a/pallets/ddc-accounts/Cargo.toml b/pallets/ddc-accounts/Cargo.toml index df6dbf097..4d5b3aa30 100644 --- a/pallets/ddc-accounts/Cargo.toml +++ b/pallets/ddc-accounts/Cargo.toml @@ -5,17 +5,17 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } log = { version = "0.4.17", default-features = false } [dev-dependencies] -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } [features] default = ["std"] diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 0c29be547..a412f0776 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -8,25 +8,25 @@ array-bytes = "6.0.0" alt_serde = { version = "1", default-features = false, features = ["derive"] } base64 = { version = "0.21.0", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } log = { version = "0.4.17", default-features = false } lite-json = { version = "0.2.0", default-features = false } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } pallet-ddc-accounts = { version = "0.1.0", default-features = false, path = "../ddc-accounts" } -pallet-ddc-staking = { version = "0.1.0", default-features = false, path = "../ddc-staking" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25", default-features = false } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } +pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } +pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25", optional = true } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } [features] default = ["std"] @@ -52,7 +52,7 @@ std = [ ] [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } -pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" } \ No newline at end of file +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } \ No newline at end of file From 5f8c8f137211d5a4c9f0cf82ad20545fb84b25bf Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 4 Jul 2023 13:01:18 +0600 Subject: [PATCH 172/544] Fix weight return --- pallets/ddc-validator/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 7953651e8..74d240d3f 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -236,7 +236,7 @@ pub mod pallet { { fn on_initialize(block_number: T::BlockNumber) -> Weight { if block_number <= 1u32.into() { - return 0 + return Weight::from_ref_time(0) } Signal::::set(Some(false)); @@ -247,7 +247,7 @@ pub mod pallet { match >::get(){ Some(last_managed_era) => { if last_managed_era > era { - return 0 + return Weight::from_ref_time(0) } else { Self::assign(3usize, era + 1); >::put(era); @@ -259,7 +259,7 @@ pub mod pallet { } } - 0 + Weight::from_ref_time(0) } fn offchain_worker(block_number: T::BlockNumber) { From 92cf3d5bf9374c97d8c62f636b09451dcd0d9a3a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 4 Jul 2023 13:05:34 +0600 Subject: [PATCH 173/544] Sort `pallet-ddc-validator` dependencies --- pallets/ddc-validator/Cargo.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index a412f0776..7672fbfbd 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -4,15 +4,15 @@ version = "0.1.0" edition = "2021" [dependencies] -array-bytes = "6.0.0" alt_serde = { version = "1", default-features = false, features = ["derive"] } +array-bytes = "6.0.0" base64 = { version = "0.21.0", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -log = { version = "0.4.17", default-features = false } lite-json = { version = "0.2.0", default-features = false } +log = { version = "0.4.17", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } pallet-ddc-accounts = { version = "0.1.0", default-features = false, path = "../ddc-accounts" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } @@ -28,13 +28,19 @@ sp-runtime = { version = "6.0.0", default-features = false, git = "https://githu sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +[dev-dependencies] +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } + [features] default = ["std"] std = [ "codec/std", + "frame-election-provider-support/std", "frame-support/std", "frame-system/std", - "frame-election-provider-support/std", "lite-json/std", "pallet-contracts/std", "pallet-ddc-accounts/std", @@ -50,9 +56,3 @@ std = [ "sp-staking/std", "sp-std/std", ] - -[dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } \ No newline at end of file From 4cddbc877cab069d1fa8b7738e66c3f7549d53c2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 4 Jul 2023 13:06:31 +0600 Subject: [PATCH 174/544] Autoformat DDC pallets --- pallets/ddc-accounts/src/lib.rs | 99 +++++++++++++++--------------- pallets/ddc-staking/src/lib.rs | 3 +- pallets/ddc-validator/src/dac.rs | 8 ++- pallets/ddc-validator/src/lib.rs | 78 +++++++++++++---------- pallets/ddc-validator/src/shm.rs | 37 ++++++----- pallets/ddc-validator/src/utils.rs | 8 +-- 6 files changed, 127 insertions(+), 106 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index d7e6e2560..1b5e4156a 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -210,7 +210,7 @@ pub mod pallet { /// from the unlocking queue. \[stash, amount\] Withdrawn(T::AccountId, BalanceOf), /// Total amount charged from all accounts to pay CDN nodes - Charged(BalanceOf), + Charged(BalanceOf), } #[pallet::error] @@ -260,31 +260,30 @@ pub mod pallet { paying_accounts: Vec>>, ) -> DispatchResult { let validator = ensure_signed(origin)?; - let mut total_charged = BalanceOf::::zero(); - - for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); - let content_owner = bucket.owner_id; - let amount = bucket_details.amount; - - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; - if ledger.active >= amount { - ledger.total -= amount; - ledger.active -= amount; - total_charged += amount; - Self::update_ledger(&content_owner, &ledger); - } else { - let diff = amount - ledger.active; - total_charged += ledger.active; - ledger.total -= ledger.active; - ledger.active = BalanceOf::::zero(); - let (ledger, charged) = ledger.charge_unlocking(diff); - Self::update_ledger(&content_owner, &ledger); - total_charged += charged; - } - - } - Self::deposit_event(Event::::Charged(total_charged)); + let mut total_charged = BalanceOf::::zero(); + + for bucket_details in paying_accounts.iter() { + let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); + let content_owner = bucket.owner_id; + let amount = bucket_details.amount; + + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; + if ledger.active >= amount { + ledger.total -= amount; + ledger.active -= amount; + total_charged += amount; + Self::update_ledger(&content_owner, &ledger); + } else { + let diff = amount - ledger.active; + total_charged += ledger.active; + ledger.total -= ledger.active; + ledger.active = BalanceOf::::zero(); + let (ledger, charged) = ledger.charge_unlocking(diff); + Self::update_ledger(&content_owner, &ledger); + total_charged += charged; + } + } + Self::deposit_event(Event::::Charged(total_charged)); Ok(()) } @@ -567,34 +566,34 @@ pub mod pallet { pub fn charge_payments_new( paying_accounts: Vec>>, ) -> DispatchResult { - let mut total_charged = BalanceOf::::zero(); - - for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); - let content_owner = bucket.owner_id; - let amount = bucket_details.amount; - - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; - if ledger.active >= amount { - ledger.total -= amount; - ledger.active -= amount; - total_charged += amount; + let mut total_charged = BalanceOf::::zero(); + + for bucket_details in paying_accounts.iter() { + let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); + let content_owner = bucket.owner_id; + let amount = bucket_details.amount; + + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; + if ledger.active >= amount { + ledger.total -= amount; + ledger.active -= amount; + total_charged += amount; log::info!("Ledger updated state: {:?}", &ledger); - Self::update_ledger(&content_owner, &ledger); - } else { - let diff = amount - ledger.active; - total_charged += ledger.active; - ledger.total -= ledger.active; - ledger.active = BalanceOf::::zero(); - let (ledger, charged) = ledger.charge_unlocking(diff); + Self::update_ledger(&content_owner, &ledger); + } else { + let diff = amount - ledger.active; + total_charged += ledger.active; + ledger.total -= ledger.active; + ledger.active = BalanceOf::::zero(); + let (ledger, charged) = ledger.charge_unlocking(diff); log::info!("Ledger updated state: {:?}", &ledger); - Self::update_ledger(&content_owner, &ledger); - total_charged += charged; - } - } + Self::update_ledger(&content_owner, &ledger); + total_charged += charged; + } + } log::info!("Total charged: {:?}", &total_charged); - Self::deposit_event(Event::::Charged(total_charged)); + Self::deposit_event(Event::::Charged(total_charged)); log::info!("Deposit event executed"); Ok(()) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index f2ece5379..8bdbf9f54 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -234,8 +234,7 @@ pub mod pallet { /// Map from all "stash" accounts to the paid out rewards #[pallet::storage] #[pallet::getter(fn rewards)] - pub type Rewards = - StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf>; + pub type Rewards = StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf>; /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to /// participate into. diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index dd1ec370b..63244a6e2 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -273,14 +273,16 @@ fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { timestamps } -pub fn get_acknowledged_bytes_bucket<'a>(file_requests: &'a Requests, acknowledged_bytes_by_bucket: &'a mut Vec<(u128, u64)>) -> &'a Vec<(u128, u64)> { +pub fn get_acknowledged_bytes_bucket<'a>( + file_requests: &'a Requests, + acknowledged_bytes_by_bucket: &'a mut Vec<(u128, u64)>, +) -> &'a Vec<(u128, u64)> { let ack_timestamps = get_timestamps_with_ack(file_requests); for (_, file_request) in file_requests { let mut total_bytes_received = 0u64; let bucket_id = file_request.bucket_id; for (_, chunk) in &file_request.chunks { - if let Some(ack) = &chunk.ack { total_bytes_received += ack.bytes_received; } else { @@ -615,7 +617,7 @@ fn find_largest_group(decisions: Vec) -> Option = - StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + pub type OffchainWorkerKeys = + StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; #[pallet::error] pub enum Error { @@ -244,19 +255,18 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); - match >::get(){ - Some(last_managed_era) => { + match >::get() { + Some(last_managed_era) => if last_managed_era > era { return Weight::from_ref_time(0) } else { Self::assign(3usize, era + 1); >::put(era); - } - } + }, None => { Self::assign(3usize, era); >::put(era); - } + }, } Weight::from_ref_time(0) @@ -279,8 +289,8 @@ pub mod pallet { //} // Print the number of broken sessions per CDN node. - // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data - // let aggregates_obj = aggregates_value.as_object().unwrap(); + // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // + // 77436 is for a mock data let aggregates_obj = aggregates_value.as_object().unwrap(); // aggregates_obj // .into_iter() // .for_each(|(cdn_node_pubkey, cdn_node_aggregates_value)| { @@ -556,18 +566,14 @@ pub mod pallet { OffchainWorkerKeys::::contains_key(&controller), Error::::OCWKeyNotRegistered ); - - >::charge_payments_new(paying_accounts); + >::charge_payments_new(paying_accounts); Ok(()) } #[pallet::weight(100_000)] - pub fn set_ocw_key( - origin: OriginFor, - ocw_pub: T::AccountId, - ) -> DispatchResult { + pub fn set_ocw_key(origin: OriginFor, ocw_pub: T::AccountId) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = staking::Ledger::::get(&controller).ok_or(Error::::NotController)?; let era = staking::Pallet::::current_era().unwrap(); @@ -619,7 +625,8 @@ pub mod pallet { // Get the current era; Shall we start era count from 0 or from 1? fn get_current_era() -> EraIndex { - ((::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) + ((::TimeProvider::now().as_millis() - TIME_START_MS) / + ERA_DURATION_MS) .try_into() .unwrap() } @@ -662,7 +669,7 @@ pub mod pallet { let mut result: Vec> = Vec::new(); if segment_len == 0 { - return result; + return result } for i in (0..list.len()).step_by(segment_len) { @@ -763,7 +770,7 @@ pub mod pallet { fn get_public_key() -> Option { match sr25519_public_keys(KEY_TYPE).first() { Some(pubkey) => Some(T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()), - None => None + None => None, } } @@ -778,7 +785,8 @@ pub mod pallet { info!("validator: {:?}", validator); - let assigned_edges = Self::assignments(current_era - 1, validator.clone()).expect("No assignments for the previous era"); + let assigned_edges = Self::assignments(current_era - 1, validator.clone()) + .expect("No assignments for the previous era"); info!("assigned_edges: {:?}", assigned_edges); @@ -836,7 +844,12 @@ pub mod pallet { let edge = utils::account_to_string::(assigned_edge.clone()); let prev_era = (current_era - 1) as EraIndex; let quorum = Self::find_validators_from_quorum(&validator, &prev_era); - let validations_res = shm::get_intermediate_decisions(&data_provider_url, &edge_str, &prev_era, quorum); + let validations_res = shm::get_intermediate_decisions( + &data_provider_url, + &edge_str, + &prev_era, + quorum, + ); log::info!("get_intermediate_decisions result: {:?}", validations_res); @@ -846,7 +859,8 @@ pub mod pallet { let mut payments = vec![]; for bucket in payments_per_bucket.into_iter() { let cere_payment: u32 = (bucket.1 / BYTES_TO_CERE) as u32; - let bucket_info = BucketsDetails {bucket_id: bucket.0, amount: cere_payment.into()}; + let bucket_info = + BucketsDetails { bucket_id: bucket.0, amount: cere_payment.into() }; payments.push(bucket_info); } log::info!("final payments: {:?}", payments); @@ -858,19 +872,21 @@ pub mod pallet { return } // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_cdn { - paying_accounts: payments.clone(), - }); + let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = + signer.send_signed_transaction(|_account| Call::charge_payments_cdn { + paying_accounts: payments.clone(), + }); let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); - let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, - cdn_node: utils::string_to_account::(edge.clone()), - validation_decision: final_res.clone(), - }); + let tx_res = + signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: current_era, + cdn_node: utils::string_to_account::(edge.clone()), + validation_decision: final_res.clone(), + }); log::info!("final_res: {:?}", final_res); } diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index ad7990b7f..72c293745 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -6,16 +6,16 @@ //! server which we maintain for DAC DataModel. use alloc::{format, string::String}; -pub use sp_std::{collections::btree_map::BTreeMap}; +pub use sp_std::collections::btree_map::BTreeMap; // ToDo: remove String usage +use crate::{dac, utils, ValidationDecision}; +use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use base64::prelude::*; use lite_json::json::JsonValue; +use log::info; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; use sp_std::prelude::*; -use crate::{dac, utils, ValidationDecision}; -use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; -use log::info; const HTTP_TIMEOUT_MS: u64 = 30_000; @@ -78,11 +78,7 @@ pub fn share_intermediate_validation_result( let url = format!( "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", - shared_memory_webdis_url, - validator, - cdn_node, - era, - url_encoded_json, + shared_memory_webdis_url, validator, cdn_node, era, url_encoded_json, ); log::info!("share_intermediate_validation_result url: {:?}", url); @@ -108,13 +104,21 @@ pub fn share_intermediate_validation_result( Ok(json) } -pub(crate) fn get_intermediate_decisions(data_provider_url: &String, edge: &str, era: &EraIndex, quorum: Vec) -> Vec { +pub(crate) fn get_intermediate_decisions( + data_provider_url: &String, + edge: &str, + era: &EraIndex, + quorum: Vec, +) -> Vec { let url = format!("{}/JSON.GET/ddc:dac:shared:nodes:{}", data_provider_url, era); let response: IntermediateDecisionsWrapper = dac::http_get_json(url.as_str()).unwrap(); - let mut edges_to_validators_decisions: BTreeMap> = serde_json::from_str(&response.json).unwrap(); + let mut edges_to_validators_decisions: BTreeMap< + String, + BTreeMap, + > = serde_json::from_str(&response.json).unwrap(); let decisions_for_edge = IntermediateDecisions { - validators_to_decisions: edges_to_validators_decisions.remove(edge).unwrap() + validators_to_decisions: edges_to_validators_decisions.remove(edge).unwrap(), }; let quorum_decisions = find_quorum_decisions(decisions_for_edge, quorum); @@ -144,7 +148,10 @@ pub(crate) fn decode_intermediate_decisions( decoded_decisions } -pub(crate) fn find_quorum_decisions(all_decisions: IntermediateDecisions, quorum: Vec) -> IntermediateDecisions { +pub(crate) fn find_quorum_decisions( + all_decisions: IntermediateDecisions, + quorum: Vec, +) -> IntermediateDecisions { let mut quorum_decisions: BTreeMap = BTreeMap::new(); for (validator_id, decision) in all_decisions.validators_to_decisions.iter() { if quorum.contains(validator_id) { @@ -152,7 +159,5 @@ pub(crate) fn find_quorum_decisions(all_decisions: IntermediateDecisions, quorum } } - IntermediateDecisions { - validators_to_decisions: quorum_decisions - } + IntermediateDecisions { validators_to_decisions: quorum_decisions } } diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs index 93c282d03..709c3aa1a 100644 --- a/pallets/ddc-validator/src/utils.rs +++ b/pallets/ddc-validator/src/utils.rs @@ -36,11 +36,11 @@ pub(crate) fn url_encode(input: &str) -> String { // Unreserved characters (alphanumeric and -_.~) b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { encoded.push(byte as char); - } + }, _ => { encoded.push('%'); encoded.push_str(&format!("{:02X}", byte)); - } + }, } } @@ -59,11 +59,11 @@ pub(crate) fn unescape(json: &str) -> String { for _ in 0..5 { chars.next(); } - } + }, _ => { // Skip over the next character chars.next(); - } + }, } } else { result.push(c); From 3966b3d3ce90c875fb236e0e638f95c916a2b6be Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 4 Jul 2023 16:24:05 +0600 Subject: [PATCH 175/544] Fix faulty testing --- pallets/ddc-validator/src/mock.rs | 54 ++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index cfbd37992..10ff240cf 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -4,6 +4,7 @@ use frame_support::{ parameter_types, traits::{ConstU16, ConstU64, Currency, Everything, Nothing, U128CurrencyToVote}, weights::Weight, + PalletId, }; use frame_system::{offchain::SendTransactionTypes, EnsureRoot}; use pallet_contracts as contracts; @@ -40,6 +41,7 @@ frame_support::construct_runtime!( Timestamp: pallet_timestamp, Session: pallet_session, Staking: pallet_staking, + DdcAccounts: pallet_ddc_accounts, DdcStaking: pallet_ddc_staking, RandomnessCollectiveFlip: pallet_randomness_collective_flip, DdcValidator: pallet_ddc_validator, @@ -48,7 +50,7 @@ frame_support::construct_runtime!( parameter_types! { pub const BlockHashCount: BlockNumber = 250; - pub const MaximumBlockWeight: Weight = 1024; + pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); pub const MaximumBlockLength: u32 = 2 * 1024; pub const AvailableBlockRatio: Perbill = Perbill::one(); } @@ -106,22 +108,27 @@ impl Convert for TestWeightToFee { } impl contracts::Config for Test { - type Time = Timestamp; - type Randomness = RandomnessCollectiveFlip; - type Currency = Balances; - type Event = Event; + type AddressGenerator = pallet_contracts::DefaultAddressGenerator; + type Call = Call; + type CallFilter = Nothing; type CallStack = [pallet_contracts::Frame; 31]; - type WeightPrice = TestWeightToFee; //pallet_transaction_payment::Module; - type WeightInfo = (); type ChainExtension = (); + // type ContractAccessWeight = pallet_contracts::DefaultContractAccessWeight; + type ContractAccessWeight = (); + type Currency = Balances; type DeletionQueueDepth = (); type DeletionWeightLimit = (); - type Schedule = Schedule; - type Call = Call; - type CallFilter = Nothing; type DepositPerByte = DepositPerByte; type DepositPerItem = DepositPerItem; - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; + type Event = Event; + type MaxCodeLen = ConstU32<{ 128 * 1024 }>; + type MaxStorageKeyLen = ConstU32<128>; + type Randomness = RandomnessCollectiveFlip; + type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>; + type Schedule = Schedule; + type Time = Timestamp; + type WeightInfo = (); + type WeightPrice = (); } parameter_types! { @@ -236,10 +243,35 @@ impl pallet_staking::Config for Test { type OnStakerSlash = (); } +parameter_types! { + pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); +} + +impl pallet_ddc_accounts::Config for Test { + type BondingDuration = BondingDuration; + type Currency = Balances; + type Event = Event; + type PalletId = DdcAccountsPalletId; + type TimeProvider = pallet_timestamp::Pallet; +} + +parameter_types! { + pub const DefaultEdgeBondSize: Balance = 100; + pub const DefaultEdgeChillDelay: EraIndex = 2; + pub const DefaultStorageBondSize: Balance = 100; + pub const DefaultStorageChillDelay: EraIndex = 2; +} + impl pallet_ddc_staking::Config for Test { type BondingDuration = BondingDuration; type Currency = Balances; + type DefaultEdgeBondSize = DefaultEdgeBondSize; + type DefaultEdgeChillDelay = DefaultEdgeChillDelay; + type DefaultStorageBondSize = DefaultStorageBondSize; + type DefaultStorageChillDelay = DefaultStorageChillDelay; type Event = Event; + type StakersPayoutSource = DdcAccountsPalletId; + type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } From 96ee036619b5c3768bb96d9ae058523a8a236d65 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 4 Jul 2023 17:28:45 +0600 Subject: [PATCH 176/544] Remove comment line --- pallets/ddc-validator/src/mock.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 10ff240cf..58f2cc4bf 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -113,7 +113,6 @@ impl contracts::Config for Test { type CallFilter = Nothing; type CallStack = [pallet_contracts::Frame; 31]; type ChainExtension = (); - // type ContractAccessWeight = pallet_contracts::DefaultContractAccessWeight; type ContractAccessWeight = (); type Currency = Balances; type DeletionQueueDepth = (); From e37e3167346ef2ce3bb6e718442e0ffdf0781d74 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 5 Jul 2023 14:04:29 +0600 Subject: [PATCH 177/544] Add job assignment related comments --- pallets/ddc-validator/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 9651eb0a7..afefb4aea 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -199,6 +199,7 @@ pub mod pallet { type ValidationThreshold: Get; } + /// The map from the era and validator stash key to the list of CDN nodes to validate. #[pallet::storage] #[pallet::getter(fn assignments)] pub(super) type Assignments = @@ -655,6 +656,7 @@ pub mod pallet { } } + /// Shuffle the `list` swapping it's random elements `list.len()` times. fn shuffle(mut list: Vec) -> Vec { let len = list.len(); for i in 1..len { @@ -665,6 +667,10 @@ pub mod pallet { list } + /// Split the `list` to several chunks `segment_len` length each. + /// + /// The very last chunk will be shorter than `segment_len` if `list.len()` is not divisible + /// by `segment_len`. fn split(list: Vec, segment_len: usize) -> Vec> { let mut result: Vec> = Vec::new(); @@ -681,6 +687,10 @@ pub mod pallet { result } + /// Assign which CDN nodes data each validator shall process. + /// + /// Each CDN node is assigned to `quorum_size` validators randomly picked from the validator + /// set. fn assign(quorum_size: usize, era: EraIndex) { let validators: Vec = >::iter_keys().collect(); log::info!("current validators: {:?}", validators); @@ -700,12 +710,17 @@ pub mod pallet { .map(|v| utils::account_to_string::(v.clone())) .collect(); + // Create several groups of validators and edges, both group types contain the same + // `quorum_size` number of participants. let quorums = Self::split(validators_keys, quorum_size); let edges_groups = Self::split(shuffled_edges, quorum_size); info!("quorums: {:?}", quorums); info!("edges_groups: {:?}", edges_groups); + // Write an assignment to each validator in each quorum. If the number of edges groups + // in higher than the number of validators groups, remaining CDN nodes will not be + // assigned to any validator. for (i, quorum) in quorums.iter().enumerate() { let edges_group = &edges_groups[i]; for validator in quorum { From 07d67bf4f0db72a10d481ab83fcd7978f5d7e662 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 5 Jul 2023 16:48:59 +0600 Subject: [PATCH 178/544] Fix validation job assignment --- pallets/ddc-validator/src/lib.rs | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index afefb4aea..fd7f970a1 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -32,7 +32,7 @@ pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; pub use core::fmt::Debug; pub use frame_support::{ - decl_event, decl_module, decl_storage, + decl_event, decl_module, decl_storage, defensive, dispatch::DispatchResult, pallet_prelude::*, parameter_types, storage, @@ -710,26 +710,26 @@ pub mod pallet { .map(|v| utils::account_to_string::(v.clone())) .collect(); - // Create several groups of validators and edges, both group types contain the same - // `quorum_size` number of participants. + // Create several groups of validators `quorum_size` length each. let quorums = Self::split(validators_keys, quorum_size); - let edges_groups = Self::split(shuffled_edges, quorum_size); - - info!("quorums: {:?}", quorums); - info!("edges_groups: {:?}", edges_groups); - - // Write an assignment to each validator in each quorum. If the number of edges groups - // in higher than the number of validators groups, remaining CDN nodes will not be - // assigned to any validator. - for (i, quorum) in quorums.iter().enumerate() { - let edges_group = &edges_groups[i]; - for validator in quorum { - Assignments::::insert( + + // Write an assignment to each validator in each quorum. The difference between the + // number of edges assigned to each validator is not higher then 1. If the number of + // edges is less then the number of quorums, some quorums will not have any edges + // assigned. + let mut quorums_cycle = quorums.iter().cycle(); + for edge in shuffled_edges { + let Some(quorum_validators) = quorums_cycle.next() else { + defensive!("unexpectedly ran out of quorums"); + return + }; + quorum_validators.iter().for_each(|validator| { + Assignments::::append( era, utils::string_to_account::(validator.clone()), - edges_group, + edge.clone(), ); - } + }); } } From b07496a740349f8260a42e914d0ca80e57604ecb Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 5 Jul 2023 17:20:40 +0600 Subject: [PATCH 179/544] Fix to assign validation tasks once per DDC era --- pallets/ddc-validator/src/lib.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index fd7f970a1..98a561f6f 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -256,19 +256,13 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); - match >::get() { - Some(last_managed_era) => - if last_managed_era > era { - return Weight::from_ref_time(0) - } else { - Self::assign(3usize, era + 1); - >::put(era); - }, - None => { + match Self::last_managed_era() { + Some(last_managed_era) if era <= last_managed_era => (), + _ => { Self::assign(3usize, era); >::put(era); }, - } + }; Weight::from_ref_time(0) } From c69cbb796e21b3bcdff3586a8b987b0631a79f79 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 5 Jul 2023 16:53:53 +0200 Subject: [PATCH 180/544] update redis url --- pallets/ddc-staking/src/lib.rs | 2 +- pallets/ddc-validator/src/dac.rs | 74 +++++++++++++++++------ pallets/ddc-validator/src/lib.rs | 100 +++++++++++++++++++++++-------- 3 files changed, 132 insertions(+), 44 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 09f92641c..7717261c5 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -838,7 +838,7 @@ pub mod pallet { } impl Pallet { - pub(super) fn do_payout_stakers(era: EraIndex) -> DispatchResult { + pub fn do_payout_stakers(era: EraIndex) -> DispatchResult { // ToDo: check that the era is finished // ToDo: check reward points are set diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 63244a6e2..29fea51b5 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -48,7 +48,7 @@ pub struct BytesSent { pub sum: u32, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequestWrapper { @@ -56,7 +56,32 @@ pub struct FileRequestWrapper { json: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct CDNNodeAggregates { + aggregate: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct CDNNodeAggregate { + total_bytes_sent: u64, + total_queries: u64, + total_reads: u64, + total_reads_acked: u64, + total_queries_acked: u64, + average_response_time_ms: f64, + total_bytes_received: u64, + pub request_ids: Vec, + total_writes_acked: u64, + average_response_time_ms_samples: u64, + total_writes: u64, +} + + +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequests { @@ -65,11 +90,11 @@ pub struct FileRequests { pub type Requests = BTreeMap; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequest { - file_request_id: String, + pub file_request_id: String, file_info: FileInfo, bucket_id: u128, timestamp: u64, @@ -77,7 +102,7 @@ pub struct FileRequest { user_public_key: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Chunk { @@ -86,46 +111,50 @@ pub struct Chunk { ack: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Ack { - bytes_received: u64, user_timestamp: u64, nonce: String, - node_public_key: String, + signature: Option, + aggregated: u64, user_public_key: String, - signature: String, + bytes_received: u64, + requested_chunk_cids: Vec, + node_public_key: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Log { #[serde(rename = "type")] log_type: u64, - session_id: String, + signature: Option, + aggregated: u64, user_public_key: String, era: u64, + bucket_id: u128, user_address: String, bytes_sent: u64, timestamp: u64, node_public_key: String, - signature: String, - bucket_id: u128, + session_id: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileInfo { #[serde(rename = "chunkCids")] - chunk_cids: Vec, + chunk_cids: Vec , #[serde(rename = "requestedChunkCids")] requested_chunk_cids: Vec, } + type EdgeId = String; type ValidatorId = String; @@ -366,14 +395,23 @@ fn get_file_request_url(data_provider_url: &String) -> String { res } -pub(crate) fn fetch_file_request(url: &String) -> Requests { +pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec { log::info!("fetch_file_request | url: {:?}", url); let response: FileRequestWrapper = http_get_json(&url).unwrap(); - let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); - let map: Requests = serde_json::from_value(value).unwrap(); + log::info!("response.json: {:?}", response.json); + let map: Vec = serde_json::from_str(response.json.as_str()).unwrap(); + // log::info!("response.json: {:?}", response.json); + map +} + +pub(crate) fn fetch_file_request(url: &String) -> FileRequest { + log::info!("fetch_file_request | url: {:?}", url); + let response: FileRequestWrapper = http_get_json(&url).unwrap(); log::info!("response.json: {:?}", response.json); + let map: FileRequest = serde_json::from_str(response.json.as_str()).unwrap(); + map } diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 98a561f6f..7b52b0738 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -78,7 +78,7 @@ pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and a /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://redis:6379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; @@ -567,6 +567,38 @@ pub mod pallet { Ok(()) } + #[pallet::weight(100_000)] + pub fn charge_payments_content_owners( + origin: OriginFor, + paying_accounts: Vec>>, + ) -> DispatchResult { + let controller = ensure_signed(origin)?; + // ensure!( + // OffchainWorkerKeys::::contains_key(&controller), + // Error::::OCWKeyNotRegistered + // ); + + >::charge_payments_new(paying_accounts); + + Ok(()) + } + + #[pallet::weight(100_000)] + pub fn payout_cdn_owners( + origin: OriginFor, + era: EraIndex, + ) -> DispatchResult { + let controller = ensure_signed(origin)?; + // ensure!( + // OffchainWorkerKeys::::contains_key(&controller), + // Error::::OCWKeyNotRegistered + // ); + + >::do_payout_stakers(era); + + Ok(()) + } + #[pallet::weight(100_000)] pub fn set_ocw_key(origin: OriginFor, ocw_pub: T::AccountId) -> DispatchResult { let controller = ensure_signed(origin)?; @@ -603,7 +635,7 @@ pub mod pallet { fn get_mock_data_url() -> String { let data_url = Self::get_data_provider_url(); - let mock_url = "/JSON.GET/testddc:dac:data"; + let mock_url = "/JSON.GET/"; let url = format!("{}{}", data_url, mock_url); url @@ -800,16 +832,38 @@ pub mod pallet { info!("assigned_edges: {:?}", assigned_edges); for assigned_edge in assigned_edges.iter() { + info!("assigned edge: {:?}", assigned_edge); + + // form url for each node + let edge_url = format!("{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:132855/$.", utils::account_to_string::(assigned_edge.clone())); + info!("edge url: {:?}", edge_url); + + let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); + info!("node aggregates: {:?}", node_aggregates); + + // No data for node + if (node_aggregates.len() == 0) { + continue + } + + let request_ids = &node_aggregates[0].request_ids; + info!("request_ids: {:?}", request_ids); + // Store bucket payments let payments_per_bucket = &mut Vec::new(); - let file_request = dac::fetch_file_request(&mock_data_url); - dac::get_acknowledged_bytes_bucket(&file_request, payments_per_bucket); - let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&file_request); + let requests = &mut dac::Requests::new(); + for request_id in request_ids.iter() { + let request_id_url = format!("{}{}{}", mock_data_url, "ddc:dac:data:file:", request_id.clone()); + let file_request = dac::fetch_file_request(&request_id_url); + requests.insert(file_request.file_request_id.clone(), file_request.clone()); + } + dac::get_acknowledged_bytes_bucket(&requests, payments_per_bucket); + let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&requests); let is_valid = Self::is_valid(bytes_sent, bytes_received); info!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); - let payload = serde_json::to_string(&file_request).unwrap(); + let payload = serde_json::to_string(&requests).unwrap(); let decision = ValidationDecision { edge: utils::account_to_string::(assigned_edge.clone()), result: is_valid, @@ -853,12 +907,7 @@ pub mod pallet { let edge = utils::account_to_string::(assigned_edge.clone()); let prev_era = (current_era - 1) as EraIndex; let quorum = Self::find_validators_from_quorum(&validator, &prev_era); - let validations_res = shm::get_intermediate_decisions( - &data_provider_url, - &edge_str, - &prev_era, - quorum, - ); + let validations_res = shm::get_intermediate_decisions(&data_provider_url, &edge_str, &prev_era, quorum); log::info!("get_intermediate_decisions result: {:?}", validations_res); @@ -868,8 +917,7 @@ pub mod pallet { let mut payments = vec![]; for bucket in payments_per_bucket.into_iter() { let cere_payment: u32 = (bucket.1 / BYTES_TO_CERE) as u32; - let bucket_info = - BucketsDetails { bucket_id: bucket.0, amount: cere_payment.into() }; + let bucket_info = BucketsDetails {bucket_id: bucket.0, amount: cere_payment.into()}; payments.push(bucket_info); } log::info!("final payments: {:?}", payments); @@ -881,21 +929,23 @@ pub mod pallet { return } // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = - signer.send_signed_transaction(|_account| Call::charge_payments_cdn { - paying_accounts: payments.clone(), - }); - + let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_content_owners { + paying_accounts: payments.clone(), + }); + + let _payout_tx_res = signer.send_signed_transaction(|_account| Call::payout_cdn_owners { + era: current_era, + }); + let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); - let tx_res = - signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, - cdn_node: utils::string_to_account::(edge.clone()), - validation_decision: final_res.clone(), - }); + let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: current_era, + cdn_node: utils::string_to_account::(edge.clone()), + validation_decision: final_res.clone(), + }); log::info!("final_res: {:?}", final_res); } From 3fe489b5a11181c3c0f6f9f8f12cefa4160f3163 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 5 Jul 2023 17:02:03 +0200 Subject: [PATCH 181/544] update validator --- pallets/ddc-validator/src/dac.rs | 90 +++++++++++++++++++++++++------- pallets/ddc-validator/src/lib.rs | 63 ++++++++++++++++------ 2 files changed, 117 insertions(+), 36 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index dd1ec370b..1c721a937 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -5,8 +5,9 @@ use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; use lite_json::json::JsonValue; +use lite_json::json_parser::parse_json; use log::info; -use serde_json::Value; +use serde_json::{Value, Map}; use sp_runtime::{ generic::Era, offchain::{ @@ -48,7 +49,7 @@ pub struct BytesSent { pub sum: u32, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequestWrapper { @@ -56,7 +57,32 @@ pub struct FileRequestWrapper { json: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct CDNNodeAggregates { + aggregate: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(crate = "alt_serde")] +#[serde(rename_all = "camelCase")] +pub struct CDNNodeAggregate { + total_bytes_sent: u64, + total_queries: u64, + total_reads: u64, + total_reads_acked: u64, + total_queries_acked: u64, + average_response_time_ms: f64, + total_bytes_received: u64, + pub request_ids: Vec, + total_writes_acked: u64, + average_response_time_ms_samples: u64, + total_writes: u64, +} + + +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequests { @@ -65,11 +91,11 @@ pub struct FileRequests { pub type Requests = BTreeMap; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileRequest { - file_request_id: String, + pub file_request_id: String, file_info: FileInfo, bucket_id: u128, timestamp: u64, @@ -77,7 +103,7 @@ pub struct FileRequest { user_public_key: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Chunk { @@ -86,41 +112,44 @@ pub struct Chunk { ack: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Ack { - bytes_received: u64, user_timestamp: u64, nonce: String, - node_public_key: String, + signature: Option, + aggregated: u64, user_public_key: String, - signature: String, + bytes_received: u64, + requested_chunk_cids: Vec, + node_public_key: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct Log { #[serde(rename = "type")] log_type: u64, - session_id: String, + signature: Option, + aggregated: u64, user_public_key: String, era: u64, + bucket_id: u128, user_address: String, bytes_sent: u64, timestamp: u64, node_public_key: String, - signature: String, - bucket_id: u128, + session_id: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileInfo { #[serde(rename = "chunkCids")] - chunk_cids: Vec, + chunk_cids: Vec , #[serde(rename = "requestedChunkCids")] requested_chunk_cids: Vec, @@ -364,14 +393,23 @@ fn get_file_request_url(data_provider_url: &String) -> String { res } -pub(crate) fn fetch_file_request(url: &String) -> Requests { +pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec { log::info!("fetch_file_request | url: {:?}", url); let response: FileRequestWrapper = http_get_json(&url).unwrap(); - let value: Value = serde_json::from_str(response.json.as_str()).unwrap(); - let map: Requests = serde_json::from_value(value).unwrap(); + log::info!("response.json: {:?}", response.json); + let map: Vec = serde_json::from_str(response.json.as_str()).unwrap(); + // log::info!("response.json: {:?}", response.json); + + map +} +pub(crate) fn fetch_file_request(url: &String) -> FileRequest { + log::info!("fetch_file_request | url: {:?}", url); + let response: FileRequestWrapper = http_get_json(&url).unwrap(); log::info!("response.json: {:?}", response.json); + let map: FileRequest = serde_json::from_str(response.json.as_str()).unwrap(); + map } @@ -450,6 +488,20 @@ pub(crate) fn http_get_json(url: &str) -> crate::ResultSt parsed } +// pub(crate) fn http_get_json_lite(url: &str) -> crate::ResultStr { +// let body = http_get_request(url).map_err(|err| { +// log::error!("[DAC Validator] Error while getting {}: {:?}", url, err); +// "HTTP GET error" +// })?; + +// let parsed = serde_json::from_slice(&body).map_err(|err| { +// log::warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); +// "HTTP JSON parse error" +// }); + +// parsed +// } + fn http_get_request(http_url: &str) -> Result, http::Error> { // log::info!("[DAC Validator] Sending request to: {:?}", http_url); diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index cd92bcbf1..a521840c5 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -78,7 +78,7 @@ pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and a /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://redis:6379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; @@ -244,17 +244,21 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); - match >::get(){ + match >::get() { Some(last_managed_era) => { if last_managed_era > era { return 0 } else { - Self::assign(3usize, era + 1); + log::info!("Assigned era again: {:?}", era); + + Self::assign(1usize, era - 1); >::put(era); } } None => { - Self::assign(3usize, era); + log::info!("Assigned era the first time: {:?}", era); + + Self::assign(1usize, era - 1); >::put(era); } } @@ -552,10 +556,10 @@ pub mod pallet { paying_accounts: Vec>>, ) -> DispatchResult { let controller = ensure_signed(origin)?; - ensure!( - OffchainWorkerKeys::::contains_key(&controller), - Error::::OCWKeyNotRegistered - ); + // ensure!( + // OffchainWorkerKeys::::contains_key(&controller), + // Error::::OCWKeyNotRegistered + // ); >::charge_payments_new(paying_accounts); @@ -568,10 +572,10 @@ pub mod pallet { era: EraIndex, ) -> DispatchResult { let controller = ensure_signed(origin)?; - ensure!( - OffchainWorkerKeys::::contains_key(&controller), - Error::::OCWKeyNotRegistered - ); + // ensure!( + // OffchainWorkerKeys::::contains_key(&controller), + // Error::::OCWKeyNotRegistered + // ); >::do_payout_stakers(era); @@ -617,7 +621,7 @@ pub mod pallet { fn get_mock_data_url() -> String { let data_url = Self::get_data_provider_url(); - let mock_url = "/JSON.GET/testddc:dac:data"; + let mock_url = "/JSON.GET/"; let url = format!("{}{}", data_url, mock_url); url @@ -716,7 +720,10 @@ pub mod pallet { for (i, quorum) in quorums.iter().enumerate() { let edges_group = &edges_groups[i]; + for validator in quorum { + info!("edges_groups to be assigned {:?} for validator {:?}", edges_groups.clone(), validator.clone()); + Assignments::::insert( era, utils::string_to_account::(validator.clone()), @@ -798,16 +805,38 @@ pub mod pallet { info!("assigned_edges: {:?}", assigned_edges); for assigned_edge in assigned_edges.iter() { + info!("assigned edge: {:?}", assigned_edge); + + // form url for each node + let edge_url = format!("{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:132855/$.", utils::account_to_string::(assigned_edge.clone())); + info!("edge url: {:?}", edge_url); + + let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); + info!("node aggregates: {:?}", node_aggregates); + + // No data for node + if (node_aggregates.len() == 0) { + continue + } + + let request_ids = &node_aggregates[0].request_ids; + info!("request_ids: {:?}", request_ids); + // Store bucket payments let payments_per_bucket = &mut Vec::new(); - let file_request = dac::fetch_file_request(&mock_data_url); - dac::get_acknowledged_bytes_bucket(&file_request, payments_per_bucket); - let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&file_request); + let requests = &mut dac::Requests::new(); + for request_id in request_ids.iter() { + let request_id_url = format!("{}{}{}", mock_data_url, "ddc:dac:data:file:", request_id.clone()); + let file_request = dac::fetch_file_request(&request_id_url); + requests.insert(file_request.file_request_id.clone(), file_request.clone()); + } + dac::get_acknowledged_bytes_bucket(&requests, payments_per_bucket); + let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&requests); let is_valid = Self::is_valid(bytes_sent, bytes_received); info!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); - let payload = serde_json::to_string(&file_request).unwrap(); + let payload = serde_json::to_string(&requests).unwrap(); let decision = ValidationDecision { edge: utils::account_to_string::(assigned_edge.clone()), result: is_valid, From d15c723bba7479327a0d682a7ac3d8650faf29fe Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 5 Jul 2023 19:47:13 +0200 Subject: [PATCH 182/544] update job assignment --- pallets/ddc-validator/src/lib.rs | 53 +++++++++++++------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index a521840c5..193549d81 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -32,7 +32,7 @@ pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; pub use core::fmt::Debug; pub use frame_support::{ - decl_event, decl_module, decl_storage, + decl_event, decl_module, decl_storage, defensive, dispatch::DispatchResult, pallet_prelude::*, parameter_types, storage, @@ -244,24 +244,13 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); - match >::get() { - Some(last_managed_era) => { - if last_managed_era > era { - return 0 - } else { - log::info!("Assigned era again: {:?}", era); - - Self::assign(1usize, era - 1); - >::put(era); - } - } - None => { - log::info!("Assigned era the first time: {:?}", era); - - Self::assign(1usize, era - 1); + match Self::last_managed_era() { + Some(last_managed_era) if era <= last_managed_era => (), + _ => { + Self::assign(3usize, era); >::put(era); - } - } + }, + }; 0 } @@ -712,24 +701,26 @@ pub mod pallet { .map(|v| utils::account_to_string::(v.clone())) .collect(); + // Create several groups of validators `quorum_size` length each. let quorums = Self::split(validators_keys, quorum_size); - let edges_groups = Self::split(shuffled_edges, quorum_size); - - info!("quorums: {:?}", quorums); - info!("edges_groups: {:?}", edges_groups); - - for (i, quorum) in quorums.iter().enumerate() { - let edges_group = &edges_groups[i]; - - for validator in quorum { - info!("edges_groups to be assigned {:?} for validator {:?}", edges_groups.clone(), validator.clone()); - Assignments::::insert( + // Write an assignment to each validator in each quorum. The difference between the + // number of edges assigned to each validator is not higher then 1. If the number of + // edges is less then the number of quorums, some quorums will not have any edges + // assigned. + let mut quorums_cycle = quorums.iter().cycle(); + for edge in shuffled_edges { + let Some(quorum_validators) = quorums_cycle.next() else { + defensive!("unexpectedly ran out of quorums"); + return + }; + quorum_validators.iter().for_each(|validator| { + Assignments::::append( era, utils::string_to_account::(validator.clone()), - edges_group, + edge.clone(), ); - } + }); } } From a5b9c434118d3dd1ccc2b56b21cc084118d1829e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 5 Jul 2023 21:27:48 +0200 Subject: [PATCH 183/544] fix url bug --- pallets/ddc-validator/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 193549d81..bdc89cc72 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -78,7 +78,7 @@ pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and a /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://redis:6379"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; @@ -781,7 +781,7 @@ pub mod pallet { } fn validate_edges() { - let current_era = Self::get_current_era(); + let current_era = Self::get_current_era() - 1; let mock_data_url = Self::get_mock_data_url(); let data_provider_url = Self::get_data_provider_url(); @@ -799,7 +799,7 @@ pub mod pallet { info!("assigned edge: {:?}", assigned_edge); // form url for each node - let edge_url = format!("{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:132855/$.", utils::account_to_string::(assigned_edge.clone())); + let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", current_era, "/$.", utils::account_to_string::(assigned_edge.clone())); info!("edge url: {:?}", edge_url); let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); From cfe9cbf9843ef3b8063d73f6db3fde852dc8c817 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 5 Jul 2023 22:07:37 +0200 Subject: [PATCH 184/544] use webdis --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index bdc89cc72..c2ade8670 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -78,7 +78,7 @@ pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and a /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; From 0c96082ab11f3b6e1e0ead17bcd2c96ddfca63b8 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 13:36:34 +0600 Subject: [PATCH 185/544] Produce tasks assignment for the next era --- pallets/ddc-validator/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 7b52b0738..6e314ffb6 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -256,11 +256,12 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); + // Produce an assignment for the next era if it's not produced yet. match Self::last_managed_era() { - Some(last_managed_era) if era <= last_managed_era => (), + Some(last_managed_era) if era < last_managed_era => (), _ => { - Self::assign(3usize, era); - >::put(era); + Self::assign(3usize, era + 1); + >::put(era + 1); }, }; From d354723dd664d27ffa4785481ffa688526aa448d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 16:58:40 +0600 Subject: [PATCH 186/544] Autoformat `pallet-ddc-validator` files --- pallets/ddc-validator/src/dac.rs | 6 ++-- pallets/ddc-validator/src/lib.rs | 57 ++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 29fea51b5..ed77c84eb 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -60,7 +60,7 @@ pub struct FileRequestWrapper { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct CDNNodeAggregates { - aggregate: Vec, + aggregate: Vec, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -80,7 +80,6 @@ pub struct CDNNodeAggregate { total_writes: u64, } - #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] @@ -148,13 +147,12 @@ pub struct Log { #[serde(rename_all = "camelCase")] pub struct FileInfo { #[serde(rename = "chunkCids")] - chunk_cids: Vec , + chunk_cids: Vec, #[serde(rename = "requestedChunkCids")] requested_chunk_cids: Vec, } - type EdgeId = String; type ValidatorId = String; diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 6e314ffb6..bdce4eee7 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -578,24 +578,21 @@ pub mod pallet { // OffchainWorkerKeys::::contains_key(&controller), // Error::::OCWKeyNotRegistered // ); - - >::charge_payments_new(paying_accounts); + + >::charge_payments_new(paying_accounts); Ok(()) } #[pallet::weight(100_000)] - pub fn payout_cdn_owners( - origin: OriginFor, - era: EraIndex, - ) -> DispatchResult { + pub fn payout_cdn_owners(origin: OriginFor, era: EraIndex) -> DispatchResult { let controller = ensure_signed(origin)?; // ensure!( // OffchainWorkerKeys::::contains_key(&controller), // Error::::OCWKeyNotRegistered // ); - >::do_payout_stakers(era); + >::do_payout_stakers(era); Ok(()) } @@ -836,7 +833,12 @@ pub mod pallet { info!("assigned edge: {:?}", assigned_edge); // form url for each node - let edge_url = format!("{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:132855/$.", utils::account_to_string::(assigned_edge.clone())); + let edge_url = format!( + "{}{}{}", + mock_data_url, + "ddc:dac:aggregation:nodes:132855/$.", + utils::account_to_string::(assigned_edge.clone()) + ); info!("edge url: {:?}", edge_url); let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); @@ -854,7 +856,8 @@ pub mod pallet { let payments_per_bucket = &mut Vec::new(); let requests = &mut dac::Requests::new(); for request_id in request_ids.iter() { - let request_id_url = format!("{}{}{}", mock_data_url, "ddc:dac:data:file:", request_id.clone()); + let request_id_url = + format!("{}{}{}", mock_data_url, "ddc:dac:data:file:", request_id.clone()); let file_request = dac::fetch_file_request(&request_id_url); requests.insert(file_request.file_request_id.clone(), file_request.clone()); } @@ -908,7 +911,12 @@ pub mod pallet { let edge = utils::account_to_string::(assigned_edge.clone()); let prev_era = (current_era - 1) as EraIndex; let quorum = Self::find_validators_from_quorum(&validator, &prev_era); - let validations_res = shm::get_intermediate_decisions(&data_provider_url, &edge_str, &prev_era, quorum); + let validations_res = shm::get_intermediate_decisions( + &data_provider_url, + &edge_str, + &prev_era, + quorum, + ); log::info!("get_intermediate_decisions result: {:?}", validations_res); @@ -918,7 +926,8 @@ pub mod pallet { let mut payments = vec![]; for bucket in payments_per_bucket.into_iter() { let cere_payment: u32 = (bucket.1 / BYTES_TO_CERE) as u32; - let bucket_info = BucketsDetails {bucket_id: bucket.0, amount: cere_payment.into()}; + let bucket_info = + BucketsDetails { bucket_id: bucket.0, amount: cere_payment.into() }; payments.push(bucket_info); } log::info!("final payments: {:?}", payments); @@ -930,23 +939,27 @@ pub mod pallet { return } // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_content_owners { - paying_accounts: payments.clone(), + let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = + signer.send_signed_transaction(|_account| { + Call::charge_payments_content_owners { + paying_accounts: payments.clone(), + } + }); + + let _payout_tx_res = signer.send_signed_transaction(|_account| { + Call::payout_cdn_owners { era: current_era } }); - let _payout_tx_res = signer.send_signed_transaction(|_account| Call::payout_cdn_owners { - era: current_era, - }); - let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); - let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, - cdn_node: utils::string_to_account::(edge.clone()), - validation_decision: final_res.clone(), - }); + let tx_res = + signer.send_signed_transaction(|_acct| Call::set_validation_decision { + era: current_era, + cdn_node: utils::string_to_account::(edge.clone()), + validation_decision: final_res.clone(), + }); log::info!("final_res: {:?}", final_res); } From 58afb8696a579f20eeb66a1a5705b4f8b065717a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 17:00:21 +0600 Subject: [PATCH 187/544] Run validation once per DDC era --- pallets/ddc-validator/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index bdce4eee7..dd0f4e2e9 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -69,6 +69,10 @@ type BalanceOf = <::Currency as Currency< type ResultStr = Result; +/// Offchain local storage key that holds the last era in which the validator completed its +/// assignment. +const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; + pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const TIME_START_MS: u128 = 1_672_531_200_000; @@ -274,8 +278,19 @@ pub mod pallet { return } + let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_KEY); + let last_validated_era = match last_validated_era_storage.get::() { + Ok(Some(last_validated_era)) => last_validated_era, + _ => 0, // let's consider an absent or undecodable data as we never did a validation + }; + let current_era = Self::get_current_era(); - let last_managed_era = Self::last_managed_era().unwrap_or(0); + + // Skip if the validation is already complete for the era. + if current_era <= last_validated_era { + return + } + let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); From 1159398b01fabf86435ab9037457ddf807bf5378 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 17:06:08 +0600 Subject: [PATCH 188/544] Fix duplicate validation start each block --- pallets/ddc-validator/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index dd0f4e2e9..2be7a3022 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -56,7 +56,9 @@ pub use scale_info::TypeInfo; pub use serde_json::Value; pub use sp_core::crypto::{AccountId32, KeyTypeId, UncheckedFrom}; pub use sp_io::crypto::sr25519_public_keys; -pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; +pub use sp_runtime::offchain::{ + http, storage::StorageValueRef, storage_lock, storage_lock::StorageLock, Duration, Timestamp, +}; pub use sp_staking::EraIndex; pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -278,6 +280,14 @@ pub mod pallet { return } + let mut validation_lock = + StorageLock::::new(LAST_VALIDATED_ERA_KEY); + + // Skip if the validation is already in progress. + let Ok(_) = validation_lock.try_lock() else { + return + }; + let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_KEY); let last_validated_era = match last_validated_era_storage.get::() { Ok(Some(last_validated_era)) => last_validated_era, From 13ff254bfc0ac83816a2b1b303d14c35bee8f7fc Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 17:49:08 +0600 Subject: [PATCH 189/544] Remove an obsolete comment --- pallets/ddc-validator/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 2be7a3022..584fe743a 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -304,10 +304,7 @@ pub mod pallet { let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - // `If` commented for testing purposes - // if current_era > last_managed_era { Self::validate_edges(); - //} // Print the number of broken sessions per CDN node. // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // From 11c834fde419e6d59d5c93a2e9a17bbd3ad3869f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 18:01:05 +0600 Subject: [PATCH 190/544] Fix validators signal check skipping --- pallets/ddc-validator/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 584fe743a..b8f9f222a 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -280,13 +280,15 @@ pub mod pallet { return } + let mut should_validate_because_new_era = true; + let mut validation_lock = StorageLock::::new(LAST_VALIDATED_ERA_KEY); // Skip if the validation is already in progress. - let Ok(_) = validation_lock.try_lock() else { - return - }; + if validation_lock.try_lock().is_err() { + should_validate_because_new_era = false; + } let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_KEY); let last_validated_era = match last_validated_era_storage.get::() { @@ -298,13 +300,15 @@ pub mod pallet { // Skip if the validation is already complete for the era. if current_era <= last_validated_era { - return + should_validate_because_new_era = false; } let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - Self::validate_edges(); + if should_validate_because_new_era { + Self::validate_edges(); + } // Print the number of broken sessions per CDN node. // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // From 66a47659f507e7d108c62833b98fa6925aab98df Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 18:10:49 +0600 Subject: [PATCH 191/544] Remove obsolete validation code used data mockups --- pallets/ddc-validator/src/lib.rs | 165 ------------------------------- 1 file changed, 165 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index b8f9f222a..ef037de1d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -344,171 +344,6 @@ pub mod pallet { log::info!("🔎 DAC Validator is idle at block {:?}, waiting for a signal, signal state is {:?}", block_number, signal); return } - - // Read from DAC. - let response = dac::fetch_data2(&data_provider_url, current_era - 1); - let (sent_query, sent, received_query, received) = match response { - Ok(data) => data, - Err(_) => { - log::info!("🔎 DAC Validator failed to get bytes sent and received from DAC"); - return - }, - }; - log::info!( - "🔎 DAC Validator is fetching data from DAC, current era: {:?}, bytes sent query: {:?}, bytes sent response: {:?}, bytes received query: {:?}, bytes received response: {:?}", - current_era, - sent_query, - sent, - received_query, - received, - ); - - // Create intermediate validation decisions - // ======================================== - - // All validators validate all CDN nodes. - let edges: Vec = >::iter_keys().collect(); - for edge in edges.iter() { - // Get string type CDN node pubkey - let edge_pubkey: String = utils::account_to_string::(edge.clone()); - - // Get bytes sent and received for the CDN node - let node_sent: &dac::BytesSent = match sent - .iter() - .find(|bytes_sent| bytes_sent.node_public_key == edge_pubkey) - { - Some(node_sent) => node_sent, - None => { - log::warn!("No logs to validate {:?}", edge); - continue - }, - }; - let client_received: &dac::BytesReceived = match received - .iter() - .find(|bytes_received| bytes_received.node_public_key == edge_pubkey) - { - Some(client_received) => client_received, - None => { - log::warn!("No acks to validate {:?}", edge); - continue - }, - }; - - // Proof-of-delivery validation - let validation_result = Self::validate(node_sent, client_received); - - // Prepare an intermediate validation decision - let validation_decision = ValidationDecision { - edge: utils::account_to_string::(edge.clone()), - result: validation_result, - payload: [0u8; 32], // ToDo: put a hash of the validated data here - totals: DacTotalAggregates { - sent: node_sent.sum as u64, - received: client_received.sum as u64, - failed_by_client: 0, // ToDo - failure_rate: 0, // ToDo - }, - }; - - // Encode validation decision to base64 - let validation_decision_serialized: Vec = validation_decision.encode(); - let validation_decision_base64 = - shm::base64_encode(&validation_decision_serialized).unwrap(); - log::info!( - "Intermediate validation decision for CDN node {:?}: , base64 encoded: {:?}", - validation_decision, - validation_decision_base64, - ); - - // Prepare values to publish validation decision and publish it - let validator_id_string = String::from("validator1"); // ToDo: get validator ID - let edge_id_string = utils::account_to_string::(edge.clone()); - let validation_decision_base64_string = - validation_decision_base64.iter().cloned().collect::(); - let response = shm::share_intermediate_validation_result( - &data_provider_url, - current_era - 1, - &validator_id_string, - &edge_id_string, - validation_result, - &validation_decision_base64_string, - ); - match response { - Ok(response) => - log::info!("Shared memory response: {:?}", response.to_string()), - Err(e) => { - log::error!("Shared memory error: {:?}", e); - continue - }, - } - } - log::info!( - "Intermediate validation results published for {} CDN nodes in era {:?}", - edges.len(), - current_era - 1 - ); - - // Set CDN nodes' reward points - // ============================ - - // Let's use a mock data until we have a real final validation decisions for all the CDN - // nodes. - let mock_final_validation_decisions: Vec<(T::AccountId, ValidationDecision)> = vec![ - ( - utils::string_to_account::( - "0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1".into(), - ), - ValidationDecision { - edge: "test".into(), - result: true, - payload: [0u8; 32], - totals: DacTotalAggregates { - sent: 100, - received: 100, - failed_by_client: 0, - failure_rate: 0, - }, - }, - ), - ( - utils::string_to_account::( - "0xa2d14e71b52e5695e72c0567926bc68b68bda74df5c1ccf1d4ba612c153ff66b".into(), - ), - ValidationDecision { - edge: "test".into(), - result: true, - payload: [0u8; 32], - totals: DacTotalAggregates { - sent: 200, - received: 200, - failed_by_client: 0, - failure_rate: 0, - }, - }, - ), - ]; - - // Calculate CDN nodes reward points from validation decision aggregates - let cdn_nodes_reward_points: Vec<(T::AccountId, u64)> = mock_final_validation_decisions - .into_iter() - .filter(|(_, validation_decision)| validation_decision.result) // skip misbehaving - .map(|(cdn_node, validation_decision)| { - // ToDo: should we use `sent` or `received` or anything else as a reward point? - (cdn_node, validation_decision.totals.sent) - }) - .collect(); - - // Store CDN node reward points on-chain - let signer: Signer = Signer::<_, _>::any_account(); - if !signer.can_sign() { - log::warn!("No local accounts available to set era reward points. Consider adding one via `author_insertKey` RPC."); - return - } - // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { - era: current_era - 1, - stakers_points: cdn_nodes_reward_points.clone(), - }); } } From 00e54b4818fa0fd43d32cb8f2dd909e6b481e708 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 18:11:58 +0600 Subject: [PATCH 192/544] Remove commented out broken sessions detection --- pallets/ddc-validator/src/lib.rs | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index ef037de1d..d80d25fdd 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -310,34 +310,6 @@ pub mod pallet { Self::validate_edges(); } - // Print the number of broken sessions per CDN node. - // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // - // 77436 is for a mock data let aggregates_obj = aggregates_value.as_object().unwrap(); - // aggregates_obj - // .into_iter() - // .for_each(|(cdn_node_pubkey, cdn_node_aggregates_value)| { - // // iterate over aggregates for each node - // let cdn_node_aggregates_obj = cdn_node_aggregates_value.as_object().unwrap(); - // // Extract `nodeInterruptedSessions` field - // let (_, cdn_node_interrupted_sessions_value) = cdn_node_aggregates_obj - // .into_iter() - // .find(|(key, _)| key.iter().copied().eq("nodeInterruptedSessions".chars())) - // .unwrap(); - // let cdn_node_interrupted_sessions_obj = - // cdn_node_interrupted_sessions_value.as_object().unwrap(); - // // Prepare CDN pubkey without heap allocated string - // let cdn_node_pubkey_vecu8: Vec = - // cdn_node_pubkey.iter().map(|c| *c as u8).collect(); - // let cdn_node_pubkey_str = - // sp_std::str::from_utf8(&cdn_node_pubkey_vecu8).unwrap(); - // log::info!( - // "Broken sessions per CDN node | Node {}: {} sessions broken", - // cdn_node_pubkey_str, - // cdn_node_interrupted_sessions_obj.len(), /* count sessions broken by the - // * node */ - // ); - // }); - // Wait for signal. let signal = Signal::::get().unwrap_or(false); if !signal { From ea666d207a5f6329c40cdf9d5fa1a709730cb206 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 18:18:22 +0600 Subject: [PATCH 193/544] Fix validation start by the signal --- pallets/ddc-validator/src/lib.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index d80d25fdd..a99ac1d7f 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -306,15 +306,11 @@ pub mod pallet { let data_provider_url = Self::get_data_provider_url(); log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - if should_validate_because_new_era { - Self::validate_edges(); - } + // Validation start forced externally? + let should_validate_because_signal = Signal::::get().unwrap_or(false); - // Wait for signal. - let signal = Signal::::get().unwrap_or(false); - if !signal { - log::info!("🔎 DAC Validator is idle at block {:?}, waiting for a signal, signal state is {:?}", block_number, signal); - return + if should_validate_because_new_era || should_validate_because_signal { + Self::validate_edges(); } } } From 22352c9db86c67b6fff38410ab4f743189fe3d69 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 6 Jul 2023 18:19:28 +0600 Subject: [PATCH 194/544] Print data provider URL only if validation starts --- pallets/ddc-validator/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index a99ac1d7f..37c6aaa94 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -303,9 +303,6 @@ pub mod pallet { should_validate_because_new_era = false; } - let data_provider_url = Self::get_data_provider_url(); - log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - // Validation start forced externally? let should_validate_because_signal = Signal::::get().unwrap_or(false); @@ -646,6 +643,7 @@ pub mod pallet { let current_era = Self::get_current_era(); let mock_data_url = Self::get_mock_data_url(); let data_provider_url = Self::get_data_provider_url(); + info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); // let signer = Self::get_signer().unwrap(); // let validator = signer.get_any_account().unwrap().id; From c006aeb45c8db9657871a28f4c473e07c3bc2c1c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 11 Jul 2023 13:06:03 +0600 Subject: [PATCH 195/544] Autoformat with `rustfmt` --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index efb6f9673..074918ba1 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -51,9 +51,9 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; pub use pallet_cere_ddc; pub use pallet_chainbridge; use pallet_contracts::weights::WeightInfo; +pub use pallet_ddc_accounts; pub use pallet_ddc_metrics_offchain_worker; pub use pallet_ddc_staking; -pub use pallet_ddc_accounts; use pallet_election_provider_multi_phase::SolutionAccuracyOf; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, From afee1b9f9ac167d4e1928fd661189887d53af2d9 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 11 Jul 2023 11:30:41 +0200 Subject: [PATCH 196/544] fix eras for exstrinsics & accumulate payments for buckets --- pallets/ddc-validator/src/lib.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index c2ade8670..e42f52125 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -878,13 +878,21 @@ pub mod pallet { if validations_res.len() == QUORUM_SIZE { log::info!("payments per bucket: {:?}", payments_per_bucket); - let mut payments = vec![]; + let mut payments: BTreeMap>> = BTreeMap::new(); for bucket in payments_per_bucket.into_iter() { let cere_payment: u32 = (bucket.1 / BYTES_TO_CERE) as u32; - let bucket_info = BucketsDetails {bucket_id: bucket.0, amount: cere_payment.into()}; - payments.push(bucket_info); + if payments.contains_key(&bucket.0) { + payments.entry(bucket.0).and_modify(|bucket_info| bucket_info.amount += cere_payment.into()); + } else { + let bucket_info = BucketsDetails {bucket_id: bucket.0, amount: cere_payment.into()}; + payments.insert(bucket.0, bucket_info); + } } - log::info!("final payments: {:?}", payments); + let mut final_payments = vec![]; + for (_, bucket_info) in payments { + final_payments.push(bucket_info); + } + log::info!("final payments: {:?}", final_payments); // Store CDN node reward points on-chain let signer: Signer = Signer::<_, _>::any_account(); @@ -894,11 +902,11 @@ pub mod pallet { } // ToDo: replace local call by a call from `ddc-staking` pallet let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| Call::charge_payments_content_owners { - paying_accounts: payments.clone(), + paying_accounts: final_payments.clone(), }); let _payout_tx_res = signer.send_signed_transaction(|_account| Call::payout_cdn_owners { - era: current_era, + era: current_era - 1, }); let final_res = dac::get_final_decision(validations_res); @@ -906,7 +914,7 @@ pub mod pallet { let signer = Self::get_signer().unwrap(); let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, + era: current_era - 1, cdn_node: utils::string_to_account::(edge.clone()), validation_decision: final_res.clone(), }); From 01421ea12c5c1d1cd65a0472d356b179c880d63b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 12 Jul 2023 09:56:14 +0200 Subject: [PATCH 197/544] add events for cluster management --- pallets/ddc-staking/src/lib.rs | 8 ++++++-- pallets/ddc-validator/src/lib.rs | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index fcbfb0dfa..44a1b083a 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -61,7 +61,7 @@ parameter_types! { } /// Reward points of an era. Used to split era total payout between stakers. -#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] pub struct EraRewardPoints { /// Total number of points. Equals the sum of reward points for each staker. pub total: RewardPoint, @@ -320,6 +320,8 @@ pub mod pallet { /// An account has declared desire to stop participating in CDN or storage network soon. /// \[stash, cluster, era\] ChillSoon(T::AccountId, ClusterId, EraIndex), + // Payout CDN nodes' stash accounts + PayoutNodes(EraIndex, EraRewardPoints, u128) } #[pallet::error] @@ -804,7 +806,7 @@ pub mod pallet { ); // Transfer a part of the budget to each CDN participant rewarded this era. - for (stash, points) in era_reward_points.individual { + for (stash, points) in era_reward_points.clone().individual { let part = Perbill::from_rational(points, era_reward_points.total); let reward: BalanceOf = part * payout_budget; log::debug!( @@ -826,6 +828,8 @@ pub mod pallet { total_rewards += reward; >::insert(&stash, total_rewards); } + Self::deposit_event(Event::::PayoutNodes(era, era_reward_points.clone() ,price_per_byte)); + log::debug!( "Balance left on payout source account {:?}", T::Currency::free_balance(&payout_source_account), diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index e42f52125..c20983d73 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -226,7 +226,10 @@ pub mod pallet { pub enum Event where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, {} + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { + // Validator submits decision for an era + ValidationDecision(EraIndex, T::AccountId, ValidationDecision), + } #[pallet::hooks] impl Hooks> for Pallet @@ -635,7 +638,7 @@ pub mod pallet { fn validate(bytes_sent: &dac::BytesSent, bytes_received: &dac::BytesReceived) -> bool { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); - return if percentage_difference > 0.0 && + return if percentage_difference >= 0.0 && (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 { true @@ -647,7 +650,7 @@ pub mod pallet { fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool { let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); - return if percentage_difference > 0.0 && + return if percentage_difference >= 0.0 && (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 { true @@ -919,6 +922,8 @@ pub mod pallet { validation_decision: final_res.clone(), }); + Self::deposit_event(Event::::ValidationDecision(current_era - 1, utils::string_to_account::(edge.clone()), final_res.clone())); + log::info!("final_res: {:?}", final_res); } } From 63f5e4cc938d008e4c1eefd72b06bc7592dd26b2 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 12 Jul 2023 17:25:37 +0200 Subject: [PATCH 198/544] update events for cluster management; incorporate missing logic for setting rewards --- pallets/ddc-staking/src/lib.rs | 7 +- pallets/ddc-validator/src/lib.rs | 264 +++++++------------------------ 2 files changed, 61 insertions(+), 210 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 44a1b083a..365e19a7a 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -794,7 +794,7 @@ pub mod pallet { Ok(value) => value, Err(_) => Err(Error::::BudgetOverflow)?, }; - log::debug!( + log::info!( "Will payout to DDC stakers for era {:?} from account {:?} with total budget {:?} \ , there are {:?} stakers earned {:?} reward points with price per byte {:?}", era, @@ -809,7 +809,7 @@ pub mod pallet { for (stash, points) in era_reward_points.clone().individual { let part = Perbill::from_rational(points, era_reward_points.total); let reward: BalanceOf = part * payout_budget; - log::debug!( + log::info!( "Rewarding {:?} with {:?} points, its part is {:?}, reward size {:?}, balance \ on payout source account {:?}", stash, @@ -826,9 +826,12 @@ pub mod pallet { )?; // ToDo: all success or noop let mut total_rewards: BalanceOf = Self::rewards(&stash).unwrap(); total_rewards += reward; + log::info!("Total rewards to be inserted: {:?}", total_rewards.clone()); + >::insert(&stash, total_rewards); } Self::deposit_event(Event::::PayoutNodes(era, era_reward_points.clone() ,price_per_byte)); + log::info!("Payout event executed"); log::debug!( "Balance left on payout source account {:?}", diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index c20983d73..0ac87d9f5 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -54,8 +54,10 @@ pub use pallet_staking::{self as staking}; pub use scale_info::TypeInfo; pub use serde_json::Value; pub use sp_core::crypto::{AccountId32, KeyTypeId, UncheckedFrom}; -pub use sp_io::crypto::sr25519_public_keys; -pub use sp_runtime::offchain::{http, storage::StorageValueRef, Duration, Timestamp}; +pub use sp_io::{crypto::sr25519_public_keys, offchain_index}; +pub use sp_runtime::offchain::{ + http, storage::StorageValueRef, storage_lock, storage_lock::StorageLock, Duration, Timestamp +}; pub use sp_staking::EraIndex; pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use log::info; @@ -76,9 +78,13 @@ pub const ERA_DURATION_MS: u128 = 120_000; pub const ERA_IN_BLOCKS: u8 = 20; pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and adjusted +/// Offchain local storage key that holds the last era in which the validator completed its +/// assignment. +const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; +// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; @@ -229,6 +235,8 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { // Validator submits decision for an era ValidationDecision(EraIndex, T::AccountId, ValidationDecision), + // Set era reward points + EraRewardPoints(EraIndex, Vec<(T::AccountId, u64)>), } #[pallet::hooks] @@ -264,215 +272,43 @@ pub mod pallet { return } - let current_era = Self::get_current_era(); - let last_managed_era = Self::last_managed_era().unwrap_or(0); - let data_provider_url = Self::get_data_provider_url(); - log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); + let mut should_validate_because_new_era = true; - // `If` commented for testing purposes - // if current_era > last_managed_era { - Self::validate_edges(); - //} - - // Print the number of broken sessions per CDN node. - // let aggregates_value = dac::fetch_aggregates(&data_provider_url, 77436).unwrap(); // 77436 is for a mock data - // let aggregates_obj = aggregates_value.as_object().unwrap(); - // aggregates_obj - // .into_iter() - // .for_each(|(cdn_node_pubkey, cdn_node_aggregates_value)| { - // // iterate over aggregates for each node - // let cdn_node_aggregates_obj = cdn_node_aggregates_value.as_object().unwrap(); - // // Extract `nodeInterruptedSessions` field - // let (_, cdn_node_interrupted_sessions_value) = cdn_node_aggregates_obj - // .into_iter() - // .find(|(key, _)| key.iter().copied().eq("nodeInterruptedSessions".chars())) - // .unwrap(); - // let cdn_node_interrupted_sessions_obj = - // cdn_node_interrupted_sessions_value.as_object().unwrap(); - // // Prepare CDN pubkey without heap allocated string - // let cdn_node_pubkey_vecu8: Vec = - // cdn_node_pubkey.iter().map(|c| *c as u8).collect(); - // let cdn_node_pubkey_str = - // sp_std::str::from_utf8(&cdn_node_pubkey_vecu8).unwrap(); - // log::info!( - // "Broken sessions per CDN node | Node {}: {} sessions broken", - // cdn_node_pubkey_str, - // cdn_node_interrupted_sessions_obj.len(), /* count sessions broken by the - // * node */ - // ); - // }); - - // Wait for signal. - let signal = Signal::::get().unwrap_or(false); - if !signal { - log::info!("🔎 DAC Validator is idle at block {:?}, waiting for a signal, signal state is {:?}", block_number, signal); - return + let mut validation_lock = + StorageLock::::new(LAST_VALIDATED_ERA_KEY); + + // Skip if the validation is already in progress. + if validation_lock.try_lock().is_err() { + should_validate_because_new_era = false; } + log::info!("Should validate {:?}", should_validate_because_new_era); - // Read from DAC. - let response = dac::fetch_data2(&data_provider_url, current_era - 1); - let (sent_query, sent, received_query, received) = match response { - Ok(data) => data, - Err(_) => { - log::info!("🔎 DAC Validator failed to get bytes sent and received from DAC"); - return - }, + let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_KEY); + let last_validated_era = match last_validated_era_storage.get::() { + Ok(Some(last_validated_era)) => last_validated_era, + _ => 0, // let's consider an absent or undecodable data as we never did a validation }; - log::info!( - "🔎 DAC Validator is fetching data from DAC, current era: {:?}, bytes sent query: {:?}, bytes sent response: {:?}, bytes received query: {:?}, bytes received response: {:?}", - current_era, - sent_query, - sent, - received_query, - received, - ); - - // Create intermediate validation decisions - // ======================================== - // All validators validate all CDN nodes. - let edges: Vec = >::iter_keys().collect(); - for edge in edges.iter() { - // Get string type CDN node pubkey - let edge_pubkey: String = utils::account_to_string::(edge.clone()); - - // Get bytes sent and received for the CDN node - let node_sent: &dac::BytesSent = match sent - .iter() - .find(|bytes_sent| bytes_sent.node_public_key == edge_pubkey) - { - Some(node_sent) => node_sent, - None => { - log::warn!("No logs to validate {:?}", edge); - continue - }, - }; - let client_received: &dac::BytesReceived = match received - .iter() - .find(|bytes_received| bytes_received.node_public_key == edge_pubkey) - { - Some(client_received) => client_received, - None => { - log::warn!("No acks to validate {:?}", edge); - continue - }, - }; - - // Proof-of-delivery validation - let validation_result = Self::validate(node_sent, client_received); + let current_era = Self::get_current_era(); - // Prepare an intermediate validation decision - let validation_decision = ValidationDecision { - edge: utils::account_to_string::(edge.clone()), - result: validation_result, - payload: [0u8; 32], // ToDo: put a hash of the validated data here - totals: DacTotalAggregates { - sent: node_sent.sum as u64, - received: client_received.sum as u64, - failed_by_client: 0, // ToDo - failure_rate: 0, // ToDo - }, - }; + // Skip if the validation is already complete for the era. + if current_era <= last_validated_era { + should_validate_because_new_era = false; + } - // Encode validation decision to base64 - let validation_decision_serialized: Vec = validation_decision.encode(); - let validation_decision_base64 = - shm::base64_encode(&validation_decision_serialized).unwrap(); - log::info!( - "Intermediate validation decision for CDN node {:?}: , base64 encoded: {:?}", - validation_decision, - validation_decision_base64, - ); + log::info!("Should validate {:?}", should_validate_because_new_era); - // Prepare values to publish validation decision and publish it - let validator_id_string = String::from("validator1"); // ToDo: get validator ID - let edge_id_string = utils::account_to_string::(edge.clone()); - let validation_decision_base64_string = - validation_decision_base64.iter().cloned().collect::(); - let response = shm::share_intermediate_validation_result( - &data_provider_url, - current_era - 1, - &validator_id_string, - &edge_id_string, - validation_result, - &validation_decision_base64_string, - ); - match response { - Ok(response) => - log::info!("Shared memory response: {:?}", response.to_string()), - Err(e) => { - log::error!("Shared memory error: {:?}", e); - continue - }, - } - } - log::info!( - "Intermediate validation results published for {} CDN nodes in era {:?}", - edges.len(), - current_era - 1 - ); + let data_provider_url = Self::get_data_provider_url(); + log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - // Set CDN nodes' reward points - // ============================ - - // Let's use a mock data until we have a real final validation decisions for all the CDN - // nodes. - let mock_final_validation_decisions: Vec<(T::AccountId, ValidationDecision)> = vec![ - ( - utils::string_to_account::( - "0xd4160f567d7265b9de2c7cbf1a5c931e5b3195efb2224f8706bfb53ea6eaacd1".into(), - ), - ValidationDecision { - edge: "test".into(), - result: true, - payload: [0u8; 32], - totals: DacTotalAggregates { - sent: 100, - received: 100, - failed_by_client: 0, - failure_rate: 0, - }, - }, - ), - ( - utils::string_to_account::( - "0xa2d14e71b52e5695e72c0567926bc68b68bda74df5c1ccf1d4ba612c153ff66b".into(), - ), - ValidationDecision { - edge: "test".into(), - result: true, - payload: [0u8; 32], - totals: DacTotalAggregates { - sent: 200, - received: 200, - failed_by_client: 0, - failure_rate: 0, - }, - }, - ), - ]; + // Validation start forced externally? + let should_validate_because_signal = Signal::::get().unwrap_or(false); - // Calculate CDN nodes reward points from validation decision aggregates - let cdn_nodes_reward_points: Vec<(T::AccountId, u64)> = mock_final_validation_decisions - .into_iter() - .filter(|(_, validation_decision)| validation_decision.result) // skip misbehaving - .map(|(cdn_node, validation_decision)| { - // ToDo: should we use `sent` or `received` or anything else as a reward point? - (cdn_node, validation_decision.totals.sent) - }) - .collect(); + log::info!("Should validate {:?}", should_validate_because_new_era); - // Store CDN node reward points on-chain - let signer: Signer = Signer::<_, _>::any_account(); - if !signer.can_sign() { - log::warn!("No local accounts available to set era reward points. Consider adding one via `author_insertKey` RPC."); - return + if should_validate_because_new_era || should_validate_because_signal { + Self::validate_edges(); } - // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { - era: current_era - 1, - stakers_points: cdn_nodes_reward_points.clone(), - }); } } @@ -507,9 +343,9 @@ pub mod pallet { // ToDo: check if the validation decision is not set yet. // ToDo: check cdn_node is known to ddc-staking. - ValidationDecisions::::insert(era, cdn_node, validation_decision); + ValidationDecisions::::insert(era, cdn_node.clone(), validation_decision.clone()); - // ToDo: emit event. + Self::deposit_event(Event::::ValidationDecision(era, cdn_node, validation_decision)); Ok(()) } @@ -533,12 +369,14 @@ pub mod pallet { ensure_signed(origin)?; >::mutate(era, |era_rewards| { - for (staker, points) in stakers_points.into_iter() { + for (staker, points) in stakers_points.clone().into_iter() { *era_rewards.individual.entry(staker).or_default() += points; era_rewards.total += points; } }); + Self::deposit_event(Event::::EraRewardPoints(era, stakers_points)); + Ok(()) } @@ -798,11 +636,15 @@ pub mod pallet { info!("assigned_edges: {:?}", assigned_edges); + // Calculate CDN nodes reward points from validation decision aggregates + let mut cdn_nodes_reward_points: Vec<(T::AccountId, u64)> = vec![]; + for assigned_edge in assigned_edges.iter() { info!("assigned edge: {:?}", assigned_edge); // form url for each node let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", current_era, "/$.", utils::account_to_string::(assigned_edge.clone())); + // let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", 132855, "/$.", utils::account_to_string::(assigned_edge.clone())); info!("edge url: {:?}", edge_url); let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); @@ -908,10 +750,6 @@ pub mod pallet { paying_accounts: final_payments.clone(), }); - let _payout_tx_res = signer.send_signed_transaction(|_account| Call::payout_cdn_owners { - era: current_era - 1, - }); - let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); @@ -922,12 +760,22 @@ pub mod pallet { validation_decision: final_res.clone(), }); - Self::deposit_event(Event::::ValidationDecision(current_era - 1, utils::string_to_account::(edge.clone()), final_res.clone())); - log::info!("final_res: {:?}", final_res); + + cdn_nodes_reward_points.push((utils::string_to_account::(final_res.edge), final_res.totals.sent)); } } } + let signer = Self::get_signer().unwrap(); + + // ToDo: replace local call by a call from `ddc-staking` pallet + let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { + era: current_era - 1, + stakers_points: cdn_nodes_reward_points.clone(), + }); + + // Set era as validated + offchain_index::set(LAST_VALIDATED_ERA_KEY, &(current_era - 1).encode()); } } } From 655061d81747f9b52c02c6d51304d58a81ebd743 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 13 Jul 2023 13:27:55 +0200 Subject: [PATCH 199/544] fix storage mutation for aggregate node rewards --- pallets/ddc-staking/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 365e19a7a..31ea79181 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -278,7 +278,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn rewards)] pub type Rewards = - StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf>; + StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf, ValueQuery>; /// The current era index. /// @@ -824,11 +824,10 @@ pub mod pallet { reward, ExistenceRequirement::AllowDeath, )?; // ToDo: all success or noop - let mut total_rewards: BalanceOf = Self::rewards(&stash).unwrap(); - total_rewards += reward; - log::info!("Total rewards to be inserted: {:?}", total_rewards.clone()); - - >::insert(&stash, total_rewards); + Rewards::::mutate(&stash, |current_balance| { + *current_balance += reward; + }); + log::info!("Total rewards to be inserted: {:?}", Self::rewards(&stash)); } Self::deposit_event(Event::::PayoutNodes(era, era_reward_points.clone() ,price_per_byte)); log::info!("Payout event executed"); From 19e2b8424e8f85ab540dd88e51a59743ea8ab294 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 13 Jul 2023 13:28:29 +0200 Subject: [PATCH 200/544] fix last era validation lock to avoid repeptitive validation --- pallets/ddc-validator/src/lib.rs | 73 +++++++++++++++++--------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 0ac87d9f5..2f3765bae 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -80,7 +80,8 @@ pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and a /// Offchain local storage key that holds the last era in which the validator completed its /// assignment. -const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; +const LAST_VALIDATED_ERA_LOCK_KEY: &[u8; 45] = b"pallet-ddc-validator::last-validated-era-lock"; +const LAST_VALIDATED_ERA_STORAGE_KEY: &[u8; 48] = b"pallet-ddc-validator::last-validated-era-storage"; /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; @@ -275,40 +276,47 @@ pub mod pallet { let mut should_validate_because_new_era = true; let mut validation_lock = - StorageLock::::new(LAST_VALIDATED_ERA_KEY); + StorageLock::::new(LAST_VALIDATED_ERA_LOCK_KEY); // Skip if the validation is already in progress. - if validation_lock.try_lock().is_err() { - should_validate_because_new_era = false; - } - log::info!("Should validate {:?}", should_validate_because_new_era); - - let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_KEY); - let last_validated_era = match last_validated_era_storage.get::() { - Ok(Some(last_validated_era)) => last_validated_era, - _ => 0, // let's consider an absent or undecodable data as we never did a validation - }; - - let current_era = Self::get_current_era(); - - // Skip if the validation is already complete for the era. - if current_era <= last_validated_era { - should_validate_because_new_era = false; - } - - log::info!("Should validate {:?}", should_validate_because_new_era); - - let data_provider_url = Self::get_data_provider_url(); - log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); + if let Ok(_guard) = validation_lock.try_lock() { - // Validation start forced externally? - let should_validate_because_signal = Signal::::get().unwrap_or(false); + log::info!("Should validate {:?}", should_validate_because_new_era); - log::info!("Should validate {:?}", should_validate_because_new_era); - - if should_validate_because_new_era || should_validate_because_signal { - Self::validate_edges(); - } + let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_STORAGE_KEY); + let last_validated_era = match last_validated_era_storage.get::() { + Ok(Some(last_validated_era)) => last_validated_era, + _ => 0, // let's consider an absent or undecodable data as we never did a validation + }; + + if let Ok(Some(res)) = last_validated_era_storage.get::() { + log::info!("cached result for last validated era: {:?}", res); + return (); + } + + let current_era = Self::get_current_era(); + + // Skip if the validation is already complete for the era. + if current_era <= last_validated_era { + should_validate_because_new_era = false; + } + + log::info!("Should validate {:?}", should_validate_because_new_era); + + let data_provider_url = Self::get_data_provider_url(); + log::info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); + + // Validation start forced externally? + let should_validate_because_signal = Signal::::get().unwrap_or(false); + + log::info!("Should validate {:?}", should_validate_because_new_era); + + if should_validate_because_new_era || should_validate_because_signal { + Self::validate_edges(); + } + + last_validated_era_storage.set(&(current_era - 1)); + }; } } @@ -773,9 +781,6 @@ pub mod pallet { era: current_era - 1, stakers_points: cdn_nodes_reward_points.clone(), }); - - // Set era as validated - offchain_index::set(LAST_VALIDATED_ERA_KEY, &(current_era - 1).encode()); } } } From bfc28ee4b2a380f1702c71399d1ce69c1c3be3b1 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 13 Jul 2023 15:05:24 +0200 Subject: [PATCH 201/544] fix typos --- pallets/ddc-validator/src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 2f3765bae..ba2895f46 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -84,8 +84,8 @@ const LAST_VALIDATED_ERA_LOCK_KEY: &[u8; 45] = b"pallet-ddc-validator::last-vali const LAST_VALIDATED_ERA_STORAGE_KEY: &[u8; 48] = b"pallet-ddc-validator::last-validated-era-storage"; /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; -// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; +// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; @@ -291,13 +291,12 @@ pub mod pallet { if let Ok(Some(res)) = last_validated_era_storage.get::() { log::info!("cached result for last validated era: {:?}", res); - return (); } let current_era = Self::get_current_era(); // Skip if the validation is already complete for the era. - if current_era <= last_validated_era { + if current_era - 1 <= last_validated_era { should_validate_because_new_era = false; } @@ -630,7 +629,7 @@ pub mod pallet { } fn validate_edges() { - let current_era = Self::get_current_era() - 1; + let current_era = Self::get_current_era(); let mock_data_url = Self::get_mock_data_url(); let data_provider_url = Self::get_data_provider_url(); @@ -651,8 +650,8 @@ pub mod pallet { info!("assigned edge: {:?}", assigned_edge); // form url for each node - let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", current_era, "/$.", utils::account_to_string::(assigned_edge.clone())); - // let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", 132855, "/$.", utils::account_to_string::(assigned_edge.clone())); + // let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", current_era, "/$.", utils::account_to_string::(assigned_edge.clone())); + let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", 132855, "/$.", utils::account_to_string::(assigned_edge.clone())); info!("edge url: {:?}", edge_url); let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); From 3507f29219cb2b0d3b474a6aa013261e4435d9c6 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 13 Jul 2023 16:30:31 +0200 Subject: [PATCH 202/544] fix urls --- pallets/ddc-validator/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index ba2895f46..8d55c983e 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -84,8 +84,8 @@ const LAST_VALIDATED_ERA_LOCK_KEY: &[u8; 45] = b"pallet-ddc-validator::last-vali const LAST_VALIDATED_ERA_STORAGE_KEY: &[u8; 48] = b"pallet-ddc-validator::last-validated-era-storage"; /// Webdis in experimental cluster connected to Redis in dev. // pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; -// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; +pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; +// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; @@ -650,8 +650,8 @@ pub mod pallet { info!("assigned edge: {:?}", assigned_edge); // form url for each node - // let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", current_era, "/$.", utils::account_to_string::(assigned_edge.clone())); - let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", 132855, "/$.", utils::account_to_string::(assigned_edge.clone())); + let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", current_era, "/$.", utils::account_to_string::(assigned_edge.clone())); + // let edge_url = format!("{}{}{}{}{}", mock_data_url, "ddc:dac:aggregation:nodes:", 132855, "/$.", utils::account_to_string::(assigned_edge.clone())); info!("edge url: {:?}", edge_url); let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); From 5d46d8a3f8c186966bf6fb4d23e1fc23a29eaed0 Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Fri, 14 Jul 2023 10:59:15 +0200 Subject: [PATCH 203/544] Simple ECR deployment --- .github/workflows/dev.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/dev.yml diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 000000000..440d32269 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,19 @@ +name: Release to dev +on: + push: + branches: + - dev + workflow_dispatch: + +permissions: + id-token: write + contents: read + +jobs: + build: + uses: Cerebellum-Network/reusable-workflows/.github/workflows/deploy-to-ecr.yaml@master + with: + environment: dev + aws_account_id: ${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }} + repository: pos-network-node + secrets: inherit From 8e133aad907d1cbf0a313f8b47591acd6f51c8b4 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 17 Jul 2023 16:04:26 +0600 Subject: [PATCH 204/544] Update dependencies --- Cargo.lock | 10423 +++++++++++++++++++++++++++++ pallets/ddc-accounts/Cargo.toml | 14 +- pallets/ddc-validator/Cargo.toml | 32 +- 3 files changed, 10446 insertions(+), 23 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 000000000..69bf795f9 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,10423 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli 0.26.2", +] + +[[package]] +name = "addr2line" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +dependencies = [ + "gimli 0.27.3", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aead" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "aes" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +dependencies = [ + "cfg-if", + "cipher 0.3.0", + "cpufeatures", + "opaque-debug 0.3.0", +] + +[[package]] +name = "aes-gcm" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" +dependencies = [ + "aead", + "aes", + "cipher 0.3.0", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.10", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + +[[package]] +name = "alt_serde" +version = "1.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbdd08f26bc9972e3597a32bb7fe2b0de4e85ccfb4214acec94165b940aa537e" +dependencies = [ + "alt_serde_derive", +] + +[[package]] +name = "alt_serde_derive" +version = "1.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "629ddaf5b2675d9a27e9521a88870f8edea113e4a83d6d5178268b0d70e9a9a3" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "anyhow" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "array-bytes" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52f63c5c1316a16a4b35eaac8b76a98248961a533f061684cb2a7cb0eafb6c6" + +[[package]] +name = "array-bytes" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b1c5a481ec30a5abd8dfbd94ab5cf1bb4e9a66be7f1b3b322f2f1170c200fd" + +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +dependencies = [ + "nodrop", +] + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "asn1_der" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "155a5a185e42c6b77ac7b88a15143d930a9e9727a5b7b77eed417404ab15c247" + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +dependencies = [ + "async-lock", + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite", + "log", + "parking", + "polling", + "rustix 0.37.23", + "slab", + "socket2 0.4.9", + "waker-fn", +] + +[[package]] +name = "async-lock" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-process" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "rustix 0.37.23", + "signal-hook", + "windows-sys 0.48.0", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite 0.2.10", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-std-resolver" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2f8a4a203be3325981310ab243a28e6e4ea55b6519bffce05d41ab60e09ad8" +dependencies = [ + "async-std", + "async-trait", + "futures-io", + "futures-util", + "pin-utils", + "socket2 0.4.9", + "trust-dns-resolver", +] + +[[package]] +name = "async-task" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" + +[[package]] +name = "async-trait" +version = "0.1.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "asynchronous-codec" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06a0daa378f5fd10634e44b0a29b2a87b890657658e072a30d6f26e57ddee182" +dependencies = [ + "bytes", + "futures-sink", + "futures-util", + "memchr", + "pin-project-lite 0.2.10", +] + +[[package]] +name = "atomic-waker" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line 0.20.0", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object 0.31.1", + "rustc-demangle", +] + +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base58" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +dependencies = [ + "serde", +] + +[[package]] +name = "bimap" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "prettyplease 0.2.10", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.26", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "blake2-rfc" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" +dependencies = [ + "arrayvec 0.4.12", + "constant_time_eq 0.1.5", +] + +[[package]] +name = "blake2b_simd" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" +dependencies = [ + "arrayref", + "arrayvec 0.7.4", + "constant_time_eq 0.2.6", +] + +[[package]] +name = "blake2s_simd" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" +dependencies = [ + "arrayref", + "arrayvec 0.7.4", + "constant_time_eq 0.2.6", +] + +[[package]] +name = "blake3" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" +dependencies = [ + "arrayref", + "arrayvec 0.7.4", + "cc", + "cfg-if", + "constant_time_eq 0.3.0", +] + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array 0.12.4", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "blocking" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "log", +] + +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + +[[package]] +name = "bstr" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "build-helper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdce191bf3fa4995ce948c8c83b4640a1745457a149e73c6db75b4ffe36aad5f" +dependencies = [ + "semver 0.6.0", +] + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "camino" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.18", + "serde", + "serde_json 1.0.103", +] + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cere" +version = "4.8.0" +dependencies = [ + "cere-cli", + "sc-cli", + "ss58-registry", + "substrate-build-script-utils", +] + +[[package]] +name = "cere-cli" +version = "4.8.0" +dependencies = [ + "cere-client", + "cere-service", + "clap", + "frame-benchmarking-cli", + "sc-cli", + "sc-service", + "substrate-build-script-utils", + "try-runtime-cli", +] + +[[package]] +name = "cere-client" +version = "4.8.0" +dependencies = [ + "cere-dev-runtime", + "cere-runtime", + "frame-benchmarking", + "frame-benchmarking-cli", + "frame-system", + "frame-system-rpc-runtime-api", + "node-primitives", + "pallet-contracts-rpc", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "sc-client-api", + "sc-executor", + "sc-service", + "sp-api", + "sp-authority-discovery", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-core", + "sp-finality-grandpa", + "sp-inherents", + "sp-keyring", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-storage", + "sp-timestamp", + "sp-transaction-pool", +] + +[[package]] +name = "cere-dev-runtime" +version = "4.8.0" +dependencies = [ + "cere-dev-runtime-constants", + "cere-runtime-common", + "frame-benchmarking", + "frame-election-provider-support", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal", + "log", + "node-primitives", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-bags-list", + "pallet-balances", + "pallet-bounties", + "pallet-cere-ddc", + "pallet-chainbridge", + "pallet-child-bounties", + "pallet-collective", + "pallet-contracts", + "pallet-contracts-primitives", + "pallet-contracts-rpc-runtime-api", + "pallet-ddc-accounts", + "pallet-ddc-metrics-offchain-worker", + "pallet-ddc-staking", + "pallet-ddc-validator", + "pallet-democracy", + "pallet-election-provider-multi-phase", + "pallet-election-provider-support-benchmarking", + "pallet-elections-phragmen", + "pallet-erc20", + "pallet-erc721", + "pallet-fast-unstake", + "pallet-grandpa", + "pallet-identity", + "pallet-im-online", + "pallet-indices", + "pallet-membership", + "pallet-multisig", + "pallet-nomination-pools", + "pallet-nomination-pools-benchmarking", + "pallet-nomination-pools-runtime-api", + "pallet-offences", + "pallet-offences-benchmarking", + "pallet-proxy", + "pallet-randomness-collective-flip", + "pallet-recovery", + "pallet-scheduler", + "pallet-session", + "pallet-session-benchmarking", + "pallet-society", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-sudo", + "pallet-timestamp", + "pallet-tips", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-transaction-storage", + "pallet-treasury", + "pallet-utility", + "pallet-vesting", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-authority-discovery", + "sp-block-builder", + "sp-consensus-babe", + "sp-core", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "sp-transaction-pool", + "sp-version", + "static_assertions", + "substrate-wasm-builder", +] + +[[package]] +name = "cere-dev-runtime-constants" +version = "4.8.0" +dependencies = [ + "node-primitives", + "sp-runtime", +] + +[[package]] +name = "cere-rpc" +version = "4.8.0" +dependencies = [ + "jsonrpsee", + "node-primitives", + "pallet-contracts-rpc", + "pallet-transaction-payment-rpc", + "sc-chain-spec", + "sc-client-api", + "sc-consensus-babe", + "sc-consensus-babe-rpc", + "sc-consensus-epochs", + "sc-finality-grandpa", + "sc-finality-grandpa-rpc", + "sc-rpc", + "sc-rpc-api", + "sc-sync-state-rpc", + "sc-transaction-pool-api", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-keystore", + "sp-runtime", + "substrate-frame-rpc-system", + "substrate-state-trie-migration-rpc", +] + +[[package]] +name = "cere-runtime" +version = "4.8.0" +dependencies = [ + "cere-runtime-common", + "cere-runtime-constants", + "frame-benchmarking", + "frame-election-provider-support", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal", + "log", + "node-primitives", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-bags-list", + "pallet-balances", + "pallet-bounties", + "pallet-cere-ddc", + "pallet-chainbridge", + "pallet-child-bounties", + "pallet-collective", + "pallet-contracts", + "pallet-contracts-primitives", + "pallet-contracts-rpc-runtime-api", + "pallet-ddc-metrics-offchain-worker", + "pallet-democracy", + "pallet-election-provider-multi-phase", + "pallet-election-provider-support-benchmarking", + "pallet-elections-phragmen", + "pallet-erc20", + "pallet-erc721", + "pallet-fast-unstake", + "pallet-grandpa", + "pallet-identity", + "pallet-im-online", + "pallet-indices", + "pallet-membership", + "pallet-multisig", + "pallet-nomination-pools", + "pallet-nomination-pools-benchmarking", + "pallet-nomination-pools-runtime-api", + "pallet-offences", + "pallet-offences-benchmarking", + "pallet-proxy", + "pallet-randomness-collective-flip", + "pallet-recovery", + "pallet-scheduler", + "pallet-session", + "pallet-session-benchmarking", + "pallet-society", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-sudo", + "pallet-timestamp", + "pallet-tips", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-transaction-storage", + "pallet-treasury", + "pallet-utility", + "pallet-vesting", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-authority-discovery", + "sp-block-builder", + "sp-consensus-babe", + "sp-core", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "sp-transaction-pool", + "sp-version", + "static_assertions", + "substrate-wasm-builder", +] + +[[package]] +name = "cere-runtime-common" +version = "4.8.0" +dependencies = [ + "frame-support", + "node-primitives", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "cere-runtime-constants" +version = "4.8.0" +dependencies = [ + "node-primitives", + "sp-runtime", +] + +[[package]] +name = "cere-service" +version = "4.8.0" +dependencies = [ + "cere-client", + "cere-dev-runtime", + "cere-dev-runtime-constants", + "cere-rpc", + "cere-runtime", + "cere-runtime-constants", + "futures", + "jsonrpsee", + "node-primitives", + "pallet-im-online", + "parity-scale-codec", + "rand 0.8.5", + "sc-authority-discovery", + "sc-basic-authorship", + "sc-chain-spec", + "sc-cli", + "sc-client-api", + "sc-consensus", + "sc-consensus-babe", + "sc-consensus-slots", + "sc-consensus-uncles", + "sc-executor", + "sc-finality-grandpa", + "sc-network", + "sc-network-common", + "sc-rpc", + "sc-service", + "sc-sync-state-rpc", + "sc-sysinfo", + "sc-telemetry", + "sc-transaction-pool", + "serde", + "sp-api", + "sp-authority-discovery", + "sp-authorship", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-core", + "sp-finality-grandpa", + "sp-runtime", + "sp-timestamp", + "sp-transaction-storage-proof", + "sp-trie", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-expr" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aacacf4d96c24b2ad6eb8ee6df040e4f27b0d0b39a5710c30091baa830485db" +dependencies = [ + "smallvec", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] +name = "chacha20" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6" +dependencies = [ + "cfg-if", + "cipher 0.3.0", + "cpufeatures", + "zeroize", +] + +[[package]] +name = "chacha20poly1305" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5" +dependencies = [ + "aead", + "chacha20", + "cipher 0.3.0", + "poly1305", + "zeroize", +] + +[[package]] +name = "chrono" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "cid" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ed9c8b2d17acb8110c46f1da5bf4a696d745e1474a16db0cd2b49cd0249bf2" +dependencies = [ + "core2", + "multibase", + "multihash", + "serde", + "unsigned-varint", +] + +[[package]] +name = "cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clang-sys" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +dependencies = [ + "glob", + "libc", + "libloading 0.7.4", +] + +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "cmake" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +dependencies = [ + "cc", +] + +[[package]] +name = "comfy-table" +version = "6.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e959d788268e3bf9d35ace83e81b124190378e4c91c9067524675e33394b8ba" +dependencies = [ + "strum", + "strum_macros", + "unicode-width", +] + +[[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "constant_time_eq" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" + +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + +[[package]] +name = "cpp_demangle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + +[[package]] +name = "cranelift-bforest" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52056f6d0584484b57fa6c1a65c1fcb15f3780d8b6a758426d9e3084169b2ddd" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fed94c8770dc25d01154c3ffa64ed0b3ba9d583736f305fed7beebe5d9cf74" +dependencies = [ + "arrayvec 0.7.4", + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity", + "cranelift-isle", + "gimli 0.26.2", + "log", + "regalloc2", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c451b81faf237d11c7e4f3165eeb6bac61112762c5cfe7b4c0fb7241474358f" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c940133198426d26128f08be2b40b0bd117b84771fd36798969c4d712d81fc" + +[[package]] +name = "cranelift-entity" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87a0f1b2fdc18776956370cf8d9b009ded3f855350c480c1c52142510961f352" +dependencies = [ + "serde", +] + +[[package]] +name = "cranelift-frontend" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34897538b36b216cc8dd324e73263596d51b8cf610da6498322838b2546baf8a" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b2629a569fae540f16a76b70afcc87ad7decb38dc28fa6c648ac73b51e78470" + +[[package]] +name = "cranelift-native" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20937dab4e14d3e225c5adfc9c7106bafd4ac669bdb43027b911ff794c6fb318" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.88.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80fc2288957a94fd342a015811479de1837850924166d1f1856d8406e6f3609b" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset 0.9.0", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" +dependencies = [ + "generic-array 0.14.7", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array 0.14.7", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array 0.14.7", + "subtle", +] + +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array 0.14.7", + "subtle", +] + +[[package]] +name = "ctor" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ctr" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" +dependencies = [ + "cipher 0.3.0", +] + +[[package]] +name = "cuckoofilter" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b810a8449931679f64cd7eef1bbd0fa315801b6d5d9cdc1ace2804d6529eee18" +dependencies = [ + "byteorder", + "fnv", + "rand 0.7.3", +] + +[[package]] +name = "curve25519-dalek" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b85542f99a2dfa2a1b8e192662741c9859a846b296bef1c92ef9b58b5a216" +dependencies = [ + "byteorder", + "digest 0.8.1", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek" +version = "4.0.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" +dependencies = [ + "cfg-if", + "fiat-crypto", + "packed_simd_2", + "platforms 3.0.2", + "subtle", + "zeroize", +] + +[[package]] +name = "data-encoding" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" + +[[package]] +name = "data-encoding-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c904b33cc60130e1aeea4956ab803d08a3f4a0ca82d64ed757afac3891f2bb99" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fdf3fce3ce863539ec1d7fd1b6dcc3c645663376b43ed376bbf887733e4f772" +dependencies = [ + "data-encoding", + "syn 1.0.109", +] + +[[package]] +name = "der" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" +dependencies = [ + "const-oid", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.4", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", + "subtle", +] + +[[package]] +name = "directories" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dns-parser" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" +dependencies = [ + "byteorder", + "quick-error", +] + +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dyn-clonable" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4" +dependencies = [ + "dyn-clonable-impl", + "dyn-clone", +] + +[[package]] +name = "dyn-clonable-impl" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "dyn-clone" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" + +[[package]] +name = "ecdsa" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d69ae62e0ce582d56380743515fefaf1a8c70cec685d9677636d7e30ae9dc9" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek 3.2.0", + "ed25519", + "rand 0.7.3", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek 3.2.0", + "hashbrown", + "hex", + "rand_core 0.6.4", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "elliptic-curve" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25b477563c2bfed38a3b7a60964c49e058b2510ad3f12ba3483fd8f62c2306d6" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "ff", + "generic-array 0.14.7", + "group", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "enum-as-inner" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "enumflags2" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c041f5090df68b32bcd905365fd51769c8b9d553fe87fde0b683534f10c01bd2" +dependencies = [ + "enumflags2_derive", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "environmental" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48c92028aaa870e83d51c64e5d4e0b6981b360c522198c23959f219a4e1b15b" + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "exit-future" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e43f2f1833d64e33f15592464d6fdd70f349dda7b1a53088eb83cd94014008c5" +dependencies = [ + "futures", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fdlimit" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4c9e43643f5a3be4ca5b67d26b98031ff9db6806c3440ae32e02e3ceac3f1b" +dependencies = [ + "libc", +] + +[[package]] +name = "ff" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" + +[[package]] +name = "file-per-thread-logger" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" +dependencies = [ + "env_logger 0.10.0", + "log", +] + +[[package]] +name = "filetime" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.2.16", + "windows-sys 0.48.0", +] + +[[package]] +name = "finality-grandpa" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36530797b9bf31cd4ff126dcfee8170f86b00cfdcea3269d73133cc0415945c3" +dependencies = [ + "either", + "futures", + "futures-timer", + "log", + "num-traits", + "parity-scale-codec", + "parking_lot 0.12.1", + "scale-info", +] + +[[package]] +name = "fixed-hash" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +dependencies = [ + "byteorder", + "rand 0.8.5", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "flate2" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +dependencies = [ + "crc32fast", + "libz-sys", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fork-tree" +version = "3.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "frame-benchmarking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "linregress", + "log", + "parity-scale-codec", + "paste", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface", + "sp-std", + "sp-storage", +] + +[[package]] +name = "frame-benchmarking-cli" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "Inflector", + "array-bytes 4.2.0", + "chrono", + "clap", + "comfy-table", + "frame-benchmarking", + "frame-support", + "frame-system", + "gethostname", + "handlebars", + "hash-db", + "itertools", + "kvdb", + "lazy_static", + "linked-hash-map", + "log", + "memory-db", + "parity-scale-codec", + "rand 0.8.5", + "rand_pcg 0.3.1", + "sc-block-builder", + "sc-cli", + "sc-client-api", + "sc-client-db", + "sc-executor", + "sc-service", + "sc-sysinfo", + "serde", + "serde_json 1.0.103", + "serde_nanos", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-database", + "sp-externalities", + "sp-inherents", + "sp-keystore", + "sp-runtime", + "sp-state-machine", + "sp-storage", + "sp-trie", + "tempfile", + "thiserror", + "thousands", +] + +[[package]] +name = "frame-election-provider-solution-type" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "frame-election-provider-support" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-election-provider-solution-type", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-npos-elections", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "frame-executive" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "frame-try-runtime", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-tracing", +] + +[[package]] +name = "frame-metadata" +version = "15.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "878babb0b136e731cc77ec2fd883ff02745ff21e6fb662729953d44923df009c" +dependencies = [ + "cfg-if", + "parity-scale-codec", + "scale-info", + "serde", +] + +[[package]] +name = "frame-support" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "bitflags 1.3.2", + "frame-metadata", + "frame-support-procedural", + "impl-trait-for-tuples", + "k256", + "log", + "once_cell", + "parity-scale-codec", + "paste", + "scale-info", + "serde", + "smallvec", + "sp-api", + "sp-arithmetic", + "sp-core", + "sp-core-hashing-proc-macro", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-state-machine", + "sp-std", + "sp-tracing", + "sp-weights", + "tt-call", +] + +[[package]] +name = "frame-support-procedural" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "Inflector", + "cfg-expr", + "frame-support-procedural-tools", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "frame-support-procedural-tools" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support-procedural-tools-derive", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "frame-support-procedural-tools-derive" +version = "3.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "frame-system" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-version", + "sp-weights", +] + +[[package]] +name = "frame-system-benchmarking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "frame-system-rpc-runtime-api" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "sp-api", +] + +[[package]] +name = "frame-try-runtime" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "fs-swap" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03d47dad3685eceed8488986cad3d5027165ea5edb164331770e2059555f10a5" +dependencies = [ + "lazy_static", + "libc", + "libloading 0.5.2", + "winapi", +] + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", + "num_cpus", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite 0.2.10", + "waker-fn", +] + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "futures-rustls" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" +dependencies = [ + "futures-io", + "rustls", + "webpki", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite 0.2.10", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "ghash" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" +dependencies = [ + "opaque-debug 0.3.0", + "polyval", +] + +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "globset" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1391ab1f92ffcc08911957149833e682aa3fe252b9f45f966d2ef972274c97df" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "group" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "h2" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "handlebars" +version = "4.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c3372087601b532857d332f5957cbae686da52bb7810bf038c3e3c3cc2fa0d" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json 1.0.103", + "thiserror", +] + +[[package]] +name = "hash-db" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d23bd4e7b5eda0d0f3a307e8b381fdc8ba9000f26fbe912250c0a4cc3956364a" + +[[package]] +name = "hash256-std-hasher" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92c171d55b98633f4ed3860808f004099b36c1cc29c42cfc53aa8591b21efcf2" +dependencies = [ + "crunchy", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" + +[[package]] +name = "hex_fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac 0.8.0", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac 0.11.1", + "digest 0.9.0", +] + +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array 0.14.7", + "hmac 0.8.1", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa 1.0.9", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite 0.2.10", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa 1.0.9", + "pin-project-lite 0.2.10", + "socket2 0.4.9", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +dependencies = [ + "http", + "hyper", + "log", + "rustls", + "rustls-native-certs", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows 0.48.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "if-addrs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc0fa01ffc752e9dbc72818cdb072cd028b86be5e09dd04c5a643704fe101a9" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "if-watch" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "015a7df1eb6dda30df37f34b63ada9b7b352984b0e84de2a20ed526345000791" +dependencies = [ + "async-io", + "core-foundation", + "fnv", + "futures", + "if-addrs", + "ipnet", + "log", + "rtnetlink", + "system-configuration", + "windows 0.34.0", +] + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-serde" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", + "serde", +] + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array 0.14.7", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "integer-sqrt" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "276ec31bcb4a9ee45f58bec6f9ec700ae4cf4f4f8f2fa7e06cb406bd5ffdd770" +dependencies = [ + "num-traits", +] + +[[package]] +name = "io-lifetimes" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.2", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "ip_network" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2f047c0a98b2f299aa5d6d7088443570faae494e9ae1305e48be000c9e0eb1" + +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.3", + "widestring", + "windows-sys 0.48.0", + "winreg", +] + +[[package]] +name = "ipnet" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi 0.3.2", + "rustix 0.38.4", + "windows-sys 0.48.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "jsonrpsee" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bd0d559d5e679b1ab2f869b486a11182923863b1b3ee8b421763cdd707b783a" +dependencies = [ + "jsonrpsee-core", + "jsonrpsee-http-server", + "jsonrpsee-proc-macros", + "jsonrpsee-types", + "jsonrpsee-ws-client", + "jsonrpsee-ws-server", + "tracing", +] + +[[package]] +name = "jsonrpsee-client-transport" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8752740ecd374bcbf8b69f3e80b0327942df76f793f8d4e60d3355650c31fb74" +dependencies = [ + "futures-util", + "http", + "jsonrpsee-core", + "jsonrpsee-types", + "pin-project", + "rustls-native-certs", + "soketto", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-util", + "tracing", + "webpki-roots", +] + +[[package]] +name = "jsonrpsee-core" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3dc3e9cf2ba50b7b1d7d76a667619f82846caa39e8e8daa8a4962d74acaddca" +dependencies = [ + "anyhow", + "arrayvec 0.7.4", + "async-lock", + "async-trait", + "beef", + "futures-channel", + "futures-timer", + "futures-util", + "globset", + "http", + "hyper", + "jsonrpsee-types", + "lazy_static", + "parking_lot 0.12.1", + "rand 0.8.5", + "rustc-hash", + "serde", + "serde_json 1.0.103", + "soketto", + "thiserror", + "tokio", + "tracing", + "tracing-futures", + "unicase", +] + +[[package]] +name = "jsonrpsee-http-server" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03802f0373a38c2420c70b5144742d800b509e2937edc4afb116434f07120117" +dependencies = [ + "futures-channel", + "futures-util", + "hyper", + "jsonrpsee-core", + "jsonrpsee-types", + "serde", + "serde_json 1.0.103", + "tokio", + "tracing", + "tracing-futures", +] + +[[package]] +name = "jsonrpsee-proc-macros" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd67957d4280217247588ac86614ead007b301ca2fa9f19c19f880a536f029e3" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "jsonrpsee-types" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e290bba767401b646812f608c099b922d8142603c9e73a50fb192d3ac86f4a0d" +dependencies = [ + "anyhow", + "beef", + "serde", + "serde_json 1.0.103", + "thiserror", + "tracing", +] + +[[package]] +name = "jsonrpsee-ws-client" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ee5feddd5188e62ac08fcf0e56478138e581509d4730f3f7be9b57dd402a4ff" +dependencies = [ + "http", + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-types", +] + +[[package]] +name = "jsonrpsee-ws-server" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d488ba74fb369e5ab68926feb75a483458b88e768d44319f37e4ecad283c7325" +dependencies = [ + "futures-channel", + "futures-util", + "http", + "jsonrpsee-core", + "jsonrpsee-types", + "serde_json 1.0.103", + "soketto", + "tokio", + "tokio-stream", + "tokio-util", + "tracing", + "tracing-futures", +] + +[[package]] +name = "k256" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sec1", +] + +[[package]] +name = "keccak" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "kvdb" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a301d8ecb7989d4a6e2c57a49baca77d353bdbf879909debe3f375fe25d61f86" +dependencies = [ + "parity-util-mem", + "smallvec", +] + +[[package]] +name = "kvdb-memorydb" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece7e668abd21387aeb6628130a6f4c802787f014fa46bc83221448322250357" +dependencies = [ + "kvdb", + "parity-util-mem", + "parking_lot 0.12.1", +] + +[[package]] +name = "kvdb-rocksdb" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca7fbdfd71cd663dceb0faf3367a99f8cf724514933e9867cec4995b6027cbc1" +dependencies = [ + "fs-swap", + "kvdb", + "log", + "num_cpus", + "owning_ref", + "parity-util-mem", + "parking_lot 0.12.1", + "regex", + "rocksdb", + "smallvec", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "libloading" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +dependencies = [ + "cc", + "winapi", +] + +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "libm" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" + +[[package]] +name = "libm" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" + +[[package]] +name = "libp2p" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81327106887e42d004fbdab1fef93675be2e2e07c1b95fce45e2cc813485611d" +dependencies = [ + "bytes", + "futures", + "futures-timer", + "getrandom 0.2.10", + "instant", + "lazy_static", + "libp2p-autonat", + "libp2p-core", + "libp2p-deflate", + "libp2p-dns", + "libp2p-floodsub", + "libp2p-gossipsub", + "libp2p-identify", + "libp2p-kad", + "libp2p-mdns", + "libp2p-metrics", + "libp2p-mplex", + "libp2p-noise", + "libp2p-ping", + "libp2p-plaintext", + "libp2p-pnet", + "libp2p-relay", + "libp2p-rendezvous", + "libp2p-request-response", + "libp2p-swarm", + "libp2p-swarm-derive", + "libp2p-tcp", + "libp2p-uds", + "libp2p-wasm-ext", + "libp2p-websocket", + "libp2p-yamux", + "multiaddr", + "parking_lot 0.12.1", + "pin-project", + "rand 0.7.3", + "smallvec", +] + +[[package]] +name = "libp2p-autonat" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4decc51f3573653a9f4ecacb31b1b922dd20c25a6322bb15318ec04287ec46f9" +dependencies = [ + "async-trait", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-request-response", + "libp2p-swarm", + "log", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.8.5", +] + +[[package]] +name = "libp2p-core" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf9b94cefab7599b2d3dff2f93bee218c6621d68590b23ede4485813cbcece6" +dependencies = [ + "asn1_der", + "bs58", + "ed25519-dalek", + "either", + "fnv", + "futures", + "futures-timer", + "instant", + "lazy_static", + "libsecp256k1", + "log", + "multiaddr", + "multihash", + "multistream-select", + "parking_lot 0.12.1", + "pin-project", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.8.5", + "ring", + "rw-stream-sink", + "sha2 0.10.7", + "smallvec", + "thiserror", + "unsigned-varint", + "void", + "zeroize", +] + +[[package]] +name = "libp2p-deflate" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0183dc2a3da1fbbf85e5b6cf51217f55b14f5daea0c455a9536eef646bfec71" +dependencies = [ + "flate2", + "futures", + "libp2p-core", +] + +[[package]] +name = "libp2p-dns" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cbf54723250fa5d521383be789bf60efdabe6bacfb443f87da261019a49b4b5" +dependencies = [ + "async-std-resolver", + "futures", + "libp2p-core", + "log", + "parking_lot 0.12.1", + "smallvec", + "trust-dns-resolver", +] + +[[package]] +name = "libp2p-floodsub" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98a4b6ffd53e355775d24b76f583fdda54b3284806f678499b57913adb94f231" +dependencies = [ + "cuckoofilter", + "fnv", + "futures", + "libp2p-core", + "libp2p-swarm", + "log", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.7.3", + "smallvec", +] + +[[package]] +name = "libp2p-gossipsub" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74b4b888cfbeb1f5551acd3aa1366e01bf88ede26cc3c4645d0d2d004d5ca7b0" +dependencies = [ + "asynchronous-codec", + "base64 0.13.1", + "byteorder", + "bytes", + "fnv", + "futures", + "hex_fmt", + "instant", + "libp2p-core", + "libp2p-swarm", + "log", + "prometheus-client", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.7.3", + "regex", + "sha2 0.10.7", + "smallvec", + "unsigned-varint", + "wasm-timer", +] + +[[package]] +name = "libp2p-identify" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c50b585518f8efd06f93ac2f976bd672e17cdac794644b3117edd078e96bda06" +dependencies = [ + "asynchronous-codec", + "futures", + "futures-timer", + "libp2p-core", + "libp2p-swarm", + "log", + "lru", + "prost 0.10.4", + "prost-build 0.10.4", + "prost-codec", + "smallvec", + "thiserror", + "void", +] + +[[package]] +name = "libp2p-kad" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740862893bb5f06ac24acc9d49bdeadc3a5e52e51818a30a25c1f3519da2c851" +dependencies = [ + "arrayvec 0.7.4", + "asynchronous-codec", + "bytes", + "either", + "fnv", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-swarm", + "log", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.7.3", + "sha2 0.10.7", + "smallvec", + "thiserror", + "uint", + "unsigned-varint", + "void", +] + +[[package]] +name = "libp2p-mdns" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66e5e5919509603281033fd16306c61df7a4428ce274b67af5e14b07de5cdcb2" +dependencies = [ + "async-io", + "data-encoding", + "dns-parser", + "futures", + "if-watch", + "lazy_static", + "libp2p-core", + "libp2p-swarm", + "log", + "rand 0.8.5", + "smallvec", + "socket2 0.4.9", + "void", +] + +[[package]] +name = "libp2p-metrics" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8aff4a1abef42328fbb30b17c853fff9be986dc39af17ee39f9c5f755c5e0c" +dependencies = [ + "libp2p-core", + "libp2p-gossipsub", + "libp2p-identify", + "libp2p-kad", + "libp2p-ping", + "libp2p-relay", + "libp2p-swarm", + "prometheus-client", +] + +[[package]] +name = "libp2p-mplex" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61fd1b20638ec209c5075dfb2e8ce6a7ea4ec3cd3ad7b77f7a477c06d53322e2" +dependencies = [ + "asynchronous-codec", + "bytes", + "futures", + "libp2p-core", + "log", + "nohash-hasher", + "parking_lot 0.12.1", + "rand 0.7.3", + "smallvec", + "unsigned-varint", +] + +[[package]] +name = "libp2p-noise" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "762408cb5d84b49a600422d7f9a42c18012d8da6ebcd570f9a4a4290ba41fb6f" +dependencies = [ + "bytes", + "curve25519-dalek 3.2.0", + "futures", + "lazy_static", + "libp2p-core", + "log", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.8.5", + "sha2 0.10.7", + "snow", + "static_assertions", + "x25519-dalek", + "zeroize", +] + +[[package]] +name = "libp2p-ping" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "100a6934ae1dbf8a693a4e7dd1d730fd60b774dafc45688ed63b554497c6c925" +dependencies = [ + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-swarm", + "log", + "rand 0.7.3", + "void", +] + +[[package]] +name = "libp2p-plaintext" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be27bf0820a6238a4e06365b096d428271cce85a129cf16f2fe9eb1610c4df86" +dependencies = [ + "asynchronous-codec", + "bytes", + "futures", + "libp2p-core", + "log", + "prost 0.10.4", + "prost-build 0.10.4", + "unsigned-varint", + "void", +] + +[[package]] +name = "libp2p-pnet" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6468f382568da936b4fa1cff273ce59b1debf873ff5f4ca412c3b91d0b37442c" +dependencies = [ + "futures", + "log", + "pin-project", + "rand 0.8.5", + "salsa20", + "sha3", +] + +[[package]] +name = "libp2p-relay" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4931547ee0cce03971ccc1733ff05bb0c4349fd89120a39e9861e2bbe18843c3" +dependencies = [ + "asynchronous-codec", + "bytes", + "either", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-swarm", + "log", + "pin-project", + "prost 0.10.4", + "prost-build 0.10.4", + "prost-codec", + "rand 0.8.5", + "smallvec", + "static_assertions", + "thiserror", + "void", +] + +[[package]] +name = "libp2p-rendezvous" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9511c9672ba33284838e349623319c8cad2d18cfad243ae46c6b7e8a2982ea4e" +dependencies = [ + "asynchronous-codec", + "bimap", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-swarm", + "log", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.8.5", + "sha2 0.10.7", + "thiserror", + "unsigned-varint", + "void", +] + +[[package]] +name = "libp2p-request-response" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "508a189e2795d892c8f5c1fa1e9e0b1845d32d7b0b249dbf7b05b18811361843" +dependencies = [ + "async-trait", + "bytes", + "futures", + "instant", + "libp2p-core", + "libp2p-swarm", + "log", + "rand 0.7.3", + "smallvec", + "unsigned-varint", +] + +[[package]] +name = "libp2p-swarm" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ac5be6c2de2d1ff3f7693fda6faf8a827b1f3e808202277783fea9f527d114" +dependencies = [ + "either", + "fnv", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "log", + "pin-project", + "rand 0.7.3", + "smallvec", + "thiserror", + "void", +] + +[[package]] +name = "libp2p-swarm-derive" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f54a64b6957249e0ce782f8abf41d97f69330d02bf229f0672d864f0650cc76" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "libp2p-tcp" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a6771dc19aa3c65d6af9a8c65222bfc8fcd446630ddca487acd161fa6096f3b" +dependencies = [ + "async-io", + "futures", + "futures-timer", + "if-watch", + "ipnet", + "libc", + "libp2p-core", + "log", + "socket2 0.4.9", +] + +[[package]] +name = "libp2p-uds" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d125e3e5f0d58f3c6ac21815b20cf4b6a88b8db9dc26368ea821838f4161fd4d" +dependencies = [ + "async-std", + "futures", + "libp2p-core", + "log", +] + +[[package]] +name = "libp2p-wasm-ext" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec894790eec3c1608f8d1a8a0bdf0dbeb79ed4de2dce964222011c2896dfa05a" +dependencies = [ + "futures", + "js-sys", + "libp2p-core", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "libp2p-websocket" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9808e57e81be76ff841c106b4c5974fb4d41a233a7bdd2afbf1687ac6def3818" +dependencies = [ + "either", + "futures", + "futures-rustls", + "libp2p-core", + "log", + "parking_lot 0.12.1", + "quicksink", + "rw-stream-sink", + "soketto", + "url", + "webpki-roots", +] + +[[package]] +name = "libp2p-yamux" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6dea686217a06072033dc025631932810e2f6ad784e4fafa42e27d311c7a81c" +dependencies = [ + "futures", + "libp2p-core", + "parking_lot 0.12.1", + "thiserror", + "yamux", +] + +[[package]] +name = "librocksdb-sys" +version = "0.6.3+6.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "184ce2a189a817be2731070775ad053b6804a340fee05c6686d711db27455917" +dependencies = [ + "bindgen", + "bzip2-sys", + "cc", + "glob", + "libc", + "libz-sys", + "tikv-jemalloc-sys", +] + +[[package]] +name = "libsecp256k1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" +dependencies = [ + "arrayref", + "base64 0.13.1", + "digest 0.9.0", + "hmac-drbg", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand 0.8.5", + "serde", + "sha2 0.9.9", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libz-sys" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "linked_hash_set" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47186c6da4d81ca383c7c47c1bfc80f4b95f4720514d860a5407aaf4233f9588" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "linregress" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6c601a85f5ecd1aba625247bca0031585fb1c446461b142878a16f8245ddeb8" +dependencies = [ + "nalgebra", + "statrs", +] + +[[package]] +name = "linux-raw-sys" +version = "0.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" + +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + +[[package]] +name = "lite-json" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0e787ffe1153141a0f6f6d759fdf1cc34b1226e088444523812fd412a5cca2" +dependencies = [ + "lite-parser", +] + +[[package]] +name = "lite-parser" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d5f9dc37c52d889a21fd701983d02bb6a84f852c5140a6c80ef4557f7dc29e" +dependencies = [ + "paste", +] + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +dependencies = [ + "value-bag", +] + +[[package]] +name = "lru" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "lz4" +version = "1.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e9e2dd86df36ce760a60f6ff6ad526f7ba1f14ba0356f8254fb6905e6494df1" +dependencies = [ + "libc", + "lz4-sys", +] + +[[package]] +name = "lz4-sys" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d27b317e207b10f69f5e75494119e391a96f48861ae870d1da6edac98ca900" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + +[[package]] +name = "matrixmultiply" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090126dc04f95dc0d1c1c91f61bdd474b3930ca064c1edc8a849da2c6cbe1e77" +dependencies = [ + "autocfg", + "rawpointer", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memfd" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" +dependencies = [ + "rustix 0.37.23", +] + +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memory-db" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" +dependencies = [ + "hash-db", + "hashbrown", + "parity-util-mem", +] + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "merlin" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e261cf0f8b3c42ded9f7d2bb59dea03aa52bc8a1cbc7482f9fc3fd1229d3b42" +dependencies = [ + "byteorder", + "keccak", + "rand_core 0.5.1", + "zeroize", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + +[[package]] +name = "multiaddr" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c580bfdd8803cce319b047d239559a22f809094aaea4ac13902a1fdcfcd4261" +dependencies = [ + "arrayref", + "bs58", + "byteorder", + "data-encoding", + "multihash", + "percent-encoding", + "serde", + "static_assertions", + "unsigned-varint", + "url", +] + +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + +[[package]] +name = "multihash" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" +dependencies = [ + "blake2b_simd", + "blake2s_simd", + "blake3", + "core2", + "digest 0.10.7", + "multihash-derive", + "sha2 0.10.7", + "sha3", + "unsigned-varint", +] + +[[package]] +name = "multihash-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" +dependencies = [ + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", + "synstructure", +] + +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + +[[package]] +name = "multistream-select" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "363a84be6453a70e63513660f4894ef815daf88e3356bffcda9ca27d810ce83b" +dependencies = [ + "bytes", + "futures", + "log", + "pin-project", + "smallvec", + "unsigned-varint", +] + +[[package]] +name = "nalgebra" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "462fffe4002f4f2e1f6a9dcf12cc1a6fc0e15989014efc02a941d3e0f5dc2120" +dependencies = [ + "approx", + "matrixmultiply", + "nalgebra-macros", + "num-complex", + "num-rational 0.4.1", + "num-traits", + "rand 0.8.5", + "rand_distr", + "simba", + "typenum", +] + +[[package]] +name = "nalgebra-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01fcc0b8149b4632adc89ac3b7b31a12fb6099a0317a4eb2ebff574ef7de7218" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "names" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7d66043b25d4a6cccb23619d10c19c25304b355a7dccd4a8e11423dd2382146" +dependencies = [ + "rand 0.8.5", +] + +[[package]] +name = "netlink-packet-core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345b8ab5bd4e71a2986663e88c56856699d060e78e152e6e9d7966fcd5491297" +dependencies = [ + "anyhow", + "byteorder", + "libc", + "netlink-packet-utils", +] + +[[package]] +name = "netlink-packet-route" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9ea4302b9759a7a88242299225ea3688e63c85ea136371bb6cf94fd674efaab" +dependencies = [ + "anyhow", + "bitflags 1.3.2", + "byteorder", + "libc", + "netlink-packet-core", + "netlink-packet-utils", +] + +[[package]] +name = "netlink-packet-utils" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" +dependencies = [ + "anyhow", + "byteorder", + "paste", + "thiserror", +] + +[[package]] +name = "netlink-proto" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65b4b14489ab424703c092062176d52ba55485a89c076b4f9db05092b7223aa6" +dependencies = [ + "bytes", + "futures", + "log", + "netlink-packet-core", + "netlink-sys", + "thiserror", + "tokio", +] + +[[package]] +name = "netlink-sys" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6471bf08e7ac0135876a9581bf3217ef0333c191c128d34878079f42ee150411" +dependencies = [ + "async-io", + "bytes", + "futures", + "libc", + "log", +] + +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + +[[package]] +name = "node-primitives" +version = "2.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec 0.7.4", + "itoa 1.0.9", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg", + "num-bigint 0.2.6", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint 0.4.3", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", + "libm 0.2.7", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.2", + "libc", +] + +[[package]] +name = "object" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "crc32fast", + "hashbrown", + "indexmap", + "memchr", +] + +[[package]] +name = "object" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "os_str_bytes" +version = "6.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" + +[[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + +[[package]] +name = "owning_ref" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "packed_simd_2" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282" +dependencies = [ + "cfg-if", + "libm 0.1.4", +] + +[[package]] +name = "pallet-authority-discovery" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "pallet-session", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-authority-discovery", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-authorship" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "sp-authorship", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-babe" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-consensus-babe", + "sp-consensus-vrf", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-bags-list" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-tracing", +] + +[[package]] +name = "pallet-balances" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-bounties" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-treasury", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-cere-ddc" +version = "4.8.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-chainbridge" +version = "4.8.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "lite-json", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-child-bounties" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-bounties", + "pallet-treasury", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-collective" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-contracts" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "bitflags 1.3.2", + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "pallet-contracts-primitives", + "pallet-contracts-proc-macro", + "parity-scale-codec", + "rand 0.8.5", + "rand_pcg 0.3.1", + "scale-info", + "serde", + "smallvec", + "sp-core", + "sp-io", + "sp-runtime", + "sp-sandbox", + "sp-std", + "wasm-instrument", + "wasmi-validation", +] + +[[package]] +name = "pallet-contracts-primitives" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "bitflags 1.3.2", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-rpc", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-contracts-proc-macro" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pallet-contracts-rpc" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "jsonrpsee", + "pallet-contracts-primitives", + "pallet-contracts-rpc-runtime-api", + "parity-scale-codec", + "serde", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-rpc", + "sp-runtime", +] + +[[package]] +name = "pallet-contracts-rpc-runtime-api" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "pallet-contracts-primitives", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-ddc-accounts" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "substrate-test-utils", +] + +[[package]] +name = "pallet-ddc-metrics-offchain-worker" +version = "4.8.0" +dependencies = [ + "alt_serde", + "frame-support", + "frame-system", + "hex", + "hex-literal", + "lite-json", + "pallet-balances", + "pallet-contracts", + "pallet-randomness-collective-flip", + "pallet-timestamp", + "parity-scale-codec", + "pretty_assertions", + "scale-info", + "serde", + "serde_json 1.0.44", + "sp-core", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-ddc-staking" +version = "4.8.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "sp-tracing", + "substrate-test-utils", +] + +[[package]] +name = "pallet-ddc-validator" +version = "0.1.0" +dependencies = [ + "alt_serde", + "array-bytes 6.1.0", + "base64 0.21.2", + "frame-election-provider-support", + "frame-support", + "frame-system", + "lite-json", + "log", + "pallet-balances", + "pallet-contracts", + "pallet-ddc-accounts", + "pallet-ddc-staking", + "pallet-randomness-collective-flip", + "pallet-session", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "serde", + "serde_json 1.0.44", + "sp-core", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-democracy" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-election-provider-multi-phase" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-election-provider-support-benchmarking", + "parity-scale-codec", + "rand 0.7.3", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-npos-elections", + "sp-runtime", + "sp-std", + "static_assertions", + "strum", +] + +[[package]] +name = "pallet-election-provider-support-benchmarking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-system", + "parity-scale-codec", + "sp-npos-elections", + "sp-runtime", +] + +[[package]] +name = "pallet-elections-phragmen" +version = "5.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-npos-elections", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-erc20" +version = "4.8.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-chainbridge", + "pallet-erc721", + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-erc721" +version = "4.8.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-chainbridge", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-fast-unstake" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-staking", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-grandpa" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-core", + "sp-finality-grandpa", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-identity" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "enumflags2", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-im-online" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-indices" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-keyring", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-membership" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-multisig" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-nomination-pools" +version = "1.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-nomination-pools-benchmarking" +version = "1.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "pallet-bags-list", + "pallet-nomination-pools", + "pallet-staking", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-runtime-interface", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-nomination-pools-runtime-api" +version = "1.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "sp-api", + "sp-std", +] + +[[package]] +name = "pallet-offences" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-offences-benchmarking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "pallet-babe", + "pallet-balances", + "pallet-grandpa", + "pallet-im-online", + "pallet-offences", + "pallet-session", + "pallet-staking", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-proxy" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-randomness-collective-flip" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "safe-mix", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-recovery" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-scheduler" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-session" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "sp-trie", +] + +[[package]] +name = "pallet-session-benchmarking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-session", + "pallet-staking", + "rand 0.7.3", + "sp-runtime", + "sp-session", + "sp-std", +] + +[[package]] +name = "pallet-society" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "rand_chacha 0.2.2", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-staking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "rand_chacha 0.2.2", + "scale-info", + "serde", + "sp-application-crypto", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-staking-reward-curve" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pallet-sudo" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-timestamp" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "pallet-tips" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-treasury", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-transaction-payment" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-transaction-payment-rpc" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "jsonrpsee", + "pallet-transaction-payment-rpc-runtime-api", + "parity-scale-codec", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-rpc", + "sp-runtime", +] + +[[package]] +name = "pallet-transaction-payment-rpc-runtime-api" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "pallet-transaction-payment", + "parity-scale-codec", + "sp-api", + "sp-runtime", +] + +[[package]] +name = "pallet-transaction-storage" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-std", + "sp-transaction-storage-proof", +] + +[[package]] +name = "pallet-treasury" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-utility" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-vesting" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "parity-db" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8fdb726a43661fa54b43e7114e6b88b2289cae388eb3ad766d9d1754d83fce" +dependencies = [ + "blake2-rfc", + "crc32fast", + "fs2", + "hex", + "libc", + "log", + "lz4", + "memmap2", + "parking_lot 0.12.1", + "rand 0.8.5", + "snap", +] + +[[package]] +name = "parity-scale-codec" +version = "3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756d439303e94fae44f288ba881ad29670c65b0c4b0e05674ca81061bb65f2c5" +dependencies = [ + "arrayvec 0.7.4", + "bitvec", + "byte-slice-cast", + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d884d78fcf214d70b1e239fcd1c6e5e95aa3be1881918da2e488cc946c7a476" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "parity-send-wrapper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" + +[[package]] +name = "parity-util-mem" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" +dependencies = [ + "cfg-if", + "hashbrown", + "impl-trait-for-tuples", + "parity-util-mem-derive", + "parking_lot 0.12.1", + "primitive-types", + "smallvec", + "winapi", +] + +[[package]] +name = "parity-util-mem-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" +dependencies = [ + "proc-macro2", + "syn 1.0.109", + "synstructure", +] + +[[package]] +name = "parity-wasm" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ad52817c4d343339b3bc2e26861bd21478eda0b7509acf83505727000512ac" +dependencies = [ + "byteorder", +] + +[[package]] +name = "parity-wasm" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" + +[[package]] +name = "parking" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.8", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "pbkdf2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216eaa586a190f0a738f2f918511eecfa90f13295abec0e457cdebcceda80cbd" +dependencies = [ + "crypto-mac 0.8.0", +] + +[[package]] +name = "pbkdf2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa" +dependencies = [ + "crypto-mac 0.11.1", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + +[[package]] +name = "pest" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" +dependencies = [ + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "pest_meta" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" +dependencies = [ + "once_cell", + "pest", + "sha2 0.10.7", +] + +[[package]] +name = "petgraph" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "pin-project" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + +[[package]] +name = "pin-project-lite" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs8" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" +dependencies = [ + "der", + "spki", + "zeroize", +] + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "platforms" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" + +[[package]] +name = "platforms" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" + +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite 0.2.10", + "windows-sys 0.48.0", +] + +[[package]] +name = "poly1305" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" +dependencies = [ + "cpufeatures", + "opaque-debug 0.3.0", + "universal-hash", +] + +[[package]] +name = "polyval" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug 0.3.0", + "universal-hash", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "pretty_assertions" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" +dependencies = [ + "ansi_term 0.11.0", + "ctor", + "difference", + "output_vt100", +] + +[[package]] +name = "prettyplease" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "prettyplease" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387" +dependencies = [ + "proc-macro2", + "syn 2.0.26", +] + +[[package]] +name = "primitive-types" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28720988bff275df1f51b171e1b2a18c30d194c4d2b61defdacecd625a5d94a" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-serde", + "scale-info", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" +dependencies = [ + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prometheus" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +dependencies = [ + "cfg-if", + "fnv", + "lazy_static", + "memchr", + "parking_lot 0.12.1", + "thiserror", +] + +[[package]] +name = "prometheus-client" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1abe0255c04d15f571427a2d1e00099016506cf3297b53853acd2b7eb87825" +dependencies = [ + "dtoa", + "itoa 1.0.9", + "owning_ref", + "prometheus-client-derive-text-encode", +] + +[[package]] +name = "prometheus-client-derive-text-encode" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8e12d01b9d66ad9eb4529c57666b6263fc1993cb30261d83ead658fdd932652" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71adf41db68aa0daaefc69bb30bcd68ded9b9abaad5d1fbb6304c4fb390e083e" +dependencies = [ + "bytes", + "prost-derive 0.10.1", +] + +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive 0.11.9", +] + +[[package]] +name = "prost-build" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae5a4388762d5815a9fc0dea33c56b021cdc8dde0c55e0c9ca57197254b0cab" +dependencies = [ + "bytes", + "cfg-if", + "cmake", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prost 0.10.4", + "prost-types 0.10.1", + "regex", + "tempfile", + "which", +] + +[[package]] +name = "prost-build" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +dependencies = [ + "bytes", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prettyplease 0.1.25", + "prost 0.11.9", + "prost-types 0.11.9", + "regex", + "syn 1.0.109", + "tempfile", + "which", +] + +[[package]] +name = "prost-codec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00af1e92c33b4813cc79fda3f2dbf56af5169709be0202df730e9ebc3e4cd007" +dependencies = [ + "asynchronous-codec", + "bytes", + "prost 0.10.4", + "thiserror", + "unsigned-varint", +] + +[[package]] +name = "prost-derive" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b670f45da57fb8542ebdbb6105a925fe571b67f9e7ed9f47a06a84e72b4e7cc" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-types" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d0a014229361011dc8e69c8a1ec6c2e8d0f2af7c91e3ea3f5b2170298461e68" +dependencies = [ + "bytes", + "prost 0.10.4", +] + +[[package]] +name = "prost-types" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +dependencies = [ + "prost 0.11.9", +] + +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quicksink" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77de3c815e5a160b1539c6592796801df2043ae35e123b46d73380cfa57af858" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project-lite 0.1.12", +] + +[[package]] +name = "quote" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", + "rand_pcg 0.2.1", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.10", +] + +[[package]] +name = "rand_distr" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_pcg" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.10", + "redox_syscall 0.2.16", + "thiserror", +] + +[[package]] +name = "ref-cast" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1641819477c319ef452a075ac34a4be92eb9ba09f6841f62d594d50fdcf0bf6b" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68bf53dad9b6086826722cdc99140793afd9f62faa14a1ad07eb4f955e7a7216" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "regalloc2" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" +dependencies = [ + "fxhash", + "log", + "slice-group-by", + "smallvec", +] + +[[package]] +name = "regex" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.3.3", + "regex-syntax 0.7.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" + +[[package]] +name = "remote-externalities" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "env_logger 0.9.3", + "jsonrpsee", + "log", + "parity-scale-codec", + "serde", + "serde_json 1.0.103", + "sp-core", + "sp-io", + "sp-runtime", + "sp-version", +] + +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", +] + +[[package]] +name = "rfc6979" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" +dependencies = [ + "crypto-bigint", + "hmac 0.11.0", + "zeroize", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rocksdb" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "620f4129485ff1a7128d184bc687470c21c7951b64779ebc9cfdad3dcd920290" +dependencies = [ + "libc", + "librocksdb-sys", +] + +[[package]] +name = "rpassword" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6678cf63ab3491898c0d021b493c94c9b221d91295294a2a5746eacbe5928322" +dependencies = [ + "libc", + "rtoolbox", + "winapi", +] + +[[package]] +name = "rtnetlink" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322c53fd76a18698f1c27381d58091de3a043d356aa5bd0d510608b565f469a0" +dependencies = [ + "async-global-executor", + "futures", + "log", + "netlink-packet-route", + "netlink-proto", + "nix", + "thiserror", +] + +[[package]] +name = "rtoolbox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "034e22c514f5c0cb8a10ff341b9b048b5ceb21591f31c8f44c43b960f9b3524a" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.18", +] + +[[package]] +name = "rustix" +version = "0.35.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6380889b07a03b5ecf1d44dc9ede6fd2145d84b502a2a9ca0b03c48e0cc3220f" +dependencies = [ + "bitflags 1.3.2", + "errno 0.2.8", + "io-lifetimes 0.7.5", + "libc", + "linux-raw-sys 0.0.46", + "windows-sys 0.42.0", +] + +[[package]] +name = "rustix" +version = "0.37.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +dependencies = [ + "bitflags 1.3.2", + "errno 0.3.1", + "io-lifetimes 1.0.11", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +dependencies = [ + "bitflags 2.3.3", + "errno 0.3.1", + "libc", + "linux-raw-sys 0.4.3", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64 0.21.2", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "rw-stream-sink" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26338f5e09bb721b85b135ea05af7767c90b52f6de4f087d4f4a3a9d64e7dc04" +dependencies = [ + "futures", + "pin-project", + "static_assertions", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "safe-mix" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d3d055a2582e6b00ed7a31c1524040aa391092bf636328350813f3a0605215c" +dependencies = [ + "rustc_version 0.2.3", +] + +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher 0.4.4", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "sc-allocator" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "log", + "sp-core", + "sp-wasm-interface", + "thiserror", +] + +[[package]] +name = "sc-authority-discovery" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "futures", + "futures-timer", + "ip_network", + "libp2p", + "log", + "parity-scale-codec", + "prost 0.10.4", + "prost-build 0.10.4", + "rand 0.7.3", + "sc-client-api", + "sc-network-common", + "sp-api", + "sp-authority-discovery", + "sp-blockchain", + "sp-core", + "sp-keystore", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror", +] + +[[package]] +name = "sc-basic-authorship" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "sc-block-builder", + "sc-client-api", + "sc-proposer-metrics", + "sc-telemetry", + "sc-transaction-pool-api", + "sp-api", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-inherents", + "sp-runtime", + "substrate-prometheus-endpoint", +] + +[[package]] +name = "sc-block-builder" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "sc-client-api", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-state-machine", +] + +[[package]] +name = "sc-chain-spec" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "impl-trait-for-tuples", + "memmap2", + "parity-scale-codec", + "sc-chain-spec-derive", + "sc-network-common", + "sc-telemetry", + "serde", + "serde_json 1.0.103", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "sc-chain-spec-derive" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sc-cli" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "chrono", + "clap", + "fdlimit", + "futures", + "libp2p", + "log", + "names", + "parity-scale-codec", + "rand 0.7.3", + "regex", + "rpassword", + "sc-client-api", + "sc-client-db", + "sc-keystore", + "sc-network", + "sc-network-common", + "sc-service", + "sc-telemetry", + "sc-tracing", + "sc-utils", + "serde", + "serde_json 1.0.103", + "sp-blockchain", + "sp-core", + "sp-keyring", + "sp-keystore", + "sp-panic-handler", + "sp-runtime", + "sp-version", + "thiserror", + "tiny-bip39", + "tokio", +] + +[[package]] +name = "sc-client-api" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "fnv", + "futures", + "hash-db", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-executor", + "sc-transaction-pool-api", + "sc-utils", + "sp-api", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-database", + "sp-externalities", + "sp-keystore", + "sp-runtime", + "sp-state-machine", + "sp-storage", + "sp-trie", + "substrate-prometheus-endpoint", +] + +[[package]] +name = "sc-client-db" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "hash-db", + "kvdb", + "kvdb-memorydb", + "kvdb-rocksdb", + "linked-hash-map", + "log", + "parity-db", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-client-api", + "sc-state-db", + "sp-arithmetic", + "sp-blockchain", + "sp-core", + "sp-database", + "sp-runtime", + "sp-state-machine", + "sp-trie", +] + +[[package]] +name = "sc-consensus" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "futures", + "futures-timer", + "libp2p", + "log", + "parking_lot 0.12.1", + "sc-client-api", + "sc-utils", + "serde", + "sp-api", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-runtime", + "sp-state-machine", + "substrate-prometheus-endpoint", + "thiserror", +] + +[[package]] +name = "sc-consensus-babe" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "fork-tree", + "futures", + "log", + "merlin", + "num-bigint 0.2.6", + "num-rational 0.2.4", + "num-traits", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.7.3", + "sc-client-api", + "sc-consensus", + "sc-consensus-epochs", + "sc-consensus-slots", + "sc-keystore", + "sc-telemetry", + "schnorrkel", + "serde", + "sp-api", + "sp-application-crypto", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-consensus-slots", + "sp-consensus-vrf", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-version", + "substrate-prometheus-endpoint", + "thiserror", +] + +[[package]] +name = "sc-consensus-babe-rpc" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "jsonrpsee", + "sc-consensus-babe", + "sc-consensus-epochs", + "sc-rpc-api", + "serde", + "sp-api", + "sp-application-crypto", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-core", + "sp-keystore", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-consensus-epochs" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "fork-tree", + "parity-scale-codec", + "sc-client-api", + "sc-consensus", + "sp-blockchain", + "sp-runtime", +] + +[[package]] +name = "sc-consensus-slots" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "sc-client-api", + "sc-consensus", + "sc-telemetry", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-state-machine", + "thiserror", +] + +[[package]] +name = "sc-consensus-uncles" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "sc-client-api", + "sp-authorship", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-executor" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "lazy_static", + "lru", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-executor-common", + "sc-executor-wasmi", + "sc-executor-wasmtime", + "sp-api", + "sp-core", + "sp-core-hashing-proc-macro", + "sp-externalities", + "sp-io", + "sp-panic-handler", + "sp-runtime-interface", + "sp-tasks", + "sp-trie", + "sp-version", + "sp-wasm-interface", + "tracing", + "wasmi", +] + +[[package]] +name = "sc-executor-common" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "environmental", + "parity-scale-codec", + "sc-allocator", + "sp-maybe-compressed-blob", + "sp-sandbox", + "sp-wasm-interface", + "thiserror", + "wasm-instrument", + "wasmi", +] + +[[package]] +name = "sc-executor-wasmi" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "log", + "parity-scale-codec", + "sc-allocator", + "sc-executor-common", + "sp-runtime-interface", + "sp-sandbox", + "sp-wasm-interface", + "wasmi", +] + +[[package]] +name = "sc-executor-wasmtime" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "cfg-if", + "libc", + "log", + "once_cell", + "parity-scale-codec", + "parity-wasm 0.45.0", + "rustix 0.35.14", + "sc-allocator", + "sc-executor-common", + "sp-runtime-interface", + "sp-sandbox", + "sp-wasm-interface", + "wasmtime", +] + +[[package]] +name = "sc-finality-grandpa" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "ahash", + "array-bytes 4.2.0", + "async-trait", + "dyn-clone", + "finality-grandpa", + "fork-tree", + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.8.5", + "sc-block-builder", + "sc-chain-spec", + "sc-client-api", + "sc-consensus", + "sc-keystore", + "sc-network", + "sc-network-common", + "sc-network-gossip", + "sc-telemetry", + "sc-utils", + "serde_json 1.0.103", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-finality-grandpa", + "sp-keystore", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror", +] + +[[package]] +name = "sc-finality-grandpa-rpc" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "finality-grandpa", + "futures", + "jsonrpsee", + "log", + "parity-scale-codec", + "sc-client-api", + "sc-finality-grandpa", + "sc-rpc", + "serde", + "serde_json 1.0.103", + "sp-blockchain", + "sp-core", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-informant" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "ansi_term 0.12.1", + "futures", + "futures-timer", + "log", + "parity-util-mem", + "sc-client-api", + "sc-network-common", + "sc-transaction-pool-api", + "sp-blockchain", + "sp-runtime", +] + +[[package]] +name = "sc-keystore" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "async-trait", + "parking_lot 0.12.1", + "serde_json 1.0.103", + "sp-application-crypto", + "sp-core", + "sp-keystore", + "thiserror", +] + +[[package]] +name = "sc-network" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "async-trait", + "asynchronous-codec", + "bitflags 1.3.2", + "bytes", + "cid", + "either", + "fnv", + "fork-tree", + "futures", + "futures-timer", + "ip_network", + "libp2p", + "linked-hash-map", + "linked_hash_set", + "log", + "lru", + "parity-scale-codec", + "parking_lot 0.12.1", + "pin-project", + "prost 0.10.4", + "rand 0.7.3", + "sc-block-builder", + "sc-client-api", + "sc-consensus", + "sc-network-common", + "sc-peerset", + "sc-utils", + "serde", + "serde_json 1.0.103", + "smallvec", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror", + "unsigned-varint", + "zeroize", +] + +[[package]] +name = "sc-network-bitswap" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "cid", + "futures", + "libp2p", + "log", + "prost 0.11.9", + "prost-build 0.11.9", + "sc-client-api", + "sc-network-common", + "sp-blockchain", + "sp-runtime", + "thiserror", + "unsigned-varint", + "void", +] + +[[package]] +name = "sc-network-common" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "bitflags 1.3.2", + "bytes", + "futures", + "futures-timer", + "libp2p", + "linked_hash_set", + "parity-scale-codec", + "prost-build 0.10.4", + "sc-consensus", + "sc-peerset", + "serde", + "smallvec", + "sp-blockchain", + "sp-consensus", + "sp-finality-grandpa", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror", +] + +[[package]] +name = "sc-network-gossip" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "ahash", + "futures", + "futures-timer", + "libp2p", + "log", + "lru", + "sc-network-common", + "sc-peerset", + "sp-runtime", + "substrate-prometheus-endpoint", + "tracing", +] + +[[package]] +name = "sc-network-light" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "futures", + "libp2p", + "log", + "parity-scale-codec", + "prost 0.10.4", + "prost-build 0.10.4", + "sc-client-api", + "sc-network-common", + "sc-peerset", + "sp-blockchain", + "sp-core", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-network-sync" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "fork-tree", + "futures", + "libp2p", + "log", + "lru", + "parity-scale-codec", + "prost 0.10.4", + "prost-build 0.10.4", + "sc-client-api", + "sc-consensus", + "sc-network-common", + "sc-peerset", + "smallvec", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-finality-grandpa", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-network-transactions" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "futures", + "hex", + "libp2p", + "log", + "parity-scale-codec", + "pin-project", + "sc-network-common", + "sc-peerset", + "sp-consensus", + "sp-runtime", + "substrate-prometheus-endpoint", +] + +[[package]] +name = "sc-offchain" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "bytes", + "fnv", + "futures", + "futures-timer", + "hyper", + "hyper-rustls", + "libp2p", + "num_cpus", + "once_cell", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.7.3", + "sc-client-api", + "sc-network-common", + "sc-peerset", + "sc-utils", + "sp-api", + "sp-core", + "sp-offchain", + "sp-runtime", + "threadpool", + "tracing", +] + +[[package]] +name = "sc-peerset" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "libp2p", + "log", + "sc-utils", + "serde_json 1.0.103", + "wasm-timer", +] + +[[package]] +name = "sc-proposer-metrics" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "log", + "substrate-prometheus-endpoint", +] + +[[package]] +name = "sc-rpc" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "hash-db", + "jsonrpsee", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-block-builder", + "sc-chain-spec", + "sc-client-api", + "sc-rpc-api", + "sc-tracing", + "sc-transaction-pool-api", + "sc-utils", + "serde_json 1.0.103", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-keystore", + "sp-offchain", + "sp-rpc", + "sp-runtime", + "sp-session", + "sp-version", +] + +[[package]] +name = "sc-rpc-api" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "jsonrpsee", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-chain-spec", + "sc-transaction-pool-api", + "scale-info", + "serde", + "serde_json 1.0.103", + "sp-core", + "sp-rpc", + "sp-runtime", + "sp-tracing", + "sp-version", + "thiserror", +] + +[[package]] +name = "sc-rpc-server" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "jsonrpsee", + "log", + "serde_json 1.0.103", + "substrate-prometheus-endpoint", + "tokio", +] + +[[package]] +name = "sc-service" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "directories", + "exit-future", + "futures", + "futures-timer", + "hash-db", + "jsonrpsee", + "log", + "parity-scale-codec", + "parity-util-mem", + "parking_lot 0.12.1", + "pin-project", + "rand 0.7.3", + "sc-block-builder", + "sc-chain-spec", + "sc-client-api", + "sc-client-db", + "sc-consensus", + "sc-executor", + "sc-informant", + "sc-keystore", + "sc-network", + "sc-network-bitswap", + "sc-network-common", + "sc-network-light", + "sc-network-sync", + "sc-network-transactions", + "sc-offchain", + "sc-rpc", + "sc-rpc-server", + "sc-sysinfo", + "sc-telemetry", + "sc-tracing", + "sc-transaction-pool", + "sc-transaction-pool-api", + "sc-utils", + "serde", + "serde_json 1.0.103", + "sp-api", + "sp-application-crypto", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-externalities", + "sp-inherents", + "sp-keystore", + "sp-runtime", + "sp-session", + "sp-state-machine", + "sp-storage", + "sp-tracing", + "sp-transaction-pool", + "sp-transaction-storage-proof", + "sp-trie", + "sp-version", + "static_init", + "substrate-prometheus-endpoint", + "tempfile", + "thiserror", + "tokio", + "tracing", + "tracing-futures", +] + +[[package]] +name = "sc-state-db" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "log", + "parity-scale-codec", + "parity-util-mem", + "parity-util-mem-derive", + "parking_lot 0.12.1", + "sc-client-api", + "sp-core", +] + +[[package]] +name = "sc-sync-state-rpc" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "jsonrpsee", + "parity-scale-codec", + "sc-chain-spec", + "sc-client-api", + "sc-consensus-babe", + "sc-consensus-epochs", + "sc-finality-grandpa", + "serde", + "serde_json 1.0.103", + "sp-blockchain", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-sysinfo" +version = "6.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "libc", + "log", + "rand 0.7.3", + "rand_pcg 0.2.1", + "regex", + "sc-telemetry", + "serde", + "serde_json 1.0.103", + "sp-core", + "sp-io", + "sp-std", +] + +[[package]] +name = "sc-telemetry" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "chrono", + "futures", + "libp2p", + "log", + "parking_lot 0.12.1", + "pin-project", + "rand 0.7.3", + "serde", + "serde_json 1.0.103", + "thiserror", + "wasm-timer", +] + +[[package]] +name = "sc-tracing" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "ansi_term 0.12.1", + "atty", + "chrono", + "lazy_static", + "libc", + "log", + "once_cell", + "parking_lot 0.12.1", + "regex", + "rustc-hash", + "sc-client-api", + "sc-rpc-server", + "sc-tracing-proc-macro", + "serde", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-rpc", + "sp-runtime", + "sp-tracing", + "thiserror", + "tracing", + "tracing-log", + "tracing-subscriber", +] + +[[package]] +name = "sc-tracing-proc-macro" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sc-transaction-pool" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "futures-timer", + "linked-hash-map", + "log", + "parity-scale-codec", + "parity-util-mem", + "parking_lot 0.12.1", + "sc-client-api", + "sc-transaction-pool-api", + "sc-utils", + "serde", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-runtime", + "sp-tracing", + "sp-transaction-pool", + "substrate-prometheus-endpoint", + "thiserror", +] + +[[package]] +name = "sc-transaction-pool-api" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "log", + "serde", + "sp-blockchain", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "sc-utils" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "futures-timer", + "lazy_static", + "log", + "parking_lot 0.12.1", + "prometheus", +] + +[[package]] +name = "scale-info" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +dependencies = [ + "bitvec", + "cfg-if", + "derive_more", + "parity-scale-codec", + "scale-info-derive", + "serde", +] + +[[package]] +name = "scale-info-derive" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "schnorrkel" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" +dependencies = [ + "arrayref", + "arrayvec 0.5.2", + "curve25519-dalek 2.1.3", + "getrandom 0.1.16", + "merlin", + "rand 0.7.3", + "rand_core 0.5.1", + "sha2 0.8.2", + "subtle", + "zeroize", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "sec1" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" +dependencies = [ + "der", + "generic-array 0.14.7", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "secp256k1" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" +dependencies = [ + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" +dependencies = [ + "cc", +] + +[[package]] +name = "secrecy" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" +dependencies = [ + "zeroize", +] + +[[package]] +name = "security-framework" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +dependencies = [ + "serde", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "serde_json" +version = "1.0.44" +source = "git+https://github.com/Cerebellum-Network/json?branch=no-std-cere#17b8b39421fb94ffb1ddb8fe65630542b0679ada" +dependencies = [ + "alt_serde", + "itoa 0.4.8", + "ryu", +] + +[[package]] +name = "serde_json" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" +dependencies = [ + "itoa 1.0.9", + "ryu", + "serde", +] + +[[package]] +name = "serde_nanos" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae801b7733ca8d6a2b580debe99f67f36826a0f5b8a36055dc6bc40f8d6bc71" +dependencies = [ + "serde", +] + +[[package]] +name = "sha-1" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + +[[package]] +name = "signal-hook" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b824b6e687aff278cdbf3b36f07aa52d4bd4099699324d5da86a2ebce3aa00b3" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "signature" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" +dependencies = [ + "digest 0.9.0", + "rand_core 0.6.4", +] + +[[package]] +name = "simba" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e82063457853d00243beda9952e910b82593e4b07ae9f721b9278a99a0d3d5c" +dependencies = [ + "approx", + "num-complex", + "num-traits", + "paste", +] + +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "snap" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" + +[[package]] +name = "snow" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ccba027ba85743e09d15c03296797cad56395089b832b48b5a5217880f57733" +dependencies = [ + "aes-gcm", + "blake2", + "chacha20poly1305", + "curve25519-dalek 4.0.0-rc.1", + "rand_core 0.6.4", + "ring", + "rustc_version 0.4.0", + "sha2 0.10.7", + "subtle", +] + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "soketto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" +dependencies = [ + "base64 0.13.1", + "bytes", + "flate2", + "futures", + "httparse", + "log", + "rand 0.8.5", + "sha-1", +] + +[[package]] +name = "sp-api" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec", + "sp-api-proc-macro", + "sp-core", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", + "sp-version", + "thiserror", +] + +[[package]] +name = "sp-api-proc-macro" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "blake2", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sp-application-crypto" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-std", +] + +[[package]] +name = "sp-arithmetic" +version = "5.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "integer-sqrt", + "num-traits", + "parity-scale-codec", + "scale-info", + "serde", + "sp-debug-derive", + "sp-std", + "static_assertions", +] + +[[package]] +name = "sp-authority-discovery" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-authorship" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "parity-scale-codec", + "sp-inherents", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-block-builder" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "sp-api", + "sp-inherents", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-blockchain" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "log", + "lru", + "parity-scale-codec", + "parking_lot 0.12.1", + "sp-api", + "sp-consensus", + "sp-database", + "sp-runtime", + "sp-state-machine", + "thiserror", +] + +[[package]] +name = "sp-consensus" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-version", + "thiserror", +] + +[[package]] +name = "sp-consensus-babe" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "merlin", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-consensus", + "sp-consensus-slots", + "sp-consensus-vrf", + "sp-core", + "sp-inherents", + "sp-keystore", + "sp-runtime", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "sp-consensus-slots" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-runtime", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "sp-consensus-vrf" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "schnorrkel", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-core" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes 4.2.0", + "base58", + "bitflags 1.3.2", + "blake2", + "byteorder", + "dyn-clonable", + "ed25519-zebra", + "futures", + "hash-db", + "hash256-std-hasher", + "impl-serde", + "lazy_static", + "libsecp256k1", + "log", + "merlin", + "num-traits", + "parity-scale-codec", + "parity-util-mem", + "parking_lot 0.12.1", + "primitive-types", + "rand 0.7.3", + "regex", + "scale-info", + "schnorrkel", + "secp256k1", + "secrecy", + "serde", + "sp-core-hashing", + "sp-debug-derive", + "sp-externalities", + "sp-runtime-interface", + "sp-std", + "sp-storage", + "ss58-registry", + "substrate-bip39", + "thiserror", + "tiny-bip39", + "wasmi", + "zeroize", +] + +[[package]] +name = "sp-core-hashing" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "blake2", + "byteorder", + "digest 0.10.7", + "sha2 0.10.7", + "sha3", + "sp-std", + "twox-hash", +] + +[[package]] +name = "sp-core-hashing-proc-macro" +version = "5.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro2", + "quote", + "sp-core-hashing", + "syn 1.0.109", +] + +[[package]] +name = "sp-database" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "kvdb", + "parking_lot 0.12.1", +] + +[[package]] +name = "sp-debug-derive" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sp-externalities" +version = "0.12.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "environmental", + "parity-scale-codec", + "sp-std", + "sp-storage", +] + +[[package]] +name = "sp-finality-grandpa" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "finality-grandpa", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-core", + "sp-keystore", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-inherents" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "impl-trait-for-tuples", + "parity-scale-codec", + "sp-core", + "sp-runtime", + "sp-std", + "thiserror", +] + +[[package]] +name = "sp-io" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "bytes", + "futures", + "hash-db", + "libsecp256k1", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "secp256k1", + "sp-core", + "sp-externalities", + "sp-keystore", + "sp-runtime-interface", + "sp-state-machine", + "sp-std", + "sp-tracing", + "sp-trie", + "sp-wasm-interface", + "tracing", + "tracing-core", +] + +[[package]] +name = "sp-keyring" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "lazy_static", + "sp-core", + "sp-runtime", + "strum", +] + +[[package]] +name = "sp-keystore" +version = "0.12.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "futures", + "merlin", + "parity-scale-codec", + "parking_lot 0.12.1", + "schnorrkel", + "serde", + "sp-core", + "sp-externalities", + "thiserror", +] + +[[package]] +name = "sp-maybe-compressed-blob" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "thiserror", + "zstd", +] + +[[package]] +name = "sp-npos-elections" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-offchain" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "sp-api", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "sp-panic-handler" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "backtrace", + "lazy_static", + "regex", +] + +[[package]] +name = "sp-rpc" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "rustc-hash", + "serde", + "sp-core", +] + +[[package]] +name = "sp-runtime" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "either", + "hash256-std-hasher", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "parity-util-mem", + "paste", + "rand 0.7.3", + "scale-info", + "serde", + "sp-application-crypto", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-std", + "sp-weights", +] + +[[package]] +name = "sp-runtime-interface" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec", + "primitive-types", + "sp-externalities", + "sp-runtime-interface-proc-macro", + "sp-std", + "sp-storage", + "sp-tracing", + "sp-wasm-interface", + "static_assertions", +] + +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "5.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "Inflector", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sp-sandbox" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "log", + "parity-scale-codec", + "sp-core", + "sp-io", + "sp-std", + "sp-wasm-interface", + "wasmi", +] + +[[package]] +name = "sp-session" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "sp-staking" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-state-machine" +version = "0.12.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "hash-db", + "log", + "num-traits", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.7.3", + "smallvec", + "sp-core", + "sp-externalities", + "sp-panic-handler", + "sp-std", + "sp-trie", + "thiserror", + "tracing", + "trie-root", +] + +[[package]] +name = "sp-std" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" + +[[package]] +name = "sp-storage" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "impl-serde", + "parity-scale-codec", + "ref-cast", + "serde", + "sp-debug-derive", + "sp-std", +] + +[[package]] +name = "sp-tasks" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "log", + "sp-core", + "sp-externalities", + "sp-io", + "sp-runtime-interface", + "sp-std", +] + +[[package]] +name = "sp-timestamp" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "futures-timer", + "log", + "parity-scale-codec", + "sp-api", + "sp-inherents", + "sp-runtime", + "sp-std", + "thiserror", +] + +[[package]] +name = "sp-tracing" +version = "5.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "sp-std", + "tracing", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "sp-transaction-pool" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "sp-api", + "sp-runtime", +] + +[[package]] +name = "sp-transaction-storage-proof" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "async-trait", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-std", + "sp-trie", +] + +[[package]] +name = "sp-trie" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "ahash", + "hash-db", + "hashbrown", + "lazy_static", + "lru", + "memory-db", + "nohash-hasher", + "parity-scale-codec", + "parking_lot 0.12.1", + "scale-info", + "sp-core", + "sp-std", + "thiserror", + "tracing", + "trie-db", + "trie-root", +] + +[[package]] +name = "sp-version" +version = "5.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "impl-serde", + "parity-scale-codec", + "parity-wasm 0.45.0", + "scale-info", + "serde", + "sp-core-hashing-proc-macro", + "sp-runtime", + "sp-std", + "sp-version-proc-macro", + "thiserror", +] + +[[package]] +name = "sp-version-proc-macro" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "parity-scale-codec", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sp-wasm-interface" +version = "6.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "sp-std", + "wasmi", + "wasmtime", +] + +[[package]] +name = "sp-weights" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "serde", + "smallvec", + "sp-arithmetic", + "sp-core", + "sp-debug-derive", + "sp-std", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spki" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "ss58-registry" +version = "1.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc443bad666016e012538782d9e3006213a7db43e9fb1dda91657dc06a6fa08" +dependencies = [ + "Inflector", + "num-format", + "proc-macro2", + "quote", + "serde", + "serde_json 1.0.103", + "unicode-xid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "static_init" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2a1c578e98c1c16fc3b8ec1328f7659a500737d7a0c6d625e73e830ff9c1f6" +dependencies = [ + "bitflags 1.3.2", + "cfg_aliases", + "libc", + "parking_lot 0.11.2", + "parking_lot_core 0.8.6", + "static_init_macro", + "winapi", +] + +[[package]] +name = "static_init_macro" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a2595fc3aa78f2d0e45dd425b22282dd863273761cc77780914b2cf3003acf" +dependencies = [ + "cfg_aliases", + "memchr", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "statrs" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05bdbb8e4e78216a85785a85d3ec3183144f98d0097b9281802c019bb07a6f05" +dependencies = [ + "approx", + "lazy_static", + "nalgebra", + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", +] + +[[package]] +name = "substrate-bip39" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49eee6965196b32f882dd2ee85a92b1dbead41b04e53907f269de3b0dc04733c" +dependencies = [ + "hmac 0.11.0", + "pbkdf2 0.8.0", + "schnorrkel", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "substrate-build-script-utils" +version = "3.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "platforms 2.0.0", +] + +[[package]] +name = "substrate-frame-rpc-system" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-system-rpc-runtime-api", + "futures", + "jsonrpsee", + "log", + "parity-scale-codec", + "sc-client-api", + "sc-rpc-api", + "sc-transaction-pool-api", + "serde_json 1.0.103", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "substrate-prometheus-endpoint" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures-util", + "hyper", + "log", + "prometheus", + "thiserror", + "tokio", +] + +[[package]] +name = "substrate-state-trie-migration-rpc" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "jsonrpsee", + "log", + "parity-scale-codec", + "sc-client-api", + "sc-rpc-api", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", + "trie-db", +] + +[[package]] +name = "substrate-test-utils" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "futures", + "substrate-test-utils-derive", + "tokio", +] + +[[package]] +name = "substrate-test-utils-derive" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "substrate-wasm-builder" +version = "5.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "ansi_term 0.12.1", + "build-helper", + "cargo_metadata", + "filetime", + "sp-maybe-compressed-blob", + "strum", + "tempfile", + "toml", + "walkdir", + "wasm-gc-api", +] + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "target-lexicon" +version = "0.12.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8e77cb757a61f51b947ec4a7e3646efd825b73561db1c232a8ccb639e611a0" + +[[package]] +name = "tempfile" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +dependencies = [ + "autocfg", + "cfg-if", + "fastrand", + "redox_syscall 0.3.5", + "rustix 0.37.23", + "windows-sys 0.48.0", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "thiserror" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tikv-jemalloc-sys" +version = "0.4.3+5.2.1-patched.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" +dependencies = [ + "cc", + "fs_extra", + "libc", +] + +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "tiny-bip39" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d" +dependencies = [ + "anyhow", + "hmac 0.8.1", + "once_cell", + "pbkdf2 0.4.0", + "rand 0.7.3", + "rustc-hash", + "sha2 0.9.9", + "thiserror", + "unicode-normalization", + "wasm-bindgen", + "zeroize", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +dependencies = [ + "autocfg", + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot 0.12.1", + "pin-project-lite 0.2.10", + "signal-hook-registry", + "socket2 0.4.9", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-stream" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +dependencies = [ + "futures-core", + "pin-project-lite 0.2.10", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +dependencies = [ + "bytes", + "futures-core", + "futures-io", + "futures-sink", + "pin-project-lite 0.2.10", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite 0.2.10", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "ansi_term 0.12.1", + "chrono", + "lazy_static", + "matchers", + "parking_lot 0.11.2", + "regex", + "serde", + "serde_json 1.0.103", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "trie-db" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "004e1e8f92535694b4cb1444dc5a8073ecf0815e3357f729638b9f8fc4062908" +dependencies = [ + "hash-db", + "hashbrown", + "log", + "rustc-hex", + "smallvec", +] + +[[package]] +name = "trie-root" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a36c5ca3911ed3c9a5416ee6c679042064b93fc637ded67e25f92e68d783891" +dependencies = [ + "hash-db", +] + +[[package]] +name = "trust-dns-proto" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.2.3", + "ipnet", + "lazy_static", + "log", + "rand 0.8.5", + "smallvec", + "thiserror", + "tinyvec", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558" +dependencies = [ + "cfg-if", + "futures-util", + "ipconfig", + "lazy_static", + "log", + "lru-cache", + "parking_lot 0.12.1", + "resolv-conf", + "smallvec", + "thiserror", + "trust-dns-proto", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "try-runtime-cli" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "clap", + "frame-try-runtime", + "jsonrpsee", + "log", + "parity-scale-codec", + "remote-externalities", + "sc-chain-spec", + "sc-cli", + "sc-executor", + "sc-service", + "serde", + "sp-core", + "sp-externalities", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-state-machine", + "sp-version", + "zstd", +] + +[[package]] +name = "tt-call" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f195fd851901624eee5a58c4bb2b4f06399148fcd0ed336e6f1cb60a9881df" + +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "digest 0.10.7", + "rand 0.8.5", + "static_assertions", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "universal-hash" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +dependencies = [ + "generic-array 0.14.7", + "subtle", +] + +[[package]] +name = "unsigned-varint" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" +dependencies = [ + "asynchronous-codec", + "bytes", + "futures-io", + "futures-util", +] + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +dependencies = [ + "form_urlencoded", + "idna 0.4.0", + "percent-encoding", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "value-bag" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92ccd67fb88503048c01b59152a04effd0782d035a83a6d256ce6085f08f4a3" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[package]] +name = "walkdir" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.26", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "wasm-gc-api" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0c32691b6c7e6c14e7f8fd55361a9088b507aa49620fcd06c09b3a1082186b9" +dependencies = [ + "log", + "parity-wasm 0.32.0", + "rustc-demangle", +] + +[[package]] +name = "wasm-instrument" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa1dafb3e60065305741e83db35c6c2584bb3725b692b5b66148a38d72ace6cd" +dependencies = [ + "parity-wasm 0.45.0", +] + +[[package]] +name = "wasm-timer" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" +dependencies = [ + "futures", + "js-sys", + "parking_lot 0.11.2", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "wasmi" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06c326c93fbf86419608361a2c925a31754cf109da1b8b55737070b4d6669422" +dependencies = [ + "parity-wasm 0.45.0", + "wasmi-validation", + "wasmi_core", +] + +[[package]] +name = "wasmi-validation" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ff416ad1ff0c42e5a926ed5d5fab74c0f098749aa0ad8b2a34b982ce0e867b" +dependencies = [ + "parity-wasm 0.45.0", +] + +[[package]] +name = "wasmi_core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d20cb3c59b788653d99541c646c561c9dd26506f25c0cebfe810659c54c6d7" +dependencies = [ + "downcast-rs", + "libm 0.2.7", + "memory_units", + "num-rational 0.4.1", + "num-traits", +] + +[[package]] +name = "wasmparser" +version = "0.89.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5d3e08b13876f96dd55608d03cd4883a0545884932d5adf11925876c96daef" +dependencies = [ + "indexmap", +] + +[[package]] +name = "wasmtime" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad5af6ba38311282f2a21670d96e78266e8c8e2f38cbcd52c254df6ccbc7731" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "indexmap", + "libc", + "log", + "object 0.29.0", + "once_cell", + "paste", + "psm", + "rayon", + "serde", + "target-lexicon", + "wasmparser", + "wasmtime-cache", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit", + "wasmtime-runtime", + "windows-sys 0.36.1", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45de63ddfc8b9223d1adc8f7b2ee5f35d1f6d112833934ad7ea66e4f4339e597" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-cache" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcd849399d17d2270141cfe47fa0d91ee52d5f8ea9b98cf7ddde0d53e5f79882" +dependencies = [ + "anyhow", + "base64 0.13.1", + "bincode", + "directories-next", + "file-per-thread-logger", + "log", + "rustix 0.35.14", + "serde", + "sha2 0.9.9", + "toml", + "windows-sys 0.36.1", + "zstd", +] + +[[package]] +name = "wasmtime-cranelift" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd91339b742ff20bfed4532a27b73c86b5bcbfedd6bea2dcdf2d64471e1b5c6" +dependencies = [ + "anyhow", + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli 0.26.2", + "log", + "object 0.29.0", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-environ", +] + +[[package]] +name = "wasmtime-environ" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebb881c61f4f627b5d45c54e629724974f8a8890d455bcbe634330cc27309644" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli 0.26.2", + "indexmap", + "log", + "object 0.29.0", + "serde", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1985c628011fe26adf5e23a5301bdc79b245e0e338f14bb58b39e4e25e4d8681" +dependencies = [ + "addr2line 0.17.0", + "anyhow", + "bincode", + "cfg-if", + "cpp_demangle", + "gimli 0.26.2", + "log", + "object 0.29.0", + "rustc-demangle", + "rustix 0.35.14", + "serde", + "target-lexicon", + "thiserror", + "wasmtime-environ", + "wasmtime-jit-debug", + "wasmtime-runtime", + "windows-sys 0.36.1", +] + +[[package]] +name = "wasmtime-jit-debug" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f671b588486f5ccec8c5a3dba6b4c07eac2e66ab8c60e6f4e53717c77f709731" +dependencies = [ + "object 0.29.0", + "once_cell", + "rustix 0.35.14", +] + +[[package]] +name = "wasmtime-runtime" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8f92ad4b61736339c29361da85769ebc200f184361959d1792832e592a1afd" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "indexmap", + "libc", + "log", + "mach", + "memfd", + "memoffset 0.6.5", + "paste", + "rand 0.8.5", + "rustix 0.35.14", + "thiserror", + "wasmtime-asm-macros", + "wasmtime-environ", + "wasmtime-jit-debug", + "windows-sys 0.36.1", +] + +[[package]] +name = "wasmtime-types" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d23d61cb4c46e837b431196dd06abb11731541021916d03476a178b54dc07aeb" +dependencies = [ + "cranelift-entity", + "serde", + "thiserror", + "wasmparser", +] + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + +[[package]] +name = "which" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +dependencies = [ + "either", + "libc", + "once_cell", +] + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45296b64204227616fdbf2614cefa4c236b98ee64dfaaaa435207ed99fe7829f" +dependencies = [ + "windows_aarch64_msvc 0.34.0", + "windows_i686_gnu 0.34.0", + "windows_i686_msvc 0.34.0", + "windows_x86_64_gnu 0.34.0", + "windows_x86_64_msvc 0.34.0", +] + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "x25519-dalek" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" +dependencies = [ + "curve25519-dalek 3.2.0", + "rand_core 0.5.1", + "zeroize", +] + +[[package]] +name = "yamux" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d9ba232399af1783a58d8eb26f6b5006fbefe2dc9ef36bd283324792d03ea5" +dependencies = [ + "futures", + "log", + "nohash-hasher", + "parking_lot 0.12.1", + "rand 0.8.5", + "static_assertions", +] + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.8+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +dependencies = [ + "cc", + "libc", + "pkg-config", +] diff --git a/pallets/ddc-accounts/Cargo.toml b/pallets/ddc-accounts/Cargo.toml index 4d5b3aa30..869e758e6 100644 --- a/pallets/ddc-accounts/Cargo.toml +++ b/pallets/ddc-accounts/Cargo.toml @@ -5,17 +5,17 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } [dev-dependencies] -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 7672fbfbd..886e6cfa6 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -8,31 +8,31 @@ alt_serde = { version = "1", default-features = false, features = ["derive"] } array-bytes = "6.0.0" base64 = { version = "0.21.0", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } lite-json = { version = "0.2.0", default-features = false } log = { version = "0.4.17", default-features = false } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-accounts = { version = "0.1.0", default-features = false, path = "../ddc-accounts" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] From f7a4edadfd121954d47a427e7a5c60afecff6698 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 17 Jul 2023 16:49:45 +0600 Subject: [PATCH 205/544] Fix `RuntimeCall` and `RuntimeEvent` types --- pallets/ddc-accounts/src/lib.rs | 2 +- pallets/ddc-validator/src/lib.rs | 4 ++-- runtime/cere-dev/src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 1b5e4156a..1d8984986 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -163,7 +163,7 @@ pub mod pallet { #[pallet::constant] type PalletId: Get; type Currency: LockableCurrency; - type Event: From> + IsType<::Event>; + type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Number of eras that staked funds must remain bonded for. #[pallet::constant] type BondingDuration: Get; diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 37c6aaa94..bf2097933 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -177,14 +177,14 @@ pub mod pallet { as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, { /// The overarching event type. - type Event: From> + IsType<::Event>; + type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Something that provides randomness in the runtime. Required by the tasks assignment /// procedure. type Randomness: Randomness; /// A dispatchable call. - type Call: From>; + type RuntimeCall: From>; type AuthorityId: AppCrypto; type TimeProvider: UnixTime; diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 9e9b1b85b..25b80213d 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1344,8 +1344,8 @@ parameter_types! { impl pallet_ddc_accounts::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; - type Event = Event; type PalletId = Ddc_Accounts_Pallet_Id; + type RuntimeEvent = RuntimeEvent; type TimeProvider = pallet_timestamp::Pallet; } @@ -1357,9 +1357,9 @@ parameter_types! { impl pallet_ddc_validator::Config for Runtime { type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; - type Event = Event; type Randomness = RandomnessCollectiveFlip; - type Call = Call; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; type TimeProvider = pallet_timestamp::Pallet; type ValidationThreshold = ValidationThreshold; From be7da1bf6581a890ad23b479f7ff56eff58bd834 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 19 Jul 2023 10:18:12 +0200 Subject: [PATCH 206/544] set OCW keys as assignees for validators & fix the bug which let to empty reward points being submitted --- pallets/ddc-validator/src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 8d55c983e..2f314cc76 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -531,7 +531,8 @@ pub mod pallet { } fn assign(quorum_size: usize, era: EraIndex) { - let validators: Vec = >::iter_keys().collect(); + let validators: Vec = OffchainWorkerKeys::::iter_values().collect(); + log::info!("current validators: {:?}", validators); let edges: Vec = >::iter_keys().collect(); @@ -776,10 +777,12 @@ pub mod pallet { let signer = Self::get_signer().unwrap(); // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { - era: current_era - 1, - stakers_points: cdn_nodes_reward_points.clone(), - }); + if cdn_nodes_reward_points.len() > 0 { + let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { + era: current_era - 1, + stakers_points: cdn_nodes_reward_points.clone(), + }); + } } } } From 2ed0114886b869946c1a1604f53a75e13ec507c3 Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Wed, 19 Jul 2023 21:03:25 +0200 Subject: [PATCH 207/544] Caching support within docker cargo build and upload to the new accounts (#66) * Cache cargo builds * Correct accounts --------- Co-authored-by: Oleg Yankovich <33641729+krolol@users.noreply.github.com> --- .dockerignore | 4 ++ .github/workflows/dev.yml | 80 +++++++++++++++++++++++++++++++----- .github/workflows/prod.yml | 79 ++++++++++++++++++++++++++++++++++++ .github/workflows/stage.yml | 81 +++++++++++++++++++++++++++++++++++++ Dockerfile | 44 ++++++++++++++++---- 5 files changed, 271 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/prod.yml create mode 100644 .github/workflows/stage.yml diff --git a/.dockerignore b/.dockerignore index 9830e0db3..b73ef56af 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,7 @@ **target* doc Dockerfile* + +!target/release/cere/ +!target/release/wbuild/cere-runtime/ +!target/release/wbuild/cere-dev-runtime/ diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 440d32269..08aae3432 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -2,18 +2,78 @@ name: Release to dev on: push: branches: - - dev + - 'dev' workflow_dispatch: -permissions: - id-token: write - contents: read +env: + PROFILE: release jobs: build: - uses: Cerebellum-Network/reusable-workflows/.github/workflows/deploy-to-ecr.yaml@master - with: - environment: dev - aws_account_id: ${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }} - repository: pos-network-node - secrets: inherit + runs-on: ubuntu-latest + concurrency: dev + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github + role-session-name: ${{ github.event.repository.name }} + aws-region: us-west-2 + + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV + echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + + tags: | + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest + +# - name: Upload cere-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm +# +# - name: Upload cere-dev-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml new file mode 100644 index 000000000..f502cfe06 --- /dev/null +++ b/.github/workflows/prod.yml @@ -0,0 +1,79 @@ +name: Release to production +on: + push: + branches: + - 'master' + workflow_dispatch: + +env: + PROFILE: release + +jobs: + build: + runs-on: ubuntu-latest + concurrency: prod + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github + role-session-name: ${{ github.event.repository.name }} + aws-region: us-west-2 + + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV + echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + + tags: | + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:prod-latest + +# - name: Upload cere-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm +# +# - name: Upload cere-dev-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 000000000..7a5995ff9 --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,81 @@ +name: Release to stage +on: + push: + branches: + - 'feature/**' + - 'release/**' + - 'hotfix/**' + workflow_dispatch: + +env: + PROFILE: release + +jobs: + build: + runs-on: ubuntu-latest + concurrency: stage + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github + role-session-name: ${{ github.event.repository.name }} + aws-region: us-west-2 + + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV + echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + + tags: | + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:stage-latest + +# - name: Upload cere-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm +# +# - name: Upload cere-dev-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm diff --git a/Dockerfile b/Dockerfile index 55ede5447..e977f7457 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,53 @@ -FROM phusion/baseimage:0.11 as builder +FROM phusion/baseimage:jammy-1.0.1 as builder LABEL maintainer="team@cere.network" LABEL description="This is the build stage to create the binary." ARG PROFILE=release WORKDIR /cerenetwork COPY . /cerenetwork -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y cmake pkg-config libssl-dev git clang unzip +RUN apt-get -qq update && \ + apt-get -qq install -y \ + clang \ + cmake \ + git \ + libpq-dev \ + libssl-dev \ + pkg-config \ + unzip \ + wget + +# Configure sccache +ENV SCCACHE_VERSION=0.5.4 +RUN wget -q https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz \ + -O - | tar -xz \ + && mv sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache /usr/local/bin/sccache \ + && chmod +x /usr/local/bin/sccache \ + && rm -rf sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl +ENV RUSTC_WRAPPER=/usr/local/bin/sccache # Installation script is taken from https://grpc.io/docs/protoc-installation/ ENV PROTOC_VERSION=3.15.8 RUN PB_REL="https://github.com/protocolbuffers/protobuf/releases" && \ - curl -LO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ + curl -sLO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ mkdir -p /usr/local/protoc && \ unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local/protoc && \ chmod +x /usr/local/protoc/bin/protoc && \ ln -s /usr/local/protoc/bin/protoc /usr/local/bin +ARG AWS_ACCESS_KEY_ID +ARG AWS_SECRET_ACCESS_KEY +ARG AWS_SESSION_TOKEN +ARG SCCACHE_REGION=us-west-2 +ARG SCCACHE_BUCKET=cere-blockchain-sccache +ENV \ + AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ + AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ + AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \ + AWS_REGION=$SCCACHE_REGION \ + SCCACHE_REGION=$SCCACHE_REGION \ + SCCACHE_BUCKET=$SCCACHE_BUCKET \ + SCCACHE_S3_USE_SSL=true + RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ @@ -29,8 +59,8 @@ LABEL maintainer="team@cere.network" LABEL description="This is the optimization to create a small image." ARG PROFILE=release COPY --from=builder /cerenetwork/target/$PROFILE/cere /usr/local/bin -COPY --from=builder /cerenetwork/target/release/wbuild/cere-runtime /home/cere/cere-runtime-artifacts -COPY --from=builder /cerenetwork/target/release/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-runtime /home/cere/cere-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts RUN mv /usr/share/ca* /tmp && \ rm -rf /usr/share/* && \ From 57c15b1041a0bec13e49a0c51f80e6a00add1b86 Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Wed, 19 Jul 2023 21:04:44 +0200 Subject: [PATCH 208/544] cleanup old ECR deployment --- .../workflows/build-and-push-docker-image.yml | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 .github/workflows/build-and-push-docker-image.yml diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml deleted file mode 100644 index c904d266a..000000000 --- a/.github/workflows/build-and-push-docker-image.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Build and push image to ECR -on: - push: - branches: - - dev - - master - - 'feature/**' - - 'release/**' - - 'hotfix/**' -env: - ECR_REPOSITORY: pos-network-node -jobs: - build-and-push: - runs-on: [self-hosted, cere-network-xlarge-workers] - steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} - aws-region: us-west-2 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Build and push image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: | - image_id=$(docker build . -q -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA) - echo IMAGE_ID=$image_id >> $GITHUB_ENV - echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA" - docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA $ECR_REGISTRY/$ECR_REPOSITORY:latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest - - name: Copy wasm artifacts from the image - run: | - container_id=$(docker create ${{ env.IMAGE_ID }}) - cere_runtime_artifact_name=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm - echo CERE_RUNTIME_ARTIFACT_NAME=$cere_runtime_artifact_name >> $GITHUB_ENV - docker cp $container_id:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm ./$cere_runtime_artifact_name - cere_dev_runtime_artifact_name=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm - echo CERE_DEV_RUNTIME_ARTIFACT_NAME=$cere_dev_runtime_artifact_name >> $GITHUB_ENV - docker cp $container_id:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm ./$cere_dev_runtime_artifact_name - - name: Upload cere-runtime wasm artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ env.CERE_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_RUNTIME_ARTIFACT_NAME }} - - name: Upload cere-dev-runtime wasm artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} From 5bf32843bbc63a6d7ff7df30493328fcf0ac31a5 Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:48:36 +0200 Subject: [PATCH 209/544] Re-organize workflows --- .github/workflows/check.yml | 4 +-- .github/workflows/{prod.yml => ci.yml} | 45 ++++++++++++++++---------- .github/workflows/dev.yml | 2 +- .github/workflows/run-tests.yml | 37 --------------------- .github/workflows/stage.yml | 3 +- 5 files changed, 32 insertions(+), 59 deletions(-) rename .github/workflows/{prod.yml => ci.yml} (71%) delete mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4c8a60cc6..1e6a57960 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -4,9 +4,9 @@ name: Check Set-Up & Build on: # Triggers the workflow on push or pull request events but only for the master branch push: - branches: [ main ] + branches: [ master ] pull_request: - branches: [ main ] + branches: [ master ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/prod.yml b/.github/workflows/ci.yml similarity index 71% rename from .github/workflows/prod.yml rename to .github/workflows/ci.yml index f502cfe06..291568c36 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,17 @@ -name: Release to production +name: CI + on: - push: + pull_request: branches: - - 'master' - workflow_dispatch: + - dev + - master + - 'feature/**' + - 'release/**' + - 'hotfix/**' + types: + - opened + - synchronize + - edited env: PROFILE: release @@ -11,7 +19,7 @@ env: jobs: build: runs-on: ubuntu-latest - concurrency: prod + concurrency: dev permissions: contents: read id-token: write @@ -50,6 +58,19 @@ jobs: id: login-ecr uses: aws-actions/amazon-ecr-login@v1 + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.tests + push: false + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + - name: Build and push docker image to ECR uses: docker/build-push-action@v4 with: @@ -64,16 +85,6 @@ jobs: tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:prod-latest -# - name: Upload cere-runtime wasm artifact -# uses: actions/upload-artifact@v3 -# with: -# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm -# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm -# -# - name: Upload cere-dev-runtime wasm artifact -# uses: actions/upload-artifact@v3 -# with: -# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm -# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + + # TODO: paveltabalko to add e2e-tests simulations diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 08aae3432..2700be48b 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -64,7 +64,7 @@ jobs: tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-${{ github.sha }} # - name: Upload cere-runtime wasm artifact # uses: actions/upload-artifact@v3 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml deleted file mode 100644 index 98c7a6f3c..000000000 --- a/.github/workflows/run-tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Run tests -on: - pull_request: - branches: - - dev - - master - - 'feature/**' - - 'release/**' - - 'hotfix/**' - types: - - opened - - synchronize - - edited - -jobs: - run-tests: - runs-on: [self-hosted, cere-network-xlarge-workers] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Free space - run: df -h - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} - aws-region: us-west-2 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Run tests - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: docker build --build-arg ECR_REGISTRY=$ECR_REGISTRY -f Dockerfile.tests -t pos-network-node:test . - - name: Free space - run: df -h diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index 7a5995ff9..ef13e7d12 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -2,9 +2,9 @@ name: Release to stage on: push: branches: - - 'feature/**' - 'release/**' - 'hotfix/**' + - 'master' workflow_dispatch: env: @@ -66,7 +66,6 @@ jobs: tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:stage-latest # - name: Upload cere-runtime wasm artifact # uses: actions/upload-artifact@v3 From 2b60d6013c240b4be784973649980529b34a92cf Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:29:17 +0200 Subject: [PATCH 210/544] Deploy to dev --- .github/workflows/dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 2700be48b..c76149855 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -65,6 +65,7 @@ jobs: tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-${{ github.sha }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest # - name: Upload cere-runtime wasm artifact # uses: actions/upload-artifact@v3 From e00a93113267b573c77de217d5bae8dad2b1de26 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 20 Jul 2023 19:00:55 +0300 Subject: [PATCH 211/544] - add ci for triggering tests (#63) * - adjust file name yml to yaml * - add steps to trigger e2e tests --- .github/workflows/{check.yml => check.yaml} | 0 .github/workflows/ci.yaml | 58 ++++++++++++ .github/workflows/ci.yml | 90 ------------------- .github/workflows/{dev.yml => dev.yaml} | 49 +++++++--- ...=> publish-docker-image-to-dockerhub.yaml} | 0 .github/workflows/{stage.yml => stage.yaml} | 2 +- 6 files changed, 95 insertions(+), 104 deletions(-) rename .github/workflows/{check.yml => check.yaml} (100%) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/ci.yml rename .github/workflows/{dev.yml => dev.yaml} (58%) rename .github/workflows/{publish-docker-image-to-dockerhub.yml => publish-docker-image-to-dockerhub.yaml} (100%) rename .github/workflows/{stage.yml => stage.yaml} (98%) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yaml similarity index 100% rename from .github/workflows/check.yml rename to .github/workflows/check.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..969c0f124 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,58 @@ +name: CI + +on: + pull_request: + branches: + - dev + - master + - 'feature/**' + - 'release/**' + - 'hotfix/**' + types: + - opened + - synchronize + - edited + +env: + PROFILE: release + +jobs: + build: + runs-on: ubuntu-latest + concurrency: dev + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Configure AWS credentials ORG + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Login to Amazon ECR ORG + id: login-ecr-org + uses: aws-actions/amazon-ecr-login@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push docker image to ECR Docker + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.tests + push: false + build-args: | + "ECR_REGISTRY=${{ steps.login-ecr-org.outputs.registry }}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 291568c36..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: CI - -on: - pull_request: - branches: - - dev - - master - - 'feature/**' - - 'release/**' - - 'hotfix/**' - types: - - opened - - synchronize - - edited - -env: - PROFILE: release - -jobs: - build: - runs-on: ubuntu-latest - concurrency: dev - permissions: - contents: read - id-token: write - steps: - - uses: actions/checkout@v3 - - - name: Cache cargo registry - uses: actions/cache@v3 - continue-on-error: false - with: - path: | - ~/.cargo/registry - ~/.cargo/git - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo- - - - name: configure aws credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github - role-session-name: ${{ github.event.repository.name }} - aws-region: us-west-2 - - - name: Get short SHA - run: | - echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV - echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Build and push docker image to ECR - uses: docker/build-push-action@v4 - with: - context: . - file: Dockerfile.tests - push: false - build-args: | - "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" - "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" - "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" - "SCCACHE_REGION=us-west-2" - "SCCACHE_BUCKET=cere-blockchain-sccache" - - - name: Build and push docker image to ECR - uses: docker/build-push-action@v4 - with: - context: . - push: true - build-args: | - "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" - "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" - "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" - "SCCACHE_REGION=us-west-2" - "SCCACHE_BUCKET=cere-blockchain-sccache" - - tags: | - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} - - - # TODO: paveltabalko to add e2e-tests simulations diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yaml similarity index 58% rename from .github/workflows/dev.yml rename to .github/workflows/dev.yaml index c76149855..311ccb13c 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yaml @@ -63,18 +63,41 @@ jobs: "SCCACHE_BUCKET=cere-blockchain-sccache" tags: | - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-${{ github.sha }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest -# - name: Upload cere-runtime wasm artifact -# uses: actions/upload-artifact@v3 -# with: -# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm -# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm -# -# - name: Upload cere-dev-runtime wasm artifact -# uses: actions/upload-artifact@v3 -# with: -# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm -# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + # - name: Upload cere-runtime wasm artifact + # uses: actions/upload-artifact@v3 + # with: + # name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm + # path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm + # + # - name: Upload cere-dev-runtime wasm artifact + # uses: actions/upload-artifact@v3 + # with: + # name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm + # path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + + trigger-e2e-tests: + runs-on: ubuntu-latest + needs: build + steps: + - name: 'Trigger e2e DDC tests' + uses: convictional/trigger-workflow-and-wait@v1.6.5 + with: + owner: Cerebellum-Network + repo: ddc-api-e2e-simulations + github_token: ${{ secrets.GH_E2E_TOKEN }} + comment_github_token: ${{ secrets.GH_E2E_TOKEN }} + github_user: devops-cere + workflow_file_name: run-basic-ddc-tests.yml + client_payload: |- + { + "POS_NODE_VERSION": "${{ env.GITHUB_SHA }}" + } + ref: master + wait_interval: 30 + propagate_failure: true + trigger_workflow: true + wait_workflow: true + comment_downstream_url: ${{ github.event.pull_request.comments_url }} diff --git a/.github/workflows/publish-docker-image-to-dockerhub.yml b/.github/workflows/publish-docker-image-to-dockerhub.yaml similarity index 100% rename from .github/workflows/publish-docker-image-to-dockerhub.yml rename to .github/workflows/publish-docker-image-to-dockerhub.yaml diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yaml similarity index 98% rename from .github/workflows/stage.yml rename to .github/workflows/stage.yaml index ef13e7d12..ca7338fcd 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yaml @@ -65,7 +65,7 @@ jobs: "SCCACHE_BUCKET=cere-blockchain-sccache" tags: | - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} # - name: Upload cere-runtime wasm artifact # uses: actions/upload-artifact@v3 From e6b22cf0205ac912cbc34f7e41ac63eb5799261f Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 20 Jul 2023 18:34:36 +0200 Subject: [PATCH 212/544] update github workflows --- .../workflows/build-and-push-docker-image.yml | 55 ------------------- .github/workflows/check.yml | 11 +++- .github/workflows/run-tests.yml | 37 ------------- Dockerfile | 54 +++++++++++++++--- Dockerfile.tests | 12 +++- 5 files changed, 66 insertions(+), 103 deletions(-) delete mode 100644 .github/workflows/build-and-push-docker-image.yml delete mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml deleted file mode 100644 index c904d266a..000000000 --- a/.github/workflows/build-and-push-docker-image.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Build and push image to ECR -on: - push: - branches: - - dev - - master - - 'feature/**' - - 'release/**' - - 'hotfix/**' -env: - ECR_REPOSITORY: pos-network-node -jobs: - build-and-push: - runs-on: [self-hosted, cere-network-xlarge-workers] - steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} - aws-region: us-west-2 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Build and push image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: | - image_id=$(docker build . -q -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA) - echo IMAGE_ID=$image_id >> $GITHUB_ENV - echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA" - docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA $ECR_REGISTRY/$ECR_REPOSITORY:latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest - - name: Copy wasm artifacts from the image - run: | - container_id=$(docker create ${{ env.IMAGE_ID }}) - cere_runtime_artifact_name=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm - echo CERE_RUNTIME_ARTIFACT_NAME=$cere_runtime_artifact_name >> $GITHUB_ENV - docker cp $container_id:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm ./$cere_runtime_artifact_name - cere_dev_runtime_artifact_name=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm - echo CERE_DEV_RUNTIME_ARTIFACT_NAME=$cere_dev_runtime_artifact_name >> $GITHUB_ENV - docker cp $container_id:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm ./$cere_dev_runtime_artifact_name - - name: Upload cere-runtime wasm artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ env.CERE_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_RUNTIME_ARTIFACT_NAME }} - - name: Upload cere-dev-runtime wasm artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d441cd3f0..103b2152c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -4,9 +4,9 @@ name: Check Set-Up & Build on: # Triggers the workflow on push or pull request events but only for the master branch push: - branches: [ main ] + branches: [ master ] pull_request: - branches: [ main ] + branches: [ master ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -32,6 +32,11 @@ jobs: rustup default stable rustup update nightly rustup update stable + rustup component add rustfmt --toolchain nightly + + - name: Check Format + run: | + cargo +nightly fmt -- --check - name: Check Build run: | @@ -40,4 +45,4 @@ jobs: - name: Check Build for Benchmarking run: > pushd node && - cargo check --features=runtime-benchmarks --release + cargo check --features=runtime-benchmarks --release \ No newline at end of file diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml deleted file mode 100644 index 98c7a6f3c..000000000 --- a/.github/workflows/run-tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Run tests -on: - pull_request: - branches: - - dev - - master - - 'feature/**' - - 'release/**' - - 'hotfix/**' - types: - - opened - - synchronize - - edited - -jobs: - run-tests: - runs-on: [self-hosted, cere-network-xlarge-workers] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Free space - run: df -h - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} - aws-region: us-west-2 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Run tests - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: docker build --build-arg ECR_REGISTRY=$ECR_REGISTRY -f Dockerfile.tests -t pos-network-node:test . - - name: Free space - run: df -h diff --git a/Dockerfile b/Dockerfile index 5168b649c..ef43ae342 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,53 @@ -FROM phusion/baseimage:0.11 as builder +FROM phusion/baseimage:jammy-1.0.1 as builder LABEL maintainer="team@cere.network" LABEL description="This is the build stage to create the binary." ARG PROFILE=release WORKDIR /cerenetwork COPY . /cerenetwork -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y cmake pkg-config libssl-dev git clang +RUN apt-get -qq update && \ + apt-get -qq install -y \ + clang \ + cmake \ + git \ + libpq-dev \ + libssl-dev \ + pkg-config \ + unzip \ + wget + +# Configure sccache +ENV SCCACHE_VERSION=0.5.4 +RUN wget -q https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz \ + -O - | tar -xz \ + && mv sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache /usr/local/bin/sccache \ + && chmod +x /usr/local/bin/sccache \ + && rm -rf sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl +ENV RUSTC_WRAPPER=/usr/local/bin/sccache + +# Installation script is taken from https://grpc.io/docs/protoc-installation/ +ENV PROTOC_VERSION=3.15.8 +RUN PB_REL="https://github.com/protocolbuffers/protobuf/releases" && \ + curl -sLO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ + mkdir -p /usr/local/protoc && \ + unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local/protoc && \ + chmod +x /usr/local/protoc/bin/protoc && \ + ln -s /usr/local/protoc/bin/protoc /usr/local/bin + +ARG AWS_ACCESS_KEY_ID +ARG AWS_SECRET_ACCESS_KEY +ARG AWS_SESSION_TOKEN +ARG SCCACHE_REGION=us-west-2 +ARG SCCACHE_BUCKET=cere-blockchain-sccache +ENV \ + AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ + AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ + AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \ + AWS_REGION=$SCCACHE_REGION \ + SCCACHE_REGION=$SCCACHE_REGION \ + SCCACHE_BUCKET=$SCCACHE_BUCKET \ + SCCACHE_S3_USE_SSL=true + RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ @@ -19,8 +59,8 @@ LABEL maintainer="team@cere.network" LABEL description="This is the optimization to create a small image." ARG PROFILE=release COPY --from=builder /cerenetwork/target/$PROFILE/cere /usr/local/bin -COPY --from=builder /cerenetwork/target/release/wbuild/cere-runtime /home/cere/cere-runtime-artifacts -COPY --from=builder /cerenetwork/target/release/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-runtime /home/cere/cere-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts RUN mv /usr/share/ca* /tmp && \ rm -rf /usr/share/* && \ @@ -37,4 +77,4 @@ USER cerenetwork EXPOSE 30333 9933 9944 9615 VOLUME ["/data"] -CMD ["/usr/local/bin/cere"] +CMD ["/usr/local/bin/cere"] \ No newline at end of file diff --git a/Dockerfile.tests b/Dockerfile.tests index 56bba2fed..23c25292b 100644 --- a/Dockerfile.tests +++ b/Dockerfile.tests @@ -17,7 +17,17 @@ COPY --from=ddc-smart-contract /ddc-smart-contract/artifacts/metadata.json /cere RUN apt-get update && \ apt-get upgrade -y && \ - apt-get install -y cmake pkg-config libssl-dev git clang + apt-get install -y cmake pkg-config libssl-dev git clang unzip + +# Installation script is taken from https://grpc.io/docs/protoc-installation/ +ENV PROTOC_VERSION=3.15.8 +RUN PB_REL="https://github.com/protocolbuffers/protobuf/releases" && \ + curl -LO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ + mkdir -p /usr/local/protoc && \ + unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local/protoc && \ + chmod +x /usr/local/protoc/bin/protoc && \ + ln -s /usr/local/protoc/bin/protoc /usr/local/bin + RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ From 420d29629548664d17b2c42179f3f555b318cba3 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 20 Jul 2023 18:35:04 +0200 Subject: [PATCH 213/544] new workflows --- .github/workflows/ci.yml | 58 ++++++++++++++++++++ .github/workflows/dev.yml | 103 ++++++++++++++++++++++++++++++++++++ .github/workflows/stage.yml | 80 ++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/stage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..dc23ea450 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +name: CI + +on: + pull_request: + branches: + - dev + - master + - 'feature/**' + - 'release/**' + - 'hotfix/**' + types: + - opened + - synchronize + - edited + +env: + PROFILE: release + +jobs: + build: + runs-on: ubuntu-latest + concurrency: dev + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Configure AWS credentials ORG + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Login to Amazon ECR ORG + id: login-ecr-org + uses: aws-actions/amazon-ecr-login@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push docker image to ECR Docker + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.tests + push: false + build-args: | + "ECR_REGISTRY=${{ steps.login-ecr-org.outputs.registry }}" \ No newline at end of file diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 000000000..c9ad21887 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,103 @@ +name: Release to dev +on: + push: + branches: + - 'dev' + workflow_dispatch: + +env: + PROFILE: release + +jobs: + build: + runs-on: ubuntu-latest + concurrency: dev + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github + role-session-name: ${{ github.event.repository.name }} + aws-region: us-west-2 + + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV + echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + + tags: | + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest + + # - name: Upload cere-runtime wasm artifact + # uses: actions/upload-artifact@v3 + # with: + # name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm + # path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm + # + # - name: Upload cere-dev-runtime wasm artifact + # uses: actions/upload-artifact@v3 + # with: + # name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm + # path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + + trigger-e2e-tests: + runs-on: ubuntu-latest + needs: build + steps: + - name: 'Trigger e2e DDC tests' + uses: convictional/trigger-workflow-and-wait@v1.6.5 + with: + owner: Cerebellum-Network + repo: ddc-api-e2e-simulations + github_token: ${{ secrets.GH_E2E_TOKEN }} + comment_github_token: ${{ secrets.GH_E2E_TOKEN }} + github_user: devops-cere + workflow_file_name: run-basic-ddc-tests.yml + client_payload: |- + { + "POS_NODE_VERSION": "${{ env.GITHUB_SHA }}" + } + ref: master + wait_interval: 30 + propagate_failure: true + trigger_workflow: true + wait_workflow: true + comment_downstream_url: ${{ github.event.pull_request.comments_url }} \ No newline at end of file diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 000000000..ca7338fcd --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,80 @@ +name: Release to stage +on: + push: + branches: + - 'release/**' + - 'hotfix/**' + - 'master' + workflow_dispatch: + +env: + PROFILE: release + +jobs: + build: + runs-on: ubuntu-latest + concurrency: stage + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github + role-session-name: ${{ github.event.repository.name }} + aws-region: us-west-2 + + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV + echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + + tags: | + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} + +# - name: Upload cere-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm +# +# - name: Upload cere-dev-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm From 97196aaff1def1aa1538f8599e58acb05fe27654 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Wed, 12 Jul 2023 02:07:52 +0200 Subject: [PATCH 214/544] test(ddc-validator): mock dac requests for tests are prepared --- pallets/ddc-staking/src/mock.rs | 2 + pallets/ddc-validator/src/lib.rs | 5 +- pallets/ddc-validator/src/mock.rs | 83 +++++++++++++++- .../mock_data/aggregation:nodes:era:edge.json | 1 + ...:6e86ac08-4af9-4353-9fec-0f3e563661d6.json | 1 + ...:7af575b7-9a83-40b6-88a7-19549b9bbc38.json | 1 + ...:80a62530-fd76-40b5-bc53-dd82365e89ce.json | 1 + ...:84640a53-fc1f-4ac5-921c-6695056840bc.json | 1 + ...:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json | 1 + .../src/mock_data/fcall:save:validation.json | 1 + .../src/mock_data/shared:nodes:era.json | 1 + pallets/ddc-validator/src/tests.rs | 98 ++++++++++++++++++- 12 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json create mode 100644 pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json create mode 100644 pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json create mode 100644 pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json create mode 100644 pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json create mode 100644 pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json create mode 100644 pallets/ddc-validator/src/mock_data/fcall:save:validation.json create mode 100644 pallets/ddc-validator/src/mock_data/shared:nodes:era.json diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index dea8eb524..c82675b73 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -95,6 +95,7 @@ parameter_types! { pub const DefaultEdgeChillDelay: EraIndex = 1; pub const DefaultStorageBondSize: Balance = 100; pub const DefaultStorageChillDelay: EraIndex = 1; + pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); } impl crate::pallet::Config for Test { @@ -107,6 +108,7 @@ impl crate::pallet::Config for Test { type RuntimeEvent = RuntimeEvent; type UnixTime = Timestamp; type WeightInfo = (); + type StakersPayoutSource = DdcAccountsPalletId; } pub(crate) type DdcStakingCall = crate::Call; diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index bf2097933..4e992c9a2 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -261,7 +261,6 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); - // Produce an assignment for the next era if it's not produced yet. match Self::last_managed_era() { Some(last_managed_era) if era < last_managed_era => (), @@ -495,6 +494,10 @@ pub mod pallet { } fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool { + if bytes_sent == bytes_received { + return true; + } + let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); return if percentage_difference > 0.0 && diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 58f2cc4bf..83cef7e8b 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -10,6 +10,7 @@ use frame_system::{offchain::SendTransactionTypes, EnsureRoot}; use pallet_contracts as contracts; use pallet_session::ShouldEndSession; use sp_core::H256; +use sp_io::TestExternalities; use sp_runtime::{ curve, curve::PiecewiseLinear, @@ -317,7 +318,87 @@ impl pallet_balances::Config for Test { // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::default().build_storage::().unwrap().into() + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let _ = pallet_balances::GenesisConfig:: { + balances: vec![ + // edge controllers + (AccountId::from([0x2; 32]), 1000), + // storage controllers + (AccountId::from([0x4; 32]), 1000), + // edge stashes + (AccountId::from([0x1; 32]), 1000), + // storage stashes + (AccountId::from([0x3; 32]), 1000), + + // validators + // (AccountId::from([0x5; 32]), 10000), + (AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), 10000), + (AccountId::from([0x55; 32]), 10000), + + + (AccountId::from([0x6; 32]), 10000), + (AccountId::from([0x66; 32]), 10000), + + (AccountId::from([0x7; 32]), 10000), + (AccountId::from([0x77; 32]), 10000), + ], + } + .assimilate_storage(&mut storage); + + + let stakers = vec![ + ( + // AccountId::from([0x5; 32]), + AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), + AccountId::from([0x55; 32]), + 1000, + pallet_staking::StakerStatus::Validator + ), + + ( + AccountId::from([0x6; 32]), + AccountId::from([0x66; 32]), + 1000, + pallet_staking::StakerStatus::Validator + ), + + ( + AccountId::from([0x7; 32]), + AccountId::from([0x77; 32]), + 1000, + pallet_staking::StakerStatus::Validator + ) + ]; + + + let _ = pallet_staking::GenesisConfig:: { stakers, ..Default::default() } + .assimilate_storage(&mut storage); + + + let edges = vec![ + ( + AccountId::from([0x1; 32]), + AccountId::from([0x2; 32]), + 100, + 1 + ) + ]; + + let storages = vec![ + ( + AccountId::from([0x3; 32]), + AccountId::from([0x4; 32]), + 100, + 1, + ) + ]; + + let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } + .assimilate_storage(&mut storage); + + TestExternalities::new(storage) + } pub type Extrinsic = TestXt; diff --git a/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json b/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json new file mode 100644 index 000000000..7e497108f --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json @@ -0,0 +1 @@ +{"JSON.GET":"[{\"totalBytesSent\":4800,\"totalQueries\":0,\"totalReads\":30,\"totalReadsAcked\":30,\"totalQueriesAcked\":0,\"averageResponseTimeMs\":1.8852459016393444,\"totalBytesReceived\":4800,\"requestIds\":[\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"6e86ac08-4af9-4353-9fec-0f3e563661d6\",\"7af575b7-9a83-40b6-88a7-19549b9bbc38\"],\"totalWritesAcked\":30,\"averageResponseTimeMsSamples\":61,\"totalWrites\":30}]"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json b/pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json new file mode 100644 index 000000000..ea2cc9127 --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"6e86ac08-4af9-4353-9fec-0f3e563661d6\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"]},\"bucketId\":5,\"timestamp\":1688473910055,\"chunks\":{\"6e86ac08-4af9-4353-9fec-0f3e563661d6:bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\":{\"log\":{\"type\":2,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49760\",\"bytesSent\":160,\"timestamp\":1688473910055,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\",\"ack\":{\"userTimestamp\":1688473910058,\"nonce\":\"6VQF3U6m8lHhJVT/Wr+tpn7OrorcqpQg9hZS8vRoBoA=\",\"signature\":\"GilWqbctk1WvySNd5+EzWU/Df9B2RM2z9/3Jzfpian7PyH9ndvvxJDtKo1/cJdrj7r5gsSEqlwPxcKjj5RJNhg==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json b/pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json new file mode 100644 index 000000000..aa68e8423 --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"7af575b7-9a83-40b6-88a7-19549b9bbc38\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\"]},\"bucketId\":5,\"timestamp\":1688473910371,\"chunks\":{\"7af575b7-9a83-40b6-88a7-19549b9bbc38:bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49770\",\"bytesSent\":160,\"timestamp\":1688473910371,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\",\"ack\":{\"userTimestamp\":1688473910373,\"nonce\":\"TwKKd2NsDkjaV9yDPqqVPh1rcSlrkmdXSQXl+zojH8M=\",\"signature\":\"EvDRqBr8zoIzxykz6NrzrIsgjDlf/++RmH/9OdQqtBb0dO1y4o/snH4OoMlJMnXTDZX9R+umQPH90PH0WvVAig==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json b/pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json new file mode 100644 index 000000000..09e491b32 --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"]},\"bucketId\":5,\"timestamp\":1688473910041,\"chunks\":{\"80a62530-fd76-40b5-bc53-dd82365e89ce:bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49736\",\"bytesSent\":160,\"timestamp\":1688473910041,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\",\"ack\":{\"userTimestamp\":1688473910043,\"nonce\":\"VU1XCPjQxA4y6TnrOAy44QabS7nmmxAU8vyduqoLt9U=\",\"signature\":\"Us7//t0+y00oHhthPSjqphHJYwE1qgPQtBSdy5hZxUInKdQXTBX58VLQekoKMHtptQQggR1gPf9Pyy1enmXziQ==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json b/pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json new file mode 100644 index 000000000..9fc7d5ef8 --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"]},\"bucketId\":5,\"timestamp\":1688473909701,\"chunks\":{\"84640a53-fc1f-4ac5-921c-6695056840bc:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49690\",\"bytesSent\":160,\"timestamp\":1688473909701,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\",\"ack\":{\"userTimestamp\":1688473909709,\"nonce\":\"Gt7AFrznCPzgI/5q+tynLy2BKUooSGAkUCaGsF6AOMs=\",\"signature\":\"Gll6xIftbtP4JPB6miy3DLKMBDrKz05QSIBNJ3RqYi0Fg1wNJRFoSIqhOJDXDUB4NlrLQdl+HWrYRL20Hsx6iA==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json b/pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json new file mode 100644 index 000000000..4519ed651 --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"]},\"bucketId\":5,\"timestamp\":1688473909723,\"chunks\":{\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\":{\"log\":{\"type\":2,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49714\",\"bytesSent\":160,\"timestamp\":1688473909723,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\",\"ack\":{\"userTimestamp\":1688473909726,\"nonce\":\"2mdA3QVq02ME77vnqGjBNQqTRhM5gHjVAWcroNd5IZA=\",\"signature\":\"6PIWJXyEyHfWZrX6HKFNj3fRm5LbBsBX54zmVZpo+nMqqTV26xaQbEsRTfuhm4k+XGxci3VSuofPWFEpRuOmhg==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/fcall:save:validation.json b/pallets/ddc-validator/src/mock_data/fcall:save:validation.json new file mode 100644 index 000000000..5fa9734a3 --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/fcall:save:validation.json @@ -0,0 +1 @@ +{"JSON.GET":null} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/shared:nodes:era.json b/pallets/ddc-validator/src/mock_data/shared:nodes:era.json new file mode 100644 index 000000000..b077de96f --- /dev/null +++ b/pallets/ddc-validator/src/mock_data/shared:nodes:era.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"0101010101010101010101010101010101010101010101010101010101010101\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\": true, \"data\": \"%7B%22data%22%3A%22eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzE5OCwxMTIsMzAsNywxNzksMTE2LDExNiwxODIsMjE2LDE4OCw3NSwxNDgsMTcsMTYwLDI1MSwxNTcsMTQzLDE3NiwxOTEsMTQyLDE4OCwxNTcsOTYsMjIsMTU0LDE2OCwxMTYsMTE1LDM3LDIyMiw0OSw2NV0sInRvdGFscyI6eyJyZWNlaXZlZCI6ODAwLCJzZW50Ijo4MDAsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19%22%2C%22result%22%3Atrue%7D\" }}}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 33c9b1071..b09b77d1f 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,7 +1,13 @@ use crate::mock::*; -use frame_support::assert_ok; -use sp_core::crypto::AccountId32; +use frame_support::{assert_ok, traits::{OffchainWorker, OnInitialize}}; use sp_runtime::DispatchResult; +use crate::mock::Timestamp; +use sp_core::{ + offchain::{testing, OffchainWorkerExt, OffchainDbExt}, + crypto::{KeyTypeId} +}; +use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; +use std::sync::Arc; #[test] fn save_validated_data_works() { @@ -9,3 +15,91 @@ fn save_validated_data_works() { assert_ok!(DispatchResult::Ok(())); }); } + +const PHRASE: &str = +"news slush supreme milk chapter athlete soap sausage put clutch what kitten"; +pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); + +#[test] +fn it_triggers_offchain_worker() { + + let mut t = new_test_ext(); + + let (offchain, offchain_state) = testing::TestOffchainExt::new(); + t.register_extension(OffchainDbExt::new(offchain.clone())); + t.register_extension(OffchainWorkerExt::new(offchain)); + let keystore = KeyStore::new(); + keystore + .sr25519_generate_new(KEY_TYPE, Some(PHRASE)) + .unwrap(); + t.register_extension(KeystoreExt(Arc::new(keystore))); + + { + let mut state = offchain_state.write(); + + let mut expect_request = |url: &str, response: &[u8]| { + state.expect_request(testing::PendingRequest { + method: "GET".into(), + uri: url.to_string(), + response: Some(response.to_vec()), + sent: true, + ..Default::default() + }); + }; + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:aggregation:nodes:132855/$.0101010101010101010101010101010101010101010101010101010101010101", + include_bytes!("./mock_data/aggregation:nodes:era:edge.json") + ); + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:data:file:84640a53-fc1f-4ac5-921c-6695056840bc", + include_bytes!("./mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json") + ); + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7", + include_bytes!("./mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json") + ); + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:data:file:80a62530-fd76-40b5-bc53-dd82365e89ce", + include_bytes!("./mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json") + ); + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6", + include_bytes!("./mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json") + ); + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38", + include_bytes!("./mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json") + ); + + expect_request( + "http://redis:6379/FCALL/save_validation_result_by_node/1/d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67:0101010101010101010101010101010101010101010101010101010101010101:3/%7B%22data%22%3A%22eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzE5OCwxMTIsMzAsNywxNzksMTE2LDExNiwxODIsMjE2LDE4OCw3NSwxNDgsMTcsMTYwLDI1MSwxNTcsMTQzLDE3NiwxOTEsMTQyLDE4OCwxNTcsOTYsMjIsMTU0LDE2OCwxMTYsMTE1LDM3LDIyMiw0OSw2NV0sInRvdGFscyI6eyJyZWNlaXZlZCI6ODAwLCJzZW50Ijo4MDAsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19%22%2C%22result%22%3Atrue%7D", + include_bytes!("./mock_data/fcall:save:validation.json") + ); + + expect_request( + "http://redis:6379/JSON.GET/ddc:dac:shared:nodes:3", + include_bytes!("./mock_data/shared:nodes:era.json") + ); + + } + + t.execute_with(|| { + + System::set_block_number(1); // required for randomness + + Timestamp::set_timestamp(1_672_531_200_000 + 120_000 * 2); + DdcValidator::on_initialize(2); + + Timestamp::set_timestamp(1_672_531_200_000 + 120_000 * 4); + DdcValidator::offchain_worker(3); + + }) +} + + From 541ed000bc093ddad84e7dde0747544228ef080e Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Wed, 12 Jul 2023 17:14:06 +0200 Subject: [PATCH 215/544] test(ddc-validator): mock request for shared decisions and tx pool extension --- .../src/mock_data/aggregation:nodes:era:edge.json | 2 +- pallets/ddc-validator/src/mock_data/shared:nodes:era.json | 2 +- pallets/ddc-validator/src/tests.rs | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json b/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json index 7e497108f..a9f63c83d 100644 --- a/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json +++ b/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json @@ -1 +1 @@ -{"JSON.GET":"[{\"totalBytesSent\":4800,\"totalQueries\":0,\"totalReads\":30,\"totalReadsAcked\":30,\"totalQueriesAcked\":0,\"averageResponseTimeMs\":1.8852459016393444,\"totalBytesReceived\":4800,\"requestIds\":[\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"6e86ac08-4af9-4353-9fec-0f3e563661d6\",\"7af575b7-9a83-40b6-88a7-19549b9bbc38\"],\"totalWritesAcked\":30,\"averageResponseTimeMsSamples\":61,\"totalWrites\":30}]"} \ No newline at end of file +{"JSON.GET":"[{\"totalBytesSent\":800,\"totalQueries\":0,\"totalReads\":30,\"totalReadsAcked\":30,\"totalQueriesAcked\":0,\"averageResponseTimeMs\":1.8852459016393444,\"totalBytesReceived\":800,\"requestIds\":[\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"6e86ac08-4af9-4353-9fec-0f3e563661d6\",\"7af575b7-9a83-40b6-88a7-19549b9bbc38\"],\"totalWritesAcked\":30,\"averageResponseTimeMsSamples\":61,\"totalWrites\":30}]"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/shared:nodes:era.json b/pallets/ddc-validator/src/mock_data/shared:nodes:era.json index b077de96f..287bcd5bf 100644 --- a/pallets/ddc-validator/src/mock_data/shared:nodes:era.json +++ b/pallets/ddc-validator/src/mock_data/shared:nodes:era.json @@ -1 +1 @@ -{"JSON.GET":"{\"0101010101010101010101010101010101010101010101010101010101010101\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\": true, \"data\": \"%7B%22data%22%3A%22eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzE5OCwxMTIsMzAsNywxNzksMTE2LDExNiwxODIsMjE2LDE4OCw3NSwxNDgsMTcsMTYwLDI1MSwxNTcsMTQzLDE3NiwxOTEsMTQyLDE4OCwxNTcsOTYsMjIsMTU0LDE2OCwxMTYsMTE1LDM3LDIyMiw0OSw2NV0sInRvdGFscyI6eyJyZWNlaXZlZCI6ODAwLCJzZW50Ijo4MDAsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19%22%2C%22result%22%3Atrue%7D\" }}}"} \ No newline at end of file +{"JSON.GET":"{\"0101010101010101010101010101010101010101010101010101010101010101\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":true,\"data\":\"eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzEwNCwyMzgsNzMsNzMsMjA0LDE3MiwyNTQsMTgxLDc3LDExNiwxMzYsMTg5LDI0Niw5MCwxNjQsMTU0LDE2NywzLDE1NSwyNTMsODAsMzMsMjUxLDE0LDc4LDIzNiwxNjcsMTM0LDE2MSw2NCwyMjIsMTgxXSwidG90YWxzIjp7InJlY2VpdmVkIjo4MDAsInNlbnQiOjgwMCwiZmFpbGVkX2J5X2NsaWVudCI6MCwiZmFpbHVyZV9yYXRlIjowfX0=\"}},\"1c4a1b081af8dd09096ebb6e7ad61dd549ac2931cdb2b1216589094ad71ca90b\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":false,\"data\":\"eyJlZGdlIjoiMWM0YTFiMDgxYWY4ZGQwOTA5NmViYjZlN2FkNjFkZDU0OWFjMjkzMWNkYjJiMTIxNjU4OTA5NGFkNzFjYTkwYiIsInJlc3VsdCI6ZmFsc2UsInBheWxvYWQiOlsxMDQsMjM4LDczLDczLDIwNCwxNzIsMjU0LDE4MSw3NywxMTYsMTM2LDE4OSwyNDYsOTAsMTY0LDE1NCwxNjcsMywxNTUsMjUzLDgwLDMzLDI1MSwxNCw3OCwyMzYsMTY3LDEzNCwxNjEsNjQsMjIyLDE4MV0sInRvdGFscyI6eyJyZWNlaXZlZCI6OTAwLCJzZW50Ijo1NDQsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19\"}}}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index b09b77d1f..48b7a3e76 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -3,7 +3,7 @@ use frame_support::{assert_ok, traits::{OffchainWorker, OnInitialize}}; use sp_runtime::DispatchResult; use crate::mock::Timestamp; use sp_core::{ - offchain::{testing, OffchainWorkerExt, OffchainDbExt}, + offchain::{testing, OffchainWorkerExt, OffchainDbExt, TransactionPoolExt}, crypto::{KeyTypeId} }; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; @@ -28,12 +28,16 @@ fn it_triggers_offchain_worker() { let (offchain, offchain_state) = testing::TestOffchainExt::new(); t.register_extension(OffchainDbExt::new(offchain.clone())); t.register_extension(OffchainWorkerExt::new(offchain)); + let keystore = KeyStore::new(); keystore .sr25519_generate_new(KEY_TYPE, Some(PHRASE)) .unwrap(); t.register_extension(KeystoreExt(Arc::new(keystore))); + let (pool, pool_state) = testing::TestTransactionPoolExt::new(); + t.register_extension(TransactionPoolExt::new(pool)); + { let mut state = offchain_state.write(); From 81029505b5d14b5dd1f2965193bdd4df5685c38a Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Wed, 12 Jul 2023 21:15:26 +0200 Subject: [PATCH 216/544] test(ddc-validator): mock transaction assertion in tests --- pallets/ddc-validator/src/tests.rs | 60 ++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 48b7a3e76..605653b82 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,13 +1,16 @@ use crate::mock::*; +use crate::mock::Timestamp; +use crate::{ValidationDecision, DacTotalAggregates}; +use pallet_ddc_accounts::BucketsDetails; use frame_support::{assert_ok, traits::{OffchainWorker, OnInitialize}}; use sp_runtime::DispatchResult; -use crate::mock::Timestamp; use sp_core::{ offchain::{testing, OffchainWorkerExt, OffchainDbExt, TransactionPoolExt}, crypto::{KeyTypeId} }; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; use std::sync::Arc; +use codec::Decode; #[test] fn save_validated_data_works() { @@ -90,8 +93,7 @@ fn it_triggers_offchain_worker() { "http://redis:6379/JSON.GET/ddc:dac:shared:nodes:3", include_bytes!("./mock_data/shared:nodes:era.json") ); - - } + } t.execute_with(|| { @@ -103,6 +105,58 @@ fn it_triggers_offchain_worker() { Timestamp::set_timestamp(1_672_531_200_000 + 120_000 * 4); DdcValidator::offchain_worker(3); + // Get the transaction from the worker. + let mut transactions = pool_state.read().transactions.clone(); + transactions.reverse(); + assert_eq!(transactions.len(), 3); + + let tx = transactions.pop().unwrap(); + let tx = Extrinsic::decode(&mut &*tx).unwrap(); + assert!(tx.signature.is_some()); + + let bucket_info = BucketsDetails { bucket_id: 5, amount: 160u128 }; + assert_eq!(tx.call, crate::mock::Call::DdcValidator( + crate::Call::charge_payments_content_owners { + paying_accounts: vec![ + bucket_info.clone(), + bucket_info.clone(), + bucket_info.clone(), + bucket_info.clone(), + bucket_info + ] + } + )); + + let tx = transactions.pop().unwrap(); + let tx = Extrinsic::decode(&mut &*tx).unwrap(); + assert!(tx.signature.is_some()); + assert_eq!(tx.call, crate::mock::Call::DdcValidator( + crate::Call::payout_cdn_owners { + era: 4 + } + )); + + let tx = transactions.pop().unwrap(); + let tx = Extrinsic::decode(&mut &*tx).unwrap(); + assert!(tx.signature.is_some()); + assert_eq!(tx.call, crate::mock::Call::DdcValidator( + crate::Call::set_validation_decision { + era: 4, + cdn_node: AccountId::from([0x1; 32]), + validation_decision: ValidationDecision { + edge: String::from("0101010101010101010101010101010101010101010101010101010101010101"), + result: true, + payload: [71, 216, 226, 58, 45, 227, 238, 47, 52, 96, 11, 175, 0, 1, 56, 247, 215, 155, 5, 94, 8, 2, 18, 213, 180, 35, 96, 124, 149, 71, 185, 25], + totals: DacTotalAggregates { + received: 800, + sent: 800, + failed_by_client: 0, + failure_rate: 0 + } + } + } + )); + }) } From 61d913f99936716835b8046231738c77f1290dad Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 13 Jul 2023 02:08:53 +0200 Subject: [PATCH 217/544] test(ddc-validator): simple test scenario for setting validation decision is added --- pallets/ddc-validator/src/lib.rs | 5 +- .../set-1/aggregated-node-data-for-era.json | 1 + .../src/mock-data/set-1/file-request1.json | 1 + .../src/mock-data/set-1/file-request2.json | 1 + .../src/mock-data/set-1/file-request3.json | 1 + .../save-validation-decision-result.json} | 0 .../shared-validation-decisions-for-era.json | 1 + .../mock-data/set-1/validation-decision.json | 1 + pallets/ddc-validator/src/mock.rs | 80 +++++------ .../mock_data/aggregation:nodes:era:edge.json | 1 - ...:6e86ac08-4af9-4353-9fec-0f3e563661d6.json | 1 - ...:7af575b7-9a83-40b6-88a7-19549b9bbc38.json | 1 - ...:80a62530-fd76-40b5-bc53-dd82365e89ce.json | 1 - ...:84640a53-fc1f-4ac5-921c-6695056840bc.json | 1 - ...:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json | 1 - .../src/mock_data/shared:nodes:era.json | 1 - pallets/ddc-validator/src/tests.rs | 127 ++++++++++-------- 17 files changed, 110 insertions(+), 115 deletions(-) create mode 100644 pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json create mode 100644 pallets/ddc-validator/src/mock-data/set-1/file-request1.json create mode 100644 pallets/ddc-validator/src/mock-data/set-1/file-request2.json create mode 100644 pallets/ddc-validator/src/mock-data/set-1/file-request3.json rename pallets/ddc-validator/src/{mock_data/fcall:save:validation.json => mock-data/set-1/save-validation-decision-result.json} (100%) create mode 100644 pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json create mode 100644 pallets/ddc-validator/src/mock-data/set-1/validation-decision.json delete mode 100644 pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json delete mode 100644 pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json delete mode 100644 pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json delete mode 100644 pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json delete mode 100644 pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json delete mode 100644 pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json delete mode 100644 pallets/ddc-validator/src/mock_data/shared:nodes:era.json diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 4e992c9a2..9c2c7b4fb 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -664,9 +664,10 @@ pub mod pallet { // form url for each node let edge_url = format!( - "{}{}{}", + "{}{}{}/$.{}", mock_data_url, - "ddc:dac:aggregation:nodes:132855/$.", + "ddc:dac:aggregation:nodes:", + current_era - 1, utils::account_to_string::(assigned_edge.clone()) ); info!("edge url: {:?}", edge_url); diff --git a/pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json b/pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json new file mode 100644 index 000000000..37b3242fe --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json @@ -0,0 +1 @@ +{"JSON.GET":"[{\"totalBytesSent\":600,\"totalQueries\":0,\"totalReads\":3,\"totalReadsAcked\":3,\"totalQueriesAcked\":0,\"averageResponseTimeMs\":1.8852459016393444,\"totalBytesReceived\":600,\"requestIds\":[\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"80a62530-fd76-40b5-bc53-dd82365e89ce\"],\"totalWritesAcked\":3,\"averageResponseTimeMsSamples\":61,\"totalWrites\":3}]"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/file-request1.json b/pallets/ddc-validator/src/mock-data/set-1/file-request1.json new file mode 100644 index 000000000..5a29a982b --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/file-request1.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"]},\"bucketId\":5,\"timestamp\":1688473909701,\"chunks\":{\"84640a53-fc1f-4ac5-921c-6695056840bc:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":3,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49690\",\"bytesSent\":100,\"timestamp\":1688473909701,\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\",\"ack\":{\"userTimestamp\":1688473909709,\"nonce\":\"Gt7AFrznCPzgI/5q+tynLy2BKUooSGAkUCaGsF6AOMs=\",\"signature\":\"Gll6xIftbtP4JPB6miy3DLKMBDrKz05QSIBNJ3RqYi0Fg1wNJRFoSIqhOJDXDUB4NlrLQdl+HWrYRL20Hsx6iA==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":100,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/file-request2.json b/pallets/ddc-validator/src/mock-data/set-1/file-request2.json new file mode 100644 index 000000000..b0e3fdc19 --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/file-request2.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\"]},\"bucketId\":5,\"timestamp\":1688473909723,\"chunks\":{\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\":{\"log\":{\"type\":2,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":3,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49714\",\"bytesSent\":200,\"timestamp\":1688473909723,\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\",\"ack\":{\"userTimestamp\":1688473909726,\"nonce\":\"2mdA3QVq02ME77vnqGjBNQqTRhM5gHjVAWcroNd5IZA=\",\"signature\":\"6PIWJXyEyHfWZrX6HKFNj3fRm5LbBsBX54zmVZpo+nMqqTV26xaQbEsRTfuhm4k+XGxci3VSuofPWFEpRuOmhg==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":200,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\"],\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/file-request3.json b/pallets/ddc-validator/src/mock-data/set-1/file-request3.json new file mode 100644 index 000000000..047c057e6 --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/file-request3.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"fileRequestId\":\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"]},\"bucketId\":5,\"timestamp\":1688473910041,\"chunks\":{\"80a62530-fd76-40b5-bc53-dd82365e89ce:bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":3,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49736\",\"bytesSent\":300,\"timestamp\":1688473910041,\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\",\"ack\":{\"userTimestamp\":1688473910043,\"nonce\":\"VU1XCPjQxA4y6TnrOAy44QabS7nmmxAU8vyduqoLt9U=\",\"signature\":\"Us7//t0+y00oHhthPSjqphHJYwE1qgPQtBSdy5hZxUInKdQXTBX58VLQekoKMHtptQQggR1gPf9Pyy1enmXziQ==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":300,\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/fcall:save:validation.json b/pallets/ddc-validator/src/mock-data/set-1/save-validation-decision-result.json similarity index 100% rename from pallets/ddc-validator/src/mock_data/fcall:save:validation.json rename to pallets/ddc-validator/src/mock-data/set-1/save-validation-decision-result.json diff --git a/pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json b/pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json new file mode 100644 index 000000000..da4aa921a --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json @@ -0,0 +1 @@ +{"JSON.GET":"{\"0101010101010101010101010101010101010101010101010101010101010101\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":true,\"data\":\"eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzI0MiwgMjIxLCA1MSwgMzQsIDI5LCAyNDIsIDE1MCwgMTE5LCA2LCAxMzEsIDQxLCAxNSwgMTYxLCAxNzMsIDEyMSwgNDMsIDIyMSwgMjIsIDE1MCwgMTczLCAxODAsIDIyNCwgMTc5LCA1OCwgNzIsIDQsIDk2LCAxODgsIDE3LCAxNjQsIDE3NywgMTA5XSwidG90YWxzIjp7InJlY2VpdmVkIjo2MDAsInNlbnQiOjYwMCwiZmFpbGVkX2J5X2NsaWVudCI6MCwiZmFpbHVyZV9yYXRlIjowfX0=\"}},\"1c4a1b081af8dd09096ebb6e7ad61dd549ac2931cdb2b1216589094ad71ca90b\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":false,\"data\":\"eyJlZGdlIjoiMWM0YTFiMDgxYWY4ZGQwOTA5NmViYjZlN2FkNjFkZDU0OWFjMjkzMWNkYjJiMTIxNjU4OTA5NGFkNzFjYTkwYiIsInJlc3VsdCI6ZmFsc2UsInBheWxvYWQiOlsxMDQsMjM4LDczLDczLDIwNCwxNzIsMjU0LDE4MSw3NywxMTYsMTM2LDE4OSwyNDYsOTAsMTY0LDE1NCwxNjcsMywxNTUsMjUzLDgwLDMzLDI1MSwxNCw3OCwyMzYsMTY3LDEzNCwxNjEsNjQsMjIyLDE4MV0sInRvdGFscyI6eyJyZWNlaXZlZCI6OTAwLCJzZW50Ijo1NDQsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19\"}}}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json new file mode 100644 index 000000000..1fd502e51 --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json @@ -0,0 +1 @@ +{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[242, 221, 51, 34, 29, 242, 150, 119, 6, 131, 41, 15, 161, 173, 121, 43, 221, 22, 150, 173, 180, 224, 179, 58, 72, 4, 96, 188, 17, 164, 177, 109],"totals":{"received":600,"sent":600,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 83cef7e8b..0180d8333 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -6,7 +6,7 @@ use frame_support::{ weights::Weight, PalletId, }; -use frame_system::{offchain::SendTransactionTypes, EnsureRoot}; +use frame_system::{offchain::SendTransactionTypes}; use pallet_contracts as contracts; use pallet_session::ShouldEndSession; use sp_core::H256; @@ -320,80 +320,64 @@ impl pallet_balances::Config for Test { pub fn new_test_ext() -> sp_io::TestExternalities { let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); - let _ = pallet_balances::GenesisConfig:: { - balances: vec![ - // edge controllers - (AccountId::from([0x2; 32]), 1000), - // storage controllers - (AccountId::from([0x4; 32]), 1000), - // edge stashes - (AccountId::from([0x1; 32]), 1000), - // storage stashes - (AccountId::from([0x3; 32]), 1000), - - // validators - // (AccountId::from([0x5; 32]), 10000), - (AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), 10000), - (AccountId::from([0x55; 32]), 10000), - - - (AccountId::from([0x6; 32]), 10000), - (AccountId::from([0x66; 32]), 10000), - - (AccountId::from([0x7; 32]), 10000), - (AccountId::from([0x77; 32]), 10000), - ], - } - .assimilate_storage(&mut storage); - + let balances = vec![ + // edge stash + (AccountId::from([0x1; 32]), 1000), + // edge controller + (AccountId::from([0x11; 32]), 1000), + + // validator1 stash; has to be equal to the OCW key in the current implementation + (AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), 10000), + // validator1 controller + (AccountId::from([0xaa; 32]), 10000), + + // validator2 stash + (AccountId::from([0xb; 32]), 10000), + // validator2 controller + (AccountId::from([0xbb; 32]), 10000), + + // validator3 stash + (AccountId::from([0xc; 32]), 10000), + // validator3 controller + (AccountId::from([0xcc; 32]), 10000), + ]; + let _ = pallet_balances::GenesisConfig:: { balances } + .assimilate_storage(&mut storage); - let stakers = vec![ + let stakers = vec![ ( - // AccountId::from([0x5; 32]), AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), - AccountId::from([0x55; 32]), + AccountId::from([0xaa; 32]), 1000, pallet_staking::StakerStatus::Validator ), ( - AccountId::from([0x6; 32]), - AccountId::from([0x66; 32]), + AccountId::from([0xb; 32]), + AccountId::from([0xbb; 32]), 1000, pallet_staking::StakerStatus::Validator ), ( - AccountId::from([0x7; 32]), - AccountId::from([0x77; 32]), + AccountId::from([0xc; 32]), + AccountId::from([0xcc; 32]), 1000, pallet_staking::StakerStatus::Validator ) ]; - - let _ = pallet_staking::GenesisConfig:: { stakers, ..Default::default() } .assimilate_storage(&mut storage); - let edges = vec![ ( AccountId::from([0x1; 32]), - AccountId::from([0x2; 32]), + AccountId::from([0x11; 32]), 100, 1 ) ]; - - let storages = vec![ - ( - AccountId::from([0x3; 32]), - AccountId::from([0x4; 32]), - 100, - 1, - ) - ]; - + let storages = vec![]; let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } .assimilate_storage(&mut storage); diff --git a/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json b/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json deleted file mode 100644 index a9f63c83d..000000000 --- a/pallets/ddc-validator/src/mock_data/aggregation:nodes:era:edge.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"[{\"totalBytesSent\":800,\"totalQueries\":0,\"totalReads\":30,\"totalReadsAcked\":30,\"totalQueriesAcked\":0,\"averageResponseTimeMs\":1.8852459016393444,\"totalBytesReceived\":800,\"requestIds\":[\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"6e86ac08-4af9-4353-9fec-0f3e563661d6\",\"7af575b7-9a83-40b6-88a7-19549b9bbc38\"],\"totalWritesAcked\":30,\"averageResponseTimeMsSamples\":61,\"totalWrites\":30}]"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json b/pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json deleted file mode 100644 index ea2cc9127..000000000 --- a/pallets/ddc-validator/src/mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"6e86ac08-4af9-4353-9fec-0f3e563661d6\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"]},\"bucketId\":5,\"timestamp\":1688473910055,\"chunks\":{\"6e86ac08-4af9-4353-9fec-0f3e563661d6:bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\":{\"log\":{\"type\":2,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49760\",\"bytesSent\":160,\"timestamp\":1688473910055,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\",\"ack\":{\"userTimestamp\":1688473910058,\"nonce\":\"6VQF3U6m8lHhJVT/Wr+tpn7OrorcqpQg9hZS8vRoBoA=\",\"signature\":\"GilWqbctk1WvySNd5+EzWU/Df9B2RM2z9/3Jzfpian7PyH9ndvvxJDtKo1/cJdrj7r5gsSEqlwPxcKjj5RJNhg==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json b/pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json deleted file mode 100644 index aa68e8423..000000000 --- a/pallets/ddc-validator/src/mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"7af575b7-9a83-40b6-88a7-19549b9bbc38\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\"]},\"bucketId\":5,\"timestamp\":1688473910371,\"chunks\":{\"7af575b7-9a83-40b6-88a7-19549b9bbc38:bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49770\",\"bytesSent\":160,\"timestamp\":1688473910371,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\",\"ack\":{\"userTimestamp\":1688473910373,\"nonce\":\"TwKKd2NsDkjaV9yDPqqVPh1rcSlrkmdXSQXl+zojH8M=\",\"signature\":\"EvDRqBr8zoIzxykz6NrzrIsgjDlf/++RmH/9OdQqtBb0dO1y4o/snH4OoMlJMnXTDZX9R+umQPH90PH0WvVAig==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzacedfeu3vcqi2kr4pl4odjbzvpt5nr3md2m4cxrxkydnd23gbaoc4ro\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json b/pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json deleted file mode 100644 index 09e491b32..000000000 --- a/pallets/ddc-validator/src/mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"]},\"bucketId\":5,\"timestamp\":1688473910041,\"chunks\":{\"80a62530-fd76-40b5-bc53-dd82365e89ce:bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49736\",\"bytesSent\":160,\"timestamp\":1688473910041,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\",\"ack\":{\"userTimestamp\":1688473910043,\"nonce\":\"VU1XCPjQxA4y6TnrOAy44QabS7nmmxAU8vyduqoLt9U=\",\"signature\":\"Us7//t0+y00oHhthPSjqphHJYwE1qgPQtBSdy5hZxUInKdQXTBX58VLQekoKMHtptQQggR1gPf9Pyy1enmXziQ==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json b/pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json deleted file mode 100644 index 9fc7d5ef8..000000000 --- a/pallets/ddc-validator/src/mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"]},\"bucketId\":5,\"timestamp\":1688473909701,\"chunks\":{\"84640a53-fc1f-4ac5-921c-6695056840bc:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49690\",\"bytesSent\":160,\"timestamp\":1688473909701,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\",\"ack\":{\"userTimestamp\":1688473909709,\"nonce\":\"Gt7AFrznCPzgI/5q+tynLy2BKUooSGAkUCaGsF6AOMs=\",\"signature\":\"Gll6xIftbtP4JPB6miy3DLKMBDrKz05QSIBNJ3RqYi0Fg1wNJRFoSIqhOJDXDUB4NlrLQdl+HWrYRL20Hsx6iA==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json b/pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json deleted file mode 100644 index 4519ed651..000000000 --- a/pallets/ddc-validator/src/mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"]},\"bucketId\":5,\"timestamp\":1688473909723,\"chunks\":{\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\":{\"log\":{\"type\":2,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":132855,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49714\",\"bytesSent\":160,\"timestamp\":1688473909723,\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\",\"ack\":{\"userTimestamp\":1688473909726,\"nonce\":\"2mdA3QVq02ME77vnqGjBNQqTRhM5gHjVAWcroNd5IZA=\",\"signature\":\"6PIWJXyEyHfWZrX6HKFNj3fRm5LbBsBX54zmVZpo+nMqqTV26xaQbEsRTfuhm4k+XGxci3VSuofPWFEpRuOmhg==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":160,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"nodePublicKey\":\"98d6387b0c5965493dcaff83aeb43c7303d87c6c750569d8dd2ef298baa12b13\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock_data/shared:nodes:era.json b/pallets/ddc-validator/src/mock_data/shared:nodes:era.json deleted file mode 100644 index 287bcd5bf..000000000 --- a/pallets/ddc-validator/src/mock_data/shared:nodes:era.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"0101010101010101010101010101010101010101010101010101010101010101\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":true,\"data\":\"eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzEwNCwyMzgsNzMsNzMsMjA0LDE3MiwyNTQsMTgxLDc3LDExNiwxMzYsMTg5LDI0Niw5MCwxNjQsMTU0LDE2NywzLDE1NSwyNTMsODAsMzMsMjUxLDE0LDc4LDIzNiwxNjcsMTM0LDE2MSw2NCwyMjIsMTgxXSwidG90YWxzIjp7InJlY2VpdmVkIjo4MDAsInNlbnQiOjgwMCwiZmFpbGVkX2J5X2NsaWVudCI6MCwiZmFpbHVyZV9yYXRlIjowfX0=\"}},\"1c4a1b081af8dd09096ebb6e7ad61dd549ac2931cdb2b1216589094ad71ca90b\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":false,\"data\":\"eyJlZGdlIjoiMWM0YTFiMDgxYWY4ZGQwOTA5NmViYjZlN2FkNjFkZDU0OWFjMjkzMWNkYjJiMTIxNjU4OTA5NGFkNzFjYTkwYiIsInJlc3VsdCI6ZmFsc2UsInBheWxvYWQiOlsxMDQsMjM4LDczLDczLDIwNCwxNzIsMjU0LDE4MSw3NywxMTYsMTM2LDE4OSwyNDYsOTAsMTY0LDE1NCwxNjcsMywxNTUsMjUzLDgwLDMzLDI1MSwxNCw3OCwyMzYsMTY3LDEzNCwxNjEsNjQsMjIyLDE4MV0sInRvdGFscyI6eyJyZWNlaXZlZCI6OTAwLCJzZW50Ijo1NDQsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19\"}}}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 605653b82..e9f3c0e4d 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,30 +1,24 @@ use crate::mock::*; use crate::mock::Timestamp; -use crate::{ValidationDecision, DacTotalAggregates}; +use crate::shm; +use crate::utils; +use crate::{EraIndex, ValidationDecision, DacTotalAggregates, KEY_TYPE, DEFAULT_DATA_PROVIDER_URL, TIME_START_MS, ERA_DURATION_MS, ERA_IN_BLOCKS}; use pallet_ddc_accounts::BucketsDetails; use frame_support::{assert_ok, traits::{OffchainWorker, OnInitialize}}; -use sp_runtime::DispatchResult; use sp_core::{ offchain::{testing, OffchainWorkerExt, OffchainDbExt, TransactionPoolExt}, - crypto::{KeyTypeId} }; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; use std::sync::Arc; use codec::Decode; -#[test] -fn save_validated_data_works() { - new_test_ext().execute_with(|| { - assert_ok!(DispatchResult::Ok(())); - }); -} -const PHRASE: &str = -"news slush supreme milk chapter athlete soap sausage put clutch what kitten"; -pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); +const OCW_PUB_KEY_STR: &str = "d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"; +const OCW_SEED: &str = "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; + #[test] -fn it_triggers_offchain_worker() { +fn it_sets_validation_decision_with_one_validator_in_quorum() { let mut t = new_test_ext(); @@ -33,14 +27,16 @@ fn it_triggers_offchain_worker() { t.register_extension(OffchainWorkerExt::new(offchain)); let keystore = KeyStore::new(); - keystore - .sr25519_generate_new(KEY_TYPE, Some(PHRASE)) - .unwrap(); + keystore.sr25519_generate_new(KEY_TYPE, Some(OCW_SEED)).unwrap(); t.register_extension(KeystoreExt(Arc::new(keystore))); let (pool, pool_state) = testing::TestTransactionPoolExt::new(); t.register_extension(TransactionPoolExt::new(pool)); + let era_to_validate: EraIndex = 3; + let cdn_node_to_validate = AccountId::from([0x1; 32]); + let cdn_node_to_validate_str = utils::account_to_string::(cdn_node_to_validate.clone()); + { let mut state = offchain_state.write(); @@ -55,57 +51,66 @@ fn it_triggers_offchain_worker() { }; expect_request( - "http://redis:6379/JSON.GET/ddc:dac:aggregation:nodes:132855/$.0101010101010101010101010101010101010101010101010101010101010101", - include_bytes!("./mock_data/aggregation:nodes:era:edge.json") + &format!("{}/JSON.GET/ddc:dac:aggregation:nodes:{}/$.{}", DEFAULT_DATA_PROVIDER_URL, era_to_validate, cdn_node_to_validate_str), + include_bytes!("./mock-data/set-1/aggregated-node-data-for-era.json") ); expect_request( - "http://redis:6379/JSON.GET/ddc:dac:data:file:84640a53-fc1f-4ac5-921c-6695056840bc", - include_bytes!("./mock_data/data:file:84640a53-fc1f-4ac5-921c-6695056840bc.json") + &format!("{}/JSON.GET/ddc:dac:data:file:84640a53-fc1f-4ac5-921c-6695056840bc", DEFAULT_DATA_PROVIDER_URL), + include_bytes!("./mock-data/set-1/file-request1.json") ); expect_request( - "http://redis:6379/JSON.GET/ddc:dac:data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7", - include_bytes!("./mock_data/data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7.json") + &format!("{}/JSON.GET/ddc:dac:data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7", DEFAULT_DATA_PROVIDER_URL), + include_bytes!("./mock-data/set-1/file-request2.json") ); expect_request( - "http://redis:6379/JSON.GET/ddc:dac:data:file:80a62530-fd76-40b5-bc53-dd82365e89ce", - include_bytes!("./mock_data/data:file:80a62530-fd76-40b5-bc53-dd82365e89ce.json") + &format!("{}/JSON.GET/ddc:dac:data:file:80a62530-fd76-40b5-bc53-dd82365e89ce", DEFAULT_DATA_PROVIDER_URL), + include_bytes!("./mock-data/set-1/file-request3.json") ); - expect_request( - "http://redis:6379/JSON.GET/ddc:dac:data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6", - include_bytes!("./mock_data/data:file:6e86ac08-4af9-4353-9fec-0f3e563661d6.json") - ); + let decision: ValidationDecision = serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")).unwrap(); + let serialized_decision = serde_json::to_string(&decision).unwrap(); + let encoded_decision_vec = shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); + let encoded_decision_str = encoded_decision_vec.iter().cloned().collect::(); + let result_json = serde_json::json!({ + "result": decision.result, + "data": encoded_decision_str, + }); + let result_json_str = serde_json::to_string(&result_json).unwrap(); + let unescaped_result_json = utils::unescape(&result_json_str); + let url_encoded_result_json = utils::url_encode(&unescaped_result_json); expect_request( - "http://redis:6379/JSON.GET/ddc:dac:data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38", - include_bytes!("./mock_data/data:file:7af575b7-9a83-40b6-88a7-19549b9bbc38.json") + &format!("{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", + DEFAULT_DATA_PROVIDER_URL, + OCW_PUB_KEY_STR, + cdn_node_to_validate_str, + era_to_validate, + url_encoded_result_json, + ), + include_bytes!("./mock-data/set-1/save-validation-decision-result.json") ); expect_request( - "http://redis:6379/FCALL/save_validation_result_by_node/1/d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67:0101010101010101010101010101010101010101010101010101010101010101:3/%7B%22data%22%3A%22eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzE5OCwxMTIsMzAsNywxNzksMTE2LDExNiwxODIsMjE2LDE4OCw3NSwxNDgsMTcsMTYwLDI1MSwxNTcsMTQzLDE3NiwxOTEsMTQyLDE4OCwxNTcsOTYsMjIsMTU0LDE2OCwxMTYsMTE1LDM3LDIyMiw0OSw2NV0sInRvdGFscyI6eyJyZWNlaXZlZCI6ODAwLCJzZW50Ijo4MDAsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19%22%2C%22result%22%3Atrue%7D", - include_bytes!("./mock_data/fcall:save:validation.json") + &format!("{}/JSON.GET/ddc:dac:shared:nodes:{}", DEFAULT_DATA_PROVIDER_URL, era_to_validate), + include_bytes!("./mock-data/set-1/shared-validation-decisions-for-era.json") ); - expect_request( - "http://redis:6379/JSON.GET/ddc:dac:shared:nodes:3", - include_bytes!("./mock_data/shared:nodes:era.json") - ); } t.execute_with(|| { - System::set_block_number(1); // required for randomness + let era_block_number = ERA_IN_BLOCKS as u32 * era_to_validate; + System::set_block_number(era_block_number); // required for randomness - Timestamp::set_timestamp(1_672_531_200_000 + 120_000 * 2); - DdcValidator::on_initialize(2); + Timestamp::set_timestamp((TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64); + DdcValidator::on_initialize(era_block_number - 1); // make assignments - Timestamp::set_timestamp(1_672_531_200_000 + 120_000 * 4); - DdcValidator::offchain_worker(3); + Timestamp::set_timestamp((TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64); + DdcValidator::offchain_worker(era_block_number + 1); // execute assignments - // Get the transaction from the worker. let mut transactions = pool_state.read().transactions.clone(); transactions.reverse(); assert_eq!(transactions.len(), 3); @@ -114,15 +119,16 @@ fn it_triggers_offchain_worker() { let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); - let bucket_info = BucketsDetails { bucket_id: 5, amount: 160u128 }; + let bucket_info1 = BucketsDetails { bucket_id: 5, amount: 100u128 }; + let bucket_info2 = BucketsDetails { bucket_id: 5, amount: 200u128 }; + let bucket_info3 = BucketsDetails { bucket_id: 5, amount: 300u128 }; + assert_eq!(tx.call, crate::mock::Call::DdcValidator( crate::Call::charge_payments_content_owners { paying_accounts: vec![ - bucket_info.clone(), - bucket_info.clone(), - bucket_info.clone(), - bucket_info.clone(), - bucket_info + bucket_info3, + bucket_info1, + bucket_info2, ] } )); @@ -132,31 +138,36 @@ fn it_triggers_offchain_worker() { assert!(tx.signature.is_some()); assert_eq!(tx.call, crate::mock::Call::DdcValidator( crate::Call::payout_cdn_owners { - era: 4 + era: era_to_validate + 1 } )); let tx = transactions.pop().unwrap(); let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); + + let common_decision: ValidationDecision = serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")).unwrap(); + let common_decisions = vec![common_decision.clone()]; + let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); + assert_eq!(tx.call, crate::mock::Call::DdcValidator( crate::Call::set_validation_decision { - era: 4, - cdn_node: AccountId::from([0x1; 32]), + era: era_to_validate + 1, + cdn_node: cdn_node_to_validate, validation_decision: ValidationDecision { - edge: String::from("0101010101010101010101010101010101010101010101010101010101010101"), + edge: cdn_node_to_validate_str, result: true, - payload: [71, 216, 226, 58, 45, 227, 238, 47, 52, 96, 11, 175, 0, 1, 56, 247, 215, 155, 5, 94, 8, 2, 18, 213, 180, 35, 96, 124, 149, 71, 185, 25], + payload: utils::hash(&serialized_decisions), totals: DacTotalAggregates { - received: 800, - sent: 800, - failed_by_client: 0, - failure_rate: 0 + received: common_decision.totals.received, + sent: common_decision.totals.sent, + failed_by_client: common_decision.totals.failed_by_client, + failure_rate: common_decision.totals.failure_rate, } } } )); - + }) } From 9b2961e4dcf16babc69eda999647e5e5d6b207cd Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Jul 2023 17:34:17 +0600 Subject: [PATCH 218/544] Autoformat `pallet-ddc-validator` code --- pallets/ddc-validator/src/lib.rs | 2 +- pallets/ddc-validator/src/mock.rs | 43 +++++---- pallets/ddc-validator/src/tests.rs | 138 ++++++++++++++++------------- 3 files changed, 99 insertions(+), 84 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 9c2c7b4fb..ceeecd7e2 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -495,7 +495,7 @@ pub mod pallet { fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool { if bytes_sent == bytes_received { - return true; + return true } let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 0180d8333..20125eb69 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -6,7 +6,7 @@ use frame_support::{ weights::Weight, PalletId, }; -use frame_system::{offchain::SendTransactionTypes}; +use frame_system::offchain::SendTransactionTypes; use pallet_contracts as contracts; use pallet_session::ShouldEndSession; use sp_core::H256; @@ -325,64 +325,61 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (AccountId::from([0x1; 32]), 1000), // edge controller (AccountId::from([0x11; 32]), 1000), - // validator1 stash; has to be equal to the OCW key in the current implementation - (AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), 10000), + ( + AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, + 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, + 0x55, 0xf4, 0xdf, 0x67, + ]), + 10000, + ), // validator1 controller (AccountId::from([0xaa; 32]), 10000), - // validator2 stash (AccountId::from([0xb; 32]), 10000), // validator2 controller (AccountId::from([0xbb; 32]), 10000), - // validator3 stash (AccountId::from([0xc; 32]), 10000), // validator3 controller (AccountId::from([0xcc; 32]), 10000), ]; - let _ = pallet_balances::GenesisConfig:: { balances } - .assimilate_storage(&mut storage); + let _ = pallet_balances::GenesisConfig:: { balances }.assimilate_storage(&mut storage); let stakers = vec![ ( - AccountId::from([0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67]), + AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, + 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, + 0x55, 0xf4, 0xdf, 0x67, + ]), AccountId::from([0xaa; 32]), 1000, - pallet_staking::StakerStatus::Validator + pallet_staking::StakerStatus::Validator, ), - ( AccountId::from([0xb; 32]), AccountId::from([0xbb; 32]), 1000, - pallet_staking::StakerStatus::Validator + pallet_staking::StakerStatus::Validator, ), - ( AccountId::from([0xc; 32]), AccountId::from([0xcc; 32]), 1000, - pallet_staking::StakerStatus::Validator - ) + pallet_staking::StakerStatus::Validator, + ), ]; let _ = pallet_staking::GenesisConfig:: { stakers, ..Default::default() } .assimilate_storage(&mut storage); - let edges = vec![ - ( - AccountId::from([0x1; 32]), - AccountId::from([0x11; 32]), - 100, - 1 - ) - ]; + let edges = vec![(AccountId::from([0x1; 32]), AccountId::from([0x11; 32]), 100, 1)]; let storages = vec![]; let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } .assimilate_storage(&mut storage); TestExternalities::new(storage) - } pub type Extrinsic = TestXt; diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index e9f3c0e4d..a05f79997 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,37 +1,36 @@ -use crate::mock::*; -use crate::mock::Timestamp; -use crate::shm; -use crate::utils; -use crate::{EraIndex, ValidationDecision, DacTotalAggregates, KEY_TYPE, DEFAULT_DATA_PROVIDER_URL, TIME_START_MS, ERA_DURATION_MS, ERA_IN_BLOCKS}; -use pallet_ddc_accounts::BucketsDetails; -use frame_support::{assert_ok, traits::{OffchainWorker, OnInitialize}}; -use sp_core::{ - offchain::{testing, OffchainWorkerExt, OffchainDbExt, TransactionPoolExt}, +use crate::{ + mock::{Timestamp, *}, + shm, utils, DacTotalAggregates, EraIndex, ValidationDecision, DEFAULT_DATA_PROVIDER_URL, + ERA_DURATION_MS, ERA_IN_BLOCKS, KEY_TYPE, TIME_START_MS, +}; +use codec::Decode; +use frame_support::{ + assert_ok, + traits::{OffchainWorker, OnInitialize}, }; +use pallet_ddc_accounts::BucketsDetails; +use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; use std::sync::Arc; -use codec::Decode; - const OCW_PUB_KEY_STR: &str = "d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"; -const OCW_SEED: &str = "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; - +const OCW_SEED: &str = + "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; #[test] fn it_sets_validation_decision_with_one_validator_in_quorum() { - let mut t = new_test_ext(); let (offchain, offchain_state) = testing::TestOffchainExt::new(); t.register_extension(OffchainDbExt::new(offchain.clone())); t.register_extension(OffchainWorkerExt::new(offchain)); - - let keystore = KeyStore::new(); - keystore.sr25519_generate_new(KEY_TYPE, Some(OCW_SEED)).unwrap(); - t.register_extension(KeystoreExt(Arc::new(keystore))); + + let keystore = KeyStore::new(); + keystore.sr25519_generate_new(KEY_TYPE, Some(OCW_SEED)).unwrap(); + t.register_extension(KeystoreExt(Arc::new(keystore))); let (pool, pool_state) = testing::TestTransactionPoolExt::new(); - t.register_extension(TransactionPoolExt::new(pool)); + t.register_extension(TransactionPoolExt::new(pool)); let era_to_validate: EraIndex = 3; let cdn_node_to_validate = AccountId::from([0x1; 32]); @@ -51,28 +50,43 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { }; expect_request( - &format!("{}/JSON.GET/ddc:dac:aggregation:nodes:{}/$.{}", DEFAULT_DATA_PROVIDER_URL, era_to_validate, cdn_node_to_validate_str), - include_bytes!("./mock-data/set-1/aggregated-node-data-for-era.json") + &format!( + "{}/JSON.GET/ddc:dac:aggregation:nodes:{}/$.{}", + DEFAULT_DATA_PROVIDER_URL, era_to_validate, cdn_node_to_validate_str + ), + include_bytes!("./mock-data/set-1/aggregated-node-data-for-era.json"), ); expect_request( - &format!("{}/JSON.GET/ddc:dac:data:file:84640a53-fc1f-4ac5-921c-6695056840bc", DEFAULT_DATA_PROVIDER_URL), - include_bytes!("./mock-data/set-1/file-request1.json") + &format!( + "{}/JSON.GET/ddc:dac:data:file:84640a53-fc1f-4ac5-921c-6695056840bc", + DEFAULT_DATA_PROVIDER_URL + ), + include_bytes!("./mock-data/set-1/file-request1.json"), ); expect_request( - &format!("{}/JSON.GET/ddc:dac:data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7", DEFAULT_DATA_PROVIDER_URL), - include_bytes!("./mock-data/set-1/file-request2.json") + &format!( + "{}/JSON.GET/ddc:dac:data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7", + DEFAULT_DATA_PROVIDER_URL + ), + include_bytes!("./mock-data/set-1/file-request2.json"), ); expect_request( - &format!("{}/JSON.GET/ddc:dac:data:file:80a62530-fd76-40b5-bc53-dd82365e89ce", DEFAULT_DATA_PROVIDER_URL), - include_bytes!("./mock-data/set-1/file-request3.json") + &format!( + "{}/JSON.GET/ddc:dac:data:file:80a62530-fd76-40b5-bc53-dd82365e89ce", + DEFAULT_DATA_PROVIDER_URL + ), + include_bytes!("./mock-data/set-1/file-request3.json"), ); - let decision: ValidationDecision = serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")).unwrap(); + let decision: ValidationDecision = + serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) + .unwrap(); let serialized_decision = serde_json::to_string(&decision).unwrap(); - let encoded_decision_vec = shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); + let encoded_decision_vec = + shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); let encoded_decision_str = encoded_decision_vec.iter().cloned().collect::(); let result_json = serde_json::json!({ "result": decision.result, @@ -83,32 +97,38 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let url_encoded_result_json = utils::url_encode(&unescaped_result_json); expect_request( - &format!("{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", + &format!( + "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", DEFAULT_DATA_PROVIDER_URL, - OCW_PUB_KEY_STR, - cdn_node_to_validate_str, + OCW_PUB_KEY_STR, + cdn_node_to_validate_str, era_to_validate, url_encoded_result_json, ), - include_bytes!("./mock-data/set-1/save-validation-decision-result.json") + include_bytes!("./mock-data/set-1/save-validation-decision-result.json"), ); expect_request( - &format!("{}/JSON.GET/ddc:dac:shared:nodes:{}", DEFAULT_DATA_PROVIDER_URL, era_to_validate), - include_bytes!("./mock-data/set-1/shared-validation-decisions-for-era.json") + &format!( + "{}/JSON.GET/ddc:dac:shared:nodes:{}", + DEFAULT_DATA_PROVIDER_URL, era_to_validate + ), + include_bytes!("./mock-data/set-1/shared-validation-decisions-for-era.json"), ); - } t.execute_with(|| { - let era_block_number = ERA_IN_BLOCKS as u32 * era_to_validate; System::set_block_number(era_block_number); // required for randomness - Timestamp::set_timestamp((TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64); + Timestamp::set_timestamp( + (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, + ); DdcValidator::on_initialize(era_block_number - 1); // make assignments - Timestamp::set_timestamp((TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64); + Timestamp::set_timestamp( + (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64, + ); DdcValidator::offchain_worker(era_block_number + 1); // execute assignments let mut transactions = pool_state.read().transactions.clone(); @@ -123,35 +143,36 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let bucket_info2 = BucketsDetails { bucket_id: 5, amount: 200u128 }; let bucket_info3 = BucketsDetails { bucket_id: 5, amount: 300u128 }; - assert_eq!(tx.call, crate::mock::Call::DdcValidator( - crate::Call::charge_payments_content_owners { - paying_accounts: vec![ - bucket_info3, - bucket_info1, - bucket_info2, - ] - } - )); + assert_eq!( + tx.call, + crate::mock::Call::DdcValidator(crate::Call::charge_payments_content_owners { + paying_accounts: vec![bucket_info3, bucket_info1, bucket_info2,] + }) + ); let tx = transactions.pop().unwrap(); let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); - assert_eq!(tx.call, crate::mock::Call::DdcValidator( - crate::Call::payout_cdn_owners { + assert_eq!( + tx.call, + crate::mock::Call::DdcValidator(crate::Call::payout_cdn_owners { era: era_to_validate + 1 - } - )); + }) + ); let tx = transactions.pop().unwrap(); let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); - let common_decision: ValidationDecision = serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")).unwrap(); + let common_decision: ValidationDecision = + serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) + .unwrap(); let common_decisions = vec![common_decision.clone()]; let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); - assert_eq!(tx.call, crate::mock::Call::DdcValidator( - crate::Call::set_validation_decision { + assert_eq!( + tx.call, + crate::mock::Call::DdcValidator(crate::Call::set_validation_decision { era: era_to_validate + 1, cdn_node: cdn_node_to_validate, validation_decision: ValidationDecision { @@ -165,10 +186,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { failure_rate: common_decision.totals.failure_rate, } } - } - )); - + }) + ); }) } - - From 74cc434cb69b95add9afeb5f67da95893531e4f6 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Jul 2023 17:37:52 +0600 Subject: [PATCH 219/544] Add `Runtime` prefix to `Call`, `Event` and etc. --- pallets/ddc-validator/src/mock.rs | 36 +++++++++++++++--------------- pallets/ddc-validator/src/tests.rs | 6 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 20125eb69..715e27965 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -60,17 +60,17 @@ impl frame_system::Config for Test { type BaseCallFilter = Everything; type BlockWeights = (); type BlockLength = (); - type Origin = Origin; + type RuntimeOrigin = RuntimeOrigin; type Index = u64; type BlockNumber = BlockNumber; type Hash = H256; - type Call = Call; + type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = AccountId; // u64; // sp_core::sr25519::Public; type Lookup = IdentityLookup; type Header = generic::Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); @@ -110,7 +110,7 @@ impl Convert for TestWeightToFee { impl contracts::Config for Test { type AddressGenerator = pallet_contracts::DefaultAddressGenerator; - type Call = Call; + type RuntimeCall = RuntimeCall; type CallFilter = Nothing; type CallStack = [pallet_contracts::Frame; 31]; type ChainExtension = (); @@ -120,7 +120,7 @@ impl contracts::Config for Test { type DeletionWeightLimit = (); type DepositPerByte = DepositPerByte; type DepositPerItem = DepositPerItem; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type MaxCodeLen = ConstU32<{ 128 * 1024 }>; type MaxStorageKeyLen = ConstU32<128>; type Randomness = RandomnessCollectiveFlip; @@ -170,7 +170,7 @@ impl From for MockSessionKeys { } impl pallet_session::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ValidatorId = AccountId; type ValidatorIdOf = (); type ShouldEndSession = TestShouldEndSession; @@ -221,7 +221,7 @@ impl pallet_staking::Config for Test { type UnixTime = Timestamp; type CurrencyToVote = U128CurrencyToVote; type RewardRemainder = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Slash = (); // send the slashed funds to the treasury. type Reward = (); // rewards are minted from the void type SessionsPerEra = SessionsPerEra; @@ -250,7 +250,7 @@ parameter_types! { impl pallet_ddc_accounts::Config for Test { type BondingDuration = BondingDuration; type Currency = Balances; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type PalletId = DdcAccountsPalletId; type TimeProvider = pallet_timestamp::Pallet; } @@ -269,7 +269,7 @@ impl pallet_ddc_staking::Config for Test { type DefaultEdgeChillDelay = DefaultEdgeChillDelay; type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type StakersPayoutSource = DdcAccountsPalletId; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; @@ -282,9 +282,9 @@ parameter_types! { impl pallet_ddc_validator::Config for Test { type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Randomness = RandomnessCollectiveFlip; - type Call = Call; + type RuntimeCall = RuntimeCall; type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; type TimeProvider = pallet_timestamp::Pallet; type ValidationThreshold = ValidationThreshold; @@ -293,9 +293,9 @@ impl pallet_ddc_validator::Config for Test { impl SendTransactionTypes for Test where - Call: From, + RuntimeCall: From, { - type OverarchingCall = Call; + type OverarchingCall = RuntimeCall; type Extrinsic = Extrinsic; } @@ -307,7 +307,7 @@ parameter_types! { impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); @@ -382,7 +382,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { TestExternalities::new(storage) } -pub type Extrinsic = TestXt; +pub type Extrinsic = TestXt; impl SigningTypes for Test { type Public = ::Signer; @@ -391,14 +391,14 @@ impl SigningTypes for Test { impl CreateSignedTransaction for Test where - Call: From, + RuntimeCall: From, { fn create_transaction>( - call: Call, + call: RuntimeCall, _public: ::Signer, _account: AccountId, nonce: u64, - ) -> Option<(Call, ::SignaturePayload)> { + ) -> Option<(RuntimeCall, ::SignaturePayload)> { Some((call, (nonce, ()))) } } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index a05f79997..400e96f64 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -145,7 +145,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { assert_eq!( tx.call, - crate::mock::Call::DdcValidator(crate::Call::charge_payments_content_owners { + crate::mock::RuntimeCall::DdcValidator(crate::Call::charge_payments_content_owners { paying_accounts: vec![bucket_info3, bucket_info1, bucket_info2,] }) ); @@ -155,7 +155,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { assert!(tx.signature.is_some()); assert_eq!( tx.call, - crate::mock::Call::DdcValidator(crate::Call::payout_cdn_owners { + crate::mock::RuntimeCall::DdcValidator(crate::Call::payout_cdn_owners { era: era_to_validate + 1 }) ); @@ -172,7 +172,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { assert_eq!( tx.call, - crate::mock::Call::DdcValidator(crate::Call::set_validation_decision { + crate::mock::RuntimeCall::DdcValidator(crate::Call::set_validation_decision { era: era_to_validate + 1, cdn_node: cdn_node_to_validate, validation_decision: ValidationDecision { From 6801c20035da0bfe4eceb5e5e3358ebf6eb3de9b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 21 Jul 2023 17:42:08 +0600 Subject: [PATCH 220/544] Fix associated types in mock for validator tests --- pallets/ddc-validator/src/mock.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 715e27965..c398c2ac8 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -124,7 +124,6 @@ impl contracts::Config for Test { type MaxCodeLen = ConstU32<{ 128 * 1024 }>; type MaxStorageKeyLen = ConstU32<128>; type Randomness = RandomnessCollectiveFlip; - type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>; type Schedule = Schedule; type Time = Timestamp; type WeightInfo = (); @@ -241,6 +240,8 @@ impl pallet_staking::Config for Test { type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; type CurrencyBalance = Balance; type OnStakerSlash = (); + type HistoryDepth = ConstU32<84>; + type TargetList = pallet_staking::UseValidatorsMap; } parameter_types! { From 5823a4bd097fe159ed5781ca589079165d4bd2d7 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 21 Jul 2023 14:57:26 +0300 Subject: [PATCH 221/544] Update dev.yaml (#67) Small fix for github sha --- .github/workflows/dev.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index 311ccb13c..31aefb459 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -82,6 +82,10 @@ jobs: runs-on: ubuntu-latest needs: build steps: + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + - name: 'Trigger e2e DDC tests' uses: convictional/trigger-workflow-and-wait@v1.6.5 with: From 53ffe5206484c54e915df60ede7c3ab5dacd7aad Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:05:20 +0200 Subject: [PATCH 222/544] Upgrade OS version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e977f7457..0cc717356 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,7 +54,7 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ cargo build --$PROFILE # ===== SECOND STAGE ====== -FROM phusion/baseimage:0.11 +FROM phusion/baseimage:jammy-1.0.1 LABEL maintainer="team@cere.network" LABEL description="This is the optimization to create a small image." ARG PROFILE=release From 717a41ec1c3012d4b246dbdf83d31317ff34aeca Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:53:52 +0200 Subject: [PATCH 223/544] Fix bash entrypoint --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 0cc717356..b891d9262 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,6 +71,7 @@ RUN mv /usr/share/ca* /tmp && \ mkdir -p /cerenetwork/.local/share/cere && \ chown -R cerenetwork:cerenetwork /cerenetwork/.local && \ ln -s /cerenetwork/.local/share/cere /data && \ + mv -t /usr/local/bin /usr/bin/bash /usr/bin/sh && \ rm -rf /usr/bin /usr/sbin USER cerenetwork From 06a1bdfad2f357806cfa65499e069eb322057398 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 27 Jul 2023 10:05:42 +0200 Subject: [PATCH 224/544] payments can only be charged by OCW registered keys --- pallets/ddc-validator/src/lib.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 2f314cc76..36fbe640e 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -393,10 +393,12 @@ pub mod pallet { paying_accounts: Vec>>, ) -> DispatchResult { let controller = ensure_signed(origin)?; - // ensure!( - // OffchainWorkerKeys::::contains_key(&controller), - // Error::::OCWKeyNotRegistered - // ); + log::info!("Controller is {:?}", controller); + + ensure!( + OffchainWorkerKeys::::contains_key(&controller), + Error::::OCWKeyNotRegistered + ); >::charge_payments_new(paying_accounts); @@ -409,10 +411,10 @@ pub mod pallet { era: EraIndex, ) -> DispatchResult { let controller = ensure_signed(origin)?; - // ensure!( - // OffchainWorkerKeys::::contains_key(&controller), - // Error::::OCWKeyNotRegistered - // ); + ensure!( + OffchainWorkerKeys::::contains_key(&controller), + Error::::OCWKeyNotRegistered + ); >::do_payout_stakers(era); @@ -433,7 +435,7 @@ pub mod pallet { Error::::NotController ); - OffchainWorkerKeys::::insert(controller, ocw_pub); + OffchainWorkerKeys::::insert(ocw_pub, controller); Ok(()) } } @@ -531,7 +533,7 @@ pub mod pallet { } fn assign(quorum_size: usize, era: EraIndex) { - let validators: Vec = OffchainWorkerKeys::::iter_values().collect(); + let validators: Vec = OffchainWorkerKeys::::iter_keys().collect(); log::info!("current validators: {:?}", validators); @@ -560,7 +562,9 @@ pub mod pallet { let mut quorums_cycle = quorums.iter().cycle(); for edge in shuffled_edges { let Some(quorum_validators) = quorums_cycle.next() else { - defensive!("unexpectedly ran out of quorums"); + log::info!("unexpectedly ran out of quorums"); + + // defensive!("unexpectedly ran out of quorums"); return }; quorum_validators.iter().for_each(|validator| { From d7a748146ecac12f0539bfb15453fc8779c7bb8c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 27 Jul 2023 17:49:16 +0200 Subject: [PATCH 225/544] skipdeserializing on incorrect type --- pallets/ddc-validator/src/dac.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 1c721a937..f1977384b 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -148,8 +148,8 @@ pub struct Log { #[serde(crate = "alt_serde")] #[serde(rename_all = "camelCase")] pub struct FileInfo { - #[serde(rename = "chunkCids")] - chunk_cids: Vec , + #[serde(rename = "chunkCids", skip_deserializing)] + chunk_cids: Option> , #[serde(rename = "requestedChunkCids")] requested_chunk_cids: Vec, From cb8d37b3a64ee08722c6d6b71ea4e3b69c80058a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 28 Jul 2023 15:25:57 +0200 Subject: [PATCH 226/544] avoid double spend of content owner funds --- pallets/ddc-validator/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 36fbe640e..cfeab2f9e 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -195,10 +195,17 @@ pub mod pallet { type ValidationThreshold: Get; } + // Map of assignments per validator per era #[pallet::storage] #[pallet::getter(fn assignments)] pub(super) type Assignments = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, Vec>; + + // Map to check if validation decision was performed for the era + #[pallet::storage] + #[pallet::getter(fn contentOwnersCharged)] + pub(super) type EraContentOwnersCharged = + StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; /// A signal to start a process on all the validators. #[pallet::storage] @@ -226,6 +233,7 @@ pub mod pallet { pub enum Error { NotController, OCWKeyNotRegistered, + ContentOwnersDoubleSpend } #[pallet::event] @@ -395,6 +403,13 @@ pub mod pallet { let controller = ensure_signed(origin)?; log::info!("Controller is {:?}", controller); + let era = Self::get_current_era(); + + ensure!( + Self::contentOwnersCharged(era, &controller), + Error::::ContentOwnersDoubleSpend + ); + ensure!( OffchainWorkerKeys::::contains_key(&controller), Error::::OCWKeyNotRegistered @@ -402,6 +417,8 @@ pub mod pallet { >::charge_payments_new(paying_accounts); + EraContentOwnersCharged::::insert(era, controller, true); + Ok(()) } From d5ca085603a39f3114ba5d3c734435be691920ad Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 2 Aug 2023 14:13:44 +0600 Subject: [PATCH 227/544] Return an error on validators assignment failure --- pallets/ddc-validator/src/lib.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index ceeecd7e2..62e4b5906 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -88,6 +88,13 @@ pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://redis:6379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; +#[derive(Debug)] +pub enum AssignmentError { + NoValidators, + NotEnoughValidators { requested_quorum: usize, available_validators: usize }, + DefensiveEmptyQuorumsCycle, +} + /// Aggregated values from DAC that describe CDN node's activity during a certain era. #[derive( PartialEq, @@ -544,15 +551,26 @@ pub mod pallet { /// /// Each CDN node is assigned to `quorum_size` validators randomly picked from the validator /// set. - fn assign(quorum_size: usize, era: EraIndex) { + fn assign(quorum_size: usize, era: EraIndex) -> Result<(), AssignmentError> { let validators: Vec = >::iter_keys().collect(); log::info!("current validators: {:?}", validators); + if validators.len() == 0 { + return Err(AssignmentError::NoValidators) + } + + if validators.len() < quorum_size { + return Err(AssignmentError::NotEnoughValidators { + requested_quorum: quorum_size, + available_validators: validators.len(), + }) + } + let edges: Vec = >::iter_keys().collect(); log::info!("current edges: {:?}", edges); if edges.len() == 0 { - return + return Ok(()) } let shuffled_validators = Self::shuffle(validators); @@ -573,8 +591,7 @@ pub mod pallet { let mut quorums_cycle = quorums.iter().cycle(); for edge in shuffled_edges { let Some(quorum_validators) = quorums_cycle.next() else { - defensive!("unexpectedly ran out of quorums"); - return + return Err(AssignmentError::DefensiveEmptyQuorumsCycle); }; quorum_validators.iter().for_each(|validator| { Assignments::::append( @@ -584,6 +601,8 @@ pub mod pallet { ); }); } + + return Ok(()) } /// Randomly choose a number in range `[0, total)`. From e52eaec2a665a57078bb23d8b4feb7011c8ec984 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 2 Aug 2023 14:45:04 +0600 Subject: [PATCH 228/544] Tasks assignment errors handling --- pallets/ddc-validator/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 62e4b5906..71424702d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -268,13 +268,19 @@ pub mod pallet { let era = Self::get_current_era(); log::info!("current era: {:?}", era); + // Produce an assignment for the next era if it's not produced yet. match Self::last_managed_era() { - Some(last_managed_era) if era < last_managed_era => (), - _ => { - Self::assign(3usize, era + 1); - >::put(era + 1); + Some(last_managed_era) if era < last_managed_era => return Weight::from_ref_time(0), + _ => (), + }; + + match Self::assign(3usize, era + 1) { + Ok(_) => >::put(era + 1), + Err(AssignmentError::DefensiveEmptyQuorumsCycle) => { + defensive!("unexpectedly empty quorums cycle"); }, + Err(e) => log::debug!("assignment error: {:?}", e), }; Weight::from_ref_time(0) From ca716fa1c582d2132ea603b00064f03e60904644 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 4 Aug 2023 12:14:05 +0200 Subject: [PATCH 229/544] add workflow --- .../workflows/build-and-push-docker-image.yml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/build-and-push-docker-image.yml diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml new file mode 100644 index 000000000..409db1db6 --- /dev/null +++ b/.github/workflows/build-and-push-docker-image.yml @@ -0,0 +1,55 @@ +name: Build and push image to ECR +on: + push: + branches: + - dev + - master + - 'feature/**' + - 'release/**' + - 'hotfix/**' +env: + ECR_REPOSITORY: pos-network-node +jobs: + build-and-push: + runs-on: [self-hosted, cere-network-xlarge-workers] + steps: + - name: Checkout repository + uses: actions/checkout@v1 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Build and push image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: | + image_id=$(docker build . -q -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA) + echo IMAGE_ID=$image_id >> $GITHUB_ENV + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA" + docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA $ECR_REGISTRY/$ECR_REPOSITORY:latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA + docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest + - name: Copy wasm artifacts from the image + run: | + container_id=$(docker create ${{ env.IMAGE_ID }}) + cere_runtime_artifact_name=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm + echo CERE_RUNTIME_ARTIFACT_NAME=$cere_runtime_artifact_name >> $GITHUB_ENV + docker cp $container_id:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm ./$cere_runtime_artifact_name + cere_dev_runtime_artifact_name=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm + echo CERE_DEV_RUNTIME_ARTIFACT_NAME=$cere_dev_runtime_artifact_name >> $GITHUB_ENV + docker cp $container_id:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm ./$cere_dev_runtime_artifact_name + - name: Upload cere-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ env.CERE_RUNTIME_ARTIFACT_NAME }} + path: ./${{ env.CERE_RUNTIME_ARTIFACT_NAME }} + - name: Upload cere-dev-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} + path: ./${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} \ No newline at end of file From 183389ebe802bc081bb4133019373b4aa415f92d Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:27:49 +0200 Subject: [PATCH 230/544] Execute build with locked Cargo.lock dependencies --- .github/workflows/dev.yaml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index 31aefb459..9180bd087 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -85,7 +85,7 @@ jobs: - name: Get short SHA run: | echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV - + - name: 'Trigger e2e DDC tests' uses: convictional/trigger-workflow-and-wait@v1.6.5 with: diff --git a/Dockerfile b/Dockerfile index b891d9262..543bc86f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ ENV \ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ - cargo build --$PROFILE + cargo build --locked --$PROFILE # ===== SECOND STAGE ====== FROM phusion/baseimage:jammy-1.0.1 From 3b8453be243562e956411ab3e001540cf7d83b2d Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:49:44 +0200 Subject: [PATCH 231/544] Archive artifacts --- .github/workflows/dev.yaml | 45 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index 9180bd087..e83f7209f 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -36,12 +36,16 @@ jobs: role-session-name: ${{ github.event.repository.name }} aws-region: us-west-2 - - name: Get short SHA + - name: Confiure environment variables run: | - echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV - echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> ${GITHUB_ENV} + + echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> ${GITHUB_ENV} + echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> ${GITHUB_ENV} + echo "AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}" >> ${GITHUB_ENV} + + echo "CERE_RUNTIME=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} + echo "CERE_DEV_RUNTIME=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -66,17 +70,24 @@ jobs: ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest - # - name: Upload cere-runtime wasm artifact - # uses: actions/upload-artifact@v3 - # with: - # name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm - # path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm - # - # - name: Upload cere-dev-runtime wasm artifact - # uses: actions/upload-artifact@v3 - # with: - # name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm - # path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + - name: Copy wasm artifacts from the image + run: | + CONTAINER_ID=$(docker create ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }}) + + docker cp "${CONTAINER_ID}:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm" "./${{ env.CERE_RUNTIME }}" + docker cp "${CONTAINER_ID}:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm" "./${{ env.CERE_DEV_RUNTIME }}" + + - name: Upload cere-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: "cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_RUNTIME }}" + + - name: Upload cere-dev-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: "cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_DEV_RUNTIME }}" trigger-e2e-tests: runs-on: ubuntu-latest @@ -84,7 +95,7 @@ jobs: steps: - name: Get short SHA run: | - echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> ${GITHUB_ENV} - name: 'Trigger e2e DDC tests' uses: convictional/trigger-workflow-and-wait@v1.6.5 From 70a66dc56159498dbc02f7b7dbfe4041b89d09dc Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:52:45 +0200 Subject: [PATCH 232/544] Stage environment --- .github/workflows/stage.yaml | 47 ++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/.github/workflows/stage.yaml b/.github/workflows/stage.yaml index ca7338fcd..02959cc64 100644 --- a/.github/workflows/stage.yaml +++ b/.github/workflows/stage.yaml @@ -5,7 +5,6 @@ on: - 'release/**' - 'hotfix/**' - 'master' - workflow_dispatch: env: PROFILE: release @@ -13,7 +12,7 @@ env: jobs: build: runs-on: ubuntu-latest - concurrency: stage + concurrency: dev permissions: contents: read id-token: write @@ -38,12 +37,16 @@ jobs: role-session-name: ${{ github.event.repository.name }} aws-region: us-west-2 - - name: Get short SHA + - name: Confiure environment variables run: | - echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV - echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> ${GITHUB_ENV} + + echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> ${GITHUB_ENV} + echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> ${GITHUB_ENV} + echo "AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}" >> ${GITHUB_ENV} + + echo "CERE_RUNTIME=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} + echo "CERE_DEV_RUNTIME=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -66,15 +69,23 @@ jobs: tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest + + - name: Copy wasm artifacts from the image + run: | + CONTAINER_ID=$(docker create ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }}) -# - name: Upload cere-runtime wasm artifact -# uses: actions/upload-artifact@v3 -# with: -# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm -# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm -# -# - name: Upload cere-dev-runtime wasm artifact -# uses: actions/upload-artifact@v3 -# with: -# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm -# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + docker cp "${CONTAINER_ID}:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm" "./${{ env.CERE_RUNTIME }}" + docker cp "${CONTAINER_ID}:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm" "./${{ env.CERE_DEV_RUNTIME }}" + + - name: Upload cere-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: "cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_RUNTIME }}" + + - name: Upload cere-dev-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: "cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_DEV_RUNTIME }}" From af26c4d08e87754db7bb23645cb23980278aaf4a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 4 Aug 2023 13:09:55 +0200 Subject: [PATCH 233/544] update workflows --- .github/workflows/dev.yml | 47 ++++++++++++++++++++++++++------------- Dockerfile | 9 ++++---- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index c9ad21887..fe851e83f 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -36,12 +36,16 @@ jobs: role-session-name: ${{ github.event.repository.name }} aws-region: us-west-2 - - name: Get short SHA + - name: Confiure environment variables run: | - echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> $GITHUB_ENV - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> $GITHUB_ENV - echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN" >> $GITHUB_ENV + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> ${GITHUB_ENV} + + echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> ${GITHUB_ENV} + echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> ${GITHUB_ENV} + echo "AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}" >> ${GITHUB_ENV} + + echo "CERE_RUNTIME=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} + echo "CERE_DEV_RUNTIME=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -66,22 +70,33 @@ jobs: ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest - # - name: Upload cere-runtime wasm artifact - # uses: actions/upload-artifact@v3 - # with: - # name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm - # path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm - # - # - name: Upload cere-dev-runtime wasm artifact - # uses: actions/upload-artifact@v3 - # with: - # name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm - # path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm + - name: Copy wasm artifacts from the image + run: | + CONTAINER_ID=$(docker create ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }}) + + docker cp "${CONTAINER_ID}:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm" "./${{ env.CERE_RUNTIME }}" + docker cp "${CONTAINER_ID}:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm" "./${{ env.CERE_DEV_RUNTIME }}" + + - name: Upload cere-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: "cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_RUNTIME }}" + + - name: Upload cere-dev-runtime wasm artifact + uses: actions/upload-artifact@v3 + with: + name: "cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_DEV_RUNTIME }}" trigger-e2e-tests: runs-on: ubuntu-latest needs: build steps: + - name: Get short SHA + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> ${GITHUB_ENV} + - name: 'Trigger e2e DDC tests' uses: convictional/trigger-workflow-and-wait@v1.6.5 with: diff --git a/Dockerfile b/Dockerfile index ef43ae342..7984c8af7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,8 @@ ARG PROFILE=release WORKDIR /cerenetwork COPY . /cerenetwork -RUN apt-get -qq update && \ - apt-get -qq install -y \ +RUN apt-get update && \ + apt-get install -y \ clang \ cmake \ git \ @@ -51,10 +51,10 @@ ENV \ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ - cargo build --$PROFILE + cargo build --locked --$PROFILE # ===== SECOND STAGE ====== -FROM phusion/baseimage:0.11 +FROM phusion/baseimage:jammy-1.0.1 LABEL maintainer="team@cere.network" LABEL description="This is the optimization to create a small image." ARG PROFILE=release @@ -71,6 +71,7 @@ RUN mv /usr/share/ca* /tmp && \ mkdir -p /cerenetwork/.local/share/cere && \ chown -R cerenetwork:cerenetwork /cerenetwork/.local && \ ln -s /cerenetwork/.local/share/cere /data && \ + mv -t /usr/local/bin /usr/bin/bash /usr/bin/sh && \ rm -rf /usr/bin /usr/sbin USER cerenetwork From c1509c46fc01cb3eef5db26e0c91f41ffbddab4b Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Fri, 4 Aug 2023 13:15:01 +0200 Subject: [PATCH 234/544] Build on official github runners --- .github/workflows/build-and-push-docker-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index 409db1db6..420de9677 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -11,7 +11,7 @@ env: ECR_REPOSITORY: pos-network-node jobs: build-and-push: - runs-on: [self-hosted, cere-network-xlarge-workers] + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v1 @@ -52,4 +52,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} \ No newline at end of file + path: ./${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} From 7134076085c366d5eb74a293aa1dc70db76df999 Mon Sep 17 00:00:00 2001 From: Alexander Dobrodey <8377544+ADobrodey@users.noreply.github.com> Date: Fri, 4 Aug 2023 13:18:35 +0200 Subject: [PATCH 235/544] Actualize build --- .../workflows/build-and-push-docker-image.yml | 99 +++++++++++++------ 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index 420de9677..9113a9e72 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -2,54 +2,89 @@ name: Build and push image to ECR on: push: branches: - - dev - - master - 'feature/**' - - 'release/**' - - 'hotfix/**' + env: + PROFILE: release ECR_REPOSITORY: pos-network-node + jobs: - build-and-push: + build: runs-on: ubuntu-latest + concurrency: dev + permissions: + contents: read + id-token: write steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + - uses: actions/checkout@v3 + + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false with: - aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github + role-session-name: ${{ github.event.repository.name }} aws-region: us-west-2 + + - name: Confiure environment variables + run: | + echo "GITHUB_SHA=${GITHUB_SHA:0:7}" >> ${GITHUB_ENV} + + echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> ${GITHUB_ENV} + echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> ${GITHUB_ENV} + echo "AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}" >> ${GITHUB_ENV} + + echo "CERE_RUNTIME=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} + echo "CERE_DEV_RUNTIME=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm" >> ${GITHUB_ENV} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - - name: Build and push image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - run: | - image_id=$(docker build . -q -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA) - echo IMAGE_ID=$image_id >> $GITHUB_ENV - echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA" - docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA $ECR_REGISTRY/$ECR_REPOSITORY:latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest + + - name: Build and push docker image to ECR + uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: | + "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" + "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" + "AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }}" + "SCCACHE_REGION=us-west-2" + "SCCACHE_BUCKET=cere-blockchain-sccache" + + tags: | + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest + - name: Copy wasm artifacts from the image run: | - container_id=$(docker create ${{ env.IMAGE_ID }}) - cere_runtime_artifact_name=cere_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm - echo CERE_RUNTIME_ARTIFACT_NAME=$cere_runtime_artifact_name >> $GITHUB_ENV - docker cp $container_id:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm ./$cere_runtime_artifact_name - cere_dev_runtime_artifact_name=cere_dev_runtime.compact.compressed.${GITHUB_SHA:0:7}.wasm - echo CERE_DEV_RUNTIME_ARTIFACT_NAME=$cere_dev_runtime_artifact_name >> $GITHUB_ENV - docker cp $container_id:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm ./$cere_dev_runtime_artifact_name + CONTAINER_ID=$(docker create ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }}) + + docker cp "${CONTAINER_ID}:/home/cere/cere-runtime-artifacts/cere_runtime.compact.compressed.wasm" "./${{ env.CERE_RUNTIME }}" + docker cp "${CONTAINER_ID}:/home/cere/cere-dev-runtime-artifacts/cere_dev_runtime.compact.compressed.wasm" "./${{ env.CERE_DEV_RUNTIME }}" + - name: Upload cere-runtime wasm artifact uses: actions/upload-artifact@v3 with: - name: ${{ env.CERE_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_RUNTIME_ARTIFACT_NAME }} + name: "cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_RUNTIME }}" + - name: Upload cere-dev-runtime wasm artifact uses: actions/upload-artifact@v3 with: - name: ${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} - path: ./${{ env.CERE_DEV_RUNTIME_ARTIFACT_NAME }} + name: "cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm" + path: "./${{ env.CERE_DEV_RUNTIME }}" From e3cc31df5dd6c84aa23af513a21d6bb7e4cbe204 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 4 Aug 2023 16:07:49 +0200 Subject: [PATCH 236/544] comment out not tested functionality --- pallets/ddc-validator/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index cfeab2f9e..016c7132b 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -405,10 +405,11 @@ pub mod pallet { let era = Self::get_current_era(); - ensure!( - Self::contentOwnersCharged(era, &controller), - Error::::ContentOwnersDoubleSpend - ); + // not tested + // ensure!( + // Self::contentOwnersCharged(era, &controller), + // Error::::ContentOwnersDoubleSpend + // ); ensure!( OffchainWorkerKeys::::contains_key(&controller), From 02fa607f8ed0ac7ad2d063bd7570c6d079e081d9 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 11 Aug 2023 15:51:25 +0600 Subject: [PATCH 237/544] Return Result from validation func --- pallets/ddc-validator/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 71424702d..98c7dcf45 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -667,7 +667,7 @@ pub mod pallet { } } - fn validate_edges() { + fn validate_edges() -> Result<(), &'static str> { let current_era = Self::get_current_era(); let mock_data_url = Self::get_mock_data_url(); let data_provider_url = Self::get_data_provider_url(); @@ -792,7 +792,7 @@ pub mod pallet { let signer: Signer = Signer::<_, _>::any_account(); if !signer.can_sign() { log::warn!("No local accounts available to charge payments for CDN. Consider adding one via `author_insertKey` RPC."); - return + return Err("signing key not set") } // ToDo: replace local call by a call from `ddc-staking` pallet let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = @@ -821,6 +821,8 @@ pub mod pallet { } } } + + Ok(()) } } } From 9f2384e52f4425243331985dc503ec22aa34bf22 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Fri, 11 Aug 2023 17:44:38 +0200 Subject: [PATCH 238/544] Revert "Merge pull request #73 from Cerebellum-Network/hotfix/revert-4.8.0-dev" This reverts commit b1c4acaaafa821bae8c30878b278392e4b736ebc, reversing changes made to 70a66dc56159498dbc02f7b7dbfe4041b89d09dc. --- .github/workflows/check.yaml | 5 + .maintain/frame-weight-template.hbs | 104 ++ .vscode/settings.json | 9 + CHANGELOG.md | 21 + Cargo.lock | 1402 ++++++++++------- Cargo.toml | 6 +- Dockerfile | 55 +- Dockerfile.tests | 12 +- cli/Cargo.toml | 12 +- cli/src/command.rs | 7 +- node/client/Cargo.toml | 56 +- node/service/Cargo.toml | 69 +- node/service/src/chain_spec.rs | 1 + node/service/src/lib.rs | 25 +- pallets/chainbridge/Cargo.toml | 20 +- pallets/chainbridge/src/lib.rs | 1064 ++++++------- pallets/chainbridge/src/mock.rs | 205 ++- pallets/chainbridge/src/tests.rs | 983 ++++++------ .../ddc-metrics-offchain-worker/Cargo.toml | 26 +- .../ddc-metrics-offchain-worker/src/lib.rs | 1324 ++++++++-------- .../src/tests/mod.rs | 648 ++++---- .../src/tests/test_runtime.rs | 240 +-- pallets/ddc-staking/Cargo.toml | 22 +- pallets/ddc-staking/README.md | 15 + pallets/ddc-staking/src/benchmarking.rs | 3 + pallets/ddc-staking/src/lib.rs | 115 +- pallets/ddc-staking/src/mock.rs | 244 +++ pallets/ddc-staking/src/tests.rs | 178 +++ pallets/ddc-staking/src/weights.rs | 144 +- pallets/ddc/Cargo.toml | 14 +- pallets/ddc/src/lib.rs | 13 +- pallets/ddc/src/mock.rs | 22 +- pallets/ddc/src/tests.rs | 6 +- pallets/erc20/Cargo.toml | 20 +- pallets/erc20/src/lib.rs | 219 ++- pallets/erc721/Cargo.toml | 18 +- pallets/erc721/src/lib.rs | 197 ++- pallets/erc721/src/mock.rs | 132 +- pallets/erc721/src/tests.rs | 132 +- rpc/Cargo.toml | 48 +- rpc/src/lib.rs | 16 +- runtime/cere-dev/Cargo.toml | 162 +- runtime/cere-dev/constants/Cargo.toml | 6 +- runtime/cere-dev/src/impls.rs | 15 +- runtime/cere-dev/src/lib.rs | 213 +-- runtime/cere/Cargo.toml | 160 +- runtime/cere/constants/Cargo.toml | 6 +- runtime/cere/src/impls.rs | 15 +- runtime/cere/src/lib.rs | 212 +-- runtime/common/Cargo.toml | 10 +- runtime/common/src/lib.rs | 16 +- scripts/init.sh | 2 + scripts/pre-commit.sh | 8 + 53 files changed, 4853 insertions(+), 3824 deletions(-) create mode 100644 .maintain/frame-weight-template.hbs create mode 100644 .vscode/settings.json create mode 100644 pallets/ddc-staking/src/mock.rs create mode 100644 pallets/ddc-staking/src/tests.rs mode change 100755 => 100644 pallets/ddc-staking/src/weights.rs create mode 100755 scripts/pre-commit.sh diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 7013c3543..1e6a57960 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -32,6 +32,11 @@ jobs: rustup default stable rustup update nightly rustup update stable + rustup component add rustfmt --toolchain nightly + + - name: Check Format + run: | + cargo +nightly fmt -- --check - name: Check Build run: | diff --git a/.maintain/frame-weight-template.hbs b/.maintain/frame-weight-template.hbs new file mode 100644 index 000000000..e2248b4e2 --- /dev/null +++ b/.maintain/frame-weight-template.hbs @@ -0,0 +1,104 @@ +//! Autogenerated weights for {{pallet}} +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` +//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for {{pallet}}. +pub trait WeightInfo { + {{#each benchmarks as |benchmark|}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{c.name}}: u32, {{/each~}} + ) -> Weight; + {{/each}} +} + +/// Weights for {{pallet}} using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +{{#if (eq pallet "frame_system")}} +impl WeightInfo for SubstrateWeight { +{{else}} +impl WeightInfo for SubstrateWeight { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + Weight::from_ref_time({{underscore benchmark.base_weight}} as u64) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_ref_time({{underscore cw.slope}} as u64).saturating_mul({{cw.name}} as u64)) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as u64)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as u64).saturating_mul({{cr.name}} as u64))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as u64)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as u64).saturating_mul({{cw.name}} as u64))) + {{/each}} + } + {{/each}} +} + +// For backwards compatibility and tests +impl WeightInfo for () { + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + Weight::from_ref_time({{underscore benchmark.base_weight}} as u64) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_ref_time({{underscore cw.slope}} as u64).saturating_mul({{cw.name}} as u64)) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as u64)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as u64).saturating_mul({{cr.name}} as u64))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as u64)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as u64).saturating_mul({{cw.name}} as u64))) + {{/each}} + } + {{/each}} +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..003fc3624 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer", + "editor.formatOnSave": true + }, + "rust-analyzer.rustfmt.extraArgs": [ + "+nightly" + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b0e24e03..9122f8269 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,33 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Legend + +[C] Cere Runtime +[D] Cere Dev Runtime + ## [vNext] +### Added + +- ... + ### Changed - ... +## [4.8.0] + +### Added + +- [D] Handlebars template to generate weights file +- [D] Genesis config for `pallet-ddc-staking` to set genesis DDC participants (empty by default) and staking settings +- [D] Unit tests in `pallet-ddc-staking` for basic staking scenario + +### Changed + +- [C,D] Updated Substrate to polkadot-v0.9.30 + ## [4.7.0] ### Changed diff --git a/Cargo.lock b/Cargo.lock index 3d4c9b4ca..8b70b378c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,9 +23,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" dependencies = [ "gimli 0.27.3", ] @@ -168,6 +168,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "array-bytes" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52f63c5c1316a16a4b35eaac8b76a98248961a533f061684cb2a7cb0eafb6c6" + [[package]] name = "arrayref" version = "0.3.7" @@ -203,9 +209,9 @@ checksum = "155a5a185e42c6b77ac7b88a15143d930a9e9727a5b7b77eed417404ab15c247" [[package]] name = "async-channel" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", "event-listener", @@ -255,7 +261,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.20", + "rustix 0.37.23", "slab", "socket2 0.4.9", "waker-fn", @@ -283,7 +289,7 @@ dependencies = [ "cfg-if", "event-listener", "futures-lite", - "rustix 0.37.20", + "rustix 0.37.23", "signal-hook", "windows-sys 0.48.0", ] @@ -309,7 +315,7 @@ dependencies = [ "log", "memchr", "once_cell", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "pin-utils", "slab", "wasm-bindgen-futures", @@ -338,13 +344,13 @@ checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -357,7 +363,7 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", ] [[package]] @@ -385,16 +391,16 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" dependencies = [ - "addr2line 0.19.0", + "addr2line 0.20.0", "cc", "cfg-if", "libc", - "miniz_oxide 0.6.2", - "object 0.30.4", + "miniz_oxide", + "object 0.31.1", "rustc-demangle", ] @@ -428,6 +434,12 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "beef" version = "0.5.2" @@ -458,19 +470,19 @@ version = "0.65.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "lazy_static", "lazycell", "peeking_take_while", - "prettyplease", + "prettyplease 0.2.10", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -479,6 +491,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + [[package]] name = "bitvec" version = "1.0.1" @@ -534,15 +552,15 @@ dependencies = [ [[package]] name = "blake3" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b71f35bd3fa1a4c86b85d32c8b9069ea7fe14f7a53cfabb65f62d4265b888" +checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" dependencies = [ "arrayref", "arrayvec 0.7.4", "cc", "cfg-if", - "constant_time_eq 0.2.6", + "constant_time_eq 0.3.0", ] [[package]] @@ -607,9 +625,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5" +checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" dependencies = [ "memchr", "serde", @@ -693,7 +711,7 @@ dependencies = [ "cargo-platform", "semver 1.0.17", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", ] [[package]] @@ -707,7 +725,7 @@ dependencies = [ [[package]] name = "cere" -version = "4.7.0" +version = "4.8.0" dependencies = [ "cere-cli", "sc-cli", @@ -717,7 +735,7 @@ dependencies = [ [[package]] name = "cere-cli" -version = "4.7.0" +version = "4.8.0" dependencies = [ "cere-client", "cere-service", @@ -731,7 +749,7 @@ dependencies = [ [[package]] name = "cere-client" -version = "4.7.0" +version = "4.8.0" dependencies = [ "cere-dev-runtime", "cere-runtime", @@ -766,7 +784,7 @@ dependencies = [ [[package]] name = "cere-dev-runtime" -version = "4.7.0" +version = "4.8.0" dependencies = [ "cere-dev-runtime-constants", "cere-runtime-common", @@ -802,6 +820,7 @@ dependencies = [ "pallet-elections-phragmen", "pallet-erc20", "pallet-erc721", + "pallet-fast-unstake", "pallet-grandpa", "pallet-identity", "pallet-im-online", @@ -853,7 +872,7 @@ dependencies = [ [[package]] name = "cere-dev-runtime-constants" -version = "4.7.0" +version = "4.8.0" dependencies = [ "node-primitives", "sp-runtime", @@ -861,7 +880,7 @@ dependencies = [ [[package]] name = "cere-rpc" -version = "4.7.0" +version = "4.8.0" dependencies = [ "jsonrpsee", "node-primitives", @@ -891,7 +910,7 @@ dependencies = [ [[package]] name = "cere-runtime" -version = "4.7.0" +version = "4.8.0" dependencies = [ "cere-runtime-common", "cere-runtime-constants", @@ -926,6 +945,7 @@ dependencies = [ "pallet-elections-phragmen", "pallet-erc20", "pallet-erc721", + "pallet-fast-unstake", "pallet-grandpa", "pallet-identity", "pallet-im-online", @@ -977,7 +997,7 @@ dependencies = [ [[package]] name = "cere-runtime-common" -version = "4.7.0" +version = "4.8.0" dependencies = [ "frame-support", "node-primitives", @@ -987,7 +1007,7 @@ dependencies = [ [[package]] name = "cere-runtime-constants" -version = "4.7.0" +version = "4.8.0" dependencies = [ "node-primitives", "sp-runtime", @@ -995,7 +1015,7 @@ dependencies = [ [[package]] name = "cere-service" -version = "4.7.0" +version = "4.8.0" dependencies = [ "cere-client", "cere-dev-runtime", @@ -1067,6 +1087,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chacha20" version = "0.8.2" @@ -1157,7 +1183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "indexmap", @@ -1236,6 +1262,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + [[package]] name = "core-foundation" version = "0.9.3" @@ -1272,28 +1304,30 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] [[package]] name = "cranelift-bforest" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "749d0d6022c9038dccf480bdde2a38d435937335bf2bb0f14e815d94517cdce8" +checksum = "52056f6d0584484b57fa6c1a65c1fcb15f3780d8b6a758426d9e3084169b2ddd" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94370cc7b37bf652ccd8bb8f09bd900997f7ccf97520edfc75554bb5c4abbea" +checksum = "18fed94c8770dc25d01154c3ffa64ed0b3ba9d583736f305fed7beebe5d9cf74" dependencies = [ + "arrayvec 0.7.4", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", @@ -1308,33 +1342,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a3cea8fdab90e44018c5b9a1dfd460d8ee265ac354337150222a354628bdb6" +checksum = "1c451b81faf237d11c7e4f3165eeb6bac61112762c5cfe7b4c0fb7241474358f" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac72f76f2698598951ab26d8c96eaa854810e693e7dd52523958b5909fde6b2" +checksum = "e7c940133198426d26128f08be2b40b0bd117b84771fd36798969c4d712d81fc" [[package]] name = "cranelift-entity" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09eaeacfcd2356fe0e66b295e8f9d59fdd1ac3ace53ba50de14d628ec902f72d" +checksum = "87a0f1b2fdc18776956370cf8d9b009ded3f855350c480c1c52142510961f352" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba69c9980d5ffd62c18a2bde927855fcd7c8dc92f29feaf8636052662cbd99c" +checksum = "34897538b36b216cc8dd324e73263596d51b8cf610da6498322838b2546baf8a" dependencies = [ "cranelift-codegen", "log", @@ -1344,15 +1378,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2920dc1e05cac40304456ed3301fde2c09bd6a9b0210bcfa2f101398d628d5b" +checksum = "1b2629a569fae540f16a76b70afcc87ad7decb38dc28fa6c648ac73b51e78470" [[package]] name = "cranelift-native" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04dfa45f9b2a6f587c564d6b63388e00cd6589d2df6ea2758cf79e1a13285e6" +checksum = "20937dab4e14d3e225c5adfc9c7106bafd4ac669bdb43027b911ff794c6fb318" dependencies = [ "cranelift-codegen", "libc", @@ -1361,9 +1395,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.85.3" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31a46513ae6f26f3f267d8d75b5373d555fbbd1e68681f348d99df43f747ec54" +checksum = "80fc2288957a94fd342a015811479de1837850924166d1f1856d8406e6f3609b" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -1685,9 +1719,9 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "dtoa" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65d09067bfacaa79114679b279d7f5885b53295b1e2cfb4e79c8e4bd3d633169" +checksum = "519b83cd10f5f6e969625a409f735182bea5558cd8b64c655806ceaae36f1999" [[package]] name = "dyn-clonable" @@ -1758,7 +1792,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ "curve25519-dalek 3.2.0", - "hashbrown 0.12.3", + "hashbrown", "hex", "rand_core 0.6.4", "sha2 0.9.9", @@ -1818,7 +1852,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -2010,7 +2044,7 @@ checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", "libz-sys", - "miniz_oxide 0.7.1", + "miniz_oxide", ] [[package]] @@ -2022,7 +2056,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2039,7 +2073,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2062,9 +2096,10 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", + "array-bytes", "chrono", "clap", "comfy-table", @@ -2074,7 +2109,6 @@ dependencies = [ "gethostname", "handlebars", "hash-db", - "hex", "itertools", "kvdb", "lazy_static", @@ -2092,7 +2126,7 @@ dependencies = [ "sc-service", "sc-sysinfo", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "serde_nanos", "sp-api", "sp-blockchain", @@ -2113,7 +2147,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2124,7 +2158,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2140,7 +2174,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2169,9 +2203,9 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "frame-metadata", "frame-support-procedural", "impl-trait-for-tuples", @@ -2194,13 +2228,14 @@ dependencies = [ "sp-state-machine", "sp-std", "sp-tracing", + "sp-weights", "tt-call", ] [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2214,7 +2249,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2226,7 +2261,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2236,7 +2271,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2248,12 +2283,13 @@ dependencies = [ "sp-runtime", "sp-std", "sp-version", + "sp-weights", ] [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2268,7 +2304,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2277,7 +2313,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -2380,7 +2416,7 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "waker-fn", ] @@ -2392,7 +2428,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -2437,7 +2473,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "pin-utils", "slab", ] @@ -2602,7 +2638,7 @@ dependencies = [ "pest", "pest_derive", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "thiserror", ] @@ -2621,15 +2657,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -2656,18 +2683,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -2737,7 +2755,7 @@ checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", - "itoa 1.0.6", + "itoa 1.0.8", ] [[package]] @@ -2748,7 +2766,7 @@ checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", ] [[package]] @@ -2784,8 +2802,8 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.6", - "pin-project-lite 0.2.9", + "itoa 1.0.8", + "pin-project-lite 0.2.10", "socket2 0.4.9", "tokio", "tower-service", @@ -2916,7 +2934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown 0.12.3", + "hashbrown", "serde", ] @@ -2947,12 +2965,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "io-lifetimes" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec58677acfea8a15352d42fc87d11d63596ade9239e0a7c9352914417515dbe6" - [[package]] name = "io-lifetimes" version = "0.7.5" @@ -2965,7 +2977,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "windows-sys 0.48.0", ] @@ -2996,13 +3008,12 @@ checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "is-terminal" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes 1.0.11", - "rustix 0.37.20", + "hermit-abi 0.3.2", + "rustix 0.38.3", "windows-sys 0.48.0", ] @@ -3023,9 +3034,9 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" [[package]] name = "jobserver" @@ -3104,7 +3115,7 @@ dependencies = [ "rand 0.8.5", "rustc-hash", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "soketto", "thiserror", "tokio", @@ -3125,7 +3136,7 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-types", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "tokio", "tracing", "tracing-futures", @@ -3152,7 +3163,7 @@ dependencies = [ "anyhow", "beef", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "thiserror", "tracing", ] @@ -3180,7 +3191,7 @@ dependencies = [ "http", "jsonrpsee-core", "jsonrpsee-types", - "serde_json 1.0.99", + "serde_json 1.0.100", "soketto", "tokio", "tokio-stream", @@ -3366,8 +3377,8 @@ dependencies = [ "libp2p-request-response", "libp2p-swarm", "log", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.8.5", ] @@ -3393,8 +3404,8 @@ dependencies = [ "multistream-select", "parking_lot 0.12.1", "pin-project", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.8.5", "ring", "rw-stream-sink", @@ -3444,8 +3455,8 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.7.3", "smallvec", ] @@ -3468,8 +3479,8 @@ dependencies = [ "libp2p-swarm", "log", "prometheus-client", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.7.3", "regex", "sha2 0.10.7", @@ -3491,8 +3502,8 @@ dependencies = [ "libp2p-swarm", "log", "lru", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "prost-codec", "smallvec", "thiserror", @@ -3516,8 +3527,8 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.7.3", "sha2 0.10.7", "smallvec", @@ -3594,8 +3605,8 @@ dependencies = [ "lazy_static", "libp2p-core", "log", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.8.5", "sha2 0.10.7", "snow", @@ -3631,8 +3642,8 @@ dependencies = [ "futures", "libp2p-core", "log", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "unsigned-varint", "void", ] @@ -3667,8 +3678,8 @@ dependencies = [ "libp2p-swarm", "log", "pin-project", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "prost-codec", "rand 0.8.5", "smallvec", @@ -3691,8 +3702,8 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.8.5", "sha2 0.10.7", "thiserror", @@ -3922,12 +3933,6 @@ dependencies = [ "statrs", ] -[[package]] -name = "linux-raw-sys" -version = "0.0.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5284f00d480e1c39af34e72f8ad60b94f47007e3481cd3b731c1d67190ddc7b7" - [[package]] name = "linux-raw-sys" version = "0.0.46" @@ -3940,6 +3945,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + [[package]] name = "lite-json" version = "0.2.0" @@ -3983,7 +3994,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" dependencies = [ - "hashbrown 0.12.3", + "hashbrown", ] [[package]] @@ -4036,7 +4047,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -4063,11 +4074,11 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memfd" -version = "0.4.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6627dc657574b49d6ad27105ed671822be56e0d2547d413bfbf3e8d8fa92e7a" +checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" dependencies = [ - "libc", + "rustix 0.37.23", ] [[package]] @@ -4104,15 +4115,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown 0.12.3", + "hashbrown", "parity-util-mem", ] [[package]] name = "memory_units" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "merlin" @@ -4132,15 +4143,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -4161,12 +4163,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "more-asserts" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" - [[package]] name = "multiaddr" version = "0.14.0" @@ -4304,7 +4300,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9ea4302b9759a7a88242299225ea3688e63c85ea136371bb6cf94fd674efaab" dependencies = [ "anyhow", - "bitflags", + "bitflags 1.3.2", "byteorder", "libc", "netlink-packet-core", @@ -4357,7 +4353,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", ] @@ -4365,7 +4361,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4408,6 +4404,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-complex" version = "0.4.3" @@ -4424,7 +4431,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" dependencies = [ "arrayvec 0.7.4", - "itoa 1.0.6", + "itoa 1.0.8", ] [[package]] @@ -4444,7 +4451,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ "autocfg", - "num-bigint", + "num-bigint 0.2.6", "num-integer", "num-traits", ] @@ -4456,6 +4463,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg", + "num-bigint 0.4.3", "num-integer", "num-traits", ] @@ -4472,31 +4480,31 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.2", "libc", ] [[package]] name = "object" -version = "0.28.4" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "crc32fast", - "hashbrown 0.11.2", + "hashbrown", "indexmap", "memchr", ] [[package]] name = "object" -version = "0.30.4" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" dependencies = [ "memchr", ] @@ -4562,7 +4570,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4578,7 +4586,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4593,7 +4601,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4617,7 +4625,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4637,7 +4645,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4652,7 +4660,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4669,7 +4677,7 @@ dependencies = [ [[package]] name = "pallet-cere-ddc" -version = "4.7.0" +version = "4.8.0" dependencies = [ "frame-support", "frame-system", @@ -4684,7 +4692,7 @@ dependencies = [ [[package]] name = "pallet-chainbridge" -version = "4.7.0" +version = "4.8.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -4703,7 +4711,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4722,7 +4730,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4739,9 +4747,9 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "frame-benchmarking", "frame-support", "frame-system", @@ -4767,9 +4775,9 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "parity-scale-codec", "scale-info", "serde", @@ -4782,7 +4790,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4792,7 +4800,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4809,7 +4817,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -4821,7 +4829,7 @@ dependencies = [ [[package]] name = "pallet-ddc-metrics-offchain-worker" -version = "4.7.0" +version = "4.8.0" dependencies = [ "alt_serde", "frame-support", @@ -4847,24 +4855,28 @@ dependencies = [ [[package]] name = "pallet-ddc-staking" -version = "4.7.0" +version = "4.8.0" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "pallet-balances", + "pallet-timestamp", "parity-scale-codec", "scale-info", + "sp-core", "sp-io", "sp-runtime", "sp-staking", "sp-std", + "sp-tracing", "substrate-test-utils", ] [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4880,13 +4892,14 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", "frame-support", "frame-system", "log", + "pallet-election-provider-support-benchmarking", "parity-scale-codec", "rand 0.7.3", "scale-info", @@ -4903,7 +4916,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4916,7 +4929,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4933,7 +4946,7 @@ dependencies = [ [[package]] name = "pallet-erc20" -version = "4.7.0" +version = "4.8.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -4953,7 +4966,7 @@ dependencies = [ [[package]] name = "pallet-erc721" -version = "4.7.0" +version = "4.8.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -4969,10 +4982,31 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-fast-unstake" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-staking", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4995,7 +5029,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5011,7 +5045,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5031,7 +5065,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5048,7 +5082,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5065,7 +5099,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5080,7 +5114,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5097,7 +5131,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5109,6 +5143,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", + "sp-runtime-interface", "sp-staking", "sp-std", ] @@ -5116,7 +5151,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5126,7 +5161,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5143,7 +5178,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5166,7 +5201,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5181,7 +5216,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5195,7 +5230,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5210,7 +5245,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5226,7 +5261,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5247,7 +5282,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5263,7 +5298,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5277,7 +5312,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5300,7 +5335,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5311,7 +5346,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5325,7 +5360,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5343,7 +5378,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5362,7 +5397,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5378,7 +5413,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5393,7 +5428,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5404,7 +5439,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5422,7 +5457,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5439,7 +5474,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5455,7 +5490,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5488,9 +5523,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.1" +version = "3.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2287753623c76f953acd29d15d8100bcab84d29db78fb6f352adb3c53e83b967" +checksum = "756d439303e94fae44f288ba881ad29670c65b0c4b0e05674ca81061bb65f2c5" dependencies = [ "arrayvec 0.7.4", "bitvec", @@ -5503,9 +5538,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.1" +version = "3.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b6937b5e67bfba3351b87b040d48352a2fcb6ad72f81855412ce97b45c8f110" +checksum = "9d884d78fcf214d70b1e239fcd1c6e5e95aa3be1881918da2e488cc946c7a476" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5526,7 +5561,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if", - "hashbrown 0.12.3", + "hashbrown", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.1", @@ -5557,9 +5592,9 @@ dependencies = [ [[package]] name = "parity-wasm" -version = "0.42.2" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" +checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" [[package]] name = "parking" @@ -5617,9 +5652,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "b4b27ab7be369122c218afc2079489cdcb4b517c0a3fc386ff11e1fedfcc2b35" [[package]] name = "pbkdf2" @@ -5681,7 +5716,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -5707,22 +5742,22 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" +checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" +checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -5733,9 +5768,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" [[package]] name = "pin-utils" @@ -5743,6 +5778,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs8" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" +dependencies = [ + "der", + "spki", + "zeroize", +] + [[package]] name = "pkg-config" version = "0.3.27" @@ -5768,12 +5814,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if", "concurrent-queue", "libc", "log", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "windows-sys 0.48.0", ] @@ -5820,12 +5866,22 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.9" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" dependencies = [ "proc-macro2", - "syn 2.0.22", + "syn 1.0.109", +] + +[[package]] +name = "prettyplease" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387" +dependencies = [ + "proc-macro2", + "syn 2.0.25", ] [[package]] @@ -5877,9 +5933,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -5905,7 +5961,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac1abe0255c04d15f571427a2d1e00099016506cf3297b53853acd2b7eb87825" dependencies = [ "dtoa", - "itoa 1.0.6", + "itoa 1.0.8", "owning_ref", "prometheus-client-derive-text-encode", ] @@ -5928,7 +5984,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71adf41db68aa0daaefc69bb30bcd68ded9b9abaad5d1fbb6304c4fb390e083e" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.10.1", +] + +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive 0.11.9", ] [[package]] @@ -5946,13 +6012,35 @@ dependencies = [ "log", "multimap", "petgraph", - "prost", - "prost-types", + "prost 0.10.4", + "prost-types 0.10.1", "regex", "tempfile", "which", ] +[[package]] +name = "prost-build" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +dependencies = [ + "bytes", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prettyplease 0.1.25", + "prost 0.11.9", + "prost-types 0.11.9", + "regex", + "syn 1.0.109", + "tempfile", + "which", +] + [[package]] name = "prost-codec" version = "0.1.0" @@ -5961,7 +6049,7 @@ checksum = "00af1e92c33b4813cc79fda3f2dbf56af5169709be0202df730e9ebc3e4cd007" dependencies = [ "asynchronous-codec", "bytes", - "prost", + "prost 0.10.4", "thiserror", "unsigned-varint", ] @@ -5979,6 +6067,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "prost-types" version = "0.10.1" @@ -5986,7 +6087,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d0a014229361011dc8e69c8a1ec6c2e8d0f2af7c91e3ea3f5b2170298461e68" dependencies = [ "bytes", - "prost", + "prost 0.10.4", +] + +[[package]] +name = "prost-types" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +dependencies = [ + "prost 0.11.9", ] [[package]] @@ -6017,9 +6127,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" dependencies = [ "proc-macro2", ] @@ -6164,7 +6274,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -6173,7 +6283,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -6189,29 +6299,29 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43faa91b1c8b36841ee70e97188a869d37ae21759da6846d4be66de5bf7b12c" +checksum = "1641819477c319ef452a075ac34a4be92eb9ba09f6841f62d594d50fdcf0bf6b" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7" +checksum = "68bf53dad9b6086826722cdc99140793afd9f62faa14a1ad07eb4f955e7a7216" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] name = "regalloc2" -version = "0.2.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a8d23b35d7177df3b9d31ed8a9ab4bf625c668be77a319d4f5efd4a5257701c" +checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" dependencies = [ "fxhash", "log", @@ -6221,13 +6331,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick 1.0.2", "memchr", - "regex-syntax 0.7.2", + "regex-automata 0.3.2", + "regex-syntax 0.7.3", ] [[package]] @@ -6240,40 +6351,39 @@ dependencies = [ ] [[package]] -name = "regex-syntax" -version = "0.6.29" +name = "regex-automata" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" +dependencies = [ + "aho-corasick 1.0.2", + "memchr", + "regex-syntax 0.7.3", +] [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] -name = "region" -version = "2.2.0" +name = "regex-syntax" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" -dependencies = [ - "bitflags", - "libc", - "mach", - "winapi", -] +checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", "log", "parity-scale-codec", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-core", "sp-io", "sp-runtime", @@ -6400,43 +6510,42 @@ dependencies = [ [[package]] name = "rustix" -version = "0.33.7" +version = "0.35.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" +checksum = "6380889b07a03b5ecf1d44dc9ede6fd2145d84b502a2a9ca0b03c48e0cc3220f" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno 0.2.8", - "io-lifetimes 0.5.3", + "io-lifetimes 0.7.5", "libc", - "linux-raw-sys 0.0.42", - "winapi", + "linux-raw-sys 0.0.46", + "windows-sys 0.42.0", ] [[package]] name = "rustix" -version = "0.35.13" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ - "bitflags", - "errno 0.2.8", - "io-lifetimes 0.7.5", + "bitflags 1.3.2", + "errno 0.3.1", + "io-lifetimes 1.0.11", "libc", - "linux-raw-sys 0.0.46", - "windows-sys 0.42.0", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", ] [[package]] name = "rustix" -version = "0.37.20" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0" +checksum = "ac5ffa1efe7548069688cd7028f32591853cd7b5b756d41bcffd2353e4fc75b4" dependencies = [ - "bitflags", + "bitflags 2.3.3", "errno 0.3.1", - "io-lifetimes 1.0.11", "libc", - "linux-raw-sys 0.3.8", + "linux-raw-sys 0.4.3", "windows-sys 0.48.0", ] @@ -6475,9 +6584,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "dc31bd9b61a32c31f9650d18add92aa83a49ba979c143eefd27fe7177b05bd5f" [[package]] name = "rw-stream-sink" @@ -6492,9 +6601,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" [[package]] name = "safe-mix" @@ -6526,7 +6635,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6537,7 +6646,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6546,8 +6655,8 @@ dependencies = [ "libp2p", "log", "parity-scale-codec", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "rand 0.7.3", "sc-client-api", "sc-network-common", @@ -6564,7 +6673,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6587,7 +6696,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6603,7 +6712,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6612,7 +6721,7 @@ dependencies = [ "sc-network-common", "sc-telemetry", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-core", "sp-runtime", ] @@ -6620,7 +6729,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6631,13 +6740,13 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "chrono", "clap", "fdlimit", "futures", - "hex", "libp2p", "log", "names", @@ -6649,12 +6758,13 @@ dependencies = [ "sc-client-db", "sc-keystore", "sc-network", + "sc-network-common", "sc-service", "sc-telemetry", "sc-tracing", "sc-utils", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-blockchain", "sp-core", "sp-keyring", @@ -6670,7 +6780,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -6698,7 +6808,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -6723,7 +6833,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6747,14 +6857,14 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", "futures", "log", "merlin", - "num-bigint", + "num-bigint 0.2.6", "num-rational 0.2.4", "num-traits", "parity-scale-codec", @@ -6789,7 +6899,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -6811,7 +6921,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -6824,7 +6934,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6842,14 +6952,13 @@ dependencies = [ "sp-inherents", "sp-runtime", "sp-state-machine", - "sp-timestamp", "thiserror", ] [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -6860,7 +6969,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -6887,7 +6996,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -6903,7 +7012,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -6918,16 +7027,15 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", "log", "once_cell", "parity-scale-codec", - "parity-wasm 0.42.2", - "rustix 0.33.7", - "rustix 0.35.13", + "parity-wasm 0.45.0", + "rustix 0.35.14", "sc-allocator", "sc-executor-common", "sp-runtime-interface", @@ -6939,16 +7047,16 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", + "array-bytes", "async-trait", "dyn-clone", "finality-grandpa", "fork-tree", "futures", "futures-timer", - "hex", "log", "parity-scale-codec", "parking_lot 0.12.1", @@ -6963,7 +7071,7 @@ dependencies = [ "sc-network-gossip", "sc-telemetry", "sc-utils", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-api", "sp-application-crypto", "sp-arithmetic", @@ -6980,7 +7088,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -6991,7 +7099,7 @@ dependencies = [ "sc-finality-grandpa", "sc-rpc", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-blockchain", "sp-core", "sp-runtime", @@ -7001,7 +7109,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7018,12 +7126,12 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "async-trait", - "hex", "parking_lot 0.12.1", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-application-crypto", "sp-core", "sp-keystore", @@ -7033,11 +7141,12 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "async-trait", "asynchronous-codec", - "bitflags", + "bitflags 1.3.2", "bytes", "cid", "either", @@ -7045,7 +7154,6 @@ dependencies = [ "fork-tree", "futures", "futures-timer", - "hex", "ip_network", "libp2p", "linked-hash-map", @@ -7055,8 +7163,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "pin-project", - "prost", - "prost-build", + "prost 0.10.4", "rand 0.7.3", "sc-block-builder", "sc-client-api", @@ -7065,7 +7172,7 @@ dependencies = [ "sc-peerset", "sc-utils", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "smallvec", "sp-arithmetic", "sp-blockchain", @@ -7075,22 +7182,43 @@ dependencies = [ "substrate-prometheus-endpoint", "thiserror", "unsigned-varint", - "void", "zeroize", ] +[[package]] +name = "sc-network-bitswap" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "cid", + "futures", + "libp2p", + "log", + "prost 0.11.9", + "prost-build 0.11.9", + "sc-client-api", + "sc-network-common", + "sp-blockchain", + "sp-runtime", + "thiserror", + "unsigned-varint", + "void", +] + [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", - "bitflags", + "bitflags 1.3.2", "bytes", "futures", + "futures-timer", "libp2p", + "linked_hash_set", "parity-scale-codec", - "prost-build", + "prost-build 0.10.4", "sc-consensus", "sc-peerset", "serde", @@ -7099,13 +7227,14 @@ dependencies = [ "sp-consensus", "sp-finality-grandpa", "sp-runtime", + "substrate-prometheus-endpoint", "thiserror", ] [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7123,15 +7252,15 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "futures", - "hex", "libp2p", "log", "parity-scale-codec", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "sc-client-api", "sc-network-common", "sc-peerset", @@ -7144,17 +7273,17 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "fork-tree", "futures", - "hex", "libp2p", "log", "lru", "parity-scale-codec", - "prost", - "prost-build", + "prost 0.10.4", + "prost-build 0.10.4", "sc-client-api", "sc-consensus", "sc-network-common", @@ -7169,16 +7298,35 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sc-network-transactions" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "array-bytes", + "futures", + "hex", + "libp2p", + "log", + "parity-scale-codec", + "pin-project", + "sc-network-common", + "sc-peerset", + "sp-consensus", + "sp-runtime", + "substrate-prometheus-endpoint", +] + [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "bytes", "fnv", "futures", "futures-timer", - "hex", "hyper", "hyper-rustls", "libp2p", @@ -7202,20 +7350,20 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", "log", "sc-utils", - "serde_json 1.0.99", + "serde_json 1.0.100", "wasm-timer", ] [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7224,7 +7372,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7239,7 +7387,7 @@ dependencies = [ "sc-tracing", "sc-transaction-pool-api", "sc-utils", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-api", "sp-blockchain", "sp-core", @@ -7254,7 +7402,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7265,7 +7413,7 @@ dependencies = [ "sc-transaction-pool-api", "scale-info", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-core", "sp-rpc", "sp-runtime", @@ -7277,12 +7425,12 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", "log", - "serde_json 1.0.99", + "serde_json 1.0.100", "substrate-prometheus-endpoint", "tokio", ] @@ -7290,7 +7438,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7314,9 +7462,11 @@ dependencies = [ "sc-informant", "sc-keystore", "sc-network", + "sc-network-bitswap", "sc-network-common", "sc-network-light", "sc-network-sync", + "sc-network-transactions", "sc-offchain", "sc-rpc", "sc-rpc-server", @@ -7327,7 +7477,7 @@ dependencies = [ "sc-transaction-pool-api", "sc-utils", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-api", "sp-application-crypto", "sp-block-builder", @@ -7346,6 +7496,7 @@ dependencies = [ "sp-transaction-storage-proof", "sp-trie", "sp-version", + "static_init", "substrate-prometheus-endpoint", "tempfile", "thiserror", @@ -7357,7 +7508,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7371,7 +7522,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7381,7 +7532,7 @@ dependencies = [ "sc-consensus-epochs", "sc-finality-grandpa", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-blockchain", "sp-runtime", "thiserror", @@ -7390,7 +7541,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7400,7 +7551,7 @@ dependencies = [ "regex", "sc-telemetry", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-core", "sp-io", "sp-std", @@ -7409,7 +7560,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7419,7 +7570,7 @@ dependencies = [ "pin-project", "rand 0.7.3", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "thiserror", "wasm-timer", ] @@ -7427,7 +7578,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7458,7 +7609,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7469,7 +7620,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7495,7 +7646,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7508,7 +7659,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7520,9 +7671,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad560913365790f17cbf12479491169f01b9d46d29cfc7422bf8c64bdc61b731" +checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" dependencies = [ "bitvec", "cfg-if", @@ -7534,9 +7685,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19df9bd9ace6cc2fe19387c96ce677e823e07d017ceed253e7bb3d1d1bd9c73b" +checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7546,11 +7697,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys 0.42.0", + "windows-sys 0.48.0", ] [[package]] @@ -7595,6 +7746,7 @@ checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", "generic-array 0.14.7", + "pkcs8", "subtle", "zeroize", ] @@ -7632,7 +7784,7 @@ version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -7684,22 +7836,22 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.164" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -7714,11 +7866,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" dependencies = [ - "itoa 1.0.6", + "itoa 1.0.8", "ryu", "serde", ] @@ -7864,9 +8016,9 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "snap" @@ -7930,7 +8082,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -7948,7 +8100,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -7960,7 +8112,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -7973,7 +8125,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -7988,7 +8140,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8001,7 +8153,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8013,7 +8165,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8025,7 +8177,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8043,7 +8195,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8062,7 +8214,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8085,7 +8237,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8099,7 +8251,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8112,18 +8264,18 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ + "array-bytes", "base58", - "bitflags", - "blake2-rfc", + "bitflags 1.3.2", + "blake2", "byteorder", "dyn-clonable", "ed25519-zebra", "futures", "hash-db", "hash256-std-hasher", - "hex", "impl-serde", "lazy_static", "libsecp256k1", @@ -8158,7 +8310,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", @@ -8172,7 +8324,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8183,7 +8335,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8192,7 +8344,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8202,7 +8354,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8213,7 +8365,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8231,7 +8383,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8245,7 +8397,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8271,7 +8423,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8282,7 +8434,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8299,7 +8451,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8308,7 +8460,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8322,7 +8474,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8332,7 +8484,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8342,7 +8494,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8352,7 +8504,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8369,12 +8521,13 @@ dependencies = [ "sp-core", "sp-io", "sp-std", + "sp-weights", ] [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8392,7 +8545,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8404,7 +8557,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8418,7 +8571,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8432,7 +8585,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8443,7 +8596,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8465,12 +8618,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8483,7 +8636,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8496,7 +8649,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8512,7 +8665,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8524,7 +8677,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8533,7 +8686,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8549,11 +8702,11 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", - "hashbrown 0.12.3", + "hashbrown", "lazy_static", "lru", "memory-db", @@ -8572,11 +8725,11 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", - "parity-wasm 0.42.2", + "parity-wasm 0.45.0", "scale-info", "serde", "sp-core-hashing-proc-macro", @@ -8589,7 +8742,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8600,7 +8753,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8610,24 +8763,50 @@ dependencies = [ "wasmtime", ] +[[package]] +name = "sp-weights" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "serde", + "smallvec", + "sp-arithmetic", + "sp-core", + "sp-debug-derive", + "sp-std", +] + [[package]] name = "spin" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spki" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "ss58-registry" -version = "1.40.0" +version = "1.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47a8ad42e5fc72d5b1eb104a5546937eaf39843499948bb666d6e93c62423b" +checksum = "bfc443bad666016e012538782d9e3006213a7db43e9fb1dda91657dc06a6fa08" dependencies = [ "Inflector", "num-format", "proc-macro2", "quote", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "unicode-xid", ] @@ -8643,6 +8822,34 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "static_init" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2a1c578e98c1c16fc3b8ec1328f7659a500737d7a0c6d625e73e830ff9c1f6" +dependencies = [ + "bitflags 1.3.2", + "cfg_aliases", + "libc", + "parking_lot 0.11.2", + "parking_lot_core 0.8.6", + "static_init_macro", + "winapi", +] + +[[package]] +name = "static_init_macro" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a2595fc3aa78f2d0e45dd425b22282dd863273761cc77780914b2cf3003acf" +dependencies = [ + "cfg_aliases", + "memchr", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "statrs" version = "0.15.0" @@ -8700,7 +8907,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -8708,7 +8915,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -8718,7 +8925,7 @@ dependencies = [ "sc-client-api", "sc-rpc-api", "sc-transaction-pool-api", - "serde_json 1.0.99", + "serde_json 1.0.100", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8729,7 +8936,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -8742,7 +8949,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -8763,7 +8970,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -8773,7 +8980,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -8784,7 +8991,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -8817,9 +9024,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.22" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ "proc-macro2", "quote", @@ -8844,7 +9051,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] @@ -8881,7 +9088,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.20", + "rustix 0.37.23", "windows-sys 0.48.0", ] @@ -8902,22 +9109,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -9003,9 +9210,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.0" +version = "1.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374442f06ee49c3a28a8fc9f01a2596fed7559c6b99b31279c3261778e77d84f" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", "backtrace", @@ -9014,7 +9221,7 @@ dependencies = [ "mio", "num_cpus", "parking_lot 0.12.1", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "signal-hook-registry", "socket2 0.4.9", "tokio-macros", @@ -9029,7 +9236,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -9050,7 +9257,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "tokio", ] @@ -9064,7 +9271,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "tokio", "tracing", ] @@ -9091,7 +9298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.10", "tracing-attributes", "tracing-core", ] @@ -9104,7 +9311,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -9161,7 +9368,7 @@ dependencies = [ "parking_lot 0.11.2", "regex", "serde", - "serde_json 1.0.99", + "serde_json 1.0.100", "sharded-slab", "smallvec", "thread_local", @@ -9178,7 +9385,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "004e1e8f92535694b4cb1444dc5a8073ecf0815e3357f729638b9f8fc4062908" dependencies = [ "hash-db", - "hashbrown 0.12.3", + "hashbrown", "log", "rustc-hex", "smallvec", @@ -9245,7 +9452,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.29#cc370aa61e15c18d23a2f686b812fd576a630afe" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", @@ -9294,9 +9501,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ucd-trie" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "uint" @@ -9327,9 +9534,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" [[package]] name = "unicode-normalization" @@ -9485,7 +9692,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", "wasm-bindgen-shared", ] @@ -9519,7 +9726,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -9543,11 +9750,11 @@ dependencies = [ [[package]] name = "wasm-instrument" -version = "0.1.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "962e5b0401bbb6c887f54e69b8c496ea36f704df65db73e81fd5ff8dc3e63a9f" +checksum = "aa1dafb3e60065305741e83db35c6c2584bb3725b692b5b66148a38d72ace6cd" dependencies = [ - "parity-wasm 0.42.2", + "parity-wasm 0.45.0", ] [[package]] @@ -9567,58 +9774,63 @@ dependencies = [ [[package]] name = "wasmi" -version = "0.9.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca00c5147c319a8ec91ec1a0edbec31e566ce2c9cc93b3f9bb86a9efd0eb795d" +checksum = "06c326c93fbf86419608361a2c925a31754cf109da1b8b55737070b4d6669422" dependencies = [ - "downcast-rs", - "libc", - "libm 0.2.7", - "memory_units", - "num-rational 0.2.4", - "num-traits", - "parity-wasm 0.42.2", + "parity-wasm 0.45.0", "wasmi-validation", + "wasmi_core", ] [[package]] name = "wasmi-validation" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" +checksum = "91ff416ad1ff0c42e5a926ed5d5fab74c0f098749aa0ad8b2a34b982ce0e867b" dependencies = [ - "parity-wasm 0.42.2", + "parity-wasm 0.45.0", +] + +[[package]] +name = "wasmi_core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d20cb3c59b788653d99541c646c561c9dd26506f25c0cebfe810659c54c6d7" +dependencies = [ + "downcast-rs", + "libm 0.2.7", + "memory_units", + "num-rational 0.4.1", + "num-traits", ] [[package]] name = "wasmparser" -version = "0.85.0" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570460c58b21e9150d2df0eaaedbb7816c34bcec009ae0dcc976e40ba81463e7" +checksum = "ab5d3e08b13876f96dd55608d03cd4883a0545884932d5adf11925876c96daef" dependencies = [ "indexmap", ] [[package]] name = "wasmtime" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f50eadf868ab6a04b7b511460233377d0bfbb92e417b2f6a98b98fef2e098f5" +checksum = "4ad5af6ba38311282f2a21670d96e78266e8c8e2f38cbcd52c254df6ccbc7731" dependencies = [ "anyhow", - "backtrace", "bincode", "cfg-if", "indexmap", - "lazy_static", "libc", "log", - "object 0.28.4", + "object 0.29.0", "once_cell", "paste", "psm", "rayon", - "region", "serde", "target-lexicon", "wasmparser", @@ -9627,14 +9839,23 @@ dependencies = [ "wasmtime-environ", "wasmtime-jit", "wasmtime-runtime", - "winapi", + "windows-sys 0.36.1", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45de63ddfc8b9223d1adc8f7b2ee5f35d1f6d112833934ad7ea66e4f4339e597" +dependencies = [ + "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1df23c642e1376892f3b72f311596976979cbf8b85469680cdd3a8a063d12a2" +checksum = "bcd849399d17d2270141cfe47fa0d91ee52d5f8ea9b98cf7ddde0d53e5f79882" dependencies = [ "anyhow", "base64 0.13.1", @@ -9642,19 +9863,19 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix 0.33.7", + "rustix 0.35.14", "serde", "sha2 0.9.9", "toml", - "winapi", + "windows-sys 0.36.1", "zstd", ] [[package]] name = "wasmtime-cranelift" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f264ff6b4df247d15584f2f53d009fbc90032cfdc2605b52b961bffc71b6eccd" +checksum = "4bd91339b742ff20bfed4532a27b73c86b5bcbfedd6bea2dcdf2d64471e1b5c6" dependencies = [ "anyhow", "cranelift-codegen", @@ -9664,8 +9885,7 @@ dependencies = [ "cranelift-wasm", "gimli 0.26.2", "log", - "more-asserts", - "object 0.28.4", + "object 0.29.0", "target-lexicon", "thiserror", "wasmparser", @@ -9674,17 +9894,16 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839d2820e4b830f4b9e7aa08d4c0acabf4a5036105d639f6dfa1c6891c73bdc6" +checksum = "ebb881c61f4f627b5d45c54e629724974f8a8890d455bcbe634330cc27309644" dependencies = [ "anyhow", "cranelift-entity", "gimli 0.26.2", "indexmap", "log", - "more-asserts", - "object 0.28.4", + "object 0.29.0", "serde", "target-lexicon", "thiserror", @@ -9694,9 +9913,9 @@ dependencies = [ [[package]] name = "wasmtime-jit" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef0a0bcbfa18b946d890078ba0e1bc76bcc53eccfb40806c0020ec29dcd1bd49" +checksum = "1985c628011fe26adf5e23a5301bdc79b245e0e338f14bb58b39e4e25e4d8681" dependencies = [ "addr2line 0.17.0", "anyhow", @@ -9705,38 +9924,36 @@ dependencies = [ "cpp_demangle", "gimli 0.26.2", "log", - "object 0.28.4", - "region", + "object 0.29.0", "rustc-demangle", - "rustix 0.33.7", + "rustix 0.35.14", "serde", "target-lexicon", "thiserror", "wasmtime-environ", "wasmtime-jit-debug", "wasmtime-runtime", - "winapi", + "windows-sys 0.36.1", ] [[package]] name = "wasmtime-jit-debug" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4779d976206c458edd643d1ac622b6c37e4a0800a8b1d25dfbf245ac2f2cac" +checksum = "f671b588486f5ccec8c5a3dba6b4c07eac2e66ab8c60e6f4e53717c77f709731" dependencies = [ - "lazy_static", - "object 0.28.4", - "rustix 0.33.7", + "object 0.29.0", + "once_cell", + "rustix 0.35.14", ] [[package]] name = "wasmtime-runtime" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7eb6ffa169eb5dcd18ac9473c817358cd57bc62c244622210566d473397954a" +checksum = "ee8f92ad4b61736339c29361da85769ebc200f184361959d1792832e592a1afd" dependencies = [ "anyhow", - "backtrace", "cc", "cfg-if", "indexmap", @@ -9745,21 +9962,21 @@ dependencies = [ "mach", "memfd", "memoffset 0.6.5", - "more-asserts", + "paste", "rand 0.8.5", - "region", - "rustix 0.33.7", + "rustix 0.35.14", "thiserror", + "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-jit-debug", - "winapi", + "windows-sys 0.36.1", ] [[package]] name = "wasmtime-types" -version = "0.38.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d932b0ac5336f7308d869703dd225610a6a3aeaa8e968c52b43eed96cefb1c2" +checksum = "d23d61cb4c46e837b431196dd06abb11731541021916d03476a178b54dc07aeb" dependencies = [ "cranelift-entity", "serde", @@ -9866,6 +10083,19 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -9892,9 +10122,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ "windows_aarch64_gnullvm 0.48.0", "windows_aarch64_msvc 0.48.0", @@ -9923,6 +10153,12 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -9941,6 +10177,12 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -9959,6 +10201,12 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -9977,6 +10225,12 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -10007,6 +10261,12 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -10080,7 +10340,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ae62d4a9f..7be78ede0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,17 +5,17 @@ path = "src/main.rs" [package] name = "cere" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" -version = "4.7.0" +version = "4.8.0" edition = "2021" build = "build.rs" [dependencies] cere-cli = { path = "cli", features = [ "cere-dev-native" ] } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } +sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } ss58-registry = { version = "1.38.0", default-features = false } [build-dependencies] -substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [workspace] members = [ diff --git a/Dockerfile b/Dockerfile index 6e3fd1bb8..543bc86f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,66 @@ -FROM phusion/baseimage:0.11 as builder +FROM phusion/baseimage:jammy-1.0.1 as builder LABEL maintainer="team@cere.network" LABEL description="This is the build stage to create the binary." ARG PROFILE=release WORKDIR /cerenetwork COPY . /cerenetwork -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y cmake pkg-config libssl-dev git clang +RUN apt-get -qq update && \ + apt-get -qq install -y \ + clang \ + cmake \ + git \ + libpq-dev \ + libssl-dev \ + pkg-config \ + unzip \ + wget + +# Configure sccache +ENV SCCACHE_VERSION=0.5.4 +RUN wget -q https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz \ + -O - | tar -xz \ + && mv sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache /usr/local/bin/sccache \ + && chmod +x /usr/local/bin/sccache \ + && rm -rf sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl +ENV RUSTC_WRAPPER=/usr/local/bin/sccache + +# Installation script is taken from https://grpc.io/docs/protoc-installation/ +ENV PROTOC_VERSION=3.15.8 +RUN PB_REL="https://github.com/protocolbuffers/protobuf/releases" && \ + curl -sLO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ + mkdir -p /usr/local/protoc && \ + unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local/protoc && \ + chmod +x /usr/local/protoc/bin/protoc && \ + ln -s /usr/local/protoc/bin/protoc /usr/local/bin + +ARG AWS_ACCESS_KEY_ID +ARG AWS_SECRET_ACCESS_KEY +ARG AWS_SESSION_TOKEN +ARG SCCACHE_REGION=us-west-2 +ARG SCCACHE_BUCKET=cere-blockchain-sccache +ENV \ + AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ + AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ + AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \ + AWS_REGION=$SCCACHE_REGION \ + SCCACHE_REGION=$SCCACHE_REGION \ + SCCACHE_BUCKET=$SCCACHE_BUCKET \ + SCCACHE_S3_USE_SSL=true + RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ cargo build --locked --$PROFILE # ===== SECOND STAGE ====== -FROM phusion/baseimage:0.11 +FROM phusion/baseimage:jammy-1.0.1 LABEL maintainer="team@cere.network" LABEL description="This is the optimization to create a small image." ARG PROFILE=release COPY --from=builder /cerenetwork/target/$PROFILE/cere /usr/local/bin -COPY --from=builder /cerenetwork/target/release/wbuild/cere-runtime /home/cere/cere-runtime-artifacts -COPY --from=builder /cerenetwork/target/release/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-runtime /home/cere/cere-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts RUN mv /usr/share/ca* /tmp && \ rm -rf /usr/share/* && \ @@ -31,6 +71,7 @@ RUN mv /usr/share/ca* /tmp && \ mkdir -p /cerenetwork/.local/share/cere && \ chown -R cerenetwork:cerenetwork /cerenetwork/.local && \ ln -s /cerenetwork/.local/share/cere /data && \ + mv -t /usr/local/bin /usr/bin/bash /usr/bin/sh && \ rm -rf /usr/bin /usr/sbin USER cerenetwork diff --git a/Dockerfile.tests b/Dockerfile.tests index 56bba2fed..23c25292b 100644 --- a/Dockerfile.tests +++ b/Dockerfile.tests @@ -17,7 +17,17 @@ COPY --from=ddc-smart-contract /ddc-smart-contract/artifacts/metadata.json /cere RUN apt-get update && \ apt-get upgrade -y && \ - apt-get install -y cmake pkg-config libssl-dev git clang + apt-get install -y cmake pkg-config libssl-dev git clang unzip + +# Installation script is taken from https://grpc.io/docs/protoc-installation/ +ENV PROTOC_VERSION=3.15.8 +RUN PB_REL="https://github.com/protocolbuffers/protobuf/releases" && \ + curl -LO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ + mkdir -p /usr/local/protoc && \ + unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local/protoc && \ + chmod +x /usr/local/protoc/bin/protoc && \ + ln -s /usr/local/protoc/bin/protoc /usr/local/bin + RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ export PATH=$PATH:$HOME/.cargo/bin && \ scripts/init.sh && \ diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 87bb9c571..4d1fe40d0 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-cli" -version = "4.7.0" +version = "4.8.0" edition = "2021" [package.metadata.wasm-pack.profile.release] @@ -13,17 +13,17 @@ crate-type = ["cdylib", "rlib"] [dependencies] clap = { version = "3.1", features = ["derive"], optional = true } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.29" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.29" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.29" } -try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.29" } +sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.30" } # Local cere-service = { path = "../node/service", default-features = false, optional = true } cere-client = { path = "../node/client", optional = true } [build-dependencies] -substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } +substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } [features] default = ["cli", "cere-native"] diff --git a/cli/src/command.rs b/cli/src/command.rs index b2e88f2f9..5884387bc 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -40,7 +40,7 @@ impl SubstrateCli for Cli { #[cfg(feature = "cere-dev-native")] "dev" => Box::new(cere_service::chain_spec::cere_dev_development_config()?), #[cfg(feature = "cere-dev-native")] - "local" => Box::new(cere_service::chain_spec::cere_dev_local_testnet_config()?), + "local" => Box::new(cere_service::chain_spec::cere_dev_local_testnet_config()?), path => { let path = std::path::PathBuf::from(path); @@ -181,6 +181,11 @@ pub fn run() -> sc_cli::Result<()> { let (client, _, _, _) = cere_service::new_chain_ops(&config)?; unwrap_client!(client, cmd.run(client.clone())) }), + #[cfg(not(feature = "runtime-benchmarks"))] + BenchmarkCmd::Storage(_) => + Err("Storage benchmarking can be enabled with `--features runtime-benchmarks`." + .into()), + #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let (client, backend, _, _) = cere_service::new_chain_ops(&config)?; let db = backend.expose_db(); diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index 9538f143e..eb4f2be13 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -1,36 +1,36 @@ [package] name = "cere-client" -version = "4.7.0" +version = "4.8.0" edition = "2021" [dependencies] -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } # Local cere-runtime = { path = "../../runtime/cere", optional = true } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 276ece98a..65c79d982 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-service" -version = "4.7.0" +version = "4.8.0" edition = "2021" [dependencies] @@ -10,39 +10,39 @@ rand = "0.8" futures = "0.3.21" jsonrpsee = { version = "0.15.1", features = ["server"] } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", features = ["wasmtime"] } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", features = ["wasmtime"] } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", features = ["wasmtime"] } -sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-authority-discovery = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-trie = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-authority-discovery = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-trie = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # Local cere-client = { path = "../client", default-features = false, optional = true } @@ -63,6 +63,7 @@ cere-dev-native = [ "cere-dev-runtime", "cere-dev-runtime-constants", "cere-clie runtime-benchmarks = [ "cere-runtime/runtime-benchmarks", "cere-dev-runtime/runtime-benchmarks", + "sc-service/runtime-benchmarks", ] try-runtime = [ diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index ebcbd8a37..fbfc8bc6a 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -193,6 +193,7 @@ pub fn cere_dev_genesis( stakers, ..Default::default() }, + ddc_staking: cere_dev::DdcStakingConfig::default(), democracy: cere_dev::DemocracyConfig::default(), elections: cere_dev::ElectionsConfig { members: endowed_accounts diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index d8b3c7407..8a84ed755 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -6,7 +6,7 @@ pub use cere_dev_runtime; pub use cere_runtime; use futures::prelude::*; -use sc_client_api::{BlockBackend, ExecutorProvider}; +use sc_client_api::BlockBackend; use sc_consensus_babe::{self, SlotProportion}; use sc_network::Event; use sc_service::{ @@ -26,9 +26,9 @@ pub use cere_client::{ pub use chain_spec::{CereChainSpec, CereDevChainSpec}; pub use node_primitives::{Block, BlockNumber}; pub use sc_executor::NativeElseWasmExecutor; +use sc_network_common::service::NetworkEventStream; pub use sc_service::ChainSpec; pub use sp_api::ConstructRuntimeApi; -use sc_network_common::{service::NetworkEventStream}; type FullSelectChain = sc_consensus::LongestChain; type FullGrandpaBlockImport = sc_finality_grandpa::GrandpaBlockImport< @@ -195,11 +195,10 @@ where let uncles = sp_authorship::InherentDataProvider::<::Header>::check_inherents(); - Ok((timestamp, slot, uncles)) + Ok((slot, timestamp, uncles)) }, &task_manager.spawn_essential_handle(), config.prometheus_registry(), - sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()), telemetry.as_ref().map(|x| x.handle()), )?; @@ -376,7 +375,7 @@ where Vec::default(), )); - let (network, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, tx_handler_controller, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -414,6 +413,7 @@ where transaction_pool: transaction_pool.clone(), task_manager: &mut task_manager, system_rpc_tx, + tx_handler_controller, telemetry: telemetry.as_mut(), })?; @@ -443,9 +443,6 @@ where telemetry.as_ref().map(|x| x.handle()), ); - let can_author_with = - sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()); - let client_clone = client.clone(); let slot_duration = babe_link.config().slot_duration(); let babe_config = sc_consensus_babe::BabeParams { @@ -478,13 +475,12 @@ where &parent, )?; - Ok((timestamp, slot, uncles, storage_proof)) + Ok((slot, timestamp, uncles, storage_proof)) } }, force_authoring, backoff_authoring_blocks, babe_link, - can_author_with, block_proposal_slot_portion: SlotProportion::new(0.5), max_block_proposal_slot_portion: None, telemetry: telemetry.as_ref().map(|x| x.handle()), @@ -645,12 +641,15 @@ pub trait IdentifyVariant { impl IdentifyVariant for Box { fn is_cere(&self) -> bool { - self.id().starts_with("cere_mainnet") || self.id().starts_with("cere_qanet") || self.id().starts_with("cere_testnet") + self.id().starts_with("cere_mainnet") || + self.id().starts_with("cere_qanet") || + self.id().starts_with("cere_testnet") } fn is_cere_dev(&self) -> bool { // Works for "cere-devnet" and "dev" arms in the load_spec(...) call. - // If you are specifying a customSpecRaw.json for "path" arm along with the "--force-cere-dev" flag, - // make sure your spec has a compatible "id" field to satisfy this condition + // If you are specifying a customSpecRaw.json for "path" arm along with the + // "--force-cere-dev" flag, make sure your spec has a compatible "id" field to satisfy this + // condition self.id().starts_with("cere_dev") } } diff --git a/pallets/chainbridge/Cargo.toml b/pallets/chainbridge/Cargo.toml index 9528fb3bc..b1f2b953a 100644 --- a/pallets/chainbridge/Cargo.toml +++ b/pallets/chainbridge/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-chainbridge" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" @@ -14,18 +14,18 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } lite-json = { version = "0.2.0", default-features = false } -sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } [features] default = ["std"] diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index 6a7d57c68..512c0a9c2 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -1,27 +1,30 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] -use sp_std::marker::PhantomData; +use codec::{Decode, Encode, EncodeLike}; use frame_support::{ - dispatch::{DispatchResult}, decl_module, decl_storage, decl_event, decl_error, - weights::{DispatchClass, ClassifyDispatch, WeighData, Weight, PaysFee, Pays, GetDispatchInfo}, + decl_error, decl_event, decl_module, decl_storage, + dispatch::{ + ClassifyDispatch, DispatchClass, DispatchResult, GetDispatchInfo, Pays, PaysFee, WeighData, + Weight, + }, ensure, traits::{EnsureOrigin, Get}, - Parameter, PalletId + PalletId, Parameter, }; -use sp_std::prelude::*; -use frame_system::{self as system, ensure_signed, ensure_root}; +use frame_system::{self as system, ensure_root, ensure_signed}; use sp_core::U256; -use codec::{Encode, Decode, EncodeLike}; use sp_runtime::{ traits::{ - SignedExtension, Bounded, SaturatedConversion, DispatchInfoOf, AccountIdConversion, Dispatchable, + AccountIdConversion, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, + SignedExtension, }, transaction_validity::{ - ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity, + InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, }, - RuntimeDebug, + RuntimeDebug, }; +use sp_std::{marker::PhantomData, prelude::*}; mod mock; mod tests; @@ -36,118 +39,121 @@ pub type ResourceId = [u8; 32]; /// Helper function to concatenate a chain ID and some bytes to produce a resource ID. /// The common format is (31 bytes unique ID + 1 byte chain ID). pub fn derive_resource_id(chain: u8, id: &[u8]) -> ResourceId { - let mut r_id: ResourceId = [0; 32]; - r_id[31] = chain; // last byte is chain id - let range = if id.len() > 31 { 31 } else { id.len() }; // Use at most 31 bytes - for i in 0..range { - r_id[30 - i] = id[range - 1 - i]; // Ensure left padding for eth compatibility - } - return r_id; + let mut r_id: ResourceId = [0; 32]; + r_id[31] = chain; // last byte is chain id + let range = if id.len() > 31 { 31 } else { id.len() }; // Use at most 31 bytes + for i in 0..range { + r_id[30 - i] = id[range - 1 - i]; // Ensure left padding for eth compatibility + } + return r_id } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] pub enum ProposalStatus { - Initiated, - Approved, - Rejected, + Initiated, + Approved, + Rejected, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] pub struct ProposalVotes { - pub votes_for: Vec, - pub votes_against: Vec, - pub status: ProposalStatus, - pub expiry: BlockNumber, + pub votes_for: Vec, + pub votes_against: Vec, + pub status: ProposalStatus, + pub expiry: BlockNumber, } impl ProposalVotes { - /// Attempts to mark the proposal as approve or rejected. - /// Returns true if the status changes from active. - fn try_to_complete(&mut self, threshold: u32, total: u32) -> ProposalStatus { - if self.votes_for.len() >= threshold as usize { - self.status = ProposalStatus::Approved; - ProposalStatus::Approved - } else if total >= threshold && self.votes_against.len() as u32 + threshold > total { - self.status = ProposalStatus::Rejected; - ProposalStatus::Rejected - } else { - ProposalStatus::Initiated - } - } - - /// Returns true if the proposal has been rejected or approved, otherwise false. - fn is_complete(&self) -> bool { - self.status != ProposalStatus::Initiated - } - - /// Returns true if `who` has voted for or against the proposal - fn has_voted(&self, who: &A) -> bool { - self.votes_for.contains(&who) || self.votes_against.contains(&who) - } - - /// Return true if the expiry time has been reached - fn is_expired(&self, now: B) -> bool { - self.expiry <= now - } + /// Attempts to mark the proposal as approve or rejected. + /// Returns true if the status changes from active. + fn try_to_complete(&mut self, threshold: u32, total: u32) -> ProposalStatus { + if self.votes_for.len() >= threshold as usize { + self.status = ProposalStatus::Approved; + ProposalStatus::Approved + } else if total >= threshold && self.votes_against.len() as u32 + threshold > total { + self.status = ProposalStatus::Rejected; + ProposalStatus::Rejected + } else { + ProposalStatus::Initiated + } + } + + /// Returns true if the proposal has been rejected or approved, otherwise false. + fn is_complete(&self) -> bool { + self.status != ProposalStatus::Initiated + } + + /// Returns true if `who` has voted for or against the proposal + fn has_voted(&self, who: &A) -> bool { + self.votes_for.contains(&who) || self.votes_against.contains(&who) + } + + /// Return true if the expiry time has been reached + fn is_expired(&self, now: B) -> bool { + self.expiry <= now + } } impl Default for ProposalVotes { - fn default() -> Self { - Self { - votes_for: vec![], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: BlockNumber::default(), - } - } + fn default() -> Self { + Self { + votes_for: vec![], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: BlockNumber::default(), + } + } } pub trait Config: system::Config { - type Event: From> + Into<::Event>; - /// Origin used to administer the pallet - type AdminOrigin: EnsureOrigin; - /// Proposed dispatchable call - type Proposal: Parameter + Dispatchable + EncodeLike + GetDispatchInfo; - /// The identifier for this chain. - /// This must be unique and must not collide with existing IDs within a set of bridged chains. - type ChainId: Get; - - type ProposalLifetime: Get; + type RuntimeEvent: From> + Into<::RuntimeEvent>; + /// Origin used to administer the pallet + type AdminOrigin: EnsureOrigin; + /// Proposed dispatchable call + type Proposal: Parameter + + Dispatchable + + EncodeLike + + GetDispatchInfo; + /// The identifier for this chain. + /// This must be unique and must not collide with existing IDs within a set of bridged chains. + type ChainId: Get; + + type ProposalLifetime: Get; } decl_error! { - pub enum Error for Module { - /// Relayer threshold not set - ThresholdNotSet, - /// Provided chain Id is not valid - InvalidChainId, - /// Relayer threshold cannot be 0 - InvalidThreshold, - /// Interactions with this chain is not permitted - ChainNotWhitelisted, - /// Chain has already been enabled - ChainAlreadyWhitelisted, - /// Resource ID provided isn't mapped to anything - ResourceDoesNotExist, - /// Relayer already in set - RelayerAlreadyExists, - /// Provided accountId is not a relayer - RelayerInvalid, - /// Protected operation, must be performed by relayer - MustBeRelayer, - /// Relayer has already submitted some vote for this proposal - RelayerAlreadyVoted, - /// A proposal with these parameters has already been submitted - ProposalAlreadyExists, - /// No proposal with the ID was found - ProposalDoesNotExist, - /// Cannot complete proposal, needs more votes - ProposalNotComplete, - /// Proposal has either failed or succeeded - ProposalAlreadyComplete, - /// Lifetime of proposal has been exceeded - ProposalExpired, - } + pub enum Error for Module { + /// Relayer threshold not set + ThresholdNotSet, + /// Provided chain Id is not valid + InvalidChainId, + /// Relayer threshold cannot be 0 + InvalidThreshold, + /// Interactions with this chain is not permitted + ChainNotWhitelisted, + /// Chain has already been enabled + ChainAlreadyWhitelisted, + /// Resource ID provided isn't mapped to anything + ResourceDoesNotExist, + /// Relayer already in set + RelayerAlreadyExists, + /// Provided accountId is not a relayer + RelayerInvalid, + /// Protected operation, must be performed by relayer + MustBeRelayer, + /// Relayer has already submitted some vote for this proposal + RelayerAlreadyVoted, + /// A proposal with these parameters has already been submitted + ProposalAlreadyExists, + /// No proposal with the ID was found + ProposalDoesNotExist, + /// Cannot complete proposal, needs more votes + ProposalNotComplete, + /// Proposal has either failed or succeeded + ProposalAlreadyComplete, + /// Lifetime of proposal has been exceeded + ProposalExpired, + } } decl_storage! { @@ -178,461 +184,427 @@ decl_storage! { decl_event!( pub enum Event where ::AccountId { - /// Vote threshold has changed (new_threshold) - RelayerThresholdChanged(u32), - /// Chain now available for transfers (chain_id) - ChainWhitelisted(ChainId), - /// Relayer added to set - RelayerAdded(AccountId), - /// Relayer removed from set - RelayerRemoved(AccountId), - /// FunglibleTransfer is for relaying fungibles (dest_id, nonce, resource_id, amount, recipient, metadata) - FungibleTransfer(ChainId, DepositNonce, ResourceId, U256, Vec), - /// NonFungibleTransfer is for relaying NFTS (dest_id, nonce, resource_id, token_id, recipient, metadata) - NonFungibleTransfer(ChainId, DepositNonce, ResourceId, Vec, Vec, Vec), - /// GenericTransfer is for a generic data payload (dest_id, nonce, resource_id, metadata) - GenericTransfer(ChainId, DepositNonce, ResourceId, Vec), - /// Vote submitted in favour of proposal - VoteFor(ChainId, DepositNonce, AccountId), - /// Vot submitted against proposal - VoteAgainst(ChainId, DepositNonce, AccountId), - /// Voting successful for a proposal - ProposalApproved(ChainId, DepositNonce), - /// Voting rejected a proposal - ProposalRejected(ChainId, DepositNonce), - /// Execution of call succeeded - ProposalSucceeded(ChainId, DepositNonce), - /// Execution of call failed - ProposalFailed(ChainId, DepositNonce), - } + /// Vote threshold has changed (new_threshold) + RelayerThresholdChanged(u32), + /// Chain now available for transfers (chain_id) + ChainWhitelisted(ChainId), + /// Relayer added to set + RelayerAdded(AccountId), + /// Relayer removed from set + RelayerRemoved(AccountId), + /// FunglibleTransfer is for relaying fungibles (dest_id, nonce, resource_id, amount, recipient, metadata) + FungibleTransfer(ChainId, DepositNonce, ResourceId, U256, Vec), + /// NonFungibleTransfer is for relaying NFTS (dest_id, nonce, resource_id, token_id, recipient, metadata) + NonFungibleTransfer(ChainId, DepositNonce, ResourceId, Vec, Vec, Vec), + /// GenericTransfer is for a generic data payload (dest_id, nonce, resource_id, metadata) + GenericTransfer(ChainId, DepositNonce, ResourceId, Vec), + /// Vote submitted in favour of proposal + VoteFor(ChainId, DepositNonce, AccountId), + /// Vot submitted against proposal + VoteAgainst(ChainId, DepositNonce, AccountId), + /// Voting successful for a proposal + ProposalApproved(ChainId, DepositNonce), + /// Voting rejected a proposal + ProposalRejected(ChainId, DepositNonce), + /// Execution of call succeeded + ProposalSucceeded(ChainId, DepositNonce), + /// Execution of call failed + ProposalFailed(ChainId, DepositNonce), + } ); decl_module! { - pub struct Module for enum Call where origin: T::Origin { - type Error = Error; - - const ChainIdentity: ChainId = T::ChainId::get(); - const ProposalLifetime: T::BlockNumber = T::ProposalLifetime::get(); - const BridgeAccountId: T::AccountId = AccountIdConversion::::into_account_truncating(&MODULE_ID); - - fn deposit_event() = default; - - /// Sets the vote threshold for proposals. - /// - /// This threshold is used to determine how many votes are required - /// before a proposal is executed. - /// - /// # - /// - O(1) lookup and insert - /// # - #[weight = 195_000_000] - pub fn set_threshold(origin, threshold: u32) -> DispatchResult { - Self::ensure_admin(origin)?; - Self::set_relayer_threshold(threshold) - } - - /// Stores a method name on chain under an associated resource ID. - /// - /// # - /// - O(1) write - /// # - #[weight = 195_000_000] - pub fn set_resource(origin, id: ResourceId, method: Vec) -> DispatchResult { - Self::ensure_admin(origin)?; - Self::register_resource(id, method) - } - - /// Removes a resource ID from the resource mapping. - /// - /// After this call, bridge transfers with the associated resource ID will - /// be rejected. - /// - /// # - /// - O(1) removal - /// # - #[weight = 195_000_000] - pub fn remove_resource(origin, id: ResourceId) -> DispatchResult { - Self::ensure_admin(origin)?; - Self::unregister_resource(id) - } - - /// Enables a chain ID as a source or destination for a bridge transfer. - /// - /// # - /// - O(1) lookup and insert - /// # - #[weight = 195_000_000] - pub fn whitelist_chain(origin, id: ChainId) -> DispatchResult { - Self::ensure_admin(origin)?; - Self::whitelist(id) - } - - /// Adds a new relayer to the relayer set. - /// - /// # - /// - O(1) lookup and insert - /// # - #[weight = 195_000_000] - pub fn add_relayer(origin, v: T::AccountId) -> DispatchResult { - Self::ensure_admin(origin)?; - Self::register_relayer(v) - } - - /// Removes an existing relayer from the set. - /// - /// # - /// - O(1) lookup and removal - /// # - #[weight = 195_000_000] - pub fn remove_relayer(origin, v: T::AccountId) -> DispatchResult { - Self::ensure_admin(origin)?; - Self::unregister_relayer(v) - } - - /// Commits a vote in favour of the provided proposal. - /// - /// If a proposal with the given nonce and source chain ID does not already exist, it will - /// be created with an initial vote in favour from the caller. - /// - /// # - /// - weight of proposed call, regardless of whether execution is performed - /// # - #[weight = (call.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), call.get_dispatch_info().class, Pays::Yes)] - pub fn acknowledge_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<::Proposal>) -> DispatchResult { - let who = ensure_signed(origin)?; - ensure!(Self::is_relayer(&who), Error::::MustBeRelayer); - ensure!(Self::chain_whitelisted(src_id), Error::::ChainNotWhitelisted); - ensure!(Self::resource_exists(r_id), Error::::ResourceDoesNotExist); - - Self::vote_for(who, nonce, src_id, call) - } - - /// Commits a vote against a provided proposal. - /// - /// # - /// - Fixed, since execution of proposal should not be included - /// # - #[weight = 195_000_000] - pub fn reject_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<::Proposal>) -> DispatchResult { - let who = ensure_signed(origin)?; - ensure!(Self::is_relayer(&who), Error::::MustBeRelayer); - ensure!(Self::chain_whitelisted(src_id), Error::::ChainNotWhitelisted); - ensure!(Self::resource_exists(r_id), Error::::ResourceDoesNotExist); - - Self::vote_against(who, nonce, src_id, call) - } - - /// Evaluate the state of a proposal given the current vote threshold. - /// - /// A proposal with enough votes will be either executed or cancelled, and the status - /// will be updated accordingly. - /// - /// # - /// - weight of proposed call, regardless of whether execution is performed - /// # - #[weight = (prop.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), prop.get_dispatch_info().class, Pays::Yes)] - pub fn eval_vote_state(origin, nonce: DepositNonce, src_id: ChainId, prop: Box<::Proposal>) -> DispatchResult { - ensure_signed(origin)?; - - Self::try_resolve_proposal(nonce, src_id, prop) - } - } + pub struct Module for enum Call where origin: T::RuntimeOrigin { + type Error = Error; + + const ChainIdentity: ChainId = T::ChainId::get(); + const ProposalLifetime: T::BlockNumber = T::ProposalLifetime::get(); + const BridgeAccountId: T::AccountId = AccountIdConversion::::into_account_truncating(&MODULE_ID); + + fn deposit_event() = default; + + /// Sets the vote threshold for proposals. + /// + /// This threshold is used to determine how many votes are required + /// before a proposal is executed. + /// + /// # + /// - O(1) lookup and insert + /// # + #[weight = 195_000_000] + pub fn set_threshold(origin, threshold: u32) -> DispatchResult { + Self::ensure_admin(origin)?; + Self::set_relayer_threshold(threshold) + } + + /// Stores a method name on chain under an associated resource ID. + /// + /// # + /// - O(1) write + /// # + #[weight = 195_000_000] + pub fn set_resource(origin, id: ResourceId, method: Vec) -> DispatchResult { + Self::ensure_admin(origin)?; + Self::register_resource(id, method) + } + + /// Removes a resource ID from the resource mapping. + /// + /// After this call, bridge transfers with the associated resource ID will + /// be rejected. + /// + /// # + /// - O(1) removal + /// # + #[weight = 195_000_000] + pub fn remove_resource(origin, id: ResourceId) -> DispatchResult { + Self::ensure_admin(origin)?; + Self::unregister_resource(id) + } + + /// Enables a chain ID as a source or destination for a bridge transfer. + /// + /// # + /// - O(1) lookup and insert + /// # + #[weight = 195_000_000] + pub fn whitelist_chain(origin, id: ChainId) -> DispatchResult { + Self::ensure_admin(origin)?; + Self::whitelist(id) + } + + /// Adds a new relayer to the relayer set. + /// + /// # + /// - O(1) lookup and insert + /// # + #[weight = 195_000_000] + pub fn add_relayer(origin, v: T::AccountId) -> DispatchResult { + Self::ensure_admin(origin)?; + Self::register_relayer(v) + } + + /// Removes an existing relayer from the set. + /// + /// # + /// - O(1) lookup and removal + /// # + #[weight = 195_000_000] + pub fn remove_relayer(origin, v: T::AccountId) -> DispatchResult { + Self::ensure_admin(origin)?; + Self::unregister_relayer(v) + } + + /// Commits a vote in favour of the provided proposal. + /// + /// If a proposal with the given nonce and source chain ID does not already exist, it will + /// be created with an initial vote in favour from the caller. + /// + /// # + /// - weight of proposed call, regardless of whether execution is performed + /// # + #[weight = (call.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), call.get_dispatch_info().class, Pays::Yes)] + pub fn acknowledge_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<::Proposal>) -> DispatchResult { + let who = ensure_signed(origin)?; + ensure!(Self::is_relayer(&who), Error::::MustBeRelayer); + ensure!(Self::chain_whitelisted(src_id), Error::::ChainNotWhitelisted); + ensure!(Self::resource_exists(r_id), Error::::ResourceDoesNotExist); + + Self::vote_for(who, nonce, src_id, call) + } + + /// Commits a vote against a provided proposal. + /// + /// # + /// - Fixed, since execution of proposal should not be included + /// # + #[weight = 195_000_000] + pub fn reject_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<::Proposal>) -> DispatchResult { + let who = ensure_signed(origin)?; + ensure!(Self::is_relayer(&who), Error::::MustBeRelayer); + ensure!(Self::chain_whitelisted(src_id), Error::::ChainNotWhitelisted); + ensure!(Self::resource_exists(r_id), Error::::ResourceDoesNotExist); + + Self::vote_against(who, nonce, src_id, call) + } + + /// Evaluate the state of a proposal given the current vote threshold. + /// + /// A proposal with enough votes will be either executed or cancelled, and the status + /// will be updated accordingly. + /// + /// # + /// - weight of proposed call, regardless of whether execution is performed + /// # + #[weight = (prop.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), prop.get_dispatch_info().class, Pays::Yes)] + pub fn eval_vote_state(origin, nonce: DepositNonce, src_id: ChainId, prop: Box<::Proposal>) -> DispatchResult { + ensure_signed(origin)?; + + Self::try_resolve_proposal(nonce, src_id, prop) + } + } } impl Module { - // *** Utility methods *** - - pub fn ensure_admin(o: T::Origin) -> DispatchResult { - T::AdminOrigin::try_origin(o) - .map(|_| ()) - .or_else(ensure_root)?; - Ok(()) - } - - /// Checks if who is a relayer - pub fn is_relayer(who: &T::AccountId) -> bool { - Self::relayers(who) - } - - /// Provides an AccountId for the pallet. - /// This is used both as an origin check and deposit/withdrawal account. - pub fn account_id() -> T::AccountId { - AccountIdConversion::::into_account_truncating(&MODULE_ID) - } - - /// Asserts if a resource is registered - pub fn resource_exists(id: ResourceId) -> bool { - return Self::resources(id) != None; - } - - /// Checks if a chain exists as a whitelisted destination - pub fn chain_whitelisted(id: ChainId) -> bool { - return Self::chains(id) != None; - } - - /// Increments the deposit nonce for the specified chain ID - fn bump_nonce(id: ChainId) -> DepositNonce { - let nonce = Self::chains(id).unwrap_or_default() + 1; - ::insert(id, nonce); - nonce - } - - // *** Admin methods *** - - /// Set a new voting threshold - pub fn set_relayer_threshold(threshold: u32) -> DispatchResult { - ensure!(threshold > 0, Error::::InvalidThreshold); - ::put(threshold); - Self::deposit_event(RawEvent::RelayerThresholdChanged(threshold)); - Ok(()) - } - - /// Register a method for a resource Id, enabling associated transfers - pub fn register_resource(id: ResourceId, method: Vec) -> DispatchResult { - ::insert(id, method); - Ok(()) - } - - /// Removes a resource ID, disabling associated transfer - pub fn unregister_resource(id: ResourceId) -> DispatchResult { - ::remove(id); - Ok(()) - } - - /// Whitelist a chain ID for transfer - pub fn whitelist(id: ChainId) -> DispatchResult { - // Cannot whitelist this chain - ensure!(id != T::ChainId::get(), Error::::InvalidChainId); - // Cannot whitelist with an existing entry - ensure!( - !Self::chain_whitelisted(id), - Error::::ChainAlreadyWhitelisted - ); - ::insert(&id, 0); - Self::deposit_event(RawEvent::ChainWhitelisted(id)); - Ok(()) - } - - /// Adds a new relayer to the set - pub fn register_relayer(relayer: T::AccountId) -> DispatchResult { - ensure!( - !Self::is_relayer(&relayer), - Error::::RelayerAlreadyExists - ); - >::insert(&relayer, true); - ::mutate(|i| *i += 1); - - Self::deposit_event(RawEvent::RelayerAdded(relayer)); - Ok(()) - } - - /// Removes a relayer from the set - pub fn unregister_relayer(relayer: T::AccountId) -> DispatchResult { - ensure!(Self::is_relayer(&relayer), Error::::RelayerInvalid); - >::remove(&relayer); - ::mutate(|i| *i -= 1); - Self::deposit_event(RawEvent::RelayerRemoved(relayer)); - Ok(()) - } - - // *** Proposal voting and execution methods *** - - /// Commits a vote for a proposal. If the proposal doesn't exist it will be created. - fn commit_vote( - who: T::AccountId, - nonce: DepositNonce, - src_id: ChainId, - prop: Box, - in_favour: bool, - ) -> DispatchResult { - let now = >::block_number(); - let mut votes = match >::get(src_id, (nonce, prop.clone())) { - Some(v) => v, - None => { - let mut v = ProposalVotes::default(); - v.expiry = now + T::ProposalLifetime::get(); - v - } - }; - - // Ensure the proposal isn't complete and relayer hasn't already voted - ensure!(!votes.is_complete(), Error::::ProposalAlreadyComplete); - ensure!(!votes.is_expired(now), Error::::ProposalExpired); - ensure!(!votes.has_voted(&who), Error::::RelayerAlreadyVoted); - - if in_favour { - votes.votes_for.push(who.clone()); - Self::deposit_event(RawEvent::VoteFor(src_id, nonce, who.clone())); - } else { - votes.votes_against.push(who.clone()); - Self::deposit_event(RawEvent::VoteAgainst(src_id, nonce, who.clone())); - } - - >::insert(src_id, (nonce, prop.clone()), votes.clone()); - - Ok(()) - } - - /// Attempts to finalize or cancel the proposal if the vote count allows. - fn try_resolve_proposal( - nonce: DepositNonce, - src_id: ChainId, - prop: Box, - ) -> DispatchResult { - if let Some(mut votes) = >::get(src_id, (nonce, prop.clone())) { - let now = >::block_number(); - ensure!(!votes.is_complete(), Error::::ProposalAlreadyComplete); - ensure!(!votes.is_expired(now), Error::::ProposalExpired); - - let status = votes.try_to_complete(::get(), ::get()); - >::insert(src_id, (nonce, prop.clone()), votes.clone()); - - match status { - ProposalStatus::Approved => Self::finalize_execution(src_id, nonce, prop), - ProposalStatus::Rejected => Self::cancel_execution(src_id, nonce), - _ => Ok(()), - } - } else { - Err(Error::::ProposalDoesNotExist)? - } - } - - /// Commits a vote in favour of the proposal and executes it if the vote threshold is met. - fn vote_for( - who: T::AccountId, - nonce: DepositNonce, - src_id: ChainId, - prop: Box, - ) -> DispatchResult { - Self::commit_vote(who, nonce, src_id, prop.clone(), true)?; - Self::try_resolve_proposal(nonce, src_id, prop) - } - - /// Commits a vote against the proposal and cancels it if more than (relayers.len() - threshold) - /// votes against exist. - fn vote_against( - who: T::AccountId, - nonce: DepositNonce, - src_id: ChainId, - prop: Box, - ) -> DispatchResult { - Self::commit_vote(who, nonce, src_id, prop.clone(), false)?; - Self::try_resolve_proposal(nonce, src_id, prop) - } - - /// Execute the proposal and signals the result as an event - fn finalize_execution( - src_id: ChainId, - nonce: DepositNonce, - call: Box, - ) -> DispatchResult { - Self::deposit_event(RawEvent::ProposalApproved(src_id, nonce)); - call.dispatch(frame_system::RawOrigin::Signed(Self::account_id()).into()) - .map(|_| ()) - .map_err(|e| e.error)?; - Self::deposit_event(RawEvent::ProposalSucceeded(src_id, nonce)); - Ok(()) - } - - /// Cancels a proposal. - fn cancel_execution(src_id: ChainId, nonce: DepositNonce) -> DispatchResult { - Self::deposit_event(RawEvent::ProposalRejected(src_id, nonce)); - Ok(()) - } - - /// Initiates a transfer of a fungible asset out of the chain. This should be called by another pallet. - pub fn transfer_fungible( - dest_id: ChainId, - resource_id: ResourceId, - to: Vec, - amount: U256, - ) -> DispatchResult { - ensure!( - Self::chain_whitelisted(dest_id), - Error::::ChainNotWhitelisted - ); - ensure!( - Self::resource_exists(resource_id), - Error::::ResourceDoesNotExist - ); - let nonce = Self::bump_nonce(dest_id); - Self::deposit_event(RawEvent::FungibleTransfer( - dest_id, - nonce, - resource_id, - amount, - to, - )); - Ok(()) - } - - /// Initiates a transfer of a nonfungible asset out of the chain. This should be called by another pallet. - pub fn transfer_nonfungible( - dest_id: ChainId, - resource_id: ResourceId, - token_id: Vec, - to: Vec, - metadata: Vec, - ) -> DispatchResult { - ensure!( - Self::chain_whitelisted(dest_id), - Error::::ChainNotWhitelisted - ); - ensure!( - Self::resource_exists(resource_id), - Error::::ResourceDoesNotExist - ); - let nonce = Self::bump_nonce(dest_id); - Self::deposit_event(RawEvent::NonFungibleTransfer( - dest_id, - nonce, - resource_id, - token_id, - to, - metadata, - )); - Ok(()) - } - - /// Initiates a transfer of generic data out of the chain. This should be called by another pallet. - pub fn transfer_generic( - dest_id: ChainId, - resource_id: ResourceId, - metadata: Vec, - ) -> DispatchResult { - ensure!( - Self::chain_whitelisted(dest_id), - Error::::ChainNotWhitelisted - ); - ensure!( - Self::resource_exists(resource_id), - Error::::ResourceDoesNotExist - ); - let nonce = Self::bump_nonce(dest_id); - Self::deposit_event(RawEvent::GenericTransfer( - dest_id, - nonce, - resource_id, - metadata, - )); - Ok(()) - } + // *** Utility methods *** + + pub fn ensure_admin(o: T::RuntimeOrigin) -> DispatchResult { + T::AdminOrigin::try_origin(o).map(|_| ()).or_else(ensure_root)?; + Ok(()) + } + + /// Checks if who is a relayer + pub fn is_relayer(who: &T::AccountId) -> bool { + Self::relayers(who) + } + + /// Provides an AccountId for the pallet. + /// This is used both as an origin check and deposit/withdrawal account. + pub fn account_id() -> T::AccountId { + AccountIdConversion::::into_account_truncating(&MODULE_ID) + } + + /// Asserts if a resource is registered + pub fn resource_exists(id: ResourceId) -> bool { + return Self::resources(id) != None + } + + /// Checks if a chain exists as a whitelisted destination + pub fn chain_whitelisted(id: ChainId) -> bool { + return Self::chains(id) != None + } + + /// Increments the deposit nonce for the specified chain ID + fn bump_nonce(id: ChainId) -> DepositNonce { + let nonce = Self::chains(id).unwrap_or_default() + 1; + ::insert(id, nonce); + nonce + } + + // *** Admin methods *** + + /// Set a new voting threshold + pub fn set_relayer_threshold(threshold: u32) -> DispatchResult { + ensure!(threshold > 0, Error::::InvalidThreshold); + ::put(threshold); + Self::deposit_event(RawEvent::RelayerThresholdChanged(threshold)); + Ok(()) + } + + /// Register a method for a resource Id, enabling associated transfers + pub fn register_resource(id: ResourceId, method: Vec) -> DispatchResult { + ::insert(id, method); + Ok(()) + } + + /// Removes a resource ID, disabling associated transfer + pub fn unregister_resource(id: ResourceId) -> DispatchResult { + ::remove(id); + Ok(()) + } + + /// Whitelist a chain ID for transfer + pub fn whitelist(id: ChainId) -> DispatchResult { + // Cannot whitelist this chain + ensure!(id != T::ChainId::get(), Error::::InvalidChainId); + // Cannot whitelist with an existing entry + ensure!(!Self::chain_whitelisted(id), Error::::ChainAlreadyWhitelisted); + ::insert(&id, 0); + Self::deposit_event(RawEvent::ChainWhitelisted(id)); + Ok(()) + } + + /// Adds a new relayer to the set + pub fn register_relayer(relayer: T::AccountId) -> DispatchResult { + ensure!(!Self::is_relayer(&relayer), Error::::RelayerAlreadyExists); + >::insert(&relayer, true); + ::mutate(|i| *i += 1); + + Self::deposit_event(RawEvent::RelayerAdded(relayer)); + Ok(()) + } + + /// Removes a relayer from the set + pub fn unregister_relayer(relayer: T::AccountId) -> DispatchResult { + ensure!(Self::is_relayer(&relayer), Error::::RelayerInvalid); + >::remove(&relayer); + ::mutate(|i| *i -= 1); + Self::deposit_event(RawEvent::RelayerRemoved(relayer)); + Ok(()) + } + + // *** Proposal voting and execution methods *** + + /// Commits a vote for a proposal. If the proposal doesn't exist it will be created. + fn commit_vote( + who: T::AccountId, + nonce: DepositNonce, + src_id: ChainId, + prop: Box, + in_favour: bool, + ) -> DispatchResult { + let now = >::block_number(); + let mut votes = match >::get(src_id, (nonce, prop.clone())) { + Some(v) => v, + None => { + let mut v = ProposalVotes::default(); + v.expiry = now + T::ProposalLifetime::get(); + v + }, + }; + + // Ensure the proposal isn't complete and relayer hasn't already voted + ensure!(!votes.is_complete(), Error::::ProposalAlreadyComplete); + ensure!(!votes.is_expired(now), Error::::ProposalExpired); + ensure!(!votes.has_voted(&who), Error::::RelayerAlreadyVoted); + + if in_favour { + votes.votes_for.push(who.clone()); + Self::deposit_event(RawEvent::VoteFor(src_id, nonce, who.clone())); + } else { + votes.votes_against.push(who.clone()); + Self::deposit_event(RawEvent::VoteAgainst(src_id, nonce, who.clone())); + } + + >::insert(src_id, (nonce, prop.clone()), votes.clone()); + + Ok(()) + } + + /// Attempts to finalize or cancel the proposal if the vote count allows. + fn try_resolve_proposal( + nonce: DepositNonce, + src_id: ChainId, + prop: Box, + ) -> DispatchResult { + if let Some(mut votes) = >::get(src_id, (nonce, prop.clone())) { + let now = >::block_number(); + ensure!(!votes.is_complete(), Error::::ProposalAlreadyComplete); + ensure!(!votes.is_expired(now), Error::::ProposalExpired); + + let status = votes.try_to_complete(::get(), ::get()); + >::insert(src_id, (nonce, prop.clone()), votes.clone()); + + match status { + ProposalStatus::Approved => Self::finalize_execution(src_id, nonce, prop), + ProposalStatus::Rejected => Self::cancel_execution(src_id, nonce), + _ => Ok(()), + } + } else { + Err(Error::::ProposalDoesNotExist)? + } + } + + /// Commits a vote in favour of the proposal and executes it if the vote threshold is met. + fn vote_for( + who: T::AccountId, + nonce: DepositNonce, + src_id: ChainId, + prop: Box, + ) -> DispatchResult { + Self::commit_vote(who, nonce, src_id, prop.clone(), true)?; + Self::try_resolve_proposal(nonce, src_id, prop) + } + + /// Commits a vote against the proposal and cancels it if more than (relayers.len() - threshold) + /// votes against exist. + fn vote_against( + who: T::AccountId, + nonce: DepositNonce, + src_id: ChainId, + prop: Box, + ) -> DispatchResult { + Self::commit_vote(who, nonce, src_id, prop.clone(), false)?; + Self::try_resolve_proposal(nonce, src_id, prop) + } + + /// Execute the proposal and signals the result as an event + fn finalize_execution( + src_id: ChainId, + nonce: DepositNonce, + call: Box, + ) -> DispatchResult { + Self::deposit_event(RawEvent::ProposalApproved(src_id, nonce)); + call.dispatch(frame_system::RawOrigin::Signed(Self::account_id()).into()) + .map(|_| ()) + .map_err(|e| e.error)?; + Self::deposit_event(RawEvent::ProposalSucceeded(src_id, nonce)); + Ok(()) + } + + /// Cancels a proposal. + fn cancel_execution(src_id: ChainId, nonce: DepositNonce) -> DispatchResult { + Self::deposit_event(RawEvent::ProposalRejected(src_id, nonce)); + Ok(()) + } + + /// Initiates a transfer of a fungible asset out of the chain. This should be called by another + /// pallet. + pub fn transfer_fungible( + dest_id: ChainId, + resource_id: ResourceId, + to: Vec, + amount: U256, + ) -> DispatchResult { + ensure!(Self::chain_whitelisted(dest_id), Error::::ChainNotWhitelisted); + ensure!(Self::resource_exists(resource_id), Error::::ResourceDoesNotExist); + let nonce = Self::bump_nonce(dest_id); + Self::deposit_event(RawEvent::FungibleTransfer(dest_id, nonce, resource_id, amount, to)); + Ok(()) + } + + /// Initiates a transfer of a nonfungible asset out of the chain. This should be called by + /// another pallet. + pub fn transfer_nonfungible( + dest_id: ChainId, + resource_id: ResourceId, + token_id: Vec, + to: Vec, + metadata: Vec, + ) -> DispatchResult { + ensure!(Self::chain_whitelisted(dest_id), Error::::ChainNotWhitelisted); + ensure!(Self::resource_exists(resource_id), Error::::ResourceDoesNotExist); + let nonce = Self::bump_nonce(dest_id); + Self::deposit_event(RawEvent::NonFungibleTransfer( + dest_id, + nonce, + resource_id, + token_id, + to, + metadata, + )); + Ok(()) + } + + /// Initiates a transfer of generic data out of the chain. This should be called by another + /// pallet. + pub fn transfer_generic( + dest_id: ChainId, + resource_id: ResourceId, + metadata: Vec, + ) -> DispatchResult { + ensure!(Self::chain_whitelisted(dest_id), Error::::ChainNotWhitelisted); + ensure!(Self::resource_exists(resource_id), Error::::ResourceDoesNotExist); + let nonce = Self::bump_nonce(dest_id); + Self::deposit_event(RawEvent::GenericTransfer(dest_id, nonce, resource_id, metadata)); + Ok(()) + } } /// Simple ensure origin for the bridge account pub struct EnsureBridge(sp_std::marker::PhantomData); -impl EnsureOrigin for EnsureBridge { - type Success = T::AccountId; - fn try_origin(o: T::Origin) -> Result { - let bridge_id = AccountIdConversion::::into_account_truncating(&MODULE_ID); - o.into().and_then(|o| match o { - system::RawOrigin::Signed(who) if who == bridge_id => Ok(bridge_id), - r => Err(T::Origin::from(r)), - }) - } +impl EnsureOrigin for EnsureBridge { + type Success = T::AccountId; + fn try_origin(o: T::RuntimeOrigin) -> Result { + let bridge_id = AccountIdConversion::::into_account_truncating(&MODULE_ID); + o.into().and_then(|o| match o { + system::RawOrigin::Signed(who) if who == bridge_id => Ok(bridge_id), + r => Err(T::RuntimeOrigin::from(r)), + }) + } #[cfg(feature = "runtime-benchmarks")] - fn successful_origin() -> T::Origin { - T::Origin::from(system::RawOrigin::Signed(>::account_id())) + fn successful_origin() -> T::RuntimeOrigin { + T::RuntimeOrigin::from(system::RawOrigin::Signed(>::account_id())) } } diff --git a/pallets/chainbridge/src/mock.rs b/pallets/chainbridge/src/mock.rs index bf49533e8..15a6a235b 100644 --- a/pallets/chainbridge/src/mock.rs +++ b/pallets/chainbridge/src/mock.rs @@ -3,103 +3,102 @@ use super::*; use frame_support::{ - assert_ok, ord_parameter_types, parameter_types, weights::Weight, PalletId, - traits::{Everything} + assert_ok, ord_parameter_types, parameter_types, traits::Everything, weights::Weight, PalletId, }; use frame_system::{self as system}; use sp_core::H256; use sp_runtime::{ - testing::Header, - traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, IdentityLookup}, - Perbill, + testing::Header, + traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, IdentityLookup}, + Perbill, }; use crate::{self as bridge, Config}; pub use pallet_balances as balances; parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); - pub const MaxLocks: u32 = 50; + pub const BlockHashCount: u64 = 250; + pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::one(); + pub const MaxLocks: u32 = 50; } impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type Origin = Origin; - type Call = Call; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - // type ModuleToIndex = (); - type PalletInfo = PalletInfo; - // type MaxLocks = MaxLocks; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + // type ModuleToIndex = (); + type PalletInfo = PalletInfo; + // type MaxLocks = MaxLocks; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { - pub const ExistentialDeposit: u64 = 1; + pub const ExistentialDeposit: u64 = 1; } ord_parameter_types! { - pub const One: u64 = 1; + pub const One: u64 = 1; } impl pallet_balances::Config for Test { - type Balance = u64; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = (); + type Balance = u64; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = (); } parameter_types! { - pub const TestChainId: u8 = 5; - pub const ProposalLifetime: u64 = 50; + pub const TestChainId: u8 = 5; + pub const ProposalLifetime: u64 = 50; } impl Config for Test { - type Event = Event; - type AdminOrigin = frame_system::EnsureRoot; - type Proposal = Call; - type ChainId = TestChainId; - type ProposalLifetime = ProposalLifetime; + type RuntimeEvent = RuntimeEvent; + type AdminOrigin = frame_system::EnsureRoot; + type Proposal = RuntimeCall; + type ChainId = TestChainId; + type ProposalLifetime = ProposalLifetime; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic - { - System: system::{Pallet, Call, Event}, - Balances: balances::{Pallet, Call, Storage, Config, Event}, - Bridge: bridge::{Pallet, Call, Storage, Event}, - } + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: system::{Pallet, Call, Event}, + Balances: balances::{Pallet, Call, Storage, Config, Event}, + Bridge: bridge::{Pallet, Call, Storage, Event}, + } ); // pub const BRIDGE_ID: u64 = @@ -110,55 +109,49 @@ pub const ENDOWED_BALANCE: u64 = 100_000_000; pub const TEST_THRESHOLD: u32 = 2; pub fn new_test_ext() -> sp_io::TestExternalities { - let bridge_id = AccountIdConversion::into_account_truncating(&MODULE_ID); - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(bridge_id, ENDOWED_BALANCE)], - } - .assimilate_storage(&mut t) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext + let bridge_id = AccountIdConversion::into_account_truncating(&MODULE_ID); + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(bridge_id, ENDOWED_BALANCE)] } + .assimilate_storage(&mut t) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext } pub fn new_test_ext_initialized( - src_id: ChainId, - r_id: ResourceId, - resource: Vec, + src_id: ChainId, + r_id: ResourceId, + resource: Vec, ) -> sp_io::TestExternalities { - let mut t = new_test_ext(); - t.execute_with(|| { - // Set and check threshold - assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD)); - assert_eq!(Bridge::relayer_threshold(), TEST_THRESHOLD); - // Add relayers - assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_A)); - assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_B)); - assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_C)); - // Whitelist chain - assert_ok!(Bridge::whitelist_chain(Origin::root(), src_id)); - // Set and check resource ID mapped to some junk data - assert_ok!(Bridge::set_resource(Origin::root(), r_id, resource)); - assert_eq!(Bridge::resource_exists(r_id), true); - }); - t + let mut t = new_test_ext(); + t.execute_with(|| { + // Set and check threshold + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD)); + assert_eq!(Bridge::relayer_threshold(), TEST_THRESHOLD); + // Add relayers + assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A)); + assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B)); + assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_C)); + // Whitelist chain + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), src_id)); + // Set and check resource ID mapped to some junk data + assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), r_id, resource)); + assert_eq!(Bridge::resource_exists(r_id), true); + }); + t } // Checks events against the latest. A contiguous set of events must be provided. They must // include the most recent event, but do not have to include every past event. -pub fn assert_events(mut expected: Vec) { - let mut actual: Vec = system::Module::::events() - .iter() - .map(|e| e.event.clone()) - .collect(); - - expected.reverse(); - - for evt in expected { - let next = actual.pop().expect("event expected"); - assert_eq!(next, evt.into(), "Events don't match (actual,expected)"); - } +pub fn assert_events(mut expected: Vec) { + let mut actual: Vec = + system::Module::::events().iter().map(|e| e.event.clone()).collect(); + + expected.reverse(); + + for evt in expected { + let next = actual.pop().expect("event expected"); + assert_eq!(next, evt.into(), "Events don't match (actual,expected)"); + } } diff --git a/pallets/chainbridge/src/tests.rs b/pallets/chainbridge/src/tests.rs index 7ceb70f69..c7b3b18a2 100644 --- a/pallets/chainbridge/src/tests.rs +++ b/pallets/chainbridge/src/tests.rs @@ -1,564 +1,569 @@ #![cfg(test)] -use super::mock::{ - assert_events, new_test_ext, Balances, Bridge, Call, Event, Origin, ProposalLifetime, System, - Test, TestChainId, ENDOWED_BALANCE, RELAYER_A, RELAYER_B, RELAYER_C, TEST_THRESHOLD, +use super::{ + mock::{ + assert_events, new_test_ext, Balances, Bridge, ProposalLifetime, RuntimeCall, RuntimeEvent, + RuntimeOrigin, System, Test, TestChainId, ENDOWED_BALANCE, RELAYER_A, RELAYER_B, RELAYER_C, + TEST_THRESHOLD, + }, + *, }; -use super::*; use crate::mock::new_test_ext_initialized; use frame_support::{assert_noop, assert_ok}; +use frame_system::Origin; #[test] fn derive_ids() { - let chain = 1; - let id = [ - 0x21, 0x60, 0x5f, 0x71, 0x84, 0x5f, 0x37, 0x2a, 0x9e, 0xd8, 0x42, 0x53, 0xd2, 0xd0, 0x24, - 0xb7, 0xb1, 0x09, 0x99, 0xf4, - ]; - let r_id = derive_resource_id(chain, &id); - let expected = [ - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x21, 0x60, 0x5f, 0x71, 0x84, 0x5f, - 0x37, 0x2a, 0x9e, 0xd8, 0x42, 0x53, 0xd2, 0xd0, 0x24, 0xb7, 0xb1, 0x09, 0x99, 0xf4, chain, - ]; - assert_eq!(r_id, expected); + let chain = 1; + let id = [ + 0x21, 0x60, 0x5f, 0x71, 0x84, 0x5f, 0x37, 0x2a, 0x9e, 0xd8, 0x42, 0x53, 0xd2, 0xd0, 0x24, + 0xb7, 0xb1, 0x09, 0x99, 0xf4, + ]; + let r_id = derive_resource_id(chain, &id); + let expected = [ + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x21, 0x60, 0x5f, 0x71, 0x84, 0x5f, + 0x37, 0x2a, 0x9e, 0xd8, 0x42, 0x53, 0xd2, 0xd0, 0x24, 0xb7, 0xb1, 0x09, 0x99, 0xf4, chain, + ]; + assert_eq!(r_id, expected); } #[test] fn complete_proposal_approved() { - let mut prop = ProposalVotes { - votes_for: vec![1, 2], - votes_against: vec![3], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get(), - }; - - prop.try_to_complete(2, 3); - assert_eq!(prop.status, ProposalStatus::Approved); + let mut prop = ProposalVotes { + votes_for: vec![1, 2], + votes_against: vec![3], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get(), + }; + + prop.try_to_complete(2, 3); + assert_eq!(prop.status, ProposalStatus::Approved); } #[test] fn complete_proposal_rejected() { - let mut prop = ProposalVotes { - votes_for: vec![1], - votes_against: vec![2, 3], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get(), - }; - - prop.try_to_complete(2, 3); - assert_eq!(prop.status, ProposalStatus::Rejected); + let mut prop = ProposalVotes { + votes_for: vec![1], + votes_against: vec![2, 3], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get(), + }; + + prop.try_to_complete(2, 3); + assert_eq!(prop.status, ProposalStatus::Rejected); } #[test] fn complete_proposal_bad_threshold() { - let mut prop = ProposalVotes { - votes_for: vec![1, 2], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get(), - }; - - prop.try_to_complete(3, 2); - assert_eq!(prop.status, ProposalStatus::Initiated); - - let mut prop = ProposalVotes { - votes_for: vec![], - votes_against: vec![1, 2], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get(), - }; - - prop.try_to_complete(3, 2); - assert_eq!(prop.status, ProposalStatus::Initiated); + let mut prop = ProposalVotes { + votes_for: vec![1, 2], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get(), + }; + + prop.try_to_complete(3, 2); + assert_eq!(prop.status, ProposalStatus::Initiated); + + let mut prop = ProposalVotes { + votes_for: vec![], + votes_against: vec![1, 2], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get(), + }; + + prop.try_to_complete(3, 2); + assert_eq!(prop.status, ProposalStatus::Initiated); } #[test] fn setup_resources() { - new_test_ext().execute_with(|| { - let id: ResourceId = [1; 32]; - let method = "Pallet.do_something".as_bytes().to_vec(); - let method2 = "Pallet.do_somethingElse".as_bytes().to_vec(); + new_test_ext().execute_with(|| { + let id: ResourceId = [1; 32]; + let method = "Pallet.do_something".as_bytes().to_vec(); + let method2 = "Pallet.do_somethingElse".as_bytes().to_vec(); - assert_ok!(Bridge::set_resource(Origin::root(), id, method.clone())); - assert_eq!(Bridge::resources(id), Some(method)); + assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method.clone())); + assert_eq!(Bridge::resources(id), Some(method)); - assert_ok!(Bridge::set_resource(Origin::root(), id, method2.clone())); - assert_eq!(Bridge::resources(id), Some(method2)); + assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method2.clone())); + assert_eq!(Bridge::resources(id), Some(method2)); - assert_ok!(Bridge::remove_resource(Origin::root(), id)); - assert_eq!(Bridge::resources(id), None); - }) + assert_ok!(Bridge::remove_resource(RuntimeOrigin::root(), id)); + assert_eq!(Bridge::resources(id), None); + }) } #[test] fn whitelist_chain() { - new_test_ext().execute_with(|| { - assert!(!Bridge::chain_whitelisted(0)); + new_test_ext().execute_with(|| { + assert!(!Bridge::chain_whitelisted(0)); - assert_ok!(Bridge::whitelist_chain(Origin::root(), 0)); - assert_noop!( - Bridge::whitelist_chain(Origin::root(), TestChainId::get()), - Error::::InvalidChainId - ); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), 0)); + assert_noop!( + Bridge::whitelist_chain(RuntimeOrigin::root(), TestChainId::get()), + Error::::InvalidChainId + ); - assert_events(vec![Event::Bridge(RawEvent::ChainWhitelisted(0))]); - }) + assert_events(vec![RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(0))]); + }) } #[test] fn set_get_threshold() { - new_test_ext().execute_with(|| { - assert_eq!(::get(), 1); + new_test_ext().execute_with(|| { + assert_eq!(::get(), 1); - assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD)); - assert_eq!(::get(), TEST_THRESHOLD); + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD)); + assert_eq!(::get(), TEST_THRESHOLD); - assert_ok!(Bridge::set_threshold(Origin::root(), 5)); - assert_eq!(::get(), 5); + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), 5)); + assert_eq!(::get(), 5); - assert_events(vec![ - Event::Bridge(RawEvent::RelayerThresholdChanged(TEST_THRESHOLD)), - Event::Bridge(RawEvent::RelayerThresholdChanged(5)), - ]); - }) + assert_events(vec![ + RuntimeEvent::Bridge(RawEvent::RelayerThresholdChanged(TEST_THRESHOLD)), + RuntimeEvent::Bridge(RawEvent::RelayerThresholdChanged(5)), + ]); + }) } #[test] fn asset_transfer_success() { - new_test_ext().execute_with(|| { - let dest_id = 2; - let to = vec![2]; - let resource_id = [1; 32]; - let metadata = vec![]; - let amount = 100; - let token_id = vec![1, 2, 3, 4]; - let method = "Erc20.transfer".as_bytes().to_vec(); - - assert_ok!(Bridge::set_resource(Origin::root(), resource_id, method.clone())); - assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD,)); - - assert_ok!(Bridge::whitelist_chain(Origin::root(), dest_id.clone())); - assert_ok!(Bridge::transfer_fungible( - dest_id.clone(), - resource_id.clone(), - to.clone(), - amount.into() - )); - assert_events(vec![ - Event::Bridge(RawEvent::ChainWhitelisted(dest_id.clone())), - Event::Bridge(RawEvent::FungibleTransfer( - dest_id.clone(), - 1, - resource_id.clone(), - amount.into(), - to.clone(), - )), - ]); - - assert_ok!(Bridge::transfer_nonfungible( - dest_id.clone(), - resource_id.clone(), - token_id.clone(), - to.clone(), - metadata.clone() - )); - assert_events(vec![Event::Bridge(RawEvent::NonFungibleTransfer( - dest_id.clone(), - 2, - resource_id.clone(), - token_id, - to.clone(), - metadata.clone(), - ))]); - - assert_ok!(Bridge::transfer_generic( - dest_id.clone(), - resource_id.clone(), - metadata.clone() - )); - assert_events(vec![Event::Bridge(RawEvent::GenericTransfer( - dest_id.clone(), - 3, - resource_id, - metadata, - ))]); - }) + new_test_ext().execute_with(|| { + let dest_id = 2; + let to = vec![2]; + let resource_id = [1; 32]; + let metadata = vec![]; + let amount = 100; + let token_id = vec![1, 2, 3, 4]; + let method = "Erc20.transfer".as_bytes().to_vec(); + + assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), resource_id, method.clone())); + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); + + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id.clone())); + assert_ok!(Bridge::transfer_fungible( + dest_id.clone(), + resource_id.clone(), + to.clone(), + amount.into() + )); + assert_events(vec![ + RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(dest_id.clone())), + RuntimeEvent::Bridge(RawEvent::FungibleTransfer( + dest_id.clone(), + 1, + resource_id.clone(), + amount.into(), + to.clone(), + )), + ]); + + assert_ok!(Bridge::transfer_nonfungible( + dest_id.clone(), + resource_id.clone(), + token_id.clone(), + to.clone(), + metadata.clone() + )); + assert_events(vec![RuntimeEvent::Bridge(RawEvent::NonFungibleTransfer( + dest_id.clone(), + 2, + resource_id.clone(), + token_id, + to.clone(), + metadata.clone(), + ))]); + + assert_ok!(Bridge::transfer_generic( + dest_id.clone(), + resource_id.clone(), + metadata.clone() + )); + assert_events(vec![RuntimeEvent::Bridge(RawEvent::GenericTransfer( + dest_id.clone(), + 3, + resource_id, + metadata, + ))]); + }) } #[test] fn asset_transfer_invalid_resource_id() { - new_test_ext().execute_with(|| { - let dest_id = 2; - let to = vec![2]; - let resource_id = [1; 32]; - let amount = 100; - - assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD,)); - assert_ok!(Bridge::whitelist_chain(Origin::root(), dest_id.clone())); - - assert_noop!( - Bridge::transfer_fungible(dest_id.clone(), resource_id.clone(), to.clone(), amount.into()), - Error::::ResourceDoesNotExist - ); - - assert_noop!( - Bridge::transfer_nonfungible(dest_id.clone(), resource_id.clone(), vec![], vec![], vec![]), - Error::::ResourceDoesNotExist - ); - - assert_noop!( - Bridge::transfer_generic(dest_id.clone(), resource_id.clone(), vec![]), - Error::::ResourceDoesNotExist - ); - }) + new_test_ext().execute_with(|| { + let dest_id = 2; + let to = vec![2]; + let resource_id = [1; 32]; + let amount = 100; + + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id.clone())); + + assert_noop!( + Bridge::transfer_fungible( + dest_id.clone(), + resource_id.clone(), + to.clone(), + amount.into() + ), + Error::::ResourceDoesNotExist + ); + + assert_noop!( + Bridge::transfer_nonfungible( + dest_id.clone(), + resource_id.clone(), + vec![], + vec![], + vec![] + ), + Error::::ResourceDoesNotExist + ); + + assert_noop!( + Bridge::transfer_generic(dest_id.clone(), resource_id.clone(), vec![]), + Error::::ResourceDoesNotExist + ); + }) } #[test] fn asset_transfer_invalid_chain() { - new_test_ext().execute_with(|| { - let chain_id = 2; - let bad_dest_id = 3; - let resource_id = [4; 32]; - - assert_ok!(Bridge::whitelist_chain(Origin::root(), chain_id.clone())); - assert_events(vec![Event::Bridge(RawEvent::ChainWhitelisted( - chain_id.clone(), - ))]); - - assert_noop!( - Bridge::transfer_fungible(bad_dest_id, resource_id.clone(), vec![], U256::zero()), - Error::::ChainNotWhitelisted - ); - - assert_noop!( - Bridge::transfer_nonfungible(bad_dest_id, resource_id.clone(), vec![], vec![], vec![]), - Error::::ChainNotWhitelisted - ); - - assert_noop!( - Bridge::transfer_generic(bad_dest_id, resource_id.clone(), vec![]), - Error::::ChainNotWhitelisted - ); - }) + new_test_ext().execute_with(|| { + let chain_id = 2; + let bad_dest_id = 3; + let resource_id = [4; 32]; + + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), chain_id.clone())); + assert_events(vec![RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(chain_id.clone()))]); + + assert_noop!( + Bridge::transfer_fungible(bad_dest_id, resource_id.clone(), vec![], U256::zero()), + Error::::ChainNotWhitelisted + ); + + assert_noop!( + Bridge::transfer_nonfungible(bad_dest_id, resource_id.clone(), vec![], vec![], vec![]), + Error::::ChainNotWhitelisted + ); + + assert_noop!( + Bridge::transfer_generic(bad_dest_id, resource_id.clone(), vec![]), + Error::::ChainNotWhitelisted + ); + }) } #[test] fn add_remove_relayer() { - new_test_ext().execute_with(|| { - assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD,)); - assert_eq!(Bridge::relayer_count(), 0); - - assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_A)); - assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_B)); - assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_C)); - assert_eq!(Bridge::relayer_count(), 3); - - // Already exists - assert_noop!( - Bridge::add_relayer(Origin::root(), RELAYER_A), - Error::::RelayerAlreadyExists - ); - - // Confirm removal - assert_ok!(Bridge::remove_relayer(Origin::root(), RELAYER_B)); - assert_eq!(Bridge::relayer_count(), 2); - assert_noop!( - Bridge::remove_relayer(Origin::root(), RELAYER_B), - Error::::RelayerInvalid - ); - assert_eq!(Bridge::relayer_count(), 2); - - assert_events(vec![ - Event::Bridge(RawEvent::RelayerAdded(RELAYER_A)), - Event::Bridge(RawEvent::RelayerAdded(RELAYER_B)), - Event::Bridge(RawEvent::RelayerAdded(RELAYER_C)), - Event::Bridge(RawEvent::RelayerRemoved(RELAYER_B)), - ]); - }) + new_test_ext().execute_with(|| { + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); + assert_eq!(Bridge::relayer_count(), 0); + + assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A)); + assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B)); + assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_C)); + assert_eq!(Bridge::relayer_count(), 3); + + // Already exists + assert_noop!( + Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A), + Error::::RelayerAlreadyExists + ); + + // Confirm removal + assert_ok!(Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B)); + assert_eq!(Bridge::relayer_count(), 2); + assert_noop!( + Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B), + Error::::RelayerInvalid + ); + assert_eq!(Bridge::relayer_count(), 2); + + assert_events(vec![ + RuntimeEvent::Bridge(RawEvent::RelayerAdded(RELAYER_A)), + RuntimeEvent::Bridge(RawEvent::RelayerAdded(RELAYER_B)), + RuntimeEvent::Bridge(RawEvent::RelayerAdded(RELAYER_C)), + RuntimeEvent::Bridge(RawEvent::RelayerRemoved(RELAYER_B)), + ]); + }) } -fn make_proposal(r: Vec) -> mock::Call { - Call::System(system::Call::remark{ remark: r }) +fn make_proposal(r: Vec) -> mock::RuntimeCall { + RuntimeCall::System(system::Call::remark { remark: r }) } #[test] fn create_sucessful_proposal() { - let src_id = 1; - let r_id = derive_resource_id(src_id, b"remark"); - - new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { - let prop_id = 1; - let proposal = make_proposal(vec![10]); - - // Create proposal (& vote) - assert_ok!(Bridge::acknowledge_proposal( - Origin::signed(RELAYER_A), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // Second relayer votes against - assert_ok!(Bridge::reject_proposal( - Origin::signed(RELAYER_B), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![RELAYER_B], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // Third relayer votes in favour - assert_ok!(Bridge::acknowledge_proposal( - Origin::signed(RELAYER_C), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A, RELAYER_C], - votes_against: vec![RELAYER_B], - status: ProposalStatus::Approved, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - assert_events(vec![ - Event::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A)), - Event::Bridge(RawEvent::VoteAgainst(src_id, prop_id, RELAYER_B)), - Event::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_C)), - Event::Bridge(RawEvent::ProposalApproved(src_id, prop_id)), - Event::Bridge(RawEvent::ProposalSucceeded(src_id, prop_id)), - ]); - }) + let src_id = 1; + let r_id = derive_resource_id(src_id, b"remark"); + + new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { + let prop_id = 1; + let proposal = make_proposal(vec![10]); + + // Create proposal (& vote) + assert_ok!(Bridge::acknowledge_proposal( + RuntimeOrigin::signed(RELAYER_A), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // Second relayer votes against + assert_ok!(Bridge::reject_proposal( + RuntimeOrigin::signed(RELAYER_B), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![RELAYER_B], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // Third relayer votes in favour + assert_ok!(Bridge::acknowledge_proposal( + RuntimeOrigin::signed(RELAYER_C), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A, RELAYER_C], + votes_against: vec![RELAYER_B], + status: ProposalStatus::Approved, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + assert_events(vec![ + RuntimeEvent::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A)), + RuntimeEvent::Bridge(RawEvent::VoteAgainst(src_id, prop_id, RELAYER_B)), + RuntimeEvent::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_C)), + RuntimeEvent::Bridge(RawEvent::ProposalApproved(src_id, prop_id)), + RuntimeEvent::Bridge(RawEvent::ProposalSucceeded(src_id, prop_id)), + ]); + }) } #[test] fn create_unsucessful_proposal() { - let src_id = 1; - let r_id = derive_resource_id(src_id, b"transfer"); - - new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { - let prop_id = 1; - let proposal = make_proposal(vec![11]); - - // Create proposal (& vote) - assert_ok!(Bridge::acknowledge_proposal( - Origin::signed(RELAYER_A), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // Second relayer votes against - assert_ok!(Bridge::reject_proposal( - Origin::signed(RELAYER_B), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![RELAYER_B], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // Third relayer votes against - assert_ok!(Bridge::reject_proposal( - Origin::signed(RELAYER_C), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![RELAYER_B, RELAYER_C], - status: ProposalStatus::Rejected, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - assert_eq!(Balances::free_balance(RELAYER_B), 0); - assert_eq!( - Balances::free_balance(Bridge::account_id()), - ENDOWED_BALANCE - ); - - assert_events(vec![ - Event::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A)), - Event::Bridge(RawEvent::VoteAgainst(src_id, prop_id, RELAYER_B)), - Event::Bridge(RawEvent::VoteAgainst(src_id, prop_id, RELAYER_C)), - Event::Bridge(RawEvent::ProposalRejected(src_id, prop_id)), - ]); - }) + let src_id = 1; + let r_id = derive_resource_id(src_id, b"transfer"); + + new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { + let prop_id = 1; + let proposal = make_proposal(vec![11]); + + // Create proposal (& vote) + assert_ok!(Bridge::acknowledge_proposal( + RuntimeOrigin::signed(RELAYER_A), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // Second relayer votes against + assert_ok!(Bridge::reject_proposal( + RuntimeOrigin::signed(RELAYER_B), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![RELAYER_B], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // Third relayer votes against + assert_ok!(Bridge::reject_proposal( + RuntimeOrigin::signed(RELAYER_C), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![RELAYER_B, RELAYER_C], + status: ProposalStatus::Rejected, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + assert_eq!(Balances::free_balance(RELAYER_B), 0); + assert_eq!(Balances::free_balance(Bridge::account_id()), ENDOWED_BALANCE); + + assert_events(vec![ + RuntimeEvent::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A)), + RuntimeEvent::Bridge(RawEvent::VoteAgainst(src_id, prop_id, RELAYER_B)), + RuntimeEvent::Bridge(RawEvent::VoteAgainst(src_id, prop_id, RELAYER_C)), + RuntimeEvent::Bridge(RawEvent::ProposalRejected(src_id, prop_id)), + ]); + }) } #[test] fn execute_after_threshold_change() { - let src_id = 1; - let r_id = derive_resource_id(src_id, b"transfer"); - - new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { - let prop_id = 1; - let proposal = make_proposal(vec![11]); - - // Create proposal (& vote) - assert_ok!(Bridge::acknowledge_proposal( - Origin::signed(RELAYER_A), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // Change threshold - assert_ok!(Bridge::set_threshold(Origin::root(), 1)); - - // Attempt to execute - assert_ok!(Bridge::eval_vote_state( - Origin::signed(RELAYER_A), - prop_id, - src_id, - Box::new(proposal.clone()) - )); - - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Approved, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - assert_eq!(Balances::free_balance(RELAYER_B), 0); - assert_eq!( - Balances::free_balance(Bridge::account_id()), - ENDOWED_BALANCE - ); - - assert_events(vec![ - Event::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A)), - Event::Bridge(RawEvent::RelayerThresholdChanged(1)), - Event::Bridge(RawEvent::ProposalApproved(src_id, prop_id)), - Event::Bridge(RawEvent::ProposalSucceeded(src_id, prop_id)), - ]); - }) + let src_id = 1; + let r_id = derive_resource_id(src_id, b"transfer"); + + new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { + let prop_id = 1; + let proposal = make_proposal(vec![11]); + + // Create proposal (& vote) + assert_ok!(Bridge::acknowledge_proposal( + RuntimeOrigin::signed(RELAYER_A), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // Change threshold + assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), 1)); + + // Attempt to execute + assert_ok!(Bridge::eval_vote_state( + RuntimeOrigin::signed(RELAYER_A), + prop_id, + src_id, + Box::new(proposal.clone()) + )); + + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Approved, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + assert_eq!(Balances::free_balance(RELAYER_B), 0); + assert_eq!(Balances::free_balance(Bridge::account_id()), ENDOWED_BALANCE); + + assert_events(vec![ + RuntimeEvent::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A)), + RuntimeEvent::Bridge(RawEvent::RelayerThresholdChanged(1)), + RuntimeEvent::Bridge(RawEvent::ProposalApproved(src_id, prop_id)), + RuntimeEvent::Bridge(RawEvent::ProposalSucceeded(src_id, prop_id)), + ]); + }) } #[test] fn proposal_expires() { - let src_id = 1; - let r_id = derive_resource_id(src_id, b"remark"); - - new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { - let prop_id = 1; - let proposal = make_proposal(vec![10]); - - // Create proposal (& vote) - assert_ok!(Bridge::acknowledge_proposal( - Origin::signed(RELAYER_A), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // Increment enough blocks such that now == expiry - System::set_block_number(ProposalLifetime::get() + 1); - - // Attempt to submit a vote should fail - assert_noop!( - Bridge::reject_proposal( - Origin::signed(RELAYER_B), - prop_id, - src_id, - r_id, - Box::new(proposal.clone()) - ), - Error::::ProposalExpired - ); - - // Proposal state should remain unchanged - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - // eval_vote_state should have no effect - assert_noop!( - Bridge::eval_vote_state( - Origin::signed(RELAYER_C), - prop_id, - src_id, - Box::new(proposal.clone()) - ), - Error::::ProposalExpired - ); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); - let expected = ProposalVotes { - votes_for: vec![RELAYER_A], - votes_against: vec![], - status: ProposalStatus::Initiated, - expiry: ProposalLifetime::get() + 1, - }; - assert_eq!(prop, expected); - - assert_events(vec![Event::Bridge(RawEvent::VoteFor( - src_id, prop_id, RELAYER_A, - ))]); - }) + let src_id = 1; + let r_id = derive_resource_id(src_id, b"remark"); + + new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| { + let prop_id = 1; + let proposal = make_proposal(vec![10]); + + // Create proposal (& vote) + assert_ok!(Bridge::acknowledge_proposal( + RuntimeOrigin::signed(RELAYER_A), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + )); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // Increment enough blocks such that now == expiry + System::set_block_number(ProposalLifetime::get() + 1); + + // Attempt to submit a vote should fail + assert_noop!( + Bridge::reject_proposal( + RuntimeOrigin::signed(RELAYER_B), + prop_id, + src_id, + r_id, + Box::new(proposal.clone()) + ), + Error::::ProposalExpired + ); + + // Proposal state should remain unchanged + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + // eval_vote_state should have no effect + assert_noop!( + Bridge::eval_vote_state( + RuntimeOrigin::signed(RELAYER_C), + prop_id, + src_id, + Box::new(proposal.clone()) + ), + Error::::ProposalExpired + ); + let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let expected = ProposalVotes { + votes_for: vec![RELAYER_A], + votes_against: vec![], + status: ProposalStatus::Initiated, + expiry: ProposalLifetime::get() + 1, + }; + assert_eq!(prop, expected); + + assert_events(vec![RuntimeEvent::Bridge(RawEvent::VoteFor(src_id, prop_id, RELAYER_A))]); + }) } diff --git a/pallets/ddc-metrics-offchain-worker/Cargo.toml b/pallets/ddc-metrics-offchain-worker/Cargo.toml index cbc8209f2..e9de68b71 100644 --- a/pallets/ddc-metrics-offchain-worker/Cargo.toml +++ b/pallets/ddc-metrics-offchain-worker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ddc-metrics-offchain-worker" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" @@ -14,19 +14,19 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["full"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } serde = { version = "1.0.136", optional = true } -sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } lite-json = { version = "0.2.0", default-features = false } alt_serde = { version = "1", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -# pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +# pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } hex-literal = "^0.3.1" hex = { version = "0.4", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } @@ -49,7 +49,7 @@ std = [ ] [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pretty_assertions = "0.6.1" diff --git a/pallets/ddc-metrics-offchain-worker/src/lib.rs b/pallets/ddc-metrics-offchain-worker/src/lib.rs index 34e8798d1..5c6c07892 100644 --- a/pallets/ddc-metrics-offchain-worker/src/lib.rs +++ b/pallets/ddc-metrics-offchain-worker/src/lib.rs @@ -9,22 +9,22 @@ mod tests; use alt_serde::{de::DeserializeOwned, Deserialize}; use codec::{Decode, Encode, HasCompact}; -use frame_support::traits::{Currency, Get}; use frame_support::{ - log::{error, info, warn}, - decl_event, decl_module, decl_storage, + decl_event, decl_module, decl_storage, + log::{error, info, warn}, + traits::{Currency, Get}, }; use frame_system::offchain::{ - AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes, + AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes, }; use hex_literal::hex; use pallet_contracts; use sp_core::crypto::{KeyTypeId, UncheckedFrom}; use sp_runtime::{ - offchain::{http, storage::StorageValueRef, Duration}, - traits::StaticLookup, - AccountId32, + offchain::{http, storage::StorageValueRef, Duration}, + traits::StaticLookup, + AccountId32, }; use sp_std::vec::Vec; @@ -47,39 +47,40 @@ pub const CURRENT_PERIOD_MS: [u8; 4] = hex!("ace4ecb3"); pub const GET_ALL_DDC_NODES_SELECTOR: [u8; 4] = hex!("e6c98b60"); pub const FINALIZE_METRIC_PERIOD: [u8; 4] = hex!("b269d557"); -type BalanceOf = -<::Currency as Currency<::AccountId>>::Balance; +type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; #[derive(Encode, Decode)] pub struct DDCNode { - p2p_id: String, - p2p_addr: String, - url: String, - permissions: u64, + p2p_id: String, + p2p_addr: String, + url: String, + permissions: u64, } struct Metric { - app_id: String, - storage_bytes: u64, - wcu_used: u64, - rcu_used: u64, + app_id: String, + storage_bytes: u64, + wcu_used: u64, + rcu_used: u64, } struct MetricDDN { - p2p_id: String, - storage_bytes: u64, - wcu_used: u64, - rcu_used: u64, + p2p_id: String, + storage_bytes: u64, + wcu_used: u64, + rcu_used: u64, } #[derive(Deserialize)] #[serde(crate = "alt_serde")] #[allow(non_snake_case)] struct ApiMetric { - appPubKey: String, - storageBytes: u64, - wcuUsed: u64, - rcuUsed: u64, + appPubKey: String, + storageBytes: u64, + wcuUsed: u64, + rcuUsed: u64, } /// Defines application identifier for crypto keys of this module. @@ -102,30 +103,30 @@ pub const HTTP_TIMEOUT_MS: u64 = 30_000; // in milli-seconds /// We can use from supported crypto kinds (`sr25519`, `ed25519` and `ecdsa`) and augment /// the types with this pallet-specific identifier. pub mod crypto { - use super::KEY_TYPE; - use frame_system::offchain::AppCrypto; - use sp_core::sr25519::Signature as Sr25519Signature; - use sp_runtime::{ - app_crypto::{app_crypto, sr25519}, - traits::Verify, - }; - app_crypto!(sr25519, KEY_TYPE); - - use sp_runtime::{MultiSignature, MultiSigner}; - - pub struct TestAuthId; - - impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } - - impl AppCrypto for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } + use super::KEY_TYPE; + use frame_system::offchain::AppCrypto; + use sp_core::sr25519::Signature as Sr25519Signature; + use sp_runtime::{ + app_crypto::{app_crypto, sr25519}, + traits::Verify, + }; + app_crypto!(sr25519, KEY_TYPE); + + use sp_runtime::{MultiSignature, MultiSigner}; + + pub struct TestAuthId; + + impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; + } + + impl AppCrypto for TestAuthId { + type RuntimeAppPublic = Public; + type GenericSignature = sp_core::sr25519::Signature; + type GenericPublic = sp_core::sr25519::Public; + } } type ResultStr = Result; @@ -133,291 +134,288 @@ type ResultStr = Result; const MS_PER_DAY: u64 = 24 * 3600 * 1000; decl_module! { - /// A public part of the pallet. - pub struct Module for enum Call where - origin: T::Origin, - ::AccountId: AsRef<[u8]>, - ::AccountId: UncheckedFrom, - as HasCompact>::Type: Clone, - as HasCompact>::Type: Eq, - as HasCompact>::Type: PartialEq, - as HasCompact>::Type: Debug, - as HasCompact>::Type: TypeInfo, - as HasCompact>::Type: Encode { - //fn deposit_event() = default; - - /// Offchain Worker entry point. - /// - /// By implementing `fn offchain_worker` within `decl_module!` you declare a new offchain - /// worker. - /// This function will be called when the node is fully synced and a new best block is - /// succesfuly imported. - /// Note that it's not guaranteed for offchain workers to run on EVERY block, there might - /// be cases where some blocks are skipped, or for some the worker runs twice (re-orgs), - /// so the code should be able to handle that. - /// You can use `Local Storage` API to coordinate runs of the worker. - /// You can use `debug::native` namespace to not log in wasm mode. - fn offchain_worker(block_number: T::BlockNumber) { - let res = Self::offchain_worker_main(block_number); - match res { - Ok(()) => info!("[OCW] Offchain Worker complete."), - Err(err) => error!("[OCW] Error in Offchain Worker: {}", err), - }; - } - } + /// A public part of the pallet. + pub struct Module for enum Call where + origin: T::RuntimeOrigin, + ::AccountId: AsRef<[u8]>, + ::AccountId: UncheckedFrom, + as HasCompact>::Type: Clone, + as HasCompact>::Type: Eq, + as HasCompact>::Type: PartialEq, + as HasCompact>::Type: Debug, + as HasCompact>::Type: TypeInfo, + as HasCompact>::Type: Encode { + //fn deposit_event() = default; + + /// Offchain Worker entry point. + /// + /// By implementing `fn offchain_worker` within `decl_module!` you declare a new offchain + /// worker. + /// This function will be called when the node is fully synced and a new best block is + /// succesfuly imported. + /// Note that it's not guaranteed for offchain workers to run on EVERY block, there might + /// be cases where some blocks are skipped, or for some the worker runs twice (re-orgs), + /// so the code should be able to handle that. + /// You can use `Local Storage` API to coordinate runs of the worker. + /// You can use `debug::native` namespace to not log in wasm mode. + fn offchain_worker(block_number: T::BlockNumber) { + let res = Self::offchain_worker_main(block_number); + match res { + Ok(()) => info!("[OCW] Offchain Worker complete."), + Err(err) => error!("[OCW] Error in Offchain Worker: {}", err), + }; + } + } } decl_storage! { - trait Store for Module as DdcMetricsOffchainWorker - where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode { - } + trait Store for Module as DdcMetricsOffchainWorker + where ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode { + } } impl Module - where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode { - fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { - let signer = match Self::get_signer() { - Err(e) => { - warn!("{:?}", e); - return Ok(()); - } - Ok(signer) => signer, - }; - - let contract_address = match Self::get_contract_id() { - None => return Ok(()), - Some(contract_address) => contract_address, - }; - - let should_proceed = Self::check_if_should_proceed(block_number); - if should_proceed == false { - return Ok(()); - } - - let day_start_ms = - Self::sc_get_current_period_ms(contract_address.clone()).map_err(|err| { - error!("[OCW] Contract error occurred: {:?}", err); - "Could not call get_current_period_ms TX" - })?; - - let day_end_ms = day_start_ms + MS_PER_DAY; - - let (aggregated_metrics, ddn_aggregated_metrics, offline_nodes) = - Self::fetch_all_metrics(contract_address.clone(), day_start_ms).map_err(|err| { - error!("[OCW] HTTP error occurred: {:?}", err); - "could not fetch metrics" - })?; - - for offline_node in offline_nodes { - let p2p_id = offline_node.p2p_id; - let contract_id = contract_address.clone(); - Self::report_ddn_status_to_sc(contract_id, &signer, &p2p_id, false).map_err(|err| { - error!("[OCW] Contract error occurred: {:?}", err); - "could not submit report_ddn_status TX" - })?; - } - - Self::send_metrics_to_sc( - contract_address.clone(), - &signer, - day_start_ms, - aggregated_metrics, - ) - .map_err(|err| { - error!("[OCW] Contract error occurred: {:?}", err); - "could not submit report_metrics TX" - })?; - - Self::send_metrics_ddn_to_sc( - contract_address.clone(), - &signer, - day_start_ms, - ddn_aggregated_metrics, - ) - .map_err(|err| { - error!("[OCW] Contract error occurred: {:?}", err); - "could not submit report_metrics_ddn TX" - })?; - - let block_timestamp = sp_io::offchain::timestamp().unix_millis(); - - if day_end_ms < block_timestamp { - Self::finalize_metric_period(contract_address.clone(), &signer, day_start_ms).map_err( - |err| { - error!("[OCW] Contract error occurred: {:?}", err); - "could not call finalize_metric_period TX" - }, - )?; - } - - Ok(()) - } - - fn get_contract_id() -> Option<::AccountId> { - let value = StorageValueRef::persistent(b"ddc-metrics-offchain-worker::sc_address").get(); - - match value { - Ok(None) => { - warn!("[OCW] Smart Contract is not configured. Please configure it using offchain_localStorageSet with key=ddc-metrics-offchain-worker::sc_address"); - None - } - Ok(Some(contract_address)) => Some(contract_address), - Err(_) => { - error!("[OCW] Smart Contract is configured but the value could not be decoded to an account ID"); - None - } - } - } +where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, +{ + fn offchain_worker_main(block_number: T::BlockNumber) -> ResultStr<()> { + let signer = match Self::get_signer() { + Err(e) => { + warn!("{:?}", e); + return Ok(()) + }, + Ok(signer) => signer, + }; + + let contract_address = match Self::get_contract_id() { + None => return Ok(()), + Some(contract_address) => contract_address, + }; + + let should_proceed = Self::check_if_should_proceed(block_number); + if should_proceed == false { + return Ok(()) + } - fn get_block_interval() -> Option { - let value = StorageValueRef::persistent(b"ddc-metrics-offchain-worker::block_interval").get::(); + let day_start_ms = + Self::sc_get_current_period_ms(contract_address.clone()).map_err(|err| { + error!("[OCW] Contract error occurred: {:?}", err); + "Could not call get_current_period_ms TX" + })?; + + let day_end_ms = day_start_ms + MS_PER_DAY; + + let (aggregated_metrics, ddn_aggregated_metrics, offline_nodes) = + Self::fetch_all_metrics(contract_address.clone(), day_start_ms).map_err(|err| { + error!("[OCW] HTTP error occurred: {:?}", err); + "could not fetch metrics" + })?; + + for offline_node in offline_nodes { + let p2p_id = offline_node.p2p_id; + let contract_id = contract_address.clone(); + Self::report_ddn_status_to_sc(contract_id, &signer, &p2p_id, false).map_err(|err| { + error!("[OCW] Contract error occurred: {:?}", err); + "could not submit report_ddn_status TX" + })?; + } + + Self::send_metrics_to_sc( + contract_address.clone(), + &signer, + day_start_ms, + aggregated_metrics, + ) + .map_err(|err| { + error!("[OCW] Contract error occurred: {:?}", err); + "could not submit report_metrics TX" + })?; + + Self::send_metrics_ddn_to_sc( + contract_address.clone(), + &signer, + day_start_ms, + ddn_aggregated_metrics, + ) + .map_err(|err| { + error!("[OCW] Contract error occurred: {:?}", err); + "could not submit report_metrics_ddn TX" + })?; + + let block_timestamp = sp_io::offchain::timestamp().unix_millis(); + + if day_end_ms < block_timestamp { + Self::finalize_metric_period(contract_address.clone(), &signer, day_start_ms).map_err( + |err| { + error!("[OCW] Contract error occurred: {:?}", err); + "could not call finalize_metric_period TX" + }, + )?; + } + + Ok(()) + } + + fn get_contract_id() -> Option<::AccountId> { + let value = StorageValueRef::persistent(b"ddc-metrics-offchain-worker::sc_address").get(); match value { Ok(None) => { + warn!("[OCW] Smart Contract is not configured. Please configure it using offchain_localStorageSet with key=ddc-metrics-offchain-worker::sc_address"); None - } - Ok(Some(block_interval)) => Some(block_interval), - Err(_) => { - error!("[OCW] Block Interval could not be decoded"); - None - } + }, + Ok(Some(contract_address)) => Some(contract_address), + Err(_) => { + error!("[OCW] Smart Contract is configured but the value could not be decoded to an account ID"); + None + }, } } - fn check_if_should_proceed(block_number: T::BlockNumber) -> bool { - let s_next_at = StorageValueRef::persistent(b"ddc-metrics-offchain-worker::next-at"); + fn get_block_interval() -> Option { + let value = StorageValueRef::persistent(b"ddc-metrics-offchain-worker::block_interval") + .get::(); - match s_next_at.mutate(|current_next_at| { - let current_next_at = match current_next_at { - Ok(Some(val)) => Some(val), - _ => Some(T::BlockNumber::default()), - }; + match value { + Ok(None) => None, + Ok(Some(block_interval)) => Some(block_interval), + Err(_) => { + error!("[OCW] Block Interval could not be decoded"); + None + }, + } + } - if let Some(current_next_at) = current_next_at { - if current_next_at > block_number { - info!( - "[OCW] Too early to execute. Current: {:?}, next execution at: {:?}", - block_number, current_next_at - ); - Err("Skipping") - } else { + fn check_if_should_proceed(block_number: T::BlockNumber) -> bool { + let s_next_at = StorageValueRef::persistent(b"ddc-metrics-offchain-worker::next-at"); + + match s_next_at.mutate(|current_next_at| { + let current_next_at = match current_next_at { + Ok(Some(val)) => Some(val), + _ => Some(T::BlockNumber::default()), + }; + + if let Some(current_next_at) = current_next_at { + if current_next_at > block_number { + info!( + "[OCW] Too early to execute. Current: {:?}, next execution at: {:?}", + block_number, current_next_at + ); + Err("Skipping") + } else { let block_interval_configured = Self::get_block_interval(); let mut block_interval = T::BlockInterval::get(); if block_interval_configured.is_some() { - block_interval = ::BlockNumber::from(block_interval_configured.unwrap()); + block_interval = ::BlockNumber::from( + block_interval_configured.unwrap(), + ); } - // set new value - Ok(block_interval + block_number) - } - } else { - error!("[OCW] Something went wrong in `check_if_should_proceed`"); - Err("Unexpected error") - } - }) { - Ok(_val) => true, - Err(_e) => false, - } - } - - fn get_start_of_day_ms() -> u64 { - let now = sp_io::offchain::timestamp(); - let day_start_ms = (now.unix_millis() / MS_PER_DAY) * MS_PER_DAY; - day_start_ms - } - - fn get_signer() -> ResultStr> { - let signer = Signer::<_, _>::any_account(); - if !signer.can_sign() { - return Err("[OCW] No local accounts available. Consider adding one via `author_insertKey` RPC."); - } - Ok(signer) - } - - fn sc_get_current_period_ms( - contract_id: ::AccountId, - ) -> ResultStr { - let call_data = Self::encode_get_current_period_ms(); - let nobody = T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()); - let contract_exec_result = pallet_contracts::Pallet::::bare_call( - nobody.unwrap(), - contract_id, - 0u32.into(), - Weight::from_ref_time(100_000_000_000), - None, - call_data, - false, - ); - - let mut data = match &contract_exec_result.result { - Ok(v) => &v.data[..], - Err(exec_error) => { - // Return default value in case of error - warn!("[OCW] Error in call get_current_period_ms of smart contract. Return default value for period. Details: {:?}", exec_error); - return Ok(Self::get_start_of_day_ms()); - } - }; - - let current_period_ms = u64::decode(&mut data) - .map_err(|_| "[OCW] error decoding get_current_period_ms result")?; - - info!( - "[OCW] sc_get_current_period_ms - data response from sc: {:?}", - current_period_ms - ); - - Ok(current_period_ms) - } - - fn finalize_metric_period( - contract_id: ::AccountId, - signer: &Signer, - in_day_start_ms: u64, - ) -> ResultStr<()> { - let contract_id_unl = - <::Lookup as StaticLookup>::unlookup(contract_id); - - let call_data = Self::encode_finalize_metric_period(in_day_start_ms); - - let results = signer.send_signed_transaction(|_account| { - pallet_contracts::Call::call { - dest: contract_id_unl.clone(), - value: 0u32.into(), - gas_limit: Weight::from_ref_time(100_000_000_000), - storage_deposit_limit: None, - data: call_data.clone(), - } - }); - - match &results { - None | Some((_, Err(()))) => { - return Err("Error while submitting finalize_metric_period TX to SC") - } - Some((_, Ok(()))) => {} - } - - Ok(()) - } - - fn send_metrics_to_sc( - contract_id: ::AccountId, - signer: &Signer, - day_start_ms: u64, - metrics: Vec, - ) -> ResultStr<()> { - info!("[OCW] Using Contract Address: {:?}", contract_id); - - for one_metric in metrics.iter() { - let app_id = Self::account_id_from_hex(&one_metric.app_id)?; - - if one_metric.storage_bytes == 0 && one_metric.wcu_used == 0 && one_metric.rcu_used == 0 - { - continue; - } - - let results = signer.send_signed_transaction(|account| { + // set new value + Ok(block_interval + block_number) + } + } else { + error!("[OCW] Something went wrong in `check_if_should_proceed`"); + Err("Unexpected error") + } + }) { + Ok(_val) => true, + Err(_e) => false, + } + } + + fn get_start_of_day_ms() -> u64 { + let now = sp_io::offchain::timestamp(); + let day_start_ms = (now.unix_millis() / MS_PER_DAY) * MS_PER_DAY; + day_start_ms + } + + fn get_signer() -> ResultStr> { + let signer = Signer::<_, _>::any_account(); + if !signer.can_sign() { + return Err("[OCW] No local accounts available. Consider adding one via `author_insertKey` RPC."); + } + Ok(signer) + } + + fn sc_get_current_period_ms( + contract_id: ::AccountId, + ) -> ResultStr { + let call_data = Self::encode_get_current_period_ms(); + let nobody = T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()); + let contract_exec_result = pallet_contracts::Pallet::::bare_call( + nobody.unwrap(), + contract_id, + 0u32.into(), + Weight::from_ref_time(100_000_000_000), + None, + call_data, + false, + ); + + let mut data = match &contract_exec_result.result { + Ok(v) => &v.data[..], + Err(exec_error) => { + // Return default value in case of error + warn!("[OCW] Error in call get_current_period_ms of smart contract. Return default value for period. Details: {:?}", exec_error); + return Ok(Self::get_start_of_day_ms()) + }, + }; + + let current_period_ms = u64::decode(&mut data) + .map_err(|_| "[OCW] error decoding get_current_period_ms result")?; + + info!("[OCW] sc_get_current_period_ms - data response from sc: {:?}", current_period_ms); + + Ok(current_period_ms) + } + + fn finalize_metric_period( + contract_id: ::AccountId, + signer: &Signer, + in_day_start_ms: u64, + ) -> ResultStr<()> { + let contract_id_unl = + <::Lookup as StaticLookup>::unlookup(contract_id); + + let call_data = Self::encode_finalize_metric_period(in_day_start_ms); + + let results = signer.send_signed_transaction(|_account| pallet_contracts::Call::call { + dest: contract_id_unl.clone(), + value: 0u32.into(), + gas_limit: Weight::from_ref_time(100_000_000_000), + storage_deposit_limit: None, + data: call_data.clone(), + }); + + match &results { + None | Some((_, Err(()))) => + return Err("Error while submitting finalize_metric_period TX to SC"), + Some((_, Ok(()))) => {}, + } + + Ok(()) + } + + fn send_metrics_to_sc( + contract_id: ::AccountId, + signer: &Signer, + day_start_ms: u64, + metrics: Vec, + ) -> ResultStr<()> { + info!("[OCW] Using Contract Address: {:?}", contract_id); + + for one_metric in metrics.iter() { + let app_id = Self::account_id_from_hex(&one_metric.app_id)?; + + if one_metric.storage_bytes == 0 && one_metric.wcu_used == 0 && one_metric.rcu_used == 0 + { + continue + } + + let results = signer.send_signed_transaction(|account| { info!( "[OCW] Sending transactions from {:?}: report_metrics({:?}, {:?}, {:?}, {:?}, {:?})", account.id, @@ -450,25 +448,25 @@ impl Module } }); - match &results { - None | Some((_, Err(()))) => return Err("Error while submitting TX to SC"), - Some((_, Ok(()))) => {} - } - } - - Ok(()) - } - - fn send_metrics_ddn_to_sc( - contract_id: ::AccountId, - signer: &Signer, - day_start_ms: u64, - metrics: Vec, - ) -> ResultStr<()> { - info!("[OCW] Using Contract Address: {:?}", contract_id); - - for one_metric in metrics.iter() { - let results = signer.send_signed_transaction(|account| { + match &results { + None | Some((_, Err(()))) => return Err("Error while submitting TX to SC"), + Some((_, Ok(()))) => {}, + } + } + + Ok(()) + } + + fn send_metrics_ddn_to_sc( + contract_id: ::AccountId, + signer: &Signer, + day_start_ms: u64, + metrics: Vec, + ) -> ResultStr<()> { + info!("[OCW] Using Contract Address: {:?}", contract_id); + + for one_metric in metrics.iter() { + let results = signer.send_signed_transaction(|account| { info!( "[OCW] Sending transactions from {:?}: report_metrics_ddn({:?}, {:?}, {:?}, {:?}, {:?})", account.id, @@ -500,362 +498,346 @@ impl Module } }); - match &results { - None | Some((_, Err(()))) => return Err("Error while submitting TX to SC"), - Some((_, Ok(()))) => {} - } - } - - Ok(()) - } - - fn report_ddn_status_to_sc( - contract_id: ::AccountId, - signer: &Signer, - p2p_id: &String, - is_online: bool, - ) -> ResultStr<()> { - info!("[OCW] Using Contract Address: {:?}", contract_id); - - let results = signer.send_signed_transaction(|account| { - info!( - "[OCW] Sending transactions from {:?}: report_ddn_status({:?}, {:?})", - account.id, p2p_id, is_online, - ); - - let call_data = Self::encode_report_ddn_status(&p2p_id, is_online); - - let contract_id_unl = - <::Lookup as StaticLookup>::unlookup( - contract_id.clone(), - ); + match &results { + None | Some((_, Err(()))) => return Err("Error while submitting TX to SC"), + Some((_, Ok(()))) => {}, + } + } - pallet_contracts::Call::call { - dest: contract_id_unl, - value: 0u32.into(), - gas_limit: Weight::from_ref_time(100_000_000_000), - storage_deposit_limit: None, - data: call_data, - } - }); - - match &results { - None | Some((_, Err(()))) => return Err("Error while submitting TX to SC"), - Some((_, Ok(()))) => {} - } - - Ok(()) - } - - fn fetch_all_metrics( - contract_id: ::AccountId, - day_start_ms: u64, - ) -> ResultStr<(Vec, Vec, Vec)> { - let a_moment_ago_ms = sp_io::offchain::timestamp() - .sub(Duration::from_millis(END_TIME_DELAY_MS)) - .unix_millis(); - - let mut aggregated_metrics = MetricsAggregator::default(); - let mut ddn_aggregated_metrics = DDNMetricsAggregator::default(); - - let nodes = Self::fetch_nodes(contract_id)?; - let mut offline_nodes: Vec = Vec::new(); - - for node in nodes { - let metrics_of_node = - match Self::fetch_node_metrics(&node.url, day_start_ms, a_moment_ago_ms) { - Ok(value) => value, - Err(_) => { - offline_nodes.push(node); - continue; - } - }; - - ddn_aggregated_metrics.add(node.p2p_id.clone(), &metrics_of_node); - - for metric in &metrics_of_node { - aggregated_metrics.add(metric); - } - } - - Ok(( - aggregated_metrics.finish(), - ddn_aggregated_metrics.finish(), - offline_nodes, - )) - } - - fn fetch_nodes( - contract_id: ::AccountId, - ) -> ResultStr> { - let nobody = T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()); - let call_data = Self::encode_get_all_ddc_nodes(); - let contract_exec_result = pallet_contracts::Pallet::::bare_call( - nobody.unwrap(), - contract_id, - 0u32.into(), - Weight::from_ref_time(100_000_000_000), - None, - call_data, - false - ); - - let mut data = match &contract_exec_result.result { - Ok(v) => &v.data[..], - Err(exec_error) => { - warn!( - "[OCW] Error in call get_all_ddc_nodes of smart contract. Error: {:?}", - exec_error - ); - return Ok(Vec::new()); - } - }; - - let ddc_nodes = Vec::::decode(&mut data) - .map_err(|_| "[OCW] error decoding get_all_ddc_nodes result")?; - - Ok(ddc_nodes) - } - - fn fetch_node_metrics( - node_url: &str, - day_start_ms: u64, - end_ms: u64, - ) -> ResultStr> { - let metrics_url = format!( - "{}{}{}{}{}{}", - node_url, - HTTP_METRICS, - METRICS_PARAM_FROM, - day_start_ms / 1000, - METRICS_PARAM_TO, - end_ms / 1000 - ); - - let metrics: Vec = Self::http_get_json(&metrics_url)?; - - Ok(metrics - .into_iter() - .map(|data| Metric { - app_id: data.appPubKey, - storage_bytes: data.storageBytes, - wcu_used: data.wcuUsed, - rcu_used: data.rcuUsed, - }) - .collect()) - } - - fn http_get_json(url: &str) -> ResultStr { - let body = Self::http_get_request(url).map_err(|err| { - error!("[OCW] Error while getting {}: {:?}", url, err); - "HTTP GET error" - })?; - - let parsed = serde_json::from_slice(&body).map_err(|err| { - warn!("[OCW] Error while parsing JSON from {}: {:?}", url, err); - "HTTP JSON parse error" - }); - - parsed - } - - fn http_get_request(http_url: &str) -> Result, http::Error> { - info!("[OCW] Sending request to: {:?}", http_url); - - // Initiate an external HTTP GET request. This is using high-level wrappers from `sp_runtime`. - let request = http::Request::get(http_url); - - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - - let pending = request - .deadline(deadline) - .send() - .map_err(|_| http::Error::IoError)?; - - let response = pending - .try_wait(deadline) - .map_err(|_| http::Error::DeadlineReached)??; - - if response.code != 200 { - warn!( - "[OCW] http_get_request unexpected status code: {}", - response.code - ); - return Err(http::Error::Unknown); - } - - // Next we fully read the response body and collect it to a vector of bytes. - Ok(response.body().collect::>()) - } - - /// Prepare get_current_period_ms call params. - /// Must match the contract function here: https://github.com/Cerebellum-Network/cere-enterprise-smart-contracts/blob/dev/cere02/lib.rs - fn encode_get_current_period_ms() -> Vec { - CURRENT_PERIOD_MS.to_vec() - } - - /// Prepare encode_get_current_period_ms call params. - fn encode_get_all_ddc_nodes() -> Vec { - GET_ALL_DDC_NODES_SELECTOR.to_vec() - } - - /// Prepare finalize_metric_period call params. - /// Must match the contract function here: https://github.com/Cerebellum-Network/cere-enterprise-smart-contracts/blob/dev/cere02/lib.rs - fn encode_finalize_metric_period(in_day_start_ms: u64) -> Vec { - let mut call_data = FINALIZE_METRIC_PERIOD.to_vec(); - in_day_start_ms.encode_to(&mut call_data); - - call_data - } - - /// Prepare report_metrics call params. - /// Must match the contract function here: https://github.com/Cerebellum-Network/cere-enterprise-smart-contracts/blob/dev/cere02/lib.rs - fn encode_report_metrics( - app_id: &AccountId32, - day_start_ms: u64, - storage_bytes: u64, - wcu_used: u64, - rcu_used: u64, - ) -> Vec { - let mut call_data = REPORT_METRICS_SELECTOR.to_vec(); - app_id.encode_to(&mut call_data); - day_start_ms.encode_to(&mut call_data); - storage_bytes.encode_to(&mut call_data); - wcu_used.encode_to(&mut call_data); - rcu_used.encode_to(&mut call_data); - - call_data - } - - fn encode_report_metrics_ddn( - p2p_id: String, - day_start_ms: u64, - storage_bytes: u64, - wcu_used: u64, - rcu_used: u64, - ) -> Vec { - let mut call_data = REPORT_METRICS_DDN_SELECTOR.to_vec(); - p2p_id.encode_to(&mut call_data); - day_start_ms.encode_to(&mut call_data); - storage_bytes.encode_to(&mut call_data); - wcu_used.encode_to(&mut call_data); - rcu_used.encode_to(&mut call_data); - - call_data - } - - fn encode_report_ddn_status(p2p_id: &String, is_online: bool) -> Vec { - let mut call_data = REPORT_DDN_STATUS_SELECTOR.to_vec(); - p2p_id.encode_to(&mut call_data); - is_online.encode_to(&mut call_data); - call_data - } - - fn account_id_from_hex(id_hex: &str) -> ResultStr { - let id_hex = id_hex.trim_start_matches("0x"); - if id_hex.len() != 64 { - return Err("Wrong length of hex-encoded account ID, expected 64"); - } - let mut bytes = [0u8; 32]; - hex::decode_to_slice(id_hex, &mut bytes).map_err(|_| "invalid hex address.")?; - Ok(AccountId32::from(bytes)) - } + Ok(()) + } + + fn report_ddn_status_to_sc( + contract_id: ::AccountId, + signer: &Signer, + p2p_id: &String, + is_online: bool, + ) -> ResultStr<()> { + info!("[OCW] Using Contract Address: {:?}", contract_id); + + let results = signer.send_signed_transaction(|account| { + info!( + "[OCW] Sending transactions from {:?}: report_ddn_status({:?}, {:?})", + account.id, p2p_id, is_online, + ); + + let call_data = Self::encode_report_ddn_status(&p2p_id, is_online); + + let contract_id_unl = <::Lookup as StaticLookup>::unlookup( + contract_id.clone(), + ); + + pallet_contracts::Call::call { + dest: contract_id_unl, + value: 0u32.into(), + gas_limit: Weight::from_ref_time(100_000_000_000), + storage_deposit_limit: None, + data: call_data, + } + }); + + match &results { + None | Some((_, Err(()))) => return Err("Error while submitting TX to SC"), + Some((_, Ok(()))) => {}, + } + + Ok(()) + } + + fn fetch_all_metrics( + contract_id: ::AccountId, + day_start_ms: u64, + ) -> ResultStr<(Vec, Vec, Vec)> { + let a_moment_ago_ms = sp_io::offchain::timestamp() + .sub(Duration::from_millis(END_TIME_DELAY_MS)) + .unix_millis(); + + let mut aggregated_metrics = MetricsAggregator::default(); + let mut ddn_aggregated_metrics = DDNMetricsAggregator::default(); + + let nodes = Self::fetch_nodes(contract_id)?; + let mut offline_nodes: Vec = Vec::new(); + + for node in nodes { + let metrics_of_node = + match Self::fetch_node_metrics(&node.url, day_start_ms, a_moment_ago_ms) { + Ok(value) => value, + Err(_) => { + offline_nodes.push(node); + continue + }, + }; + + ddn_aggregated_metrics.add(node.p2p_id.clone(), &metrics_of_node); + + for metric in &metrics_of_node { + aggregated_metrics.add(metric); + } + } + + Ok((aggregated_metrics.finish(), ddn_aggregated_metrics.finish(), offline_nodes)) + } + + fn fetch_nodes(contract_id: ::AccountId) -> ResultStr> { + let nobody = T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()); + let call_data = Self::encode_get_all_ddc_nodes(); + let contract_exec_result = pallet_contracts::Pallet::::bare_call( + nobody.unwrap(), + contract_id, + 0u32.into(), + Weight::from_ref_time(100_000_000_000), + None, + call_data, + false, + ); + + let mut data = match &contract_exec_result.result { + Ok(v) => &v.data[..], + Err(exec_error) => { + warn!( + "[OCW] Error in call get_all_ddc_nodes of smart contract. Error: {:?}", + exec_error + ); + return Ok(Vec::new()) + }, + }; + + let ddc_nodes = Vec::::decode(&mut data) + .map_err(|_| "[OCW] error decoding get_all_ddc_nodes result")?; + + Ok(ddc_nodes) + } + + fn fetch_node_metrics( + node_url: &str, + day_start_ms: u64, + end_ms: u64, + ) -> ResultStr> { + let metrics_url = format!( + "{}{}{}{}{}{}", + node_url, + HTTP_METRICS, + METRICS_PARAM_FROM, + day_start_ms / 1000, + METRICS_PARAM_TO, + end_ms / 1000 + ); + + let metrics: Vec = Self::http_get_json(&metrics_url)?; + + Ok(metrics + .into_iter() + .map(|data| Metric { + app_id: data.appPubKey, + storage_bytes: data.storageBytes, + wcu_used: data.wcuUsed, + rcu_used: data.rcuUsed, + }) + .collect()) + } + + fn http_get_json(url: &str) -> ResultStr { + let body = Self::http_get_request(url).map_err(|err| { + error!("[OCW] Error while getting {}: {:?}", url, err); + "HTTP GET error" + })?; + + let parsed = serde_json::from_slice(&body).map_err(|err| { + warn!("[OCW] Error while parsing JSON from {}: {:?}", url, err); + "HTTP JSON parse error" + }); + + parsed + } + + fn http_get_request(http_url: &str) -> Result, http::Error> { + info!("[OCW] Sending request to: {:?}", http_url); + + // Initiate an external HTTP GET request. This is using high-level wrappers from + // `sp_runtime`. + let request = http::Request::get(http_url); + + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); + + let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; + + let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; + + if response.code != 200 { + warn!("[OCW] http_get_request unexpected status code: {}", response.code); + return Err(http::Error::Unknown) + } + + // Next we fully read the response body and collect it to a vector of bytes. + Ok(response.body().collect::>()) + } + + /// Prepare get_current_period_ms call params. + /// Must match the contract function here: https://github.com/Cerebellum-Network/cere-enterprise-smart-contracts/blob/dev/cere02/lib.rs + fn encode_get_current_period_ms() -> Vec { + CURRENT_PERIOD_MS.to_vec() + } + + /// Prepare encode_get_current_period_ms call params. + fn encode_get_all_ddc_nodes() -> Vec { + GET_ALL_DDC_NODES_SELECTOR.to_vec() + } + + /// Prepare finalize_metric_period call params. + /// Must match the contract function here: https://github.com/Cerebellum-Network/cere-enterprise-smart-contracts/blob/dev/cere02/lib.rs + fn encode_finalize_metric_period(in_day_start_ms: u64) -> Vec { + let mut call_data = FINALIZE_METRIC_PERIOD.to_vec(); + in_day_start_ms.encode_to(&mut call_data); + + call_data + } + + /// Prepare report_metrics call params. + /// Must match the contract function here: https://github.com/Cerebellum-Network/cere-enterprise-smart-contracts/blob/dev/cere02/lib.rs + fn encode_report_metrics( + app_id: &AccountId32, + day_start_ms: u64, + storage_bytes: u64, + wcu_used: u64, + rcu_used: u64, + ) -> Vec { + let mut call_data = REPORT_METRICS_SELECTOR.to_vec(); + app_id.encode_to(&mut call_data); + day_start_ms.encode_to(&mut call_data); + storage_bytes.encode_to(&mut call_data); + wcu_used.encode_to(&mut call_data); + rcu_used.encode_to(&mut call_data); + + call_data + } + + fn encode_report_metrics_ddn( + p2p_id: String, + day_start_ms: u64, + storage_bytes: u64, + wcu_used: u64, + rcu_used: u64, + ) -> Vec { + let mut call_data = REPORT_METRICS_DDN_SELECTOR.to_vec(); + p2p_id.encode_to(&mut call_data); + day_start_ms.encode_to(&mut call_data); + storage_bytes.encode_to(&mut call_data); + wcu_used.encode_to(&mut call_data); + rcu_used.encode_to(&mut call_data); + + call_data + } + + fn encode_report_ddn_status(p2p_id: &String, is_online: bool) -> Vec { + let mut call_data = REPORT_DDN_STATUS_SELECTOR.to_vec(); + p2p_id.encode_to(&mut call_data); + is_online.encode_to(&mut call_data); + call_data + } + + fn account_id_from_hex(id_hex: &str) -> ResultStr { + let id_hex = id_hex.trim_start_matches("0x"); + if id_hex.len() != 64 { + return Err("Wrong length of hex-encoded account ID, expected 64") + } + let mut bytes = [0u8; 32]; + hex::decode_to_slice(id_hex, &mut bytes).map_err(|_| "invalid hex address.")?; + Ok(AccountId32::from(bytes)) + } } #[derive(Default)] struct MetricsAggregator(Vec); impl MetricsAggregator { - fn add(&mut self, metric: &Metric) { - let existing_pubkey_index = self - .0 - .iter() - .position(|one_result_obj| metric.app_id == one_result_obj.app_id); - - if existing_pubkey_index.is_none() { - // New app. - let new_metric_obj = Metric { - app_id: metric.app_id.clone(), - storage_bytes: metric.storage_bytes, - wcu_used: metric.wcu_used, - rcu_used: metric.rcu_used, - }; - self.0.push(new_metric_obj); - } else { - // Add to metrics of an existing app. - self.0[existing_pubkey_index.unwrap()].storage_bytes += metric.storage_bytes; - self.0[existing_pubkey_index.unwrap()].wcu_used += metric.wcu_used; - self.0[existing_pubkey_index.unwrap()].rcu_used += metric.rcu_used; - } - } - - fn finish(self) -> Vec { - self.0 - } + fn add(&mut self, metric: &Metric) { + let existing_pubkey_index = + self.0.iter().position(|one_result_obj| metric.app_id == one_result_obj.app_id); + + if existing_pubkey_index.is_none() { + // New app. + let new_metric_obj = Metric { + app_id: metric.app_id.clone(), + storage_bytes: metric.storage_bytes, + wcu_used: metric.wcu_used, + rcu_used: metric.rcu_used, + }; + self.0.push(new_metric_obj); + } else { + // Add to metrics of an existing app. + self.0[existing_pubkey_index.unwrap()].storage_bytes += metric.storage_bytes; + self.0[existing_pubkey_index.unwrap()].wcu_used += metric.wcu_used; + self.0[existing_pubkey_index.unwrap()].rcu_used += metric.rcu_used; + } + } + + fn finish(self) -> Vec { + self.0 + } } #[derive(Default)] struct DDNMetricsAggregator(Vec); impl DDNMetricsAggregator { - fn add(&mut self, p2p_id: String, metrics: &Vec) { - let existing_pubkey_index = self - .0 - .iter() - .position(|one_result_obj| p2p_id == one_result_obj.p2p_id); - - // Only if key does not exists - add new item, otherwise - skip - if existing_pubkey_index.is_none() { - let mut storage_bytes_sum = 0; - let mut wcu_used_sum = 0; - let mut rcu_used_sum = 0; - - for metric_item in metrics.iter() { - storage_bytes_sum += metric_item.storage_bytes; - wcu_used_sum += metric_item.wcu_used; - rcu_used_sum += metric_item.rcu_used; - } - - let new_metric_obj = MetricDDN { - p2p_id, - storage_bytes: storage_bytes_sum, - wcu_used: wcu_used_sum, - rcu_used: rcu_used_sum, - }; - self.0.push(new_metric_obj); - } - } - - fn finish(self) -> Vec { - self.0 - } + fn add(&mut self, p2p_id: String, metrics: &Vec) { + let existing_pubkey_index = + self.0.iter().position(|one_result_obj| p2p_id == one_result_obj.p2p_id); + + // Only if key does not exists - add new item, otherwise - skip + if existing_pubkey_index.is_none() { + let mut storage_bytes_sum = 0; + let mut wcu_used_sum = 0; + let mut rcu_used_sum = 0; + + for metric_item in metrics.iter() { + storage_bytes_sum += metric_item.storage_bytes; + wcu_used_sum += metric_item.wcu_used; + rcu_used_sum += metric_item.rcu_used; + } + + let new_metric_obj = MetricDDN { + p2p_id, + storage_bytes: storage_bytes_sum, + wcu_used: wcu_used_sum, + rcu_used: rcu_used_sum, + }; + self.0.push(new_metric_obj); + } + } + + fn finish(self) -> Vec { + self.0 + } } // TODO: remove, or write meaningful events. decl_event!( - /// Events generated by the module. - pub enum Event - where - AccountId = ::AccountId, - { - NewDdcMetric(AccountId, Vec), - } + /// Events generated by the module. + pub enum Event + where + AccountId = ::AccountId, + { + NewDdcMetric(AccountId, Vec), + } ); -pub trait Config: frame_system::Config + pallet_contracts::Config + CreateSignedTransaction> - where ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode { - /// The identifier type for an offchain worker. - type AuthorityId: AppCrypto< - ::Public, - ::Signature, - >; - - // TODO: remove, or use Event and Call. - /// The overarching event type. - type Event: From> + Into<::Event>; - /// The overarching dispatch call type. - type Call: From>; - - type BlockInterval: Get; +pub trait Config: + frame_system::Config + + pallet_contracts::Config + + CreateSignedTransaction> +where + ::AccountId: AsRef<[u8]> + UncheckedFrom, + as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, +{ + /// The identifier type for an offchain worker. + type AuthorityId: AppCrypto<::Public, ::Signature>; + + // TODO: remove, or use Event and Call. + /// The overarching event type. + type RuntimeEvent: From> + Into<::RuntimeEvent>; + /// The overarching dispatch call type. + type RuntimeCall: From>; + + type BlockInterval: Get; } diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs index 461016c3f..6c0dbbe09 100644 --- a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs +++ b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs @@ -1,21 +1,20 @@ use frame_support::traits::{Currency, OffchainWorker}; use frame_system::Config as FSC; use pallet_contracts::{self as contracts, Config as CC}; -use sp_core::{ - offchain::{testing, OffchainWorkerExt, OffchainDbExt, Timestamp as OCWTimestamp, TransactionPoolExt} +use sp_core::offchain::{ + testing, OffchainDbExt, OffchainWorkerExt, Timestamp as OCWTimestamp, TransactionPoolExt, }; use sp_runtime::{traits::Hash, AccountId32, RuntimeAppPublic}; use test_runtime::{ - AccountId, Balance, Balances, Contracts, DdcMetricsOffchainWorker, Origin, System, Test, - Timestamp, + AccountId, Balance, Balances, Contracts, DdcMetricsOffchainWorker, RuntimeOrigin, System, Test, + Timestamp, }; -use sp_keystore::{KeystoreExt, testing::KeyStore}; -use sp_keystore::SyncCryptoStore; +use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; use std::sync::Arc; use crate::{ - CURRENT_PERIOD_MS, FINALIZE_METRIC_PERIOD, REPORT_DDN_STATUS_SELECTOR, REPORT_METRICS_SELECTOR, + CURRENT_PERIOD_MS, FINALIZE_METRIC_PERIOD, REPORT_DDN_STATUS_SELECTOR, REPORT_METRICS_SELECTOR, }; use codec::Encode; use frame_support::weights::Weight; @@ -28,145 +27,123 @@ type T = Test; #[test] fn test_contract_api() { - // Parse the contract spec. - let contract_meta = include_str!("./test_data/metadata.json"); - let contract_meta: serde_json::Value = serde_json::from_str(contract_meta).unwrap(); - let messages = contract_meta - .pointer("/spec/messages") - .unwrap() - .as_array() - .unwrap(); - - // Find the report_metrics function. - let report_metrics = messages - .iter() - .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "report_metrics") - .unwrap(); - - // Check the selector. - let selector = from_hex(report_metrics.get("selector").unwrap().as_str().unwrap()).unwrap(); - assert_eq!(REPORT_METRICS_SELECTOR.to_vec(), selector); - - // Find the get_current_period_ms function. - let get_current_period_ms = messages - .iter() - .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "get_current_period_ms") - .unwrap(); - - // Check the selector for get_current_period_ms - let selector_get_current_period_ms = from_hex( - get_current_period_ms - .get("selector") - .unwrap() - .as_str() - .unwrap(), - ) - .unwrap(); - assert_eq!(CURRENT_PERIOD_MS.to_vec(), selector_get_current_period_ms); - - // Find the finalize_metric_period function. - let finalize_metric_period = messages - .iter() - .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "finalize_metric_period") - .unwrap(); - - // Check the selector for finalize_metric_period - let selector_finalize_metric_period = from_hex( - finalize_metric_period - .get("selector") - .unwrap() - .as_str() - .unwrap(), - ) - .unwrap(); - assert_eq!( - FINALIZE_METRIC_PERIOD.to_vec(), - selector_finalize_metric_period - ); - - // Find the report_ddn_status function. - let report_ddn_status = messages - .iter() - .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "report_ddn_status") - .unwrap(); - - // Check the selector for report_ddn_status - let selector_report_ddn_status = - from_hex(report_ddn_status.get("selector").unwrap().as_str().unwrap()).unwrap(); - assert_eq!( - REPORT_DDN_STATUS_SELECTOR.to_vec(), - selector_report_ddn_status - ); + // Parse the contract spec. + let contract_meta = include_str!("./test_data/metadata.json"); + let contract_meta: serde_json::Value = serde_json::from_str(contract_meta).unwrap(); + let messages = contract_meta.pointer("/spec/messages").unwrap().as_array().unwrap(); + + // Find the report_metrics function. + let report_metrics = messages + .iter() + .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "report_metrics") + .unwrap(); + + // Check the selector. + let selector = from_hex(report_metrics.get("selector").unwrap().as_str().unwrap()).unwrap(); + assert_eq!(REPORT_METRICS_SELECTOR.to_vec(), selector); + + // Find the get_current_period_ms function. + let get_current_period_ms = messages + .iter() + .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "get_current_period_ms") + .unwrap(); + + // Check the selector for get_current_period_ms + let selector_get_current_period_ms = + from_hex(get_current_period_ms.get("selector").unwrap().as_str().unwrap()).unwrap(); + assert_eq!(CURRENT_PERIOD_MS.to_vec(), selector_get_current_period_ms); + + // Find the finalize_metric_period function. + let finalize_metric_period = messages + .iter() + .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "finalize_metric_period") + .unwrap(); + + // Check the selector for finalize_metric_period + let selector_finalize_metric_period = + from_hex(finalize_metric_period.get("selector").unwrap().as_str().unwrap()).unwrap(); + assert_eq!(FINALIZE_METRIC_PERIOD.to_vec(), selector_finalize_metric_period); + + // Find the report_ddn_status function. + let report_ddn_status = messages + .iter() + .find(|msg| msg.pointer("/name/0").unwrap().as_str().unwrap() == "report_ddn_status") + .unwrap(); + + // Check the selector for report_ddn_status + let selector_report_ddn_status = + from_hex(report_ddn_status.get("selector").unwrap().as_str().unwrap()).unwrap(); + assert_eq!(REPORT_DDN_STATUS_SELECTOR.to_vec(), selector_report_ddn_status); } #[test] fn test_encode_report_metrics() { - let call_data = DdcMetricsOffchainWorker::encode_report_metrics( - &AccountId32::from([2; 32]), - 3 + (4 << 8), - 5 + (6 << 16), - 7 + (8 << 24), - 9 + (16 << 24), - ); - assert_eq!( - call_data, - vec![ - 53, 50, 11, 190, // Selector - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, // 32 bytes, app_id - 3, 4, 0, 0, 0, 0, 0, 0, // 8 bytes, day_start_ms - 5, 0, 6, 0, 0, 0, 0, 0, // 8 bytes, storage_bytes - 7, 0, 0, 8, 0, 0, 0, 0, // 8 bytes, wcu_used - 9, 0, 0, 16, 0, 0, 0, 0 // 8 bytes, rcu_used - ] - ); + let call_data = DdcMetricsOffchainWorker::encode_report_metrics( + &AccountId32::from([2; 32]), + 3 + (4 << 8), + 5 + (6 << 16), + 7 + (8 << 24), + 9 + (16 << 24), + ); + assert_eq!( + call_data, + vec![ + 53, 50, 11, 190, // Selector + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, // 32 bytes, app_id + 3, 4, 0, 0, 0, 0, 0, 0, // 8 bytes, day_start_ms + 5, 0, 6, 0, 0, 0, 0, 0, // 8 bytes, storage_bytes + 7, 0, 0, 8, 0, 0, 0, 0, // 8 bytes, wcu_used + 9, 0, 0, 16, 0, 0, 0, 0 // 8 bytes, rcu_used + ] + ); } #[test] fn test_encode_get_current_period_ms() { - let call_data = DdcMetricsOffchainWorker::encode_get_current_period_ms(); - assert_eq!( - call_data, - vec![ + let call_data = DdcMetricsOffchainWorker::encode_get_current_period_ms(); + assert_eq!( + call_data, + vec![ 172, 228, 236, 179, // Selector ] - ); + ); } #[test] fn test_encode_finalize_metric_period() { - let call_data = DdcMetricsOffchainWorker::encode_finalize_metric_period(INIT_TIME_MS); - assert_eq!( - call_data, - vec![ - 178, 105, 213, 87, // Selector - 80, 152, 94, 120, 118, 1, 0, 0, // 8 bytes, in_day_start_ms - ] - ); + let call_data = DdcMetricsOffchainWorker::encode_finalize_metric_period(INIT_TIME_MS); + assert_eq!( + call_data, + vec![ + 178, 105, 213, 87, // Selector + 80, 152, 94, 120, 118, 1, 0, 0, // 8 bytes, in_day_start_ms + ] + ); } #[test] fn test_encode_report_ddn_status() { - let call_data = DdcMetricsOffchainWorker::encode_report_ddn_status( - &String::from_utf8(vec![0, 1, 2, 3]).unwrap(), - true, - ); - assert_eq!( - call_data, - [ - REPORT_DDN_STATUS_SELECTOR.to_vec(), // Selector - vec![ - 16, // size of p2p_id - 0, 1, 2, 3, // p2p_id - 1 // is_online - ], - ] - .concat() - ); + let call_data = DdcMetricsOffchainWorker::encode_report_ddn_status( + &String::from_utf8(vec![0, 1, 2, 3]).unwrap(), + true, + ); + assert_eq!( + call_data, + [ + REPORT_DDN_STATUS_SELECTOR.to_vec(), // Selector + vec![ + 16, // size of p2p_id + 0, 1, 2, 3, // p2p_id + 1 // is_online + ], + ] + .concat() + ); } fn build_ext() -> sp_io::TestExternalities { - build_ext_for_contracts() + build_ext_for_contracts() } // Some day, and some time during that day. @@ -175,241 +152,232 @@ const INIT_TIME_MS: u64 = INIT_DAY_MS + 1234 * 1000; // Taken from pallet_contracts::tests::ExtBuilder fn build_ext_for_contracts() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - pallet_balances::GenesisConfig:: { balances: vec![] } - .assimilate_storage(&mut t) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| { - System::set_block_number(1); - Timestamp::set_timestamp(INIT_TIME_MS); - }); - ext + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![] } + .assimilate_storage(&mut t) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + Timestamp::set_timestamp(INIT_TIME_MS); + }); + ext } #[test] fn should_submit_signed_transaction_on_chain() { - let mut t = build_ext(); - - let (pool, pool_state) = testing::TestTransactionPoolExt::new(); - t.register_extension(TransactionPoolExt::new(pool)); - - const PHRASE: &str = - "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; - let keystore = KeyStore::new(); - keystore - .sr25519_generate_new( - crate::crypto::Public::ID, - Some(&format!("{}/hunter1", PHRASE)), - ) - .unwrap(); - t.register_extension(KeystoreExt(Arc::new(keystore))); - - let (offchain, offchain_state) = testing::TestOffchainExt::new(); - t.register_extension(OffchainDbExt::new(offchain.clone())); - t.register_extension(OffchainWorkerExt::new(offchain)); - - { - let mut state = offchain_state.write(); - - state.timestamp = OCWTimestamp::from_unix_millis(INIT_TIME_MS); - - let mut expect_request = |url: &str, response: &[u8]| { - state.expect_request(testing::PendingRequest { - method: "GET".into(), - uri: url.to_string(), - response: Some(response.to_vec()), - sent: true, - ..Default::default() - }); - }; - - // List partitions from a boot node. - expect_request("https://node-0.ddc.stage.cere.network/api/rest/metrics?isMaster=true&active=true&from=1608336000&to=1608337114", + let mut t = build_ext(); + + let (pool, pool_state) = testing::TestTransactionPoolExt::new(); + t.register_extension(TransactionPoolExt::new(pool)); + + const PHRASE: &str = + "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; + let keystore = KeyStore::new(); + keystore + .sr25519_generate_new(crate::crypto::Public::ID, Some(&format!("{}/hunter1", PHRASE))) + .unwrap(); + t.register_extension(KeystoreExt(Arc::new(keystore))); + + let (offchain, offchain_state) = testing::TestOffchainExt::new(); + t.register_extension(OffchainDbExt::new(offchain.clone())); + t.register_extension(OffchainWorkerExt::new(offchain)); + + { + let mut state = offchain_state.write(); + + state.timestamp = OCWTimestamp::from_unix_millis(INIT_TIME_MS); + + let mut expect_request = |url: &str, response: &[u8]| { + state.expect_request(testing::PendingRequest { + method: "GET".into(), + uri: url.to_string(), + response: Some(response.to_vec()), + sent: true, + ..Default::default() + }); + }; + + // List partitions from a boot node. + expect_request("https://node-0.ddc.stage.cere.network/api/rest/metrics?isMaster=true&active=true&from=1608336000&to=1608337114", include_bytes!("test_data/ddc_metrics_node-0.json")); - // List partitions from a boot node. - expect_request("https://node-3.ddc.stage.cere.network/api/rest/metrics?isMaster=true&active=true&from=1608336000&to=1608337114", + // List partitions from a boot node. + expect_request("https://node-3.ddc.stage.cere.network/api/rest/metrics?isMaster=true&active=true&from=1608336000&to=1608337114", include_bytes!("test_data/ddc_metrics_node-3.json")); - } - - t.execute_with(|| { - let contract_id = deploy_contract(); - - let kind = sp_core::offchain::StorageKind::PERSISTENT; - sp_io::offchain::local_storage_set( - kind, - b"ddc-metrics-offchain-worker::sc_address", - contract_id.as_ref(), - ); - - // Trigger the worker. - DdcMetricsOffchainWorker::offchain_worker(0); - - let events = System::events(); - eprintln!("Events: {:?}\n", events); - - // Get the transaction from the worker. - let transactions = pool_state.read().transactions.clone(); - eprintln!("Transactions: {:?}\n", transactions); - assert_eq!(transactions.len(), 4); // (2 x send_metrics_to_sc) + (2 x send_metrics_ddn_to_sc) - - // Check metrics of an app based on ddc_metrics_node-0.json and ddc_metrics_node-3.json. - let app_id = AccountId32::from(hex!( - "00a2e826451b78afb99241b1331e7594526329225ff8937dbc62f43ec20d1830" - )); - let expected_call = - DdcMetricsOffchainWorker::encode_report_metrics(&app_id, INIT_DAY_MS, 2 + 20, 0, 0); - assert!( - transactions[0].ends_with(&expected_call), - "Expected a specific call to the report_metrics function" - ); - - // Check metrics of the second app. - let app_id = AccountId32::from(hex!( - "100ad4097b6e60700a5d5c5294cb6d663090ef5f547e84cc20ec6bcc7a552f13" - )); - let expected_call = - DdcMetricsOffchainWorker::encode_report_metrics(&app_id, INIT_DAY_MS, 200, 0, 0); - assert!( - transactions[1].ends_with(&expected_call), - "Expected a specific call to the report_metrics function" - ); - - let expected_call = DdcMetricsOffchainWorker::encode_report_metrics_ddn( - "12D3KooWB4SMhKK12ASU4qH1ZYh3pN9vsW9QbFTwkjZxUhTqmYaS".to_string(), - INIT_DAY_MS, - 2 + 200, - 0, - 0, - ); - assert!( - transactions[2].ends_with(&expected_call), - "Expected a specific call to the report_metrics_ddn function" - ); - - let expected_call = DdcMetricsOffchainWorker::encode_report_metrics_ddn( - "12D3KooWJLuJEmtYf3bakUwe2q1uMcnbCBKRg7GkpG6Ws74Aq6NC".to_string(), - INIT_DAY_MS, - 20, - 0, - 0, - ); - assert!( - transactions[3].ends_with(&expected_call), - "Expected a specific call to the report_metrics_ddn function" - ); - }); + } + + t.execute_with(|| { + let contract_id = deploy_contract(); + + let kind = sp_core::offchain::StorageKind::PERSISTENT; + sp_io::offchain::local_storage_set( + kind, + b"ddc-metrics-offchain-worker::sc_address", + contract_id.as_ref(), + ); + + // Trigger the worker. + DdcMetricsOffchainWorker::offchain_worker(0); + + let events = System::events(); + eprintln!("Events: {:?}\n", events); + + // Get the transaction from the worker. + let transactions = pool_state.read().transactions.clone(); + eprintln!("Transactions: {:?}\n", transactions); + assert_eq!(transactions.len(), 4); // (2 x send_metrics_to_sc) + (2 x send_metrics_ddn_to_sc) + + // Check metrics of an app based on ddc_metrics_node-0.json and ddc_metrics_node-3.json. + let app_id = AccountId32::from(hex!( + "00a2e826451b78afb99241b1331e7594526329225ff8937dbc62f43ec20d1830" + )); + let expected_call = + DdcMetricsOffchainWorker::encode_report_metrics(&app_id, INIT_DAY_MS, 2 + 20, 0, 0); + assert!( + transactions[0].ends_with(&expected_call), + "Expected a specific call to the report_metrics function" + ); + + // Check metrics of the second app. + let app_id = AccountId32::from(hex!( + "100ad4097b6e60700a5d5c5294cb6d663090ef5f547e84cc20ec6bcc7a552f13" + )); + let expected_call = + DdcMetricsOffchainWorker::encode_report_metrics(&app_id, INIT_DAY_MS, 200, 0, 0); + assert!( + transactions[1].ends_with(&expected_call), + "Expected a specific call to the report_metrics function" + ); + + let expected_call = DdcMetricsOffchainWorker::encode_report_metrics_ddn( + "12D3KooWB4SMhKK12ASU4qH1ZYh3pN9vsW9QbFTwkjZxUhTqmYaS".to_string(), + INIT_DAY_MS, + 2 + 200, + 0, + 0, + ); + assert!( + transactions[2].ends_with(&expected_call), + "Expected a specific call to the report_metrics_ddn function" + ); + + let expected_call = DdcMetricsOffchainWorker::encode_report_metrics_ddn( + "12D3KooWJLuJEmtYf3bakUwe2q1uMcnbCBKRg7GkpG6Ws74Aq6NC".to_string(), + INIT_DAY_MS, + 20, + 0, + 0, + ); + assert!( + transactions[3].ends_with(&expected_call), + "Expected a specific call to the report_metrics_ddn function" + ); + }); } #[test] fn should_run_contract() { - let mut t = build_ext(); - - t.execute_with(|| { - let alice = AccountId::from([1; 32]); - let contract_id = deploy_contract(); - let call_data = DdcMetricsOffchainWorker::encode_get_current_period_ms(); - - pallet_contracts::Module::::call( - Origin::signed(alice.clone()), - contract_id.clone(), - 0, - Weight::from_ref_time(100_000_000_000), - None, - call_data.clone(), - ) - .unwrap(); - - let contract_exec_result = pallet_contracts::Pallet::::bare_call( - alice.clone(), - contract_id, - 0, - Weight::from_ref_time(100_000_000_000), - None, - call_data, - false, - ); - match &contract_exec_result.result { - Ok(res) => { - //println!("XXX Contract returned {:?}", res.data); - assert_eq!(res.data.len(), 8); // size of u64 - } - Err(_) => panic!("error in contract call"), - }; - }); + let mut t = build_ext(); + + t.execute_with(|| { + let alice = AccountId::from([1; 32]); + let contract_id = deploy_contract(); + let call_data = DdcMetricsOffchainWorker::encode_get_current_period_ms(); + + pallet_contracts::Module::::call( + RuntimeOrigin::signed(alice.clone()), + contract_id.clone(), + 0, + Weight::from_ref_time(100_000_000_000), + None, + call_data.clone(), + ) + .unwrap(); + + let contract_exec_result = pallet_contracts::Pallet::::bare_call( + alice.clone(), + contract_id, + 0, + Weight::from_ref_time(100_000_000_000), + None, + call_data, + false, + ); + match &contract_exec_result.result { + Ok(res) => { + //println!("XXX Contract returned {:?}", res.data); + assert_eq!(res.data.len(), 8); // size of u64 + }, + Err(_) => panic!("error in contract call"), + }; + }); } pub const CTOR_SELECTOR: [u8; 4] = hex!("9bae9d5e"); fn encode_constructor() -> Vec { - let mut call_data = CTOR_SELECTOR.to_vec(); - let x = 0 as u128; - for _ in 0..9 { - x.encode_to(&mut call_data); - } - call_data + let mut call_data = CTOR_SELECTOR.to_vec(); + let x = 0 as u128; + for _ in 0..9 { + x.encode_to(&mut call_data); + } + call_data } fn deploy_contract() -> AccountId { - // Admin account who deploys the contract. - let alice = AccountId::from([1; 32]); - let _ = Balances::deposit_creating(&alice, 1_000_000_000_000); - - // Load the contract code. - let wasm = &include_bytes!("./test_data/ddc.wasm")[..]; - let wasm_hash = ::Hashing::hash(wasm); - let contract_args = encode_constructor(); - - // Deploy the contract. - //let endowment = contracts::Config::::subsistence_threshold_uncached(); - const GAS_LIMIT: frame_support::weights::Weight = Weight::from_ref_time(100_000_000_000); - const ENDOWMENT: Balance = 100_000_000_000; - Contracts::instantiate_with_code( - Origin::signed(alice.clone()), - ENDOWMENT, - GAS_LIMIT, - None, - wasm.to_vec(), - contract_args.clone(), - vec![] - ) - .unwrap(); - - // Configure worker with the contract address. - let contract_id = Contracts::contract_address( - &alice, - &wasm_hash, - &vec![], - ); - - pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("11a9e1b9"); - - let call_data_items = vec![ + // Admin account who deploys the contract. + let alice = AccountId::from([1; 32]); + let _ = Balances::deposit_creating(&alice, 1_000_000_000_000); + + // Load the contract code. + let wasm = &include_bytes!("./test_data/ddc.wasm")[..]; + let wasm_hash = ::Hashing::hash(wasm); + let contract_args = encode_constructor(); + + // Deploy the contract. + //let endowment = contracts::Config::::subsistence_threshold_uncached(); + const GAS_LIMIT: frame_support::weights::Weight = Weight::from_ref_time(100_000_000_000); + const ENDOWMENT: Balance = 100_000_000_000; + Contracts::instantiate_with_code( + RuntimeOrigin::signed(alice.clone()), + ENDOWMENT, + GAS_LIMIT, + None, + wasm.to_vec(), + contract_args.clone(), + vec![], + ) + .unwrap(); + + // Configure worker with the contract address. + let contract_id = Contracts::contract_address(&alice, &wasm_hash, &vec![]); + + pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("11a9e1b9"); + + let call_data_items = vec![ ["12D3KooWB4SMhKK12ASU4qH1ZYh3pN9vsW9QbFTwkjZxUhTqmYaS", "/dns4/node-0.ddc.dev.cere.network/tcp/5000/p2p/12D3KooWB4SMhKK12ASU4qH1ZYh3pN9vsW9QbFTwkjZxUhTqmYaS", "https://node-0.ddc.stage.cere.network"], ["12D3KooWJLuJEmtYf3bakUwe2q1uMcnbCBKRg7GkpG6Ws74Aq6NC", "/dns4/node-3.ddc.dev.cere.network/tcp/5000/p2p/12D3KooWJLuJEmtYf3bakUwe2q1uMcnbCBKRg7GkpG6Ws74Aq6NC", "https://node-3.ddc.stage.cere.network"], ]; - let permissions: u64 = 1; - - for call_data_item in call_data_items { - let mut call_data = ADD_DDC_NODE_SELECTOR.to_vec(); - call_data_item[0].encode_to(&mut call_data); - call_data_item[1].encode_to(&mut call_data); - call_data_item[2].encode_to(&mut call_data); - permissions.encode_to(&mut call_data); - - let results = Contracts::call( - Origin::signed(alice.clone()), - contract_id.clone(), - 0, - Weight::from_ref_time(1_000_000_000_000), - None, - call_data, - ); - results.unwrap(); - } - - contract_id + let permissions: u64 = 1; + + for call_data_item in call_data_items { + let mut call_data = ADD_DDC_NODE_SELECTOR.to_vec(); + call_data_item[0].encode_to(&mut call_data); + call_data_item[1].encode_to(&mut call_data); + call_data_item[2].encode_to(&mut call_data); + permissions.encode_to(&mut call_data); + + let results = Contracts::call( + RuntimeOrigin::signed(alice.clone()), + contract_id.clone(), + 0, + Weight::from_ref_time(1_000_000_000_000), + None, + call_data, + ); + results.unwrap(); + } + + contract_id } diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs b/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs index 5f851003f..10cee8408 100644 --- a/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs +++ b/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs @@ -2,19 +2,22 @@ // // Inspired from pos-network-node/frame/contracts/src/tests.rs -use crate::{*, self as pallet_ddc_metrics_offchain_worker}; +use crate::{self as pallet_ddc_metrics_offchain_worker, *}; use codec::{Decode, Encode}; -use frame_support::{ parameter_types, traits::Get, weights::Weight }; -use frame_support::traits::{ConstU32, Currency, Everything, Nothing}; +use frame_support::{ + parameter_types, + traits::{ConstU32, Currency, Everything, Get, Nothing}, + weights::Weight, +}; use sp_core::H256; use sp_runtime::{ - generic, - testing::TestXt, - traits::{ - BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, - }, - MultiSignature, Perbill, + generic, + testing::TestXt, + traits::{ + BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, + }, + MultiSignature, Perbill, }; use std::cell::RefCell; @@ -42,179 +45,178 @@ frame_support::construct_runtime!( { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - Contracts: contracts::{Pallet, Call, Storage, Event}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, - Randomness: pallet_randomness_collective_flip::{Pallet, Storage}, - DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Event}, - } + Contracts: contracts::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Randomness: pallet_randomness_collective_flip::{Pallet, Storage}, + DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Event}, + } ); parameter_types! { - pub const BlockHashCount: BlockNumber = 250; - pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); + pub const BlockHashCount: BlockNumber = 250; + pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::one(); } impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type Origin = Origin; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type Call = Call; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - // u64; // sp_core::sr25519::Public; - type Lookup = IdentityLookup; - type Header = generic::Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type RuntimeOrigin = RuntimeOrigin; + type Index = u64; + type BlockNumber = BlockNumber; + type Hash = H256; + type RuntimeCall = RuntimeCall; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + // u64; // sp_core::sr25519::Public; + type Lookup = IdentityLookup; + type Header = generic::Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; } impl pallet_balances::Config for Test { - type Balance = Balance; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = (); + type Balance = Balance; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = (); } thread_local! { - static EXISTENTIAL_DEPOSIT: RefCell = RefCell::new(1); + static EXISTENTIAL_DEPOSIT: RefCell = RefCell::new(1); } pub struct ExistentialDeposit; impl Get for ExistentialDeposit { - fn get() -> Balance { - EXISTENTIAL_DEPOSIT.with(|v| *v.borrow()) - } + fn get() -> Balance { + EXISTENTIAL_DEPOSIT.with(|v| *v.borrow()) + } } parameter_types! { - pub const MinimumPeriod: u64 = 1; + pub const MinimumPeriod: u64 = 1; } impl pallet_timestamp::Config for Test { - type Moment = Moment; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); } parameter_types! { - pub const SignedClaimHandicap: BlockNumber = 2; - pub const TombstoneDeposit: Balance = 16; - pub const StorageSizeOffset: u32 = 8; - pub const RentByteFee: Balance = 4; - pub const RentDepositOffset: Balance = 10_000; - pub const SurchargeReward: Balance = 150; - pub const MaxDepth: u32 = 100; - pub const MaxValueSize: u32 = 16_384; - pub Schedule: pallet_contracts::Schedule = Default::default(); + pub const SignedClaimHandicap: BlockNumber = 2; + pub const TombstoneDeposit: Balance = 16; + pub const StorageSizeOffset: u32 = 8; + pub const RentByteFee: Balance = 4; + pub const RentDepositOffset: Balance = 10_000; + pub const SurchargeReward: Balance = 150; + pub const MaxDepth: u32 = 100; + pub const MaxValueSize: u32 = 16_384; + pub Schedule: pallet_contracts::Schedule = Default::default(); } // Contracts for Test Runtime. -use contracts::{Config as contractsConfig}; +use contracts::Config as contractsConfig; -type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; impl contracts::Config for Test { - type Time = Timestamp; - type Randomness = Randomness; - type Currency = Balances; - type Event = Event; - type CallStack = [pallet_contracts::Frame; 31]; - type WeightPrice = Self; //pallet_transaction_payment::Module; - type WeightInfo = (); - type ChainExtension = (); - type DeletionQueueDepth = (); - type DeletionWeightLimit = (); - type Schedule = Schedule; - type Call = Call; - type CallFilter = Nothing; - type DepositPerByte = DepositPerByte; - type DepositPerItem = DepositPerItem; - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; - type ContractAccessWeight = (); - type MaxCodeLen = ConstU32<{ 128 * 1024 }>; - type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>; - type MaxStorageKeyLen = ConstU32<128>; + type Time = Timestamp; + type Randomness = Randomness; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type CallStack = [pallet_contracts::Frame; 31]; + type WeightPrice = Self; //pallet_transaction_payment::Module; + type WeightInfo = (); + type ChainExtension = (); + type DeletionQueueDepth = (); + type DeletionWeightLimit = (); + type Schedule = Schedule; + type RuntimeCall = RuntimeCall; + type CallFilter = Nothing; + type DepositPerByte = DepositPerByte; + type DepositPerItem = DepositPerItem; + type AddressGenerator = pallet_contracts::DefaultAddressGenerator; + type ContractAccessWeight = (); + type MaxCodeLen = ConstU32<{ 128 * 1024 }>; + type MaxStorageKeyLen = ConstU32<128>; } parameter_types! { - pub const TransactionByteFee: u64 = 0; - pub const DepositPerItem: Balance = 0; + pub const TransactionByteFee: u64 = 0; + pub const DepositPerItem: Balance = 0; pub const DepositPerByte: Balance = 0; } impl Convert> for Test { - fn convert(w: Weight) -> BalanceOf { - w.ref_time().into() - } + fn convert(w: Weight) -> BalanceOf { + w.ref_time().into() + } } // -- End contracts runtime -- use frame_system::offchain::{ - AppCrypto, CreateSignedTransaction, SendTransactionTypes, SigningTypes, + AppCrypto, CreateSignedTransaction, SendTransactionTypes, SigningTypes, }; -pub type Extrinsic = TestXt; +pub type Extrinsic = TestXt; impl SigningTypes for Test { - type Public = ::Signer; - type Signature = Signature; + type Public = ::Signer; + type Signature = Signature; } impl SendTransactionTypes for Test where - Call: From, + RuntimeCall: From, { - type OverarchingCall = Call; - type Extrinsic = Extrinsic; - + type OverarchingCall = RuntimeCall; + type Extrinsic = Extrinsic; } impl pallet_randomness_collective_flip::Config for Test {} impl CreateSignedTransaction for Test where - Call: From, + RuntimeCall: From, { - fn create_transaction>( - call: Call, - _public: ::Signer, - _account: AccountId, - nonce: u64, - ) -> Option<(Call, ::SignaturePayload)> { - Some((call, (nonce, ()))) - } + fn create_transaction>( + call: RuntimeCall, + _public: ::Signer, + _account: AccountId, + nonce: u64, + ) -> Option<(RuntimeCall, ::SignaturePayload)> { + Some((call, (nonce, ()))) + } } parameter_types! { - pub const OcwBlockInterval: u32 = crate::BLOCK_INTERVAL; + pub const OcwBlockInterval: u32 = crate::BLOCK_INTERVAL; } impl Config for Test { - type BlockInterval = OcwBlockInterval; + type BlockInterval = OcwBlockInterval; - type AuthorityId = crypto::TestAuthId; + type AuthorityId = crypto::TestAuthId; - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; } diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index aef51993e..c5a4e6873 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -1,22 +1,26 @@ [package] name = "pallet-ddc-staking" -version = "4.7.0" +version = "4.8.0" edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } [dev-dependencies] -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-staking/README.md b/pallets/ddc-staking/README.md index ce688f876..ef00bef50 100644 --- a/pallets/ddc-staking/README.md +++ b/pallets/ddc-staking/README.md @@ -1 +1,16 @@ # DDC Staking Pallet + +The DDC Staking module is used to manage funds at stake by Cere DDC participants. + +## Overview + +The DDC Staking module is the means by which an account can voluntarily place funds under deposit to join DDC CDN or storage network. + +### Terminology + +- DDC Staking: The process of locking up funds for some time in order to become a participant of the DDC. +- Stash account: The account holding an owner's funds used for staking. +- Controller account: The account that controls an owner's funds for staking. +- Edge: CDN participant. +- Storage: Storage network participant. +- Era: A time period of DDC participants activity data capture and accumulation which will further be used to calculate pay outs. diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index bb1d513c1..87b671426 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -86,6 +86,9 @@ benchmarks! { let (edge_stash, edge_controller) = create_stash_controller_with_balance::(0, T::DefaultEdgeBondSize::get())?; DdcStaking::::serve(RawOrigin::Signed(edge_controller.clone()).into(), 1)?; assert!(Edges::::contains_key(&edge_stash)); + CurrentEra::::put(1); + DdcStaking::::chill(RawOrigin::Signed(edge_controller.clone()).into())?; + CurrentEra::::put(1 + Settings::::get(1).edge_chill_delay); whitelist_account!(edge_controller); }: _(RawOrigin::Signed(edge_controller)) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 2105e53f9..27d430ede 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -1,17 +1,35 @@ +//! # DDC Staking Pallet +//! +//! The DDC Staking pallet is used to manage funds at stake by CDN and storage network maintainers. +//! +//! - [`Config`] +//! - [`Call`] +//! - [`Pallet`] +//! +//! ## GenesisConfig +//! +//! The DDC Staking pallet depends on the [`GenesisConfig`]. The +//! `GenesisConfig` is optional and allow to set some initial stakers in DDC. + #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; - #[cfg(any(feature = "runtime-benchmarks", test))] pub mod testing_utils; +#[cfg(test)] +pub(crate) mod mock; +#[cfg(test)] +mod tests; + pub mod weights; use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; use frame_support::{ + assert_ok, pallet_prelude::*, parameter_types, traits::{ @@ -178,7 +196,7 @@ pub mod pallet { #[pallet::constant] type DefaultStorageChillDelay: Get; - type Event: From> + IsType<::Event>; + type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Number of eras that staked funds must remain bonded for. #[pallet::constant] type BondingDuration: Get; @@ -227,6 +245,83 @@ pub mod pallet { #[pallet::getter(fn current_era)] pub type CurrentEra = StorageValue<_, EraIndex>; + #[pallet::genesis_config] + pub struct GenesisConfig { + pub edges: Vec<(T::AccountId, T::AccountId, BalanceOf, ClusterId)>, + pub storages: Vec<(T::AccountId, T::AccountId, BalanceOf, ClusterId)>, + pub settings: Vec<(ClusterId, BalanceOf, EraIndex, BalanceOf, EraIndex)>, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { + edges: Default::default(), + storages: Default::default(), + settings: Default::default(), + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + // clusters' settings + for &( + cluster, + edge_bond_size, + edge_chill_delay, + storage_bond_size, + storage_chill_delay, + ) in &self.settings + { + Settings::::insert( + cluster, + ClusterSettings:: { + edge_bond_size, + edge_chill_delay, + storage_bond_size, + storage_chill_delay, + }, + ); + } + + // Add initial CDN participants + for &(ref stash, ref controller, balance, cluster) in &self.edges { + assert!( + T::Currency::free_balance(&stash) >= balance, + "Stash do not have enough balance to participate in CDN." + ); + assert_ok!(Pallet::::bond( + T::RuntimeOrigin::from(Some(stash.clone()).into()), + T::Lookup::unlookup(controller.clone()), + balance, + )); + assert_ok!(Pallet::::serve( + T::RuntimeOrigin::from(Some(controller.clone()).into()), + cluster, + )); + } + + // Add initial storage network participants + for &(ref stash, ref controller, balance, cluster) in &self.storages { + assert!( + T::Currency::free_balance(&stash) >= balance, + "Stash do not have enough balance to participate in storage network." + ); + assert_ok!(Pallet::::bond( + T::RuntimeOrigin::from(Some(stash.clone()).into()), + T::Lookup::unlookup(controller.clone()), + balance, + )); + assert_ok!(Pallet::::store( + T::RuntimeOrigin::from(Some(controller.clone()).into()), + cluster, + )); + } + } + } + #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { @@ -709,10 +804,6 @@ pub mod pallet { /// This function will add a CDN participant to the `Edges` storage map. /// /// If the CDN participant already exists, their cluster will be updated. - /// - /// NOTE: you must ALWAYS use this function to add a CDN participant to the system. Any - /// access to `Edges` outside of this function is almost certainly - /// wrong. pub fn do_add_edge(who: &T::AccountId, cluster: ClusterId) { Edges::::insert(who, cluster); } @@ -720,10 +811,6 @@ pub mod pallet { /// This function will remove a CDN participant from the `Edges` map. /// /// Returns true if `who` was removed from `Edges`, otherwise false. - /// - /// NOTE: you must ALWAYS use this function to remove a storage network participant from the - /// system. Any access to `Edges` outside of this function is almost certainly - /// wrong. pub fn do_remove_edge(who: &T::AccountId) -> bool { Edges::::take(who).is_some() } @@ -731,10 +818,6 @@ pub mod pallet { /// This function will add a storage network participant to the `Storages` storage map. /// /// If the storage network participant already exists, their cluster will be updated. - /// - /// NOTE: you must ALWAYS use this function to add a storage network participant to the - /// system. Any access to `Storages` outside of this function is almost certainly - /// wrong. pub fn do_add_storage(who: &T::AccountId, cluster: ClusterId) { Storages::::insert(who, cluster); } @@ -742,10 +825,6 @@ pub mod pallet { /// This function will remove a storage network participant from the `Storages` map. /// /// Returns true if `who` was removed from `Storages`, otherwise false. - /// - /// NOTE: you must ALWAYS use this function to remove a storage network participant from the - /// system. Any access to `Storages` outside of this function is almost certainly - /// wrong. pub fn do_remove_storage(who: &T::AccountId) -> bool { Storages::::take(who).is_some() } diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs new file mode 100644 index 000000000..dea8eb524 --- /dev/null +++ b/pallets/ddc-staking/src/mock.rs @@ -0,0 +1,244 @@ +//! Test utilities + +#![allow(dead_code)] + +use crate::{self as pallet_ddc_staking, *}; +use frame_support::{ + construct_runtime, + traits::{ConstU32, ConstU64, Everything, GenesisBuild}, + weights::constants::RocksDbWeight, +}; +use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; +use sp_core::H256; +use sp_io::TestExternalities; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; +use sp_std::collections::btree_map::BTreeMap; + +/// The AccountId alias in this test module. +pub(crate) type AccountId = u64; +pub(crate) type AccountIndex = u64; +pub(crate) type BlockNumber = u64; +pub(crate) type Balance = u128; + +type UncheckedExtrinsic = MockUncheckedExtrinsic; +type Block = MockBlock; + +construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + DdcStaking: pallet_ddc_staking::{Pallet, Call, Config, Storage, Event}, + } +); + +parameter_types! { + pub static ExistentialDeposit: Balance = 1; +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = RocksDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type MaxLocks = ConstU32<1024>; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<5>; + type WeightInfo = (); +} + +parameter_types! { + pub const BondingDuration: EraIndex = 10; + pub const DefaultEdgeBondSize: Balance = 100; + pub const DefaultEdgeChillDelay: EraIndex = 1; + pub const DefaultStorageBondSize: Balance = 100; + pub const DefaultStorageChillDelay: EraIndex = 1; +} + +impl crate::pallet::Config for Test { + type BondingDuration = BondingDuration; + type Currency = Balances; + type DefaultEdgeBondSize = DefaultEdgeBondSize; + type DefaultEdgeChillDelay = DefaultEdgeChillDelay; + type DefaultStorageBondSize = DefaultStorageBondSize; + type DefaultStorageChillDelay = DefaultStorageChillDelay; + type RuntimeEvent = RuntimeEvent; + type UnixTime = Timestamp; + type WeightInfo = (); +} + +pub(crate) type DdcStakingCall = crate::Call; +pub(crate) type TestRuntimeCall = ::RuntimeCall; + +pub struct ExtBuilder { + has_edges: bool, + has_storages: bool, + stakes: BTreeMap, + edges: Vec<(AccountId, AccountId, Balance, ClusterId)>, + storages: Vec<(AccountId, AccountId, Balance, ClusterId)>, +} + +impl Default for ExtBuilder { + fn default() -> Self { + Self { + has_edges: true, + has_storages: true, + stakes: Default::default(), + edges: Default::default(), + storages: Default::default(), + } + } +} + +impl ExtBuilder { + pub fn has_edges(mut self, has: bool) -> Self { + self.has_edges = has; + self + } + pub fn has_storages(mut self, has: bool) -> Self { + self.has_storages = has; + self + } + pub fn set_stake(mut self, who: AccountId, stake: Balance) -> Self { + self.stakes.insert(who, stake); + self + } + pub fn add_edge( + mut self, + stash: AccountId, + controller: AccountId, + stake: Balance, + cluster: ClusterId, + ) -> Self { + self.edges.push((stash, controller, stake, cluster)); + self + } + pub fn add_storage( + mut self, + stash: AccountId, + controller: AccountId, + stake: Balance, + cluster: ClusterId, + ) -> Self { + self.storages.push((stash, controller, stake, cluster)); + self + } + fn build(self) -> TestExternalities { + sp_tracing::try_init_simple(); + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let _ = pallet_balances::GenesisConfig:: { + balances: vec![ + (1, 100), + (2, 100), + (3, 100), + (4, 100), + // edge controllers + (10, 100), + (20, 100), + // storage controllers + (30, 100), + (40, 100), + // edge stashes + (11, 100), + (21, 100), + // storage stashes + (31, 100), + (41, 100), + ], + } + .assimilate_storage(&mut storage); + let mut edges = vec![]; + if self.has_edges { + edges = vec![ + // (stash, controller, stake, cluster) + (11, 10, 100, 1), + (21, 20, 100, 1), + ]; + } + let mut storages = vec![]; + if self.has_storages { + storages = vec![ + // (stash, controller, stake, cluster) + (31, 30, 100, 1), + (41, 40, 100, 1), + ]; + } + + let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } + .assimilate_storage(&mut storage); + + TestExternalities::new(storage) + } + pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + sp_tracing::try_init_simple(); + let mut ext = self.build(); + ext.execute_with(test); + ext.execute_with(post_condition); + } +} + +fn post_condition() { + check_ledgers(); +} + +fn check_ledgers() { + // check the ledger of all stakers. + Bonded::::iter().for_each(|(_, controller)| assert_ledger_consistent(controller)) +} + +fn assert_ledger_consistent(controller: AccountId) { + // ensures ledger.total == ledger.active + sum(ledger.unlocking). + let ledger = DdcStaking::ledger(controller).expect("Not a controller."); + let real_total: Balance = ledger.unlocking.iter().fold(ledger.active, |a, c| a + c.value); + assert_eq!(real_total, ledger.total); + assert!( + ledger.active >= Balances::minimum_balance() || ledger.active == 0, + "{}: active ledger amount ({}) must be greater than ED {}", + controller, + ledger.active, + Balances::minimum_balance() + ); +} diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs new file mode 100644 index 000000000..461f064d5 --- /dev/null +++ b/pallets/ddc-staking/src/tests.rs @@ -0,0 +1,178 @@ +//! Tests for the module. + +use super::{mock::*, *}; +use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; +use pallet_balances::Error as BalancesError; + +pub const BLOCK_TIME: u64 = 1000; +pub const INIT_TIMESTAMP: u64 = 30_000; + +#[test] +fn set_settings_works() { + ExtBuilder::default().build_and_execute(|| { + // setting works + assert_ok!(DdcStaking::set_settings( + RuntimeOrigin::root(), + 1, + Some(ClusterSettings { + edge_bond_size: 10, + edge_chill_delay: 2, + storage_bond_size: 10, + storage_chill_delay: 2, + }), + )); + let settings = DdcStaking::settings(1); + assert_eq!(settings.edge_bond_size, 10); + assert_eq!(settings.edge_chill_delay, 2); + assert_eq!(settings.storage_bond_size, 10); + assert_eq!(settings.storage_chill_delay, 2); + + // removing works + assert_ok!(DdcStaking::set_settings(RuntimeOrigin::root(), 1, None)); + let settings = DdcStaking::settings(1); + let default_settings: ClusterSettings = Default::default(); + assert_eq!(settings.edge_bond_size, default_settings.edge_bond_size); + assert_eq!(settings.edge_chill_delay, default_settings.edge_chill_delay); + assert_eq!(settings.storage_bond_size, default_settings.storage_bond_size); + assert_eq!(settings.storage_chill_delay, default_settings.storage_chill_delay); + }); +} + +#[test] +fn basic_setup_works() { + // Verifies initial conditions of mock + ExtBuilder::default().build_and_execute(|| { + // Account 11 is stashed and locked, and account 10 is the controller + assert_eq!(DdcStaking::bonded(&11), Some(10)); + // Account 21 is stashed and locked, and account 20 is the controller + assert_eq!(DdcStaking::bonded(&21), Some(20)); + // Account 1 is not a stashed + assert_eq!(DdcStaking::bonded(&1), None); + + // Account 10 controls the stash from account 11, which is 100 units + assert_eq!( + DdcStaking::ledger(&10), + Some(StakingLedger { + stash: 11, + total: 100, + active: 100, + chilling: Default::default(), + unlocking: Default::default(), + }) + ); + // Account 20 controls the stash from account 21, which is 100 units + assert_eq!( + DdcStaking::ledger(&20), + Some(StakingLedger { + stash: 21, + total: 100, + active: 100, + chilling: Default::default(), + unlocking: Default::default(), + }) + ); + // Account 1 does not control any stash + assert_eq!(DdcStaking::ledger(&1), None); + + // Cluster 1 settings are default + assert_eq!(DdcStaking::settings(1), Default::default()); + }); +} + +#[test] +fn change_controller_works() { + ExtBuilder::default().build_and_execute(|| { + // 10 and 11 are bonded as stash controller. + assert_eq!(DdcStaking::bonded(&11), Some(10)); + + // 10 can control 11 who is initially a validator. + assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(10))); + + // Change controller. + assert_ok!(DdcStaking::set_controller(RuntimeOrigin::signed(11), 3)); + assert_eq!(DdcStaking::bonded(&11), Some(3)); + + // 10 is no longer in control. + assert_noop!(DdcStaking::serve(RuntimeOrigin::signed(10), 1), Error::::NotController); + // 3 is a new controller. + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), 1)); + }) +} + +#[test] +fn staking_should_work() { + ExtBuilder::default().build_and_execute(|| { + // Put some money in account that we'll use. + for i in 1..5 { + let _ = Balances::make_free_balance_be(&i, 2000); + } + + // Add new CDN participant, account 3 controlled by 4. + assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, 1500)); + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), 1)); + + // Account 4 controls the stash from account 3, which is 1500 units and 3 is a CDN + // participant. + assert_eq!(DdcStaking::bonded(&3), Some(4)); + assert_eq!( + DdcStaking::ledger(&4), + Some(StakingLedger { + stash: 3, + total: 1500, + active: 1500, + chilling: Default::default(), + unlocking: Default::default(), + }) + ); + assert_eq!(DdcStaking::edges(3), Some(1)); + + // Set `CurrentEra`. + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + DdcStaking::on_finalize(System::block_number()); + + // Schedule CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); + + // Removal is scheduled, stashed value of 4 is still lock. + let chilling = + DdcStaking::current_era().unwrap() + DdcStaking::settings(1).edge_chill_delay; + assert_eq!( + DdcStaking::ledger(&4), + Some(StakingLedger { + stash: 3, + total: 1500, + active: 1500, + chilling: Some(chilling), + unlocking: Default::default(), + }) + ); + // It cannot reserve more than 500 that it has free from the total 2000 + assert_noop!(Balances::reserve(&3, 501), BalancesError::::LiquidityRestrictions); + assert_ok!(Balances::reserve(&3, 409)); + + // Set `CurrentEra` to the value allows us to chill. + while DdcStaking::current_era().unwrap() < chilling { + System::set_block_number(System::block_number() + 1); + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + DdcStaking::on_finalize(System::block_number()); + } + + // Ledger is not changed until we make another call to `chill`. + assert_eq!( + DdcStaking::ledger(&4), + Some(StakingLedger { + stash: 3, + total: 1500, + active: 1500, + chilling: Some(chilling), + unlocking: Default::default(), + }) + ); + + // Actual CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); + + // Account 3 is no longer a CDN participant. + assert_eq!(DdcStaking::edges(3), None); + }); +} diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs old mode 100755 new mode 100644 index f08655fb9..937eece23 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -1,8 +1,8 @@ - -//! Autogenerated weights for `pallet_ddc_staking` +//! Autogenerated weights for pallet_ddc_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-02, STEPS: `500`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-07-04, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `e14`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -10,23 +10,23 @@ // benchmark // pallet // --chain=dev -// --steps=500 -// --repeat=200 +// --steps=50 +// --repeat=20 // --pallet=pallet_ddc_staking // --extrinsic=* // --execution=wasm // --wasm-execution=compiled -// --output=./frame/ddc-staking/src +// --template=./.maintain/frame-weight-template.hbs +// --output=./pallets/ddc-staking/src #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; - -/// Weight functions needed for pallet_staking. +/// Weight functions needed for pallet_ddc_staking. pub trait WeightInfo { fn bond() -> Weight; fn unbond() -> Weight; @@ -37,63 +37,137 @@ pub trait WeightInfo { fn set_controller() -> Weight; } -/// Weight functions for `pallet_ddc_staking`. +/// Weights for pallet_ddc_staking using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(51_000_000) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) + Weight::from_ref_time(49_113_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) } - // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(10_000_000) - .saturating_add(T::DbWeight::get().reads(1)) + Weight::from_ref_time(47_727_000 as u64) + .saturating_add(T::DbWeight::get().reads(6 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(46_000_000) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + Weight::from_ref_time(69_750_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) } // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking MinStorageBond (r:1 w:0) + // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Edges (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) - // Storage: DdcStaking CounterForStorages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(22_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(2)) + Weight::from_ref_time(26_112_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking MinEdgeBond (r:1 w:0) + // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Edges (r:1 w:1) - // Storage: DdcStaking CounterForEdges (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(22_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(2)) + Weight::from_ref_time(19_892_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } - // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Edges (r:1 w:1) + // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) + fn chill() -> Weight { + Weight::from_ref_time(77_450_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: DdcStaking Bonded (r:1 w:1) + // Storage: DdcStaking Ledger (r:2 w:2) + fn set_controller() -> Weight { + Weight::from_ref_time(38_521_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: DdcStaking Bonded (r:1 w:1) + // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + fn bond() -> Weight { + Weight::from_ref_time(49_113_000 as u64) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().writes(3 as u64)) + } + // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn unbond() -> Weight { + Weight::from_ref_time(47_727_000 as u64) + .saturating_add(RocksDbWeight::get().reads(6 as u64)) + .saturating_add(RocksDbWeight::get().writes(3 as u64)) + } + // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn withdraw_unbonded() -> Weight { + Weight::from_ref_time(69_750_000 as u64) + .saturating_add(RocksDbWeight::get().reads(4 as u64)) + .saturating_add(RocksDbWeight::get().writes(3 as u64)) + } + // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:1) + fn store() -> Weight { + Weight::from_ref_time(26_112_000 as u64) + .saturating_add(RocksDbWeight::get().reads(4 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } + // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Edges (r:1 w:1) + fn serve() -> Weight { + Weight::from_ref_time(19_892_000 as u64) + .saturating_add(RocksDbWeight::get().reads(4 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } + // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Edges (r:1 w:1) + // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(15_000_000) - .saturating_add(T::DbWeight::get().reads(3)) + Weight::from_ref_time(77_450_000 as u64) + .saturating_add(RocksDbWeight::get().reads(5 as u64)) + .saturating_add(RocksDbWeight::get().writes(2 as u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(20_000_000) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) + Weight::from_ref_time(38_521_000 as u64) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().writes(3 as u64)) } } diff --git a/pallets/ddc/Cargo.toml b/pallets/ddc/Cargo.toml index 94c517cea..c15ee4ac7 100644 --- a/pallets/ddc/Cargo.toml +++ b/pallets/ddc/Cargo.toml @@ -6,7 +6,7 @@ homepage = 'https://www.cere.network/' license = 'Unlicense' name = 'pallet-cere-ddc' repository = 'https://github.com/Cerebellum-Network/ddc-pallet' -version = '4.7.0' +version = '4.8.0' readme = 'README.md' [package.metadata.docs.rs] @@ -14,15 +14,15 @@ targets = ['x86_64-unknown-linux-gnu'] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } [dev-dependencies] -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } serde = { version = "1.0.101" } [features] diff --git a/pallets/ddc/src/lib.rs b/pallets/ddc/src/lib.rs index d8008c2b8..e1d572af6 100644 --- a/pallets/ddc/src/lib.rs +++ b/pallets/ddc/src/lib.rs @@ -1,10 +1,13 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::{ - decl_error, decl_event, decl_module, decl_storage, + decl_error, + decl_event, + decl_module, + decl_storage, // dispatch, ensure, - traits::{ Get }, + traits::Get, }; use frame_system::ensure_signed; @@ -22,7 +25,7 @@ mod tests; /// Configure the pallet by specifying the parameters and types on which it depends. pub trait Config: frame_system::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. - type Event: From> + Into<::Event>; + type RuntimeEvent: From> + Into<::RuntimeEvent>; /// The minimum length a name may be. type MinLength: Get; @@ -52,7 +55,7 @@ decl_event!( { /// A data string was set. \[who\] DataStringSet(AccountId), - + /// A data string was changed. \[who\] DataStringChanged(AccountId), } @@ -73,7 +76,7 @@ decl_error! { // Dispatchable functions must be annotated with a weight and must return a DispatchResult. decl_module! { /// CereDDCModule declaration. - pub struct Module for enum Call where origin: T::Origin { + pub struct Module for enum Call where origin: T::RuntimeOrigin { // Errors must be initialized if they are used by the pallet. type Error = Error; diff --git a/pallets/ddc/src/mock.rs b/pallets/ddc/src/mock.rs index ff59e6902..0bb912223 100644 --- a/pallets/ddc/src/mock.rs +++ b/pallets/ddc/src/mock.rs @@ -1,14 +1,12 @@ -use crate::{Module}; +use crate as pallet_cere_ddc; +use crate::Module; +use frame_support::{construct_runtime, parameter_types, traits::Everything}; +use frame_system as system; use sp_core::H256; -use frame_support::{ - traits::{Everything}, - construct_runtime, parameter_types -}; use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, testing::Header, + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, }; -use frame_system as system; -use crate as pallet_cere_ddc; // Configure a mock runtime to test the pallet. type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -33,8 +31,8 @@ impl system::Config for Test { type BaseCallFilter = Everything; type BlockWeights = (); type BlockLength = (); - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -42,7 +40,7 @@ impl system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type RuntimeEvent = (); type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); @@ -62,7 +60,7 @@ parameter_types! { } impl pallet_cere_ddc::Config for Test { - type Event = (); + type RuntimeEvent = (); type MinLength = MinLength; type MaxLength = MaxLength; } diff --git a/pallets/ddc/src/tests.rs b/pallets/ddc/src/tests.rs index 512eaac29..95f5927ae 100644 --- a/pallets/ddc/src/tests.rs +++ b/pallets/ddc/src/tests.rs @@ -7,7 +7,7 @@ const BOB: u64 = 2; fn send_data_works_valid_input() { new_test_ext().execute_with(|| { // Dispatch a signed extrinsic. - assert_ok!(CereDDCModule::send_data(Origin::signed(1), BOB, b"12345678".to_vec())); + assert_ok!(CereDDCModule::send_data(RuntimeOrigin::signed(1), BOB, b"12345678".to_vec())); }); } @@ -16,7 +16,7 @@ fn send_data_error_too_long() { new_test_ext().execute_with(|| { // Ensure the expected error is thrown when no value is present. assert_noop!( - CereDDCModule::send_data(Origin::signed(1), BOB, b"TestTooLongString".to_vec()), + CereDDCModule::send_data(RuntimeOrigin::signed(1), BOB, b"TestTooLongString".to_vec()), Error::::TooLong ); }); @@ -27,7 +27,7 @@ fn send_data_error_too_short() { new_test_ext().execute_with(|| { // Ensure the expected error is thrown when no value is present. assert_noop!( - CereDDCModule::send_data(Origin::signed(1), BOB, b"Short".to_vec()), + CereDDCModule::send_data(RuntimeOrigin::signed(1), BOB, b"Short".to_vec()), Error::::TooShort ); }); diff --git a/pallets/erc20/Cargo.toml b/pallets/erc20/Cargo.toml index 8d1cb2536..fafa6ae83 100644 --- a/pallets/erc20/Cargo.toml +++ b/pallets/erc20/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-erc20" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" @@ -15,19 +15,19 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } -sp-arithmetic = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-arithmetic = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } pallet-erc721 = { version = "4.2.0", default-features = false, path = "../erc721" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } [features] default = ["std"] diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index cd7fb21e2..8f861d10d 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -4,50 +4,49 @@ use pallet_chainbridge as bridge; use pallet_erc721 as erc721; -use sp_std::marker::PhantomData; +use codec::{Decode, Encode}; use frame_support::{ - dispatch::{DispatchResult}, decl_module, decl_storage, decl_event, decl_error, - traits::{Currency, EnsureOrigin, ExistenceRequirement::AllowDeath, Get}, + decl_error, decl_event, decl_module, decl_storage, + dispatch::DispatchResult, ensure, - weights::{DispatchClass, ClassifyDispatch, WeighData, Weight, PaysFee, Pays}, + traits::{Currency, EnsureOrigin, ExistenceRequirement::AllowDeath, Get}, + weights::{ClassifyDispatch, DispatchClass, Pays, PaysFee, WeighData, Weight}, }; -use sp_std::prelude::*; -use frame_system::{self as system, ensure_signed, ensure_root}; +use frame_system::{self as system, ensure_root, ensure_signed}; use sp_arithmetic::traits::SaturatedConversion; use sp_core::U256; -use codec::{Encode, Decode}; use sp_runtime::{ - traits::{ - SignedExtension, Bounded, DispatchInfoOf, UniqueSaturatedInto, - }, + traits::{Bounded, DispatchInfoOf, SignedExtension, UniqueSaturatedInto}, transaction_validity::{ - ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity, + InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, }, }; +use sp_std::{marker::PhantomData, prelude::*}; type ResourceId = bridge::ResourceId; type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; + <::Currency as Currency<::AccountId>>::Balance; pub trait Config: system::Config + bridge::Config + erc721::Config { - type Event: From> + Into<::Event>; - /// Specifies the origin check provided by the bridge for calls that can only be called by the bridge pallet - type BridgeOrigin: EnsureOrigin; - - /// The currency mechanism. - type Currency: Currency; - - /// Ids can be defined by the runtime and passed in, perhaps from blake2b_128 hashes. - type HashId: Get; - type NativeTokenId: Get; - type Erc721Id: Get; + type RuntimeEvent: From> + Into<::RuntimeEvent>; + /// Specifies the origin check provided by the bridge for calls that can only be called by the + /// bridge pallet + type BridgeOrigin: EnsureOrigin; + + /// The currency mechanism. + type Currency: Currency; + + /// Ids can be defined by the runtime and passed in, perhaps from blake2b_128 hashes. + type HashId: Get; + type NativeTokenId: Get; + type Erc721Id: Get; } decl_error! { - pub enum Error for Module{ - InvalidTransfer, - } + pub enum Error for Module{ + InvalidTransfer, + } } decl_storage! { @@ -55,93 +54,93 @@ decl_storage! { } decl_event!( - pub enum Event where - ::Hash, - { - Remark(Hash), - } + pub enum Event where + ::Hash, + { + Remark(Hash), + } ); decl_module! { - pub struct Module for enum Call where origin: T::Origin { - const HashId: ResourceId = T::HashId::get(); - const NativeTokenId: ResourceId = T::NativeTokenId::get(); - const Erc721Id: ResourceId = T::Erc721Id::get(); - - fn deposit_event() = default; - - // - // Initiation calls. These start a bridge transfer. - // - - /// Transfers an arbitrary hash to a (whitelisted) destination chain. - #[weight = 195_000_000] - pub fn transfer_hash(origin, hash: T::Hash, dest_id: bridge::ChainId) -> DispatchResult { - ensure_signed(origin)?; - - let resource_id = T::HashId::get(); - let metadata: Vec = hash.as_ref().to_vec(); - >::transfer_generic(dest_id, resource_id, metadata) - } - - /// Transfers some amount of the native token to some recipient on a (whitelisted) destination chain. - #[weight = 195_000_000] - pub fn transfer_native(origin, amount: BalanceOf, recipient: Vec, dest_id: bridge::ChainId) -> DispatchResult { - let source = ensure_signed(origin)?; - ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); - let bridge_id = >::account_id(); - T::Currency::transfer(&source, &bridge_id, amount.into(), AllowDeath)?; - - let resource_id = T::NativeTokenId::get(); + pub struct Module for enum Call where origin: T::RuntimeOrigin { + const HashId: ResourceId = T::HashId::get(); + const NativeTokenId: ResourceId = T::NativeTokenId::get(); + const Erc721Id: ResourceId = T::Erc721Id::get(); + + fn deposit_event() = default; + + // + // Initiation calls. These start a bridge transfer. + // + + /// Transfers an arbitrary hash to a (whitelisted) destination chain. + #[weight = 195_000_000] + pub fn transfer_hash(origin, hash: T::Hash, dest_id: bridge::ChainId) -> DispatchResult { + ensure_signed(origin)?; + + let resource_id = T::HashId::get(); + let metadata: Vec = hash.as_ref().to_vec(); + >::transfer_generic(dest_id, resource_id, metadata) + } + + /// Transfers some amount of the native token to some recipient on a (whitelisted) destination chain. + #[weight = 195_000_000] + pub fn transfer_native(origin, amount: BalanceOf, recipient: Vec, dest_id: bridge::ChainId) -> DispatchResult { + let source = ensure_signed(origin)?; + ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); + let bridge_id = >::account_id(); + T::Currency::transfer(&source, &bridge_id, amount.into(), AllowDeath)?; + + let resource_id = T::NativeTokenId::get(); let number_amount: u128 = amount.saturated_into(); - >::transfer_fungible(dest_id, resource_id, recipient, U256::from(number_amount)) - } - - - /// Transfer a non-fungible token (erc721) to a (whitelisted) destination chain. - #[weight = 195_000_000] - pub fn transfer_erc721(origin, recipient: Vec, token_id: U256, dest_id: bridge::ChainId) -> DispatchResult { - let source = ensure_signed(origin)?; - ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); - match >::tokens(&token_id) { - Some(token) => { - >::burn_token(source, token_id)?; - let resource_id = T::Erc721Id::get(); - let tid: &mut [u8] = &mut[0; 32]; - token_id.to_big_endian(tid); - >::transfer_nonfungible(dest_id, resource_id, tid.to_vec(), recipient, token.metadata) - } - None => Err(Error::::InvalidTransfer)? - } - } - - // - // Executable calls. These can be triggered by a bridge transfer initiated on another chain - // - - /// Executes a simple currency transfer using the bridge account as the source - #[weight = 195_000_000] - pub fn transfer(origin, to: T::AccountId, amount: BalanceOf) -> DispatchResult { - let source = T::BridgeOrigin::ensure_origin(origin)?; - ::Currency::transfer(&source, &to, amount.into(), AllowDeath)?; - Ok(()) - } - - /// This can be called by the bridge to demonstrate an arbitrary call from a proposal. - #[weight = 195_000_000] - pub fn remark(origin, hash: T::Hash) -> DispatchResult { - T::BridgeOrigin::ensure_origin(origin)?; - Self::deposit_event(RawEvent::Remark(hash)); - Ok(()) - } - - /// Allows the bridge to issue new erc721 tokens - #[weight = 195_000_000] - pub fn mint_erc721(origin, recipient: T::AccountId, id: U256, metadata: Vec) -> DispatchResult { - T::BridgeOrigin::ensure_origin(origin)?; - >::mint_token(recipient, id, metadata)?; - Ok(()) - } - } + >::transfer_fungible(dest_id, resource_id, recipient, U256::from(number_amount)) + } + + + /// Transfer a non-fungible token (erc721) to a (whitelisted) destination chain. + #[weight = 195_000_000] + pub fn transfer_erc721(origin, recipient: Vec, token_id: U256, dest_id: bridge::ChainId) -> DispatchResult { + let source = ensure_signed(origin)?; + ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); + match >::tokens(&token_id) { + Some(token) => { + >::burn_token(source, token_id)?; + let resource_id = T::Erc721Id::get(); + let tid: &mut [u8] = &mut[0; 32]; + token_id.to_big_endian(tid); + >::transfer_nonfungible(dest_id, resource_id, tid.to_vec(), recipient, token.metadata) + } + None => Err(Error::::InvalidTransfer)? + } + } + + // + // Executable calls. These can be triggered by a bridge transfer initiated on another chain + // + + /// Executes a simple currency transfer using the bridge account as the source + #[weight = 195_000_000] + pub fn transfer(origin, to: T::AccountId, amount: BalanceOf) -> DispatchResult { + let source = T::BridgeOrigin::ensure_origin(origin)?; + ::Currency::transfer(&source, &to, amount.into(), AllowDeath)?; + Ok(()) + } + + /// This can be called by the bridge to demonstrate an arbitrary call from a proposal. + #[weight = 195_000_000] + pub fn remark(origin, hash: T::Hash) -> DispatchResult { + T::BridgeOrigin::ensure_origin(origin)?; + Self::deposit_event(RawEvent::Remark(hash)); + Ok(()) + } + + /// Allows the bridge to issue new erc721 tokens + #[weight = 195_000_000] + pub fn mint_erc721(origin, recipient: T::AccountId, id: U256, metadata: Vec) -> DispatchResult { + T::BridgeOrigin::ensure_origin(origin)?; + >::mint_token(recipient, id, metadata)?; + Ok(()) + } + } } diff --git a/pallets/erc721/Cargo.toml b/pallets/erc721/Cargo.toml index 210c4f2f7..5f7d02e22 100644 --- a/pallets/erc721/Cargo.toml +++ b/pallets/erc721/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-erc721" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" @@ -15,17 +15,17 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false,git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false,git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } [features] default = ["std"] diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index f43413aec..c0da9c7a3 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -1,26 +1,24 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] -use sp_std::marker::PhantomData; +use codec::{Decode, Encode}; use frame_support::{ - dispatch::{DispatchResult}, decl_module, decl_storage, decl_event, decl_error, + decl_error, decl_event, decl_module, decl_storage, + dispatch::{ClassifyDispatch, DispatchClass, DispatchResult, Pays, PaysFee, WeighData}, ensure, traits::Get, - weights::{DispatchClass, ClassifyDispatch, WeighData, Weight, PaysFee, Pays}, + weights::Weight, }; -use sp_std::prelude::*; -use frame_system::{self as system, ensure_signed, ensure_root}; +use frame_system::{self as system, ensure_root, ensure_signed}; use sp_core::U256; -use codec::{Encode, Decode}; use sp_runtime::{ - traits::{ - SignedExtension, Bounded, SaturatedConversion, DispatchInfoOf, - }, + traits::{Bounded, DispatchInfoOf, SaturatedConversion, SignedExtension}, transaction_validity::{ - ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity, + InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, }, RuntimeDebug, }; +use sp_std::{marker::PhantomData, prelude::*}; mod mock; mod tests; @@ -29,135 +27,136 @@ type TokenId = U256; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] pub struct Erc721Token { - pub id: TokenId, - pub metadata: Vec, + pub id: TokenId, + pub metadata: Vec, } pub trait Config: system::Config { - type Event: From> + Into<::Event>; + type RuntimeEvent: From> + Into<::RuntimeEvent>; - /// Some identifier for this token type, possibly the originating ethereum address. - /// This is not explicitly used for anything, but may reflect the bridge's notion of resource ID. - type Identifier: Get<[u8; 32]>; + /// Some identifier for this token type, possibly the originating ethereum address. + /// This is not explicitly used for anything, but may reflect the bridge's notion of resource + /// ID. + type Identifier: Get<[u8; 32]>; } decl_error! { - pub enum Error for Module { - /// ID not recognized - TokenIdDoesNotExist, - /// Already exists with an owner - TokenAlreadyExists, - /// Origin is not owner - NotOwner, - } + pub enum Error for Module { + /// ID not recognized + TokenIdDoesNotExist, + /// Already exists with an owner + TokenAlreadyExists, + /// Origin is not owner + NotOwner, + } } decl_storage! { trait Store for Module as TokenStorage { - /// Maps tokenId to Erc721 object - Tokens get(fn tokens): map hasher(opaque_blake2_256) TokenId => Option; - /// Maps tokenId to owner - TokenOwner get(fn owner_of): map hasher(opaque_blake2_256) TokenId => Option; - /// Total number of tokens in existence - TokenCount get(fn token_count): U256 = U256::zero(); - } + /// Maps tokenId to Erc721 object + Tokens get(fn tokens): map hasher(opaque_blake2_256) TokenId => Option; + /// Maps tokenId to owner + TokenOwner get(fn owner_of): map hasher(opaque_blake2_256) TokenId => Option; + /// Total number of tokens in existence + TokenCount get(fn token_count): U256 = U256::zero(); + } } decl_event!( pub enum Event - where - ::AccountId, - { - /// New token created - Minted(AccountId, TokenId), - /// Token transfer between two parties - Transferred(AccountId, AccountId, TokenId), - /// Token removed from the system - Burned(TokenId), - } + where + ::AccountId, + { + /// New token created + Minted(AccountId, TokenId), + /// Token transfer between two parties + Transferred(AccountId, AccountId, TokenId), + /// Token removed from the system + Burned(TokenId), + } ); decl_module! { - pub struct Module for enum Call where origin: T::Origin { - type Error = Error; - fn deposit_event() = default; + pub struct Module for enum Call where origin: T::RuntimeOrigin { + type Error = Error; + fn deposit_event() = default; - /// Creates a new token with the given token ID and metadata, and gives ownership to owner - #[weight = 195_000_000] - pub fn mint(origin, owner: T::AccountId, id: TokenId, metadata: Vec) -> DispatchResult { - ensure_root(origin)?; + /// Creates a new token with the given token ID and metadata, and gives ownership to owner + #[weight = 195_000_000] + pub fn mint(origin, owner: T::AccountId, id: TokenId, metadata: Vec) -> DispatchResult { + ensure_root(origin)?; - Self::mint_token(owner, id, metadata)?; + Self::mint_token(owner, id, metadata)?; - Ok(()) - } + Ok(()) + } - /// Changes ownership of a token sender owns - #[weight = 195_000_000] - pub fn transfer(origin, to: T::AccountId, id: TokenId) -> DispatchResult { - let sender = ensure_signed(origin)?; + /// Changes ownership of a token sender owns + #[weight = 195_000_000] + pub fn transfer(origin, to: T::AccountId, id: TokenId) -> DispatchResult { + let sender = ensure_signed(origin)?; - Self::transfer_from(sender, to, id)?; + Self::transfer_from(sender, to, id)?; - Ok(()) - } + Ok(()) + } - /// Remove token from the system - #[weight = 195_000_000] - pub fn burn(origin, id: TokenId) -> DispatchResult { - ensure_root(origin)?; + /// Remove token from the system + #[weight = 195_000_000] + pub fn burn(origin, id: TokenId) -> DispatchResult { + ensure_root(origin)?; - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; - Self::burn_token(owner, id)?; + Self::burn_token(owner, id)?; - Ok(()) - } - } + Ok(()) + } + } } impl Module { - /// Creates a new token in the system. - pub fn mint_token(owner: T::AccountId, id: TokenId, metadata: Vec) -> DispatchResult { - ensure!(!Tokens::contains_key(id), Error::::TokenAlreadyExists); + /// Creates a new token in the system. + pub fn mint_token(owner: T::AccountId, id: TokenId, metadata: Vec) -> DispatchResult { + ensure!(!Tokens::contains_key(id), Error::::TokenAlreadyExists); - let new_token = Erc721Token { id, metadata }; + let new_token = Erc721Token { id, metadata }; - ::insert(&id, new_token); - >::insert(&id, owner.clone()); - let new_total = ::get().saturating_add(U256::one()); - ::put(new_total); + ::insert(&id, new_token); + >::insert(&id, owner.clone()); + let new_total = ::get().saturating_add(U256::one()); + ::put(new_total); - Self::deposit_event(RawEvent::Minted(owner, id)); + Self::deposit_event(RawEvent::Minted(owner, id)); - Ok(()) - } + Ok(()) + } - /// Modifies ownership of a token - pub fn transfer_from(from: T::AccountId, to: T::AccountId, id: TokenId) -> DispatchResult { - // Check from is owner and token exists - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; - ensure!(owner == from, Error::::NotOwner); - // Update owner - >::insert(&id, to.clone()); + /// Modifies ownership of a token + pub fn transfer_from(from: T::AccountId, to: T::AccountId, id: TokenId) -> DispatchResult { + // Check from is owner and token exists + let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + ensure!(owner == from, Error::::NotOwner); + // Update owner + >::insert(&id, to.clone()); - Self::deposit_event(RawEvent::Transferred(from, to, id)); + Self::deposit_event(RawEvent::Transferred(from, to, id)); - Ok(()) - } + Ok(()) + } - /// Deletes a token from the system. - pub fn burn_token(from: T::AccountId, id: TokenId) -> DispatchResult { - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; - ensure!(owner == from, Error::::NotOwner); + /// Deletes a token from the system. + pub fn burn_token(from: T::AccountId, id: TokenId) -> DispatchResult { + let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + ensure!(owner == from, Error::::NotOwner); - ::remove(&id); - >::remove(&id); - let new_total = ::get().saturating_sub(U256::one()); - ::put(new_total); + ::remove(&id); + >::remove(&id); + let new_total = ::get().saturating_sub(U256::one()); + ::put(new_total); - Self::deposit_event(RawEvent::Burned(id)); + Self::deposit_event(RawEvent::Burned(id)); - Ok(()) - } + Ok(()) + } } diff --git a/pallets/erc721/src/mock.rs b/pallets/erc721/src/mock.rs index bb872fa8f..24ee23b92 100644 --- a/pallets/erc721/src/mock.rs +++ b/pallets/erc721/src/mock.rs @@ -1,96 +1,94 @@ #![cfg(test)] -use frame_support::{ord_parameter_types, parameter_types, weights::Weight}; -use frame_support::traits::Everything; +use frame_support::{ord_parameter_types, parameter_types, traits::Everything, weights::Weight}; use frame_system::{self as system}; -use sp_core::hashing::blake2_128; -use sp_core::H256; +use sp_core::{hashing::blake2_128, H256}; use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, Block as BlockT, IdentityLookup}, - BuildStorage, Perbill, + testing::Header, + traits::{BlakeTwo256, Block as BlockT, IdentityLookup}, + BuildStorage, Perbill, }; use crate::{self as erc721, Config}; -use pallet_chainbridge as bridge; pub use pallet_balances as balances; +use pallet_chainbridge as bridge; parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); + pub const BlockHashCount: u64 = 250; + pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::one(); } impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type Origin = Origin; - type Call = Call; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { - pub const ExistentialDeposit: u64 = 1; + pub const ExistentialDeposit: u64 = 1; } ord_parameter_types! { - pub const One: u64 = 1; + pub const One: u64 = 1; } impl pallet_balances::Config for Test { - type Balance = u64; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = (); + type Balance = u64; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = (); } parameter_types! { - pub Erc721Id: bridge::ResourceId = bridge::derive_resource_id(1, &blake2_128(b"NFT")); + pub Erc721Id: bridge::ResourceId = bridge::derive_resource_id(1, &blake2_128(b"NFT")); } impl Config for Test { - type Event = Event; - type Identifier = Erc721Id; + type RuntimeEvent = RuntimeEvent; + type Identifier = Erc721Id; } pub type Block = sp_runtime::generic::Block; -pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; +pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic - { - System: system::{Pallet, Call, Event}, - Balances: balances::{Pallet, Call, Storage, Config, Event}, - Erc721: erc721::{Pallet, Call, Storage, Event}, - } + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: system::{Pallet, Call, Event}, + Balances: balances::{Pallet, Call, Storage, Config, Event}, + Erc721: erc721::{Pallet, Call, Storage, Event}, + } ); pub const USER_A: u64 = 0x1; @@ -99,12 +97,10 @@ pub const USER_C: u64 = 0x3; pub const ENDOWED_BALANCE: u64 = 100_000_000; pub fn new_test_ext() -> sp_io::TestExternalities { - GenesisConfig { - balances: balances::GenesisConfig { - balances: vec![(USER_A, ENDOWED_BALANCE)], - }, - } - .build_storage() - .unwrap() - .into() + GenesisConfig { + balances: balances::GenesisConfig { balances: vec![(USER_A, ENDOWED_BALANCE)] }, + } + .build_storage() + .unwrap() + .into() } diff --git a/pallets/erc721/src/tests.rs b/pallets/erc721/src/tests.rs index 416a71737..f273f83a3 100644 --- a/pallets/erc721/src/tests.rs +++ b/pallets/erc721/src/tests.rs @@ -1,99 +1,75 @@ #![cfg(test)] -use super::mock::{new_test_ext, Erc721, Origin, Test, USER_A, USER_B, USER_C}; -use super::*; +use super::{ + mock::{new_test_ext, Erc721, RuntimeOrigin, Test, USER_A, USER_B, USER_C}, + *, +}; use frame_support::{assert_noop, assert_ok}; use sp_core::U256; #[test] fn mint_burn_tokens() { - new_test_ext().execute_with(|| { - let id_a: U256 = 1.into(); - let id_b: U256 = 2.into(); - let metadata_a: Vec = vec![1, 2, 3]; - let metadata_b: Vec = vec![4, 5, 6]; + new_test_ext().execute_with(|| { + let id_a: U256 = 1.into(); + let id_b: U256 = 2.into(); + let metadata_a: Vec = vec![1, 2, 3]; + let metadata_b: Vec = vec![4, 5, 6]; - assert_ok!(Erc721::mint( - Origin::root(), - USER_A, - id_a, - metadata_a.clone() - )); - assert_eq!( - Erc721::tokens(id_a).unwrap(), - Erc721Token { - id: id_a, - metadata: metadata_a.clone() - } - ); - assert_eq!(Erc721::token_count(), 1.into()); - assert_noop!( - Erc721::mint(Origin::root(), USER_A, id_a, metadata_a.clone()), - Error::::TokenAlreadyExists - ); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone())); + assert_eq!( + Erc721::tokens(id_a).unwrap(), + Erc721Token { id: id_a, metadata: metadata_a.clone() } + ); + assert_eq!(Erc721::token_count(), 1.into()); + assert_noop!( + Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone()), + Error::::TokenAlreadyExists + ); - assert_ok!(Erc721::mint( - Origin::root(), - USER_A, - id_b, - metadata_b.clone() - )); - assert_eq!( - Erc721::tokens(id_b).unwrap(), - Erc721Token { - id: id_b, - metadata: metadata_b.clone() - } - ); - assert_eq!(Erc721::token_count(), 2.into()); - assert_noop!( - Erc721::mint(Origin::root(), USER_A, id_b, metadata_b.clone()), - Error::::TokenAlreadyExists - ); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone())); + assert_eq!( + Erc721::tokens(id_b).unwrap(), + Erc721Token { id: id_b, metadata: metadata_b.clone() } + ); + assert_eq!(Erc721::token_count(), 2.into()); + assert_noop!( + Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone()), + Error::::TokenAlreadyExists + ); - assert_ok!(Erc721::burn(Origin::root(), id_a)); - assert_eq!(Erc721::token_count(), 1.into()); - assert!(!::contains_key(&id_a)); - assert!(!>::contains_key(&id_a)); + assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_a)); + assert_eq!(Erc721::token_count(), 1.into()); + assert!(!::contains_key(&id_a)); + assert!(!>::contains_key(&id_a)); - assert_ok!(Erc721::burn(Origin::root(), id_b)); - assert_eq!(Erc721::token_count(), 0.into()); - assert!(!::contains_key(&id_b)); - assert!(!>::contains_key(&id_b)); - }) + assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_b)); + assert_eq!(Erc721::token_count(), 0.into()); + assert!(!::contains_key(&id_b)); + assert!(!>::contains_key(&id_b)); + }) } #[test] fn transfer_tokens() { - new_test_ext().execute_with(|| { - let id_a: U256 = 1.into(); - let id_b: U256 = 2.into(); - let metadata_a: Vec = vec![1, 2, 3]; - let metadata_b: Vec = vec![4, 5, 6]; + new_test_ext().execute_with(|| { + let id_a: U256 = 1.into(); + let id_b: U256 = 2.into(); + let metadata_a: Vec = vec![1, 2, 3]; + let metadata_b: Vec = vec![4, 5, 6]; - assert_ok!(Erc721::mint( - Origin::root(), - USER_A, - id_a, - metadata_a.clone() - )); - assert_ok!(Erc721::mint( - Origin::root(), - USER_A, - id_b, - metadata_b.clone() - )); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone())); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone())); - assert_ok!(Erc721::transfer(Origin::signed(USER_A), USER_B, id_a)); - assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B); + assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_B, id_a)); + assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B); - assert_ok!(Erc721::transfer(Origin::signed(USER_A), USER_C, id_b)); - assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_C); + assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_C, id_b)); + assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_C); - assert_ok!(Erc721::transfer(Origin::signed(USER_B), USER_A, id_a)); - assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_A); + assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_B), USER_A, id_a)); + assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_A); - assert_ok!(Erc721::transfer(Origin::signed(USER_C), USER_A, id_b)); - assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_A); - }) + assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_C), USER_A, id_b)); + assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_A); + }) } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 6fbcee84a..65de7e088 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -1,30 +1,30 @@ [package] name = "cere-rpc" -version = "4.7.0" +version = "4.8.0" edition = "2021" [dependencies] jsonrpsee = { version = "0.15.1", features = ["server"] } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-consensus-babe-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-consensus-epochs = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-finality-grandpa-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -substrate-state-trie-migration-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus-babe-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus-epochs = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-finality-grandpa-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-state-trie-migration-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index a47380803..9abf2af02 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -93,13 +93,13 @@ where B: sc_client_api::Backend + Send + Sync + 'static, B::State: sc_client_api::backend::StateBackend>, { - use pallet_contracts_rpc::{ContractsApiServer, Contracts}; - use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPayment}; - use sc_consensus_babe_rpc::{BabeApiServer, Babe}; + use pallet_contracts_rpc::{Contracts, ContractsApiServer}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use sc_consensus_babe_rpc::{Babe, BabeApiServer}; use sc_finality_grandpa_rpc::GrandpaApiServer; use sc_rpc::dev::{Dev, DevApiServer}; use sc_sync_state_rpc::{SyncState, SyncStateApiServer}; - use substrate_frame_rpc_system::{SystemApiServer, System}; + use substrate_frame_rpc_system::{System, SystemApiServer}; use substrate_state_trie_migration_rpc::StateMigrationApiServer; let mut io = RpcModule::new(()); @@ -148,8 +148,12 @@ where )?; io.merge( - substrate_state_trie_migration_rpc::StateMigration::new(client.clone(), backend, deny_unsafe) - .into_rpc(), + substrate_state_trie_migration_rpc::StateMigration::new( + client.clone(), + backend, + deny_unsafe, + ) + .into_rpc(), )?; io.merge(Dev::new(client, deny_unsafe).into_rpc())?; diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index a969e8de0..885bd1c58 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-dev-runtime" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" build = "build.rs" @@ -24,86 +24,87 @@ hex-literal = { version = "0.3.4", optional = true } log = { version = "0.4.16", default-features = false } # primitives -sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false, version = "4.0.0-dev" } -sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } +sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } -pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } -pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.29" } -pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false, optional = true } -pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } -pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false, optional = true } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.30" } +pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-dev-runtime-constants = { path = "./constants", default-features = false } -pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../../pallets/ddc-staking" } -pallet-chainbridge = { version = "4.7.0", default-features = false, path = "../../pallets/chainbridge" } -pallet-cere-ddc = { version = "4.7.0", default-features = false, path = "../../pallets/ddc" } -pallet-erc721 = { version = "4.7.0", default-features = false, path = "../../pallets/erc721" } -pallet-erc20 = { version = "4.7.0", default-features = false, path = "../../pallets/erc20" } -pallet-ddc-metrics-offchain-worker = { version = "4.7.0", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-staking = { version = "4.8.0", default-features = false, path = "../../pallets/ddc-staking" } +pallet-chainbridge = { version = "4.8.0", default-features = false, path = "../../pallets/chainbridge" } +pallet-cere-ddc = { version = "4.8.0", default-features = false, path = "../../pallets/ddc" } +pallet-erc721 = { version = "4.8.0", default-features = false, path = "../../pallets/erc721" } +pallet-erc20 = { version = "4.8.0", default-features = false, path = "../../pallets/erc20" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.0", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } [build-dependencies] -substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] @@ -125,6 +126,7 @@ std = [ "pallet-contracts-primitives/std", "pallet-contracts-rpc-runtime-api/std", "pallet-democracy/std", + "pallet-fast-unstake/std", "pallet-elections-phragmen/std", "frame-executive/std", "pallet-cere-ddc/std", @@ -197,6 +199,7 @@ runtime-benchmarks = [ "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-election-provider-support-benchmarking/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", + "pallet-fast-unstake/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-identity/runtime-benchmarks", "pallet-im-online/runtime-benchmarks", @@ -204,11 +207,11 @@ runtime-benchmarks = [ "pallet-membership/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nomination-pools/runtime-benchmarks", - "pallet-nomination-pools-benchmarking", - "pallet-offences-benchmarking", + "pallet-nomination-pools-benchmarking/runtime-benchmarks", + "pallet-offences-benchmarking/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", - "pallet-session-benchmarking", + "pallet-session-benchmarking/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-ddc-staking/runtime-benchmarks", @@ -217,7 +220,7 @@ runtime-benchmarks = [ "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", - "frame-system-benchmarking", + "frame-system-benchmarking/runtime-benchmarks", "hex-literal", ] try-runtime = [ @@ -236,6 +239,7 @@ try-runtime = [ "pallet-democracy/try-runtime", "pallet-election-provider-multi-phase/try-runtime", "pallet-elections-phragmen/try-runtime", + "pallet-fast-unstake/try-runtime", "pallet-grandpa/try-runtime", "pallet-identity/try-runtime", "pallet-im-online/try-runtime", diff --git a/runtime/cere-dev/constants/Cargo.toml b/runtime/cere-dev/constants/Cargo.toml index 84ab98517..68ca79a56 100644 --- a/runtime/cere-dev/constants/Cargo.toml +++ b/runtime/cere-dev/constants/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "cere-dev-runtime-constants" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" [dependencies] -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/runtime/cere-dev/src/impls.rs b/runtime/cere-dev/src/impls.rs index d23489fb8..dd38a6a1d 100644 --- a/runtime/cere-dev/src/impls.rs +++ b/runtime/cere-dev/src/impls.rs @@ -31,18 +31,18 @@ impl OnUnbalanced for Author { #[cfg(test)] mod multiplier_tests { + use crate::{ + AdjustmentVariable, MinimumMultiplier, Runtime, RuntimeBlockWeights as BlockWeights, + System, TargetBlockFullness, TransactionPayment, + }; + use cere_dev_runtime_constants::{currency::*, time::*}; + use frame_support::weights::{DispatchClass, Weight, WeightToFee as WeightToFeeT}; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_runtime::{ assert_eq_error_rate, traits::{Convert, One, Zero}, FixedPointNumber, }; - use cere_dev_runtime_constants::{currency::*, time::*}; - use crate::{ - AdjustmentVariable, MinimumMultiplier, Runtime, RuntimeBlockWeights as BlockWeights, - System, TargetBlockFullness, TransactionPayment, - }; - use frame_support::weights::{DispatchClass, Weight, WeightToFee as WeightToFeeT}; fn max_normal() -> Weight { BlockWeights::get() @@ -197,7 +197,8 @@ mod multiplier_tests { // `cargo test congested_chain_simulation -- --nocapture` to get some insight. // almost full. The entire quota of normal transactions is taken. - let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() - Weight::from_ref_time(100); + let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() - + Weight::from_ref_time(100); // Default substrate weight. let tx_weight = frame_support::weights::constants::ExtrinsicBaseWeight::get(); diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index f3806856c..439fcadb3 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -22,17 +22,18 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +use cere_runtime_common::{BalanceToU256, U256ToBalance}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ - onchain, ExtendedBalance, SequentialPhragmen, VoteWeight, BalancingConfig + onchain, BalancingConfig, ExtendedBalance, SequentialPhragmen, VoteWeight, }; use frame_support::{ construct_runtime, pallet_prelude::Get, parameter_types, traits::{ - ConstU16, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, - InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, + ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, + Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, }, weights::{ @@ -74,7 +75,7 @@ use sp_runtime::{ SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedU128, FixedPointNumber, Perbill, Percent, Permill, Perquintill, + ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, }; use sp_staking::EraIndex; use sp_std::prelude::*; @@ -82,7 +83,6 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use cere_runtime_common::{BalanceToU256, U256ToBalance}; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -130,10 +130,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 47000, + spec_version: 48000, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 4, + transaction_version: 5, state_version: 0, }; @@ -209,8 +209,8 @@ impl frame_system::Config for Runtime { type BlockWeights = RuntimeBlockWeights; type BlockLength = RuntimeBlockLength; type DbWeight = RocksDbWeight; - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = Index; type BlockNumber = BlockNumber; type Hash = Hash; @@ -218,7 +218,7 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; type Lookup = Indices; type Header = generic::Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = Version; type PalletInfo = PalletInfo; @@ -234,8 +234,8 @@ impl frame_system::Config for Runtime { impl pallet_randomness_collective_flip::Config for Runtime {} impl pallet_utility::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; type PalletsOrigin = OriginCaller; type WeightInfo = pallet_utility::weights::SubstrateWeight; } @@ -248,8 +248,8 @@ parameter_types! { } impl pallet_multisig::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; type Currency = Balances; type DepositBase = DepositBase; type DepositFactor = DepositFactor; @@ -291,25 +291,27 @@ impl Default for ProxyType { Self::Any } } -impl InstanceFilter for ProxyType { - fn filter(&self, c: &Call) -> bool { +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - Call::Balances(..) | - Call::Vesting(pallet_vesting::Call::vested_transfer { .. }) | - Call::Indices(pallet_indices::Call::transfer { .. }) | - Call::NominationPools(..) + RuntimeCall::Balances(..) | + RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) | + RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) | + RuntimeCall::NominationPools(..) ), ProxyType::Governance => matches!( c, - Call::Democracy(..) | - Call::Council(..) | Call::Society(..) | - Call::TechnicalCommittee(..) | - Call::Elections(..) | Call::Treasury(..) + RuntimeCall::Democracy(..) | + RuntimeCall::Council(..) | + RuntimeCall::Society(..) | + RuntimeCall::TechnicalCommittee(..) | + RuntimeCall::Elections(..) | + RuntimeCall::Treasury(..) ), - ProxyType::Staking => matches!(c, Call::Staking(..)), + ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)), } } fn is_superset(&self, o: &Self) -> bool { @@ -324,8 +326,8 @@ impl InstanceFilter for ProxyType { } impl pallet_proxy::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = ProxyType; type ProxyDepositBase = ProxyDepositBase; @@ -344,10 +346,10 @@ parameter_types! { } impl pallet_scheduler::Config for Runtime { - type Event = Event; - type Origin = Origin; + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type PalletsOrigin = OriginCaller; - type Call = Call; + type RuntimeCall = RuntimeCall; type MaximumWeight = MaximumSchedulerWeight; type ScheduleOrigin = EnsureRoot; type MaxScheduledPerBlock = ConstU32<50>; @@ -399,7 +401,7 @@ impl pallet_indices::Config for Runtime { type AccountIndex = AccountIndex; type Currency = Balances; type Deposit = IndexDeposit; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_indices::weights::SubstrateWeight; } @@ -417,7 +419,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type WeightInfo = pallet_balances::weights::SubstrateWeight; @@ -432,7 +434,7 @@ parameter_types! { } impl pallet_transaction_payment::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = IdentityFee; @@ -473,7 +475,7 @@ impl_opaque_keys! { } impl pallet_session::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ValidatorId = ::AccountId; type ValidatorIdOf = pallet_staking::StashOf; type ShouldEndSession = Babe; @@ -523,7 +525,7 @@ impl pallet_staking::Config for Runtime { type UnixTime = Timestamp; type CurrencyToVote = U128CurrencyToVote; type RewardRemainder = Treasury; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Slash = Treasury; // send the slashed funds to the treasury. type Reward = (); // rewards are minted from the void type SessionsPerEra = SessionsPerEra; @@ -542,12 +544,22 @@ impl pallet_staking::Config for Runtime { type ElectionProvider = ElectionProviderMultiPhase; type GenesisElectionProvider = onchain::UnboundedExecution; type VoterList = VoterList; + type TargetList = pallet_staking::UseValidatorsMap; type MaxUnlockingChunks = ConstU32<32>; + type HistoryDepth = frame_support::traits::ConstU32<84>; type OnStakerSlash = NominationPools; type WeightInfo = pallet_staking::weights::SubstrateWeight; type BenchmarkingConfig = StakingBenchmarkingConfig; } +impl pallet_fast_unstake::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ControlOrigin = frame_system::EnsureRoot; + type Deposit = ConstU128<{ DOLLARS }>; + type DepositCurrency = Balances; + type WeightInfo = (); +} + parameter_types! { // phase durations. 1/4 of the last session for each. pub const SignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; @@ -666,7 +678,7 @@ impl pallet_election_provider_multi_phase::MinerConfig for Runtime { } impl pallet_election_provider_multi_phase::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type EstimateCallFee = TransactionPayment; type SignedPhase = SignedPhase; @@ -701,8 +713,9 @@ parameter_types! { pub const BagThresholds: &'static [u64] = &voter_bags::THRESHOLDS; } -impl pallet_bags_list::Config for Runtime { - type Event = Event; +type VoterBagsListInstance = pallet_bags_list::Instance1; +impl pallet_bags_list::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type ScoreProvider = Staking; type WeightInfo = pallet_bags_list::weights::SubstrateWeight; type BagThresholds = BagThresholds; @@ -720,8 +733,8 @@ parameter_types! { } impl pallet_democracy::Config for Runtime { - type Proposal = Call; - type Event = Event; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type EnactmentPeriod = EnactmentPeriod; type LaunchPeriod = LaunchPeriod; @@ -778,9 +791,9 @@ parameter_types! { type CouncilCollective = pallet_collective::Instance1; impl pallet_collective::Config for Runtime { - type Origin = Origin; - type Proposal = Call; - type Event = Event; + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type MotionDuration = CouncilMotionDuration; type MaxProposals = CouncilMaxProposals; type MaxMembers = CouncilMaxMembers; @@ -805,7 +818,7 @@ parameter_types! { const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get()); impl pallet_elections_phragmen::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type PalletId = ElectionsPhragmenPalletId; type Currency = Balances; type ChangeMembers = Council; @@ -834,9 +847,9 @@ parameter_types! { type TechnicalCollective = pallet_collective::Instance2; impl pallet_collective::Config for Runtime { - type Origin = Origin; - type Proposal = Call; - type Event = Event; + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type MotionDuration = TechnicalMotionDuration; type MaxProposals = TechnicalMaxProposals; type MaxMembers = TechnicalMaxMembers; @@ -849,7 +862,7 @@ type EnsureRootOrHalfCouncil = EitherOfDiverse< pallet_collective::EnsureProportionMoreThan, >; impl pallet_membership::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type AddOrigin = EnsureRootOrHalfCouncil; type RemoveOrigin = EnsureRootOrHalfCouncil; type SwapOrigin = EnsureRootOrHalfCouncil; @@ -886,7 +899,7 @@ impl pallet_treasury::Config for Runtime { EnsureRoot, pallet_collective::EnsureProportionMoreThan, >; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type OnSlash = (); type ProposalBond = ProposalBond; type ProposalBondMinimum = ProposalBondMinimum; @@ -912,7 +925,7 @@ parameter_types! { } impl pallet_bounties::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BountyDepositBase = BountyDepositBase; type BountyDepositPayoutDelay = BountyDepositPayoutDelay; type BountyUpdatePeriod = BountyUpdatePeriod; @@ -931,14 +944,14 @@ parameter_types! { } impl pallet_child_bounties::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type MaxActiveChildBountyCount = ConstU32<5>; type ChildBountyValueMinimum = ChildBountyValueMinimum; type WeightInfo = pallet_child_bounties::weights::SubstrateWeight; } impl pallet_tips::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type DataDepositPerByte = DataDepositPerByte; type MaximumReasonLength = MaximumReasonLength; type Tippers = Elections; @@ -966,8 +979,8 @@ impl pallet_contracts::Config for Runtime { type Time = Timestamp; type Randomness = RandomnessCollectiveFlip; type Currency = Balances; - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; /// The safest default is to allow no calls at all. /// /// Runtimes should whitelist dispatchables that are allowed to be called from contracts @@ -987,13 +1000,12 @@ impl pallet_contracts::Config for Runtime { type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type ContractAccessWeight = pallet_contracts::DefaultContractAccessWeight; type MaxCodeLen = ConstU32<{ 128 * 1024 }>; - type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>; type MaxStorageKeyLen = ConstU32<128>; } impl pallet_sudo::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; } parameter_types! { @@ -1008,14 +1020,14 @@ parameter_types! { impl frame_system::offchain::CreateSignedTransaction for Runtime where - Call: From, + RuntimeCall: From, { fn create_transaction>( - call: Call, + call: RuntimeCall, public: ::Signer, account: AccountId, nonce: Index, - ) -> Option<(Call, ::SignaturePayload)> { + ) -> Option<(RuntimeCall, ::SignaturePayload)> { let tip = 0; // take the biggest period possible. let period = @@ -1055,15 +1067,15 @@ impl frame_system::offchain::SigningTypes for Runtime { impl frame_system::offchain::SendTransactionTypes for Runtime where - Call: From, + RuntimeCall: From, { type Extrinsic = UncheckedExtrinsic; - type OverarchingCall = Call; + type OverarchingCall = RuntimeCall; } impl pallet_im_online::Config for Runtime { type AuthorityId = ImOnlineId; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type NextSessionRotation = Babe; type ValidatorSet = Historical; type ReportUnresponsiveness = Offences; @@ -1075,7 +1087,7 @@ impl pallet_im_online::Config for Runtime { } impl pallet_offences::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; } @@ -1085,8 +1097,7 @@ impl pallet_authority_discovery::Config for Runtime { } impl pallet_grandpa::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; type KeyOwnerProofSystem = Historical; @@ -1118,7 +1129,7 @@ parameter_types! { } impl pallet_identity::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; type FieldDeposit = FieldDeposit; @@ -1140,9 +1151,9 @@ parameter_types! { } impl pallet_recovery::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_recovery::weights::SubstrateWeight; - type Call = Call; + type RuntimeCall = RuntimeCall; type Currency = Balances; type ConfigDepositBase = ConfigDepositBase; type FriendDepositFactor = FriendDepositFactor; @@ -1163,7 +1174,7 @@ parameter_types! { } impl pallet_society::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type PalletId = SocietyPalletId; type Currency = Balances; type Randomness = RandomnessCollectiveFlip; @@ -1186,7 +1197,7 @@ parameter_types! { } impl pallet_vesting::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BlockNumberToBalance = ConvertInto; type MinVestedTransfer = MinVestedTransfer; @@ -1208,7 +1219,7 @@ impl pallet_cere_ddc::Config for Runtime { type MinLength = MinDataLength; type MaxLength = MaxDataLength; // The ubiquitous event type. - type Event = Event; + type RuntimeEvent = RuntimeEvent; } parameter_types! { @@ -1218,9 +1229,9 @@ parameter_types! { /// Configure the send data pallet impl pallet_chainbridge::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type AdminOrigin = frame_system::EnsureRoot; - type Proposal = Call; + type Proposal = RuntimeCall; type ChainId = ChainId; type ProposalLifetime = ProposalLifetime; } @@ -1234,12 +1245,12 @@ parameter_types! { } impl pallet_erc721::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Identifier = NFTTokenId; } impl pallet_erc20::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BridgeOrigin = pallet_chainbridge::EnsureBridge; type Currency = pallet_balances::Pallet; type HashId = HashId; @@ -1258,7 +1269,7 @@ parameter_types! { } impl pallet_nomination_pools::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type CurrencyBalance = Balance; type RewardCounter = FixedU128; @@ -1301,8 +1312,8 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { type AuthorityId = pallet_ddc_metrics_offchain_worker::crypto::TestAuthId; - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; } parameter_types! { @@ -1319,7 +1330,7 @@ impl pallet_ddc_staking::Config for Runtime { type DefaultEdgeChillDelay = DefaultEdgeChillDelay; type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } @@ -1366,9 +1377,10 @@ construct_runtime!( Multisig: pallet_multisig, Bounties: pallet_bounties, Tips: pallet_tips, - VoterList: pallet_bags_list, + VoterList: pallet_bags_list::, ChildBounties: pallet_child_bounties, NominationPools: pallet_nomination_pools, + FastUnstake: pallet_fast_unstake, CereDDCModule: pallet_cere_ddc::{Pallet, Call, Storage, Event}, ChainBridge: pallet_chainbridge::{Pallet, Call, Storage, Event}, Erc721: pallet_erc721::{Pallet, Call, Storage, Event}, @@ -1403,12 +1415,21 @@ pub type SignedExtra = ( frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, ); + +pub struct StakingMigrationV11OldPallet; +impl Get<&'static str> for StakingMigrationV11OldPallet { + fn get() -> &'static str { + "VoterList" + } +} + /// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; /// The payload being signed in transactions. -pub type SignedPayload = generic::SignedPayload; +pub type SignedPayload = generic::SignedPayload; /// Extrinsic type that has already been checked. -pub type CheckedExtrinsic = generic::CheckedExtrinsic; +pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -1416,7 +1437,14 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (InitiateNominationPools, pallet_nomination_pools::migration::v3::MigrateToV3), + ( + pallet_staking::migrations::v11::MigrateToV11< + Runtime, + VoterList, + StakingMigrationV11OldPallet, + >, + pallet_staking::migrations::v12::MigrateToV12, + ), >; #[cfg(feature = "runtime-benchmarks")] @@ -1438,6 +1466,7 @@ mod benches { [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] [pallet_election_provider_support_benchmarking, EPSBench::] [pallet_elections_phragmen, Elections] + [pallet_fast_unstake, FastUnstake] [pallet_grandpa, Grandpa] [pallet_identity, Identity] [pallet_im_online, ImOnline] @@ -1670,13 +1699,13 @@ impl_runtime_apis! { } } - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi for Runtime { - fn query_call_info(call: Call, len: u32) -> RuntimeDispatchInfo { + fn query_call_info(call: RuntimeCall, len: u32) -> RuntimeDispatchInfo { TransactionPayment::query_call_info(call, len) } - fn query_call_fee_details(call: Call, len: u32) -> FeeDetails { + fn query_call_fee_details(call: RuntimeCall, len: u32) -> FeeDetails { TransactionPayment::query_call_fee_details(call, len) } } @@ -1817,7 +1846,7 @@ mod tests { fn validate_transaction_submitter_bounds() { fn is_submit_signed_transaction() where - T: CreateSignedTransaction, + T: CreateSignedTransaction, { } @@ -1837,11 +1866,11 @@ mod tests { #[test] fn call_size() { - let size = core::mem::size_of::(); + let size = core::mem::size_of::(); assert!( size <= 208, - "size of Call {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the - size of Call. + "size of RuntimeCall {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the + size of RuntimeCall. If the limit is too strong, maybe consider increase the limit to 300.", size, ); diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index dc0e26fa4..30c080f8f 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-runtime" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" build = "build.rs" @@ -24,85 +24,86 @@ hex-literal = { version = "0.3.4", optional = true } log = { version = "0.4.16", default-features = false } # primitives -sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false, version = "4.0.0-dev" } -sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } +sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", optional = true } -pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } -pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } -pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.29" } -pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false, optional = true } -pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false } -pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29", default-features = false, optional = true } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.30" } +pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-runtime-constants = { path = "./constants", default-features = false } -pallet-chainbridge = { version = "4.7.0", default-features = false, path = "../../pallets/chainbridge" } -pallet-cere-ddc = { version = "4.7.0", default-features = false, path = "../../pallets/ddc" } -pallet-erc721 = { version = "4.7.0", default-features = false, path = "../../pallets/erc721" } -pallet-erc20 = { version = "4.7.0", default-features = false, path = "../../pallets/erc20" } -pallet-ddc-metrics-offchain-worker = { version = "4.7.0", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-chainbridge = { version = "4.8.0", default-features = false, path = "../../pallets/chainbridge" } +pallet-cere-ddc = { version = "4.8.0", default-features = false, path = "../../pallets/ddc" } +pallet-erc721 = { version = "4.8.0", default-features = false, path = "../../pallets/erc721" } +pallet-erc20 = { version = "4.8.0", default-features = false, path = "../../pallets/erc20" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.0", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } [build-dependencies] -substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } +substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] @@ -124,6 +125,7 @@ std = [ "pallet-contracts-primitives/std", "pallet-contracts-rpc-runtime-api/std", "pallet-democracy/std", + "pallet-fast-unstake/std", "pallet-elections-phragmen/std", "frame-executive/std", "pallet-cere-ddc/std", @@ -195,6 +197,7 @@ runtime-benchmarks = [ "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-election-provider-support-benchmarking/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", + "pallet-fast-unstake/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-identity/runtime-benchmarks", "pallet-im-online/runtime-benchmarks", @@ -202,11 +205,11 @@ runtime-benchmarks = [ "pallet-membership/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nomination-pools/runtime-benchmarks", - "pallet-nomination-pools-benchmarking", - "pallet-offences-benchmarking", + "pallet-nomination-pools-benchmarking/runtime-benchmarks", + "pallet-offences-benchmarking/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", - "pallet-session-benchmarking", + "pallet-session-benchmarking/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", @@ -214,7 +217,7 @@ runtime-benchmarks = [ "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", - "frame-system-benchmarking", + "frame-system-benchmarking/runtime-benchmarks", "hex-literal", ] try-runtime = [ @@ -233,6 +236,7 @@ try-runtime = [ "pallet-democracy/try-runtime", "pallet-election-provider-multi-phase/try-runtime", "pallet-elections-phragmen/try-runtime", + "pallet-fast-unstake/try-runtime", "pallet-grandpa/try-runtime", "pallet-identity/try-runtime", "pallet-im-online/try-runtime", diff --git a/runtime/cere/constants/Cargo.toml b/runtime/cere/constants/Cargo.toml index d43ceedc5..cfbde8792 100644 --- a/runtime/cere/constants/Cargo.toml +++ b/runtime/cere/constants/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "cere-runtime-constants" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" [dependencies] -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/runtime/cere/src/impls.rs b/runtime/cere/src/impls.rs index 9d2b654b0..9597162dc 100644 --- a/runtime/cere/src/impls.rs +++ b/runtime/cere/src/impls.rs @@ -31,18 +31,18 @@ impl OnUnbalanced for Author { #[cfg(test)] mod multiplier_tests { + use crate::{ + AdjustmentVariable, MinimumMultiplier, Runtime, RuntimeBlockWeights as BlockWeights, + System, TargetBlockFullness, TransactionPayment, + }; + use cere_runtime_constants::{currency::*, time::*}; + use frame_support::weights::{DispatchClass, Weight, WeightToFee as WeightToFeeT}; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_runtime::{ assert_eq_error_rate, traits::{Convert, One, Zero}, FixedPointNumber, }; - use cere_runtime_constants::{currency::*, time::*}; - use crate::{ - AdjustmentVariable, MinimumMultiplier, Runtime, RuntimeBlockWeights as BlockWeights, - System, TargetBlockFullness, TransactionPayment, - }; - use frame_support::weights::{DispatchClass, Weight, WeightToFee as WeightToFeeT}; fn max_normal() -> Weight { BlockWeights::get() @@ -197,7 +197,8 @@ mod multiplier_tests { // `cargo test congested_chain_simulation -- --nocapture` to get some insight. // almost full. The entire quota of normal transactions is taken. - let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() - Weight::from_ref_time(100); + let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() - + Weight::from_ref_time(100); // Default substrate weight. let tx_weight = frame_support::weights::constants::ExtrinsicBaseWeight::get(); diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index bdfe7eeff..33150f46f 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -22,17 +22,18 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +use cere_runtime_common::{BalanceToU256, U256ToBalance}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ - onchain, ExtendedBalance, SequentialPhragmen, VoteWeight, BalancingConfig + onchain, BalancingConfig, ExtendedBalance, SequentialPhragmen, VoteWeight, }; use frame_support::{ construct_runtime, pallet_prelude::Get, parameter_types, traits::{ - ConstU16, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, - InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, + ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, + Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, }, weights::{ @@ -73,14 +74,13 @@ use sp_runtime::{ SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedU128, FixedPointNumber, Perbill, Percent, Permill, Perquintill, + ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, }; use sp_std::prelude::*; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use cere_runtime_common::{BalanceToU256, U256ToBalance}; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -128,10 +128,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 47000, + spec_version: 48000, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 4, + transaction_version: 5, state_version: 0, }; @@ -207,8 +207,8 @@ impl frame_system::Config for Runtime { type BlockWeights = RuntimeBlockWeights; type BlockLength = RuntimeBlockLength; type DbWeight = RocksDbWeight; - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = Index; type BlockNumber = BlockNumber; type Hash = Hash; @@ -216,7 +216,7 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; type Lookup = Indices; type Header = generic::Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = Version; type PalletInfo = PalletInfo; @@ -232,8 +232,8 @@ impl frame_system::Config for Runtime { impl pallet_randomness_collective_flip::Config for Runtime {} impl pallet_utility::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; type PalletsOrigin = OriginCaller; type WeightInfo = pallet_utility::weights::SubstrateWeight; } @@ -246,8 +246,8 @@ parameter_types! { } impl pallet_multisig::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; type Currency = Balances; type DepositBase = DepositBase; type DepositFactor = DepositFactor; @@ -289,25 +289,27 @@ impl Default for ProxyType { Self::Any } } -impl InstanceFilter for ProxyType { - fn filter(&self, c: &Call) -> bool { +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - Call::Balances(..) | - Call::Vesting(pallet_vesting::Call::vested_transfer { .. }) | - Call::Indices(pallet_indices::Call::transfer { .. }) | - Call::NominationPools(..) + RuntimeCall::Balances(..) | + RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) | + RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) | + RuntimeCall::NominationPools(..) ), ProxyType::Governance => matches!( c, - Call::Democracy(..) | - Call::Council(..) | Call::Society(..) | - Call::TechnicalCommittee(..) | - Call::Elections(..) | Call::Treasury(..) + RuntimeCall::Democracy(..) | + RuntimeCall::Council(..) | + RuntimeCall::Society(..) | + RuntimeCall::TechnicalCommittee(..) | + RuntimeCall::Elections(..) | + RuntimeCall::Treasury(..) ), - ProxyType::Staking => matches!(c, Call::Staking(..)), + ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)), } } fn is_superset(&self, o: &Self) -> bool { @@ -322,8 +324,8 @@ impl InstanceFilter for ProxyType { } impl pallet_proxy::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = ProxyType; type ProxyDepositBase = ProxyDepositBase; @@ -342,10 +344,10 @@ parameter_types! { } impl pallet_scheduler::Config for Runtime { - type Event = Event; - type Origin = Origin; + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type PalletsOrigin = OriginCaller; - type Call = Call; + type RuntimeCall = RuntimeCall; type MaximumWeight = MaximumSchedulerWeight; type ScheduleOrigin = EnsureRoot; type MaxScheduledPerBlock = ConstU32<50>; @@ -397,7 +399,7 @@ impl pallet_indices::Config for Runtime { type AccountIndex = AccountIndex; type Currency = Balances; type Deposit = IndexDeposit; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_indices::weights::SubstrateWeight; } @@ -415,7 +417,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type WeightInfo = pallet_balances::weights::SubstrateWeight; @@ -430,7 +432,7 @@ parameter_types! { } impl pallet_transaction_payment::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = IdentityFee; @@ -471,7 +473,7 @@ impl_opaque_keys! { } impl pallet_session::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ValidatorId = ::AccountId; type ValidatorIdOf = pallet_staking::StashOf; type ShouldEndSession = Babe; @@ -506,6 +508,7 @@ parameter_types! { pub const MaxNominatorRewardedPerValidator: u32 = 256; pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); pub OffchainRepeat: BlockNumber = 5; + pub HistoryDepth: u32 = 84; } pub struct StakingBenchmarkingConfig; @@ -521,7 +524,7 @@ impl pallet_staking::Config for Runtime { type UnixTime = Timestamp; type CurrencyToVote = U128CurrencyToVote; type RewardRemainder = Treasury; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Slash = Treasury; // send the slashed funds to the treasury. type Reward = (); // rewards are minted from the void type SessionsPerEra = SessionsPerEra; @@ -540,12 +543,22 @@ impl pallet_staking::Config for Runtime { type ElectionProvider = ElectionProviderMultiPhase; type GenesisElectionProvider = onchain::UnboundedExecution; type VoterList = VoterList; + type TargetList = pallet_staking::UseValidatorsMap; type MaxUnlockingChunks = ConstU32<32>; + type HistoryDepth = HistoryDepth; type OnStakerSlash = NominationPools; type WeightInfo = pallet_staking::weights::SubstrateWeight; type BenchmarkingConfig = StakingBenchmarkingConfig; } +impl pallet_fast_unstake::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ControlOrigin = frame_system::EnsureRoot; + type Deposit = ConstU128<{ DOLLARS }>; + type DepositCurrency = Balances; + type WeightInfo = (); +} + parameter_types! { // phase durations. 1/4 of the last session for each. pub const SignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; @@ -664,7 +677,7 @@ impl pallet_election_provider_multi_phase::MinerConfig for Runtime { } impl pallet_election_provider_multi_phase::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type EstimateCallFee = TransactionPayment; type SignedPhase = SignedPhase; @@ -699,8 +712,9 @@ parameter_types! { pub const BagThresholds: &'static [u64] = &voter_bags::THRESHOLDS; } -impl pallet_bags_list::Config for Runtime { - type Event = Event; +type VoterBagsListInstance = pallet_bags_list::Instance1; +impl pallet_bags_list::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type ScoreProvider = Staking; type WeightInfo = pallet_bags_list::weights::SubstrateWeight; type BagThresholds = BagThresholds; @@ -718,8 +732,8 @@ parameter_types! { } impl pallet_democracy::Config for Runtime { - type Proposal = Call; - type Event = Event; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type EnactmentPeriod = EnactmentPeriod; type LaunchPeriod = LaunchPeriod; @@ -776,9 +790,9 @@ parameter_types! { type CouncilCollective = pallet_collective::Instance1; impl pallet_collective::Config for Runtime { - type Origin = Origin; - type Proposal = Call; - type Event = Event; + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type MotionDuration = CouncilMotionDuration; type MaxProposals = CouncilMaxProposals; type MaxMembers = CouncilMaxMembers; @@ -803,7 +817,7 @@ parameter_types! { const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get()); impl pallet_elections_phragmen::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type PalletId = ElectionsPhragmenPalletId; type Currency = Balances; type ChangeMembers = Council; @@ -832,9 +846,9 @@ parameter_types! { type TechnicalCollective = pallet_collective::Instance2; impl pallet_collective::Config for Runtime { - type Origin = Origin; - type Proposal = Call; - type Event = Event; + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; type MotionDuration = TechnicalMotionDuration; type MaxProposals = TechnicalMaxProposals; type MaxMembers = TechnicalMaxMembers; @@ -847,7 +861,7 @@ type EnsureRootOrHalfCouncil = EitherOfDiverse< pallet_collective::EnsureProportionMoreThan, >; impl pallet_membership::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type AddOrigin = EnsureRootOrHalfCouncil; type RemoveOrigin = EnsureRootOrHalfCouncil; type SwapOrigin = EnsureRootOrHalfCouncil; @@ -884,7 +898,7 @@ impl pallet_treasury::Config for Runtime { EnsureRoot, pallet_collective::EnsureProportionMoreThan, >; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type OnSlash = (); type ProposalBond = ProposalBond; type ProposalBondMinimum = ProposalBondMinimum; @@ -910,7 +924,7 @@ parameter_types! { } impl pallet_bounties::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BountyDepositBase = BountyDepositBase; type BountyDepositPayoutDelay = BountyDepositPayoutDelay; type BountyUpdatePeriod = BountyUpdatePeriod; @@ -929,14 +943,14 @@ parameter_types! { } impl pallet_child_bounties::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type MaxActiveChildBountyCount = ConstU32<5>; type ChildBountyValueMinimum = ChildBountyValueMinimum; type WeightInfo = pallet_child_bounties::weights::SubstrateWeight; } impl pallet_tips::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type DataDepositPerByte = DataDepositPerByte; type MaximumReasonLength = MaximumReasonLength; type Tippers = Elections; @@ -964,8 +978,8 @@ impl pallet_contracts::Config for Runtime { type Time = Timestamp; type Randomness = RandomnessCollectiveFlip; type Currency = Balances; - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; /// The safest default is to allow no calls at all. /// /// Runtimes should whitelist dispatchables that are allowed to be called from contracts @@ -985,13 +999,12 @@ impl pallet_contracts::Config for Runtime { type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type ContractAccessWeight = pallet_contracts::DefaultContractAccessWeight; type MaxCodeLen = ConstU32<{ 128 * 1024 }>; - type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>; type MaxStorageKeyLen = ConstU32<128>; } impl pallet_sudo::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; } parameter_types! { @@ -1006,14 +1019,14 @@ parameter_types! { impl frame_system::offchain::CreateSignedTransaction for Runtime where - Call: From, + RuntimeCall: From, { fn create_transaction>( - call: Call, + call: RuntimeCall, public: ::Signer, account: AccountId, nonce: Index, - ) -> Option<(Call, ::SignaturePayload)> { + ) -> Option<(RuntimeCall, ::SignaturePayload)> { let tip = 0; // take the biggest period possible. let period = @@ -1053,15 +1066,15 @@ impl frame_system::offchain::SigningTypes for Runtime { impl frame_system::offchain::SendTransactionTypes for Runtime where - Call: From, + RuntimeCall: From, { type Extrinsic = UncheckedExtrinsic; - type OverarchingCall = Call; + type OverarchingCall = RuntimeCall; } impl pallet_im_online::Config for Runtime { type AuthorityId = ImOnlineId; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type NextSessionRotation = Babe; type ValidatorSet = Historical; type ReportUnresponsiveness = Offences; @@ -1073,7 +1086,7 @@ impl pallet_im_online::Config for Runtime { } impl pallet_offences::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; } @@ -1083,8 +1096,7 @@ impl pallet_authority_discovery::Config for Runtime { } impl pallet_grandpa::Config for Runtime { - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; type KeyOwnerProofSystem = Historical; @@ -1116,7 +1128,7 @@ parameter_types! { } impl pallet_identity::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; type FieldDeposit = FieldDeposit; @@ -1138,9 +1150,9 @@ parameter_types! { } impl pallet_recovery::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_recovery::weights::SubstrateWeight; - type Call = Call; + type RuntimeCall = RuntimeCall; type Currency = Balances; type ConfigDepositBase = ConfigDepositBase; type FriendDepositFactor = FriendDepositFactor; @@ -1161,7 +1173,7 @@ parameter_types! { } impl pallet_society::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type PalletId = SocietyPalletId; type Currency = Balances; type Randomness = RandomnessCollectiveFlip; @@ -1184,7 +1196,7 @@ parameter_types! { } impl pallet_vesting::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BlockNumberToBalance = ConvertInto; type MinVestedTransfer = MinVestedTransfer; @@ -1206,7 +1218,7 @@ impl pallet_cere_ddc::Config for Runtime { type MinLength = MinDataLength; type MaxLength = MaxDataLength; // The ubiquitous event type. - type Event = Event; + type RuntimeEvent = RuntimeEvent; } parameter_types! { @@ -1216,9 +1228,9 @@ parameter_types! { /// Configure the send data pallet impl pallet_chainbridge::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type AdminOrigin = frame_system::EnsureRoot; - type Proposal = Call; + type Proposal = RuntimeCall; type ChainId = ChainId; type ProposalLifetime = ProposalLifetime; } @@ -1232,12 +1244,12 @@ parameter_types! { } impl pallet_erc721::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Identifier = NFTTokenId; } impl pallet_erc20::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BridgeOrigin = pallet_chainbridge::EnsureBridge; type Currency = pallet_balances::Pallet; type HashId = HashId; @@ -1256,7 +1268,7 @@ parameter_types! { } impl pallet_nomination_pools::Config for Runtime { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type CurrencyBalance = Balance; type RewardCounter = FixedU128; @@ -1299,8 +1311,8 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { type AuthorityId = pallet_ddc_metrics_offchain_worker::crypto::TestAuthId; - type Event = Event; - type Call = Call; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; } construct_runtime!( @@ -1345,9 +1357,10 @@ construct_runtime!( Multisig: pallet_multisig, Bounties: pallet_bounties, Tips: pallet_tips, - VoterList: pallet_bags_list, + VoterList: pallet_bags_list::, ChildBounties: pallet_child_bounties, NominationPools: pallet_nomination_pools, + FastUnstake: pallet_fast_unstake, CereDDCModule: pallet_cere_ddc::{Pallet, Call, Storage, Event}, ChainBridge: pallet_chainbridge::{Pallet, Call, Storage, Event}, Erc721: pallet_erc721::{Pallet, Call, Storage, Event}, @@ -1381,12 +1394,21 @@ pub type SignedExtra = ( frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, ); + +pub struct StakingMigrationV11OldPallet; +impl Get<&'static str> for StakingMigrationV11OldPallet { + fn get() -> &'static str { + "VoterList" + } +} + /// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; /// The payload being signed in transactions. -pub type SignedPayload = generic::SignedPayload; +pub type SignedPayload = generic::SignedPayload; /// Extrinsic type that has already been checked. -pub type CheckedExtrinsic = generic::CheckedExtrinsic; +pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -1394,7 +1416,14 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (InitiateNominationPools, pallet_nomination_pools::migration::v3::MigrateToV3), + ( + pallet_staking::migrations::v11::MigrateToV11< + Runtime, + VoterList, + StakingMigrationV11OldPallet, + >, + pallet_staking::migrations::v12::MigrateToV12, + ), >; #[cfg(feature = "runtime-benchmarks")] @@ -1416,6 +1445,7 @@ mod benches { [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] [pallet_election_provider_support_benchmarking, EPSBench::] [pallet_elections_phragmen, Elections] + [pallet_fast_unstake, FastUnstake] [pallet_grandpa, Grandpa] [pallet_identity, Identity] [pallet_im_online, ImOnline] @@ -1647,13 +1677,13 @@ impl_runtime_apis! { } } - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi for Runtime { - fn query_call_info(call: Call, len: u32) -> RuntimeDispatchInfo { + fn query_call_info(call: RuntimeCall, len: u32) -> RuntimeDispatchInfo { TransactionPayment::query_call_info(call, len) } - fn query_call_fee_details(call: Call, len: u32) -> FeeDetails { + fn query_call_fee_details(call: RuntimeCall, len: u32) -> FeeDetails { TransactionPayment::query_call_fee_details(call, len) } } @@ -1794,7 +1824,7 @@ mod tests { fn validate_transaction_submitter_bounds() { fn is_submit_signed_transaction() where - T: CreateSignedTransaction, + T: CreateSignedTransaction, { } @@ -1814,11 +1844,11 @@ mod tests { #[test] fn call_size() { - let size = core::mem::size_of::(); + let size = core::mem::size_of::(); assert!( size <= 208, - "size of Call {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the - size of Call. + "size of RuntimeCall {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the + size of RuntimeCall. If the limit is too strong, maybe consider increase the limit to 300.", size, ); diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 4bb9ac00c..0871c1d68 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-runtime-common" -version = "4.7.0" +version = "4.8.0" authors = ["Parity Technologies "] edition = "2021" @@ -10,7 +10,7 @@ no_std = [] std = [] [dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.29" } -frame-support = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.29" } -sp-core = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.29" } -node-primitives = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.29" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +frame-support = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } +node-primitives = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 4a322d5e4..03d133233 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -1,20 +1,20 @@ #![cfg_attr(not(feature = "std"), no_std)] -use node_primitives::{Balance}; +use node_primitives::Balance; /// Convert a balance to an unsigned 256-bit number, use in nomination pools. pub struct BalanceToU256; impl sp_runtime::traits::Convert for BalanceToU256 { - fn convert(n: Balance) -> sp_core::U256 { - n.into() - } + fn convert(n: Balance) -> sp_core::U256 { + n.into() + } } /// Convert an unsigned 256-bit number to balance, use in nomination pools. pub struct U256ToBalance; impl sp_runtime::traits::Convert for U256ToBalance { - fn convert(n: sp_core::U256) -> Balance { - use frame_support::traits::Defensive; - n.try_into().defensive_unwrap_or(Balance::MAX) - } + fn convert(n: sp_core::U256) -> Balance { + use frame_support::traits::Defensive; + n.try_into().defensive_unwrap_or(Balance::MAX) + } } diff --git a/scripts/init.sh b/scripts/init.sh index 0d2354d27..beca622b2 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -7,3 +7,5 @@ echo "*** Initializing WASM build environment" rustup install nightly-2022-10-09 rustup target add wasm32-unknown-unknown --toolchain nightly-2022-10-09 + +ln -sf $PWD/scripts/pre-commit.sh $PWD/.git/hooks/pre-commit || true diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 000000000..d84399d28 --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Prevent committing badly formatted code +cargo +nightly fmt -- --check +if [ $? -ne 0 ]; then + echo "Run \`cargo +nightly fmt\` to fix formatting issues before committing." + exit 1 +fi From c21ced4daa60fd6e626339b150becd759460ac9d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 14 Aug 2023 14:55:04 +0600 Subject: [PATCH 239/544] Get DDC era from DDC staking pallet --- pallets/ddc-validator/src/lib.rs | 50 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 98c7dcf45..a4f92d645 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -266,17 +266,24 @@ pub mod pallet { Signal::::set(Some(false)); - let era = Self::get_current_era(); - log::info!("current era: {:?}", era); + let current_ddc_era = match ddc_staking::pallet::Pallet::::current_era() { + Some(era) => era, + None => { + defensive!("DDC era not set"); + return Weight::from_ref_time(0) + }, + }; + log::info!("current DDC era: {:?}", current_ddc_era); // Produce an assignment for the next era if it's not produced yet. match Self::last_managed_era() { - Some(last_managed_era) if era < last_managed_era => return Weight::from_ref_time(0), + Some(last_managed_era) if current_ddc_era < last_managed_era => + return Weight::from_ref_time(0), _ => (), }; - match Self::assign(3usize, era + 1) { - Ok(_) => >::put(era + 1), + match Self::assign(3usize, current_ddc_era + 1) { + Ok(_) => >::put(current_ddc_era + 1), Err(AssignmentError::DefensiveEmptyQuorumsCycle) => { defensive!("unexpectedly empty quorums cycle"); }, @@ -308,10 +315,16 @@ pub mod pallet { _ => 0, // let's consider an absent or undecodable data as we never did a validation }; - let current_era = Self::get_current_era(); + let current_ddc_era = match ddc_staking::pallet::Pallet::::current_era() { + Some(era) => era, + None => { + defensive!("DDC era not set"); + return + }, + }; // Skip if the validation is already complete for the era. - if current_era <= last_validated_era { + if current_ddc_era <= last_validated_era { should_validate_because_new_era = false; } @@ -486,14 +499,6 @@ pub mod pallet { Ok(signer) } - // Get the current era; Shall we start era count from 0 or from 1? - fn get_current_era() -> EraIndex { - ((::TimeProvider::now().as_millis() - TIME_START_MS) / - ERA_DURATION_MS) - .try_into() - .unwrap() - } - fn validate(bytes_sent: &dac::BytesSent, bytes_received: &dac::BytesReceived) -> bool { let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); @@ -668,7 +673,8 @@ pub mod pallet { } fn validate_edges() -> Result<(), &'static str> { - let current_era = Self::get_current_era(); + let current_ddc_era = + ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; let mock_data_url = Self::get_mock_data_url(); let data_provider_url = Self::get_data_provider_url(); info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); @@ -679,7 +685,7 @@ pub mod pallet { info!("validator: {:?}", validator); - let assigned_edges = Self::assignments(current_era - 1, validator.clone()) + let assigned_edges = Self::assignments(current_ddc_era - 1, validator.clone()) .expect("No assignments for the previous era"); info!("assigned_edges: {:?}", assigned_edges); @@ -692,7 +698,7 @@ pub mod pallet { "{}{}{}/$.{}", mock_data_url, "ddc:dac:aggregation:nodes:", - current_era - 1, + current_ddc_era - 1, utils::account_to_string::(assigned_edge.clone()) ); info!("edge url: {:?}", edge_url); @@ -748,7 +754,7 @@ pub mod pallet { let response = shm::share_intermediate_validation_result( &data_provider_url, - current_era - 1, + current_ddc_era - 1, &validator_str, &edge_str, is_valid, @@ -765,7 +771,7 @@ pub mod pallet { if let Ok(res) = response { let edge = utils::account_to_string::(assigned_edge.clone()); - let prev_era = (current_era - 1) as EraIndex; + let prev_era = (current_ddc_era - 1) as EraIndex; let quorum = Self::find_validators_from_quorum(&validator, &prev_era); let validations_res = shm::get_intermediate_decisions( &data_provider_url, @@ -803,7 +809,7 @@ pub mod pallet { }); let _payout_tx_res = signer.send_signed_transaction(|_account| { - Call::payout_cdn_owners { era: current_era } + Call::payout_cdn_owners { era: current_ddc_era } }); let final_res = dac::get_final_decision(validations_res); @@ -812,7 +818,7 @@ pub mod pallet { let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era, + era: current_ddc_era, cdn_node: utils::string_to_account::(edge.clone()), validation_decision: final_res.clone(), }); From 4a358b46b8bbba68ebbd4b93e8f34c4f6b9aae95 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 14 Aug 2023 15:37:44 +0600 Subject: [PATCH 240/544] Prevent OCW panic on validator's key absence --- pallets/ddc-validator/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index a4f92d645..31bae53c0 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -681,7 +681,10 @@ pub mod pallet { // let signer = Self::get_signer().unwrap(); // let validator = signer.get_any_account().unwrap().id; - let validator = Self::get_public_key().unwrap(); + let validator = match Self::get_public_key() { + Some(key) => key, + None => return Err("No validator public key found."), + }; info!("validator: {:?}", validator); From dafb2e8debb9349550db420dee94c5619fe5856a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 14 Aug 2023 16:07:13 +0600 Subject: [PATCH 241/544] Log warning with DDC validation error --- pallets/ddc-validator/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 31bae53c0..0d0a08da4 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -332,7 +332,10 @@ pub mod pallet { let should_validate_because_signal = Signal::::get().unwrap_or(false); if should_validate_because_new_era || should_validate_because_signal { - Self::validate_edges(); + let validation_result = Self::validate_edges(); + if let Err(e) = validation_result { + log::warn!("🔎 DDC validation failed. {}", e); + } } } } From 7418abb57ba466281e12d21289f817050c5daa8a Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 18 Jul 2023 16:18:58 +0200 Subject: [PATCH 242/544] Fix contracts dissapearing --- runtime/cere-dev/src/lib.rs | 1 + runtime/cere/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 439fcadb3..c71b6c699 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1444,6 +1444,7 @@ pub type Executive = frame_executive::Executive< StakingMigrationV11OldPallet, >, pallet_staking::migrations::v12::MigrateToV12, + pallet_contracts::Migration, ), >; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 33150f46f..bfd41e3b5 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -1423,6 +1423,7 @@ pub type Executive = frame_executive::Executive< StakingMigrationV11OldPallet, >, pallet_staking::migrations::v12::MigrateToV12, + pallet_contracts::Migration, ), >; From 7aace6503944e7eacada5f6d5c267488e7c5ff6b Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 14 Aug 2023 13:08:50 +0200 Subject: [PATCH 243/544] Bump version --- CHANGELOG.md | 6 ++++ Cargo.lock | 32 +++++++++---------- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- node/client/Cargo.toml | 2 +- node/service/Cargo.toml | 2 +- pallets/chainbridge/Cargo.toml | 2 +- .../ddc-metrics-offchain-worker/Cargo.toml | 2 +- pallets/ddc-staking/Cargo.toml | 2 +- pallets/ddc/Cargo.toml | 2 +- pallets/erc20/Cargo.toml | 2 +- pallets/erc721/Cargo.toml | 2 +- rpc/Cargo.toml | 2 +- runtime/cere-dev/Cargo.toml | 14 ++++---- runtime/cere-dev/constants/Cargo.toml | 2 +- runtime/cere-dev/src/lib.rs | 2 +- runtime/cere/Cargo.toml | 12 +++---- runtime/cere/constants/Cargo.toml | 2 +- runtime/cere/src/lib.rs | 2 +- runtime/common/Cargo.toml | 2 +- 20 files changed, 51 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9122f8269..e378bf759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ... +## [4.8.1] + +### Added + +- [C,D] Contract migration + ## [4.8.0] ### Added diff --git a/Cargo.lock b/Cargo.lock index 8b70b378c..004f09538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -725,7 +725,7 @@ dependencies = [ [[package]] name = "cere" -version = "4.8.0" +version = "4.8.1" dependencies = [ "cere-cli", "sc-cli", @@ -735,7 +735,7 @@ dependencies = [ [[package]] name = "cere-cli" -version = "4.8.0" +version = "4.8.1" dependencies = [ "cere-client", "cere-service", @@ -749,7 +749,7 @@ dependencies = [ [[package]] name = "cere-client" -version = "4.8.0" +version = "4.8.1" dependencies = [ "cere-dev-runtime", "cere-runtime", @@ -784,7 +784,7 @@ dependencies = [ [[package]] name = "cere-dev-runtime" -version = "4.8.0" +version = "4.8.1" dependencies = [ "cere-dev-runtime-constants", "cere-runtime-common", @@ -872,7 +872,7 @@ dependencies = [ [[package]] name = "cere-dev-runtime-constants" -version = "4.8.0" +version = "4.8.1" dependencies = [ "node-primitives", "sp-runtime", @@ -880,7 +880,7 @@ dependencies = [ [[package]] name = "cere-rpc" -version = "4.8.0" +version = "4.8.1" dependencies = [ "jsonrpsee", "node-primitives", @@ -910,7 +910,7 @@ dependencies = [ [[package]] name = "cere-runtime" -version = "4.8.0" +version = "4.8.1" dependencies = [ "cere-runtime-common", "cere-runtime-constants", @@ -997,7 +997,7 @@ dependencies = [ [[package]] name = "cere-runtime-common" -version = "4.8.0" +version = "4.8.1" dependencies = [ "frame-support", "node-primitives", @@ -1007,7 +1007,7 @@ dependencies = [ [[package]] name = "cere-runtime-constants" -version = "4.8.0" +version = "4.8.1" dependencies = [ "node-primitives", "sp-runtime", @@ -1015,7 +1015,7 @@ dependencies = [ [[package]] name = "cere-service" -version = "4.8.0" +version = "4.8.1" dependencies = [ "cere-client", "cere-dev-runtime", @@ -4677,7 +4677,7 @@ dependencies = [ [[package]] name = "pallet-cere-ddc" -version = "4.8.0" +version = "4.8.1" dependencies = [ "frame-support", "frame-system", @@ -4692,7 +4692,7 @@ dependencies = [ [[package]] name = "pallet-chainbridge" -version = "4.8.0" +version = "4.8.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -4829,7 +4829,7 @@ dependencies = [ [[package]] name = "pallet-ddc-metrics-offchain-worker" -version = "4.8.0" +version = "4.8.1" dependencies = [ "alt_serde", "frame-support", @@ -4855,7 +4855,7 @@ dependencies = [ [[package]] name = "pallet-ddc-staking" -version = "4.8.0" +version = "4.8.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -4946,7 +4946,7 @@ dependencies = [ [[package]] name = "pallet-erc20" -version = "4.8.0" +version = "4.8.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -4966,7 +4966,7 @@ dependencies = [ [[package]] name = "pallet-erc721" -version = "4.8.0" +version = "4.8.1" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index 7be78ede0..21bfbe271 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ path = "src/main.rs" [package] name = "cere" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" -version = "4.8.0" +version = "4.8.1" edition = "2021" build = "build.rs" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4d1fe40d0..460371d3c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-cli" -version = "4.8.0" +version = "4.8.1" edition = "2021" [package.metadata.wasm-pack.profile.release] diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index eb4f2be13..dbafa5fa8 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-client" -version = "4.8.0" +version = "4.8.1" edition = "2021" [dependencies] diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 65c79d982..d444e3244 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-service" -version = "4.8.0" +version = "4.8.1" edition = "2021" [dependencies] diff --git a/pallets/chainbridge/Cargo.toml b/pallets/chainbridge/Cargo.toml index b1f2b953a..de714f861 100644 --- a/pallets/chainbridge/Cargo.toml +++ b/pallets/chainbridge/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-chainbridge" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" diff --git a/pallets/ddc-metrics-offchain-worker/Cargo.toml b/pallets/ddc-metrics-offchain-worker/Cargo.toml index e9de68b71..74747a397 100644 --- a/pallets/ddc-metrics-offchain-worker/Cargo.toml +++ b/pallets/ddc-metrics-offchain-worker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ddc-metrics-offchain-worker" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index c5a4e6873..ce16ead54 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ddc-staking" -version = "4.8.0" +version = "4.8.1" edition = "2021" [dependencies] diff --git a/pallets/ddc/Cargo.toml b/pallets/ddc/Cargo.toml index c15ee4ac7..9c89014d1 100644 --- a/pallets/ddc/Cargo.toml +++ b/pallets/ddc/Cargo.toml @@ -6,7 +6,7 @@ homepage = 'https://www.cere.network/' license = 'Unlicense' name = 'pallet-cere-ddc' repository = 'https://github.com/Cerebellum-Network/ddc-pallet' -version = '4.8.0' +version = '4.8.1' readme = 'README.md' [package.metadata.docs.rs] diff --git a/pallets/erc20/Cargo.toml b/pallets/erc20/Cargo.toml index fafa6ae83..6cce2c8d4 100644 --- a/pallets/erc20/Cargo.toml +++ b/pallets/erc20/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-erc20" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" diff --git a/pallets/erc721/Cargo.toml b/pallets/erc721/Cargo.toml index 5f7d02e22..3f586f103 100644 --- a/pallets/erc721/Cargo.toml +++ b/pallets/erc721/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-erc721" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" license = "Unlicense" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 65de7e088..e037f35f4 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-rpc" -version = "4.8.0" +version = "4.8.1" edition = "2021" [dependencies] diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 885bd1c58..830a27c08 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-dev-runtime" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" build = "build.rs" @@ -96,12 +96,12 @@ pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-dev-runtime-constants = { path = "./constants", default-features = false } -pallet-ddc-staking = { version = "4.8.0", default-features = false, path = "../../pallets/ddc-staking" } -pallet-chainbridge = { version = "4.8.0", default-features = false, path = "../../pallets/chainbridge" } -pallet-cere-ddc = { version = "4.8.0", default-features = false, path = "../../pallets/ddc" } -pallet-erc721 = { version = "4.8.0", default-features = false, path = "../../pallets/erc721" } -pallet-erc20 = { version = "4.8.0", default-features = false, path = "../../pallets/erc20" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.0", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } +pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } +pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } +pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } +pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/constants/Cargo.toml b/runtime/cere-dev/constants/Cargo.toml index 68ca79a56..5fdb89737 100644 --- a/runtime/cere-dev/constants/Cargo.toml +++ b/runtime/cere-dev/constants/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-dev-runtime-constants" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index c71b6c699..1823209fc 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48000, + spec_version: 48001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 30c080f8f..59a2668cd 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-runtime" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" build = "build.rs" @@ -96,11 +96,11 @@ pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-runtime-constants = { path = "./constants", default-features = false } -pallet-chainbridge = { version = "4.8.0", default-features = false, path = "../../pallets/chainbridge" } -pallet-cere-ddc = { version = "4.8.0", default-features = false, path = "../../pallets/ddc" } -pallet-erc721 = { version = "4.8.0", default-features = false, path = "../../pallets/erc721" } -pallet-erc20 = { version = "4.8.0", default-features = false, path = "../../pallets/erc20" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.0", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } +pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } +pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } +pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere/constants/Cargo.toml b/runtime/cere/constants/Cargo.toml index cfbde8792..2188486ef 100644 --- a/runtime/cere/constants/Cargo.toml +++ b/runtime/cere/constants/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-runtime-constants" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index bfd41e3b5..9145da19c 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -128,7 +128,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48000, + spec_version: 48001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 0871c1d68..15c08df07 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cere-runtime-common" -version = "4.8.0" +version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" From 49df91579aa456eee23a999db00fdf779fa3d556 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 14 Aug 2023 14:05:02 +0200 Subject: [PATCH 244/544] add data structures for UI --- pallets/ddc-staking/src/lib.rs | 36 ++++++++++++++++++++++++++++++++ pallets/ddc-validator/src/lib.rs | 15 ++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 31ea79181..f810e8bad 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -69,6 +69,24 @@ pub struct EraRewardPoints { pub individual: BTreeMap, } +/// Reward points of an era. Used to split era total payout between stakers. +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] +pub struct EraRewardPointsPerNode { + /// Era points accrued + pub era: EraIndex, + /// Total number of points for node + pub points: RewardPoint +} + +/// Reward paid for some era. +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] +pub struct EraRewardsPaid { + /// Era number + pub era: EraIndex, + /// Cere tokens paid + pub reward: Balance, +} + impl Default for EraRewardPoints { fn default() -> Self { EraRewardPoints { total: Default::default(), individual: BTreeMap::new() } @@ -279,6 +297,12 @@ pub mod pallet { #[pallet::getter(fn rewards)] pub type Rewards = StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf, ValueQuery>; + + /// Map from all "stash" accounts to the paid out rewards + #[pallet::storage] + #[pallet::getter(fn paideras)] + pub type PaidEras = + StorageMap<_, Blake2_128Concat, T::AccountId, Vec>>, ValueQuery>; /// The current era index. /// @@ -296,6 +320,14 @@ pub mod pallet { pub type ErasEdgesRewardPoints = StorageMap<_, Twox64Concat, EraIndex, EraRewardPoints, ValueQuery>; + /// The reward each CDN participant earned in the era. + /// + /// See also [`pallet_staking::ErasRewardPoints`]. + #[pallet::storage] + #[pallet::getter(fn eras_edges_reward_points_per_node)] + pub type ErasEdgesRewardPointsPerNode = + StorageMap<_, Twox64Concat, T::AccountId, Vec, ValueQuery>; + /// Price per byte of the bucket traffic in smallest units of the currency. #[pallet::storage] #[pallet::getter(fn pricing)] @@ -828,6 +860,10 @@ pub mod pallet { *current_balance += reward; }); log::info!("Total rewards to be inserted: {:?}", Self::rewards(&stash)); + PaidEras::::mutate(&stash, |current_rewards| { + let rewards = EraRewardsPaid { era, reward }; + current_rewards.push(rewards); + }); } Self::deposit_event(Event::::PayoutNodes(era, era_reward_points.clone() ,price_per_byte)); log::info!("Payout event executed"); diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 016c7132b..56bd56a30 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -385,8 +385,12 @@ pub mod pallet { >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { - *era_rewards.individual.entry(staker).or_default() += points; + *era_rewards.individual.entry(staker.clone()).or_default() += points; era_rewards.total += points; + >::mutate(staker, |current_reward_points| { + let rewards = ddc_staking::EraRewardPointsPerNode { era, points }; + current_reward_points.push(rewards); + }); } }); @@ -681,9 +685,8 @@ pub mod pallet { info!("node aggregates: {:?}", node_aggregates); // No data for node - if (node_aggregates.len() == 0) { - continue - } + if node_aggregates.len() == 0 { continue; } + let request_ids = &node_aggregates[0].request_ids; info!("request_ids: {:?}", request_ids); @@ -715,11 +718,13 @@ pub mod pallet { }, }; - info!("decision: {:?}", decision); + info!("decision to be encoded: {:?}", decision); let serialized_decision = serde_json::to_string(&decision).unwrap(); let encoded_decision = shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); + info!("encoded decision: {:?}", encoded_decision); + let validator_str = utils::account_to_string::(validator.clone()); let edge_str = utils::account_to_string::(assigned_edge.clone()); From 10edd8344db7bb07368c3f1cb911a012fdfaa1b0 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 14 Aug 2023 18:01:39 +0200 Subject: [PATCH 245/544] update double spend protection for charging owners & paying stakers --- pallets/ddc-staking/src/lib.rs | 28 +++++++++++++++++++++++++--- pallets/ddc-validator/src/lib.rs | 10 +++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index f810e8bad..748e4d85f 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -300,9 +300,22 @@ pub mod pallet { /// Map from all "stash" accounts to the paid out rewards #[pallet::storage] - #[pallet::getter(fn paideras)] - pub type PaidEras = + #[pallet::getter(fn paideraspernode)] + pub type PaidErasPerNode = StorageMap<_, Blake2_128Concat, T::AccountId, Vec>>, ValueQuery>; + + // Map to check if validation decision was performed for the era + #[pallet::storage] + #[pallet::getter(fn paideras)] + pub(super) type PaidEras = + StorageMap<_, Twox64Concat, EraIndex, bool, ValueQuery>; + + // Map to check if validation decision was performed for the era + #[pallet::storage] + #[pallet::getter(fn contentownerscharged)] + pub(super) type EraContentOwnersCharged = + StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + /// The current era index. /// @@ -380,6 +393,7 @@ pub mod pallet { /// Action is allowed at some point of time in future not reached yet. TooEarly, DuplicateRewardPoints, + DoubleSpendRewards, PricingNotSet, BudgetOverflow, } @@ -758,6 +772,14 @@ pub mod pallet { #[pallet::weight(100_000)] pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { ensure_signed(origin)?; + + // not tested + ensure!( + !Self::paideras(era), + Error::::DoubleSpendRewards + ); + + PaidEras::::insert(era, true); Self::do_payout_stakers(era) } @@ -860,7 +882,7 @@ pub mod pallet { *current_balance += reward; }); log::info!("Total rewards to be inserted: {:?}", Self::rewards(&stash)); - PaidEras::::mutate(&stash, |current_rewards| { + PaidErasPerNode::::mutate(&stash, |current_rewards| { let rewards = EraRewardsPaid { era, reward }; current_rewards.push(rewards); }); diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 56bd56a30..80b2cbd82 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -203,7 +203,7 @@ pub mod pallet { // Map to check if validation decision was performed for the era #[pallet::storage] - #[pallet::getter(fn contentOwnersCharged)] + #[pallet::getter(fn content_owners_charged)] pub(super) type EraContentOwnersCharged = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; @@ -410,10 +410,10 @@ pub mod pallet { let era = Self::get_current_era(); // not tested - // ensure!( - // Self::contentOwnersCharged(era, &controller), - // Error::::ContentOwnersDoubleSpend - // ); + ensure!( + !Self::content_owners_charged(era, &controller), + Error::::ContentOwnersDoubleSpend + ); ensure!( OffchainWorkerKeys::::contains_key(&controller), From 9a3e6e043b7940c4bcc5f79ed4d7393f3b95c019 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 15 Aug 2023 12:16:04 +0600 Subject: [PATCH 246/544] Fix faulty test --- pallets/ddc-validator/src/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 400e96f64..343f86dfa 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -6,7 +6,7 @@ use crate::{ use codec::Decode; use frame_support::{ assert_ok, - traits::{OffchainWorker, OnInitialize}, + traits::{OffchainWorker, OnFinalize, OnInitialize}, }; use pallet_ddc_accounts::BucketsDetails; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; @@ -124,11 +124,13 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { Timestamp::set_timestamp( (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, ); + DdcStaking::on_finalize(era_block_number - 1); // set DDC era counter DdcValidator::on_initialize(era_block_number - 1); // make assignments Timestamp::set_timestamp( (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64, ); + DdcStaking::on_finalize(era_block_number + 1); // inc DDC era counter DdcValidator::offchain_worker(era_block_number + 1); // execute assignments let mut transactions = pool_state.read().transactions.clone(); From 92c909aa31cc02359ca49ee482ef89947650dd8e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 15 Aug 2023 16:46:06 +0200 Subject: [PATCH 247/544] fix trigerring payments for era not validated --- pallets/ddc-staking/src/lib.rs | 17 ++++++++++++++++- runtime/cere-dev/src/lib.rs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 748e4d85f..95a36e1e0 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -260,6 +260,8 @@ pub mod pallet { /// Time used for computing era index. It is guaranteed to start being called from the first /// `on_finalize`. type UnixTime: UnixTime; + + type TimeProvider: UnixTime; } @@ -392,6 +394,7 @@ pub mod pallet { AlreadyInRole, /// Action is allowed at some point of time in future not reached yet. TooEarly, + EraNotValidated, DuplicateRewardPoints, DoubleSpendRewards, PricingNotSet, @@ -772,13 +775,18 @@ pub mod pallet { #[pallet::weight(100_000)] pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { ensure_signed(origin)?; + let current_era = Self::get_current_era(); - // not tested ensure!( !Self::paideras(era), Error::::DoubleSpendRewards ); + ensure!( + current_era >= era + 2, + Error::::EraNotValidated + ); + PaidEras::::insert(era, true); Self::do_payout_stakers(era) } @@ -1022,5 +1030,12 @@ pub mod pallet { } }); } + + // Get the current era; Shall we start era count from 0 or from 1? + fn get_current_era() -> EraIndex { + ((::TimeProvider::now().as_millis() - DDC_ERA_START_MS) / DDC_ERA_DURATION_MS) + .try_into() + .unwrap() + } } } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 6e882828d..12728a6ad 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1270,6 +1270,7 @@ impl pallet_ddc_staking::Config for Runtime { type DefaultStorageChillDelay = DefaultStorageChillDelay; type Event = Event; type UnixTime = Timestamp; + type TimeProvider = pallet_timestamp::Pallet; type StakersPayoutSource = Ddc_Accounts_Pallet_Id; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } From 542571f16872b90baa5572f5e7ac8cbbe89a60c1 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 16 Aug 2023 14:39:40 +0600 Subject: [PATCH 248/544] Fix validation rerun by validated era storing --- pallets/ddc-validator/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 0d0a08da4..e457260bd 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -331,12 +331,17 @@ pub mod pallet { // Validation start forced externally? let should_validate_because_signal = Signal::::get().unwrap_or(false); - if should_validate_because_new_era || should_validate_because_signal { - let validation_result = Self::validate_edges(); - if let Err(e) = validation_result { - log::warn!("🔎 DDC validation failed. {}", e); - } + if !should_validate_because_new_era && !should_validate_because_signal { + return + } + + if let Err(e) = Self::validate_edges() { + log::warn!("🔎 DDC validation failed. {}", e); + return } + + last_validated_era_storage.set(¤t_ddc_era); + log::info!("🔎 DDC validation complete for {} era.", current_ddc_era); } } From f47e62096ff81a842e332d64d436413d48667351 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 16 Aug 2023 10:55:12 +0200 Subject: [PATCH 249/544] extra checks intermediate progress --- pallets/ddc-validator/src/lib.rs | 44 +++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 80b2cbd82..fed90bb3f 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -218,6 +218,12 @@ pub mod pallet { pub type ValidationDecisions = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; + // Map to check if validation decision was performed for the era + #[pallet::storage] + #[pallet::getter(fn validation_decision_set_for_node)] + pub(super) type ValidationDecisionSetForNode = + StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + /// The last era for which the tasks assignment produced. #[pallet::storage] #[pallet::getter(fn last_managed_era)] @@ -233,7 +239,8 @@ pub mod pallet { pub enum Error { NotController, OCWKeyNotRegistered, - ContentOwnersDoubleSpend + ContentOwnersDoubleSpend, + ValidationDecisionAlreadySet, } #[pallet::event] @@ -351,16 +358,25 @@ pub mod pallet { cdn_node: T::AccountId, validation_decision: ValidationDecision, ) -> DispatchResult { - ensure_signed(origin)?; + let controller = ensure_signed(origin)?; - // ToDo: check if origin is a validator. + ensure!( + OffchainWorkerKeys::::contains_key(&controller), + Error::::OCWKeyNotRegistered + ); + + ensure!( + !Self::validation_decision_set_for_node(era, &cdn_node), + Error::::ValidationDecisionAlreadySet + ); // ToDo: check if the era is current - 1. - // ToDo: check if the validation decision is not set yet. // ToDo: check cdn_node is known to ddc-staking. ValidationDecisions::::insert(era, cdn_node.clone(), validation_decision.clone()); - Self::deposit_event(Event::::ValidationDecision(era, cdn_node, validation_decision)); + Self::deposit_event(Event::::ValidationDecision(era, cdn_node.clone(), validation_decision)); + + ValidationDecisionSetForNode::::insert(era, cdn_node, true); Ok(()) } @@ -381,7 +397,12 @@ pub mod pallet { era: EraIndex, stakers_points: Vec<(T::AccountId, u64)>, ) -> DispatchResult { - ensure_signed(origin)?; + let controller = ensure_signed(origin)?; + + ensure!( + OffchainWorkerKeys::::contains_key(&controller), + Error::::OCWKeyNotRegistered + ); >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { @@ -409,7 +430,6 @@ pub mod pallet { let era = Self::get_current_era(); - // not tested ensure!( !Self::content_owners_charged(era, &controller), Error::::ContentOwnersDoubleSpend @@ -432,15 +452,9 @@ pub mod pallet { origin: OriginFor, era: EraIndex, ) -> DispatchResult { - let controller = ensure_signed(origin)?; - ensure!( - OffchainWorkerKeys::::contains_key(&controller), - Error::::OCWKeyNotRegistered - ); - - >::do_payout_stakers(era); + ensure_signed(origin)?; - Ok(()) + >::do_payout_stakers(era) } #[pallet::weight(100_000)] From c638a3aa52dcf6d09e742b8a3c07879be944ef24 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 16 Aug 2023 18:02:12 +0200 Subject: [PATCH 250/544] finish with safety checks --- pallets/ddc-validator/src/lib.rs | 40 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index fed90bb3f..baef8543f 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -224,6 +224,12 @@ pub mod pallet { pub(super) type ValidationDecisionSetForNode = StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + // Map to check if reward points were set for the era + #[pallet::storage] + #[pallet::getter(fn reward_points_set_for_node)] + pub(super) type RewardPointsSetForNode = + StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + /// The last era for which the tasks assignment produced. #[pallet::storage] #[pallet::getter(fn last_managed_era)] @@ -241,6 +247,7 @@ pub mod pallet { OCWKeyNotRegistered, ContentOwnersDoubleSpend, ValidationDecisionAlreadySet, + NodeNotActive } #[pallet::event] @@ -369,8 +376,12 @@ pub mod pallet { !Self::validation_decision_set_for_node(era, &cdn_node), Error::::ValidationDecisionAlreadySet ); + + ensure!( + >::contains_key(&cdn_node), + Error::::NodeNotActive + ); // ToDo: check if the era is current - 1. - // ToDo: check cdn_node is known to ddc-staking. ValidationDecisions::::insert(era, cdn_node.clone(), validation_decision.clone()); @@ -406,12 +417,17 @@ pub mod pallet { >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { - *era_rewards.individual.entry(staker.clone()).or_default() += points; - era_rewards.total += points; - >::mutate(staker, |current_reward_points| { - let rewards = ddc_staking::EraRewardPointsPerNode { era, points }; - current_reward_points.push(rewards); - }); + if !Self::reward_points_set_for_node(era, &staker) { // check if rewards were not yet set for era for node + if >::contains_key(&staker) { // check if node is active + *era_rewards.individual.entry(staker.clone()).or_default() += points; + era_rewards.total += points; + >::mutate(&staker, |current_reward_points| { + let rewards = ddc_staking::EraRewardPointsPerNode { era, points }; + current_reward_points.push(rewards); + }); + RewardPointsSetForNode::::insert(era, staker, true); + } + } } }); @@ -429,16 +445,16 @@ pub mod pallet { log::info!("Controller is {:?}", controller); let era = Self::get_current_era(); - - ensure!( - !Self::content_owners_charged(era, &controller), - Error::::ContentOwnersDoubleSpend - ); ensure!( OffchainWorkerKeys::::contains_key(&controller), Error::::OCWKeyNotRegistered ); + + ensure!( + !Self::content_owners_charged(era, &controller), + Error::::ContentOwnersDoubleSpend + ); >::charge_payments_new(paying_accounts); From a316d65ef7e44de3ae22813adc3fe56b0f637872 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 17 Aug 2023 10:27:17 +0200 Subject: [PATCH 251/544] charge content owners based on pricing (fix bug) --- pallets/ddc-accounts/src/lib.rs | 4 +++- pallets/ddc-validator/src/lib.rs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index d7e6e2560..ebc877c81 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -12,6 +12,7 @@ use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, RuntimeDebug, + SaturatedConversion, }; use sp_staking::EraIndex; @@ -566,13 +567,14 @@ pub mod pallet { // Charge payments from content owners pub fn charge_payments_new( paying_accounts: Vec>>, + pricing: u128, ) -> DispatchResult { let mut total_charged = BalanceOf::::zero(); for bucket_details in paying_accounts.iter() { let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); let content_owner = bucket.owner_id; - let amount = bucket_details.amount; + let amount = bucket_details.amount * pricing.saturated_into::>(); let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; if ledger.active >= amount { diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index baef8543f..75eb21ee1 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -456,7 +456,8 @@ pub mod pallet { Error::::ContentOwnersDoubleSpend ); - >::charge_payments_new(paying_accounts); + let pricing: u128 = >::pricing().unwrap(); + >::charge_payments_new(paying_accounts, pricing); EraContentOwnersCharged::::insert(era, controller, true); From fe7f288fb519f17abd5c13db92fedd38cf169dbd Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 17 Aug 2023 17:12:04 +0600 Subject: [PATCH 252/544] Enable DDC validation depending on storage key --- pallets/ddc-validator/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index e457260bd..45519095d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -75,6 +75,10 @@ type ResultStr = Result; /// assignment. const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; +/// Local storage key that holds the flag to enable DDC validation. Set it to true (0x01) to enable +/// DDC validation, set it to false (0x00) or delete the key to disable it. +const ENABLE_DDC_VALIDATION_KEY: &[u8; 21] = b"enable-ddc-validation"; + pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const TIME_START_MS: u128 = 1_672_531_200_000; @@ -299,6 +303,12 @@ pub mod pallet { return } + // Skip if DDC validation is not enabled. + match StorageValueRef::persistent(ENABLE_DDC_VALIDATION_KEY).get::() { + Ok(Some(enabled)) if enabled == true => (), + _ => return, + } + let mut should_validate_because_new_era = true; let mut validation_lock = From f398b0c11fb6faed08fc2258cd61f86776d3aad6 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 17 Aug 2023 18:58:48 +0600 Subject: [PATCH 253/544] New CLI parameter for enabling DDC validation --- cli/src/cli.rs | 5 +++++ cli/src/command.rs | 10 +++++++--- node/service/src/lib.rs | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index b9759c047..b60cea5b2 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -13,6 +13,11 @@ pub struct RunCmd { #[clap(flatten)] pub base: sc_cli::RunCmd, + /// Enable DDC validation (disabled by default). Works only on validator nodes with enabled + /// offchain workers. + #[clap(long)] + pub enable_ddc_validation: bool, + /// Force using Cere Dev runtime. #[clap(long = "force-cere-dev")] pub force_cere_dev: bool, diff --git a/cli/src/command.rs b/cli/src/command.rs index 5884387bc..0c86611fb 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -242,9 +242,13 @@ pub fn run() -> sc_cli::Result<()> { None => { let runner = cli.create_runner(&cli.run.base)?; runner.run_node_until_exit(|config| async move { - cere_service::build_full(config, cli.run.no_hardware_benchmarks) - .map(|full| full.task_manager) - .map_err(Error::Service) + cere_service::build_full( + config, + cli.run.no_hardware_benchmarks, + cli.run.enable_ddc_validation, + ) + .map(|full| full.task_manager) + .map_err(Error::Service) }) }, } diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 8a84ed755..3f6ffa118 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -6,7 +6,7 @@ pub use cere_dev_runtime; pub use cere_runtime; use futures::prelude::*; -use sc_client_api::BlockBackend; +use sc_client_api::{Backend, BlockBackend}; use sc_consensus_babe::{self, SlotProportion}; use sc_network::Event; use sc_service::{ @@ -29,6 +29,7 @@ pub use sc_executor::NativeElseWasmExecutor; use sc_network_common::service::NetworkEventStream; pub use sc_service::ChainSpec; pub use sp_api::ConstructRuntimeApi; +pub use sp_core::offchain::OffchainStorage; type FullSelectChain = sc_consensus::LongestChain; type FullGrandpaBlockImport = sc_finality_grandpa::GrandpaBlockImport< @@ -269,12 +270,14 @@ where pub fn build_full( config: Configuration, disable_hardware_benchmarks: bool, + enable_ddc_validation: bool, ) -> Result, ServiceError> { #[cfg(feature = "cere-dev-native")] if config.chain_spec.is_cere_dev() { return new_full::( config, disable_hardware_benchmarks, + enable_ddc_validation, |_, _| (), ) .map(|full| full.with_client(Client::CereDev)) @@ -285,6 +288,7 @@ pub fn build_full( return new_full::( config, disable_hardware_benchmarks, + enable_ddc_validation, |_, _| (), ) .map(|full| full.with_client(Client::Cere)) @@ -318,6 +322,7 @@ impl NewFull { pub fn new_full( mut config: Configuration, disable_hardware_benchmarks: bool, + enable_ddc_validation: bool, with_startup_data: impl FnOnce( &sc_consensus_babe::BabeBlockImport< Block, @@ -347,6 +352,16 @@ where let basics = new_partial_basics::(&config)?; + basics + .backend + .offchain_storage() + .expect("no off-chain storage, DDC validation is not possible") + .set( + sp_core::offchain::STORAGE_PREFIX, + b"enable-ddc-validation", + if enable_ddc_validation { &[1] } else { &[0] }, + ); + let sc_service::PartialComponents { client, backend, From 2886959cab0922aef01547e03e09cbc67288348e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 18 Aug 2023 13:10:04 +0600 Subject: [PATCH 254/544] Enable validation while testing --- pallets/ddc-validator/src/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 343f86dfa..918668a64 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,7 +1,7 @@ use crate::{ mock::{Timestamp, *}, shm, utils, DacTotalAggregates, EraIndex, ValidationDecision, DEFAULT_DATA_PROVIDER_URL, - ERA_DURATION_MS, ERA_IN_BLOCKS, KEY_TYPE, TIME_START_MS, + ENABLE_DDC_VALIDATION_KEY, ERA_DURATION_MS, ERA_IN_BLOCKS, KEY_TYPE, TIME_START_MS, }; use codec::Decode; use frame_support::{ @@ -11,6 +11,7 @@ use frame_support::{ use pallet_ddc_accounts::BucketsDetails; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; +use sp_runtime::offchain::storage::StorageValueRef; use std::sync::Arc; const OCW_PUB_KEY_STR: &str = "d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"; @@ -131,6 +132,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64, ); DdcStaking::on_finalize(era_block_number + 1); // inc DDC era counter + StorageValueRef::persistent(ENABLE_DDC_VALIDATION_KEY).set(&true); // enable validation DdcValidator::offchain_worker(era_block_number + 1); // execute assignments let mut transactions = pool_state.read().transactions.clone(); From f50d1cc8c23a2647bddda6e6a50a92df0fe85b53 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 18 Aug 2023 14:22:48 +0600 Subject: [PATCH 255/544] Simplify imports --- pallets/ddc-validator/src/tests.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 918668a64..ab3cbad39 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,13 +1,6 @@ -use crate::{ - mock::{Timestamp, *}, - shm, utils, DacTotalAggregates, EraIndex, ValidationDecision, DEFAULT_DATA_PROVIDER_URL, - ENABLE_DDC_VALIDATION_KEY, ERA_DURATION_MS, ERA_IN_BLOCKS, KEY_TYPE, TIME_START_MS, -}; +use super::*; +use crate::mock::{Timestamp, *}; use codec::Decode; -use frame_support::{ - assert_ok, - traits::{OffchainWorker, OnFinalize, OnInitialize}, -}; use pallet_ddc_accounts::BucketsDetails; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; From 713612b21a43ee57f523a44ae7754dcc40688c90 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 18 Aug 2023 14:37:53 +0600 Subject: [PATCH 256/544] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e378bf759..9cef36998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- ... +- [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument. It will only work on the nodes with validation and offchain workers enabled as well. +- [D] Several calls for `pallet-ddc-staking` to distribute rewards. ### Changed From c024cd8ab8d83b8c3679e3533367ef14a75968a9 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 18 Aug 2023 14:38:59 +0600 Subject: [PATCH 257/544] Bump spec version --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 8a65c5727..7bfa438ae 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -131,7 +131,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48001, + spec_version: 48002, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From de7ad9495940ad184a16bc1d268ad0e2040b485a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 18 Aug 2023 17:30:24 +0600 Subject: [PATCH 258/544] Prevent panicking during the validation assignment --- pallets/ddc-validator/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 45519095d..ed5f29d01 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -273,7 +273,7 @@ pub mod pallet { let current_ddc_era = match ddc_staking::pallet::Pallet::::current_era() { Some(era) => era, None => { - defensive!("DDC era not set"); + log::debug!("DDC era not set"); return Weight::from_ref_time(0) }, }; @@ -289,7 +289,7 @@ pub mod pallet { match Self::assign(3usize, current_ddc_era + 1) { Ok(_) => >::put(current_ddc_era + 1), Err(AssignmentError::DefensiveEmptyQuorumsCycle) => { - defensive!("unexpectedly empty quorums cycle"); + log::debug!("unexpectedly empty quorums cycle"); }, Err(e) => log::debug!("assignment error: {:?}", e), }; From 225f8a5f03fe0aad558207317cc26e46e3ac1e5d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 18 Aug 2023 17:36:37 +0600 Subject: [PATCH 259/544] Decrease validation assignment logs severity --- pallets/ddc-validator/src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index ed5f29d01..b97e10259 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -273,26 +273,23 @@ pub mod pallet { let current_ddc_era = match ddc_staking::pallet::Pallet::::current_era() { Some(era) => era, None => { - log::debug!("DDC era not set"); + log::debug!("DDC era not set."); return Weight::from_ref_time(0) }, }; - log::info!("current DDC era: {:?}", current_ddc_era); + log::debug!("Current DDC era: {:?}.", current_ddc_era); // Produce an assignment for the next era if it's not produced yet. match Self::last_managed_era() { Some(last_managed_era) if current_ddc_era < last_managed_era => return Weight::from_ref_time(0), _ => (), - }; + } match Self::assign(3usize, current_ddc_era + 1) { Ok(_) => >::put(current_ddc_era + 1), - Err(AssignmentError::DefensiveEmptyQuorumsCycle) => { - log::debug!("unexpectedly empty quorums cycle"); - }, - Err(e) => log::debug!("assignment error: {:?}", e), - }; + Err(e) => log::debug!("DDC validation assignment error: {:?}.", e), + } Weight::from_ref_time(0) } @@ -582,7 +579,7 @@ pub mod pallet { /// set. fn assign(quorum_size: usize, era: EraIndex) -> Result<(), AssignmentError> { let validators: Vec = >::iter_keys().collect(); - log::info!("current validators: {:?}", validators); + log::debug!("Current validators: {:?}.", validators); if validators.len() == 0 { return Err(AssignmentError::NoValidators) @@ -596,7 +593,7 @@ pub mod pallet { } let edges: Vec = >::iter_keys().collect(); - log::info!("current edges: {:?}", edges); + log::debug!("Current edges: {:?}.", edges); if edges.len() == 0 { return Ok(()) From 64aae9cf6ebd9b49cb661acb353faf96e5ee868f Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 18 Aug 2023 15:24:55 +0200 Subject: [PATCH 260/544] Return validation errro in absence of assignment --- pallets/ddc-validator/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index f78ba66f6..019d0db9d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -761,8 +761,10 @@ pub mod pallet { info!("validator: {:?}", validator); - let assigned_edges = Self::assignments(current_ddc_era - 1, validator.clone()) - .expect("No assignments for the previous era"); + let assigned_edges = match Self::assignments(current_ddc_era - 1, validator.clone()) { + Some(edges) => edges, + None => return Err("No assignments for the previous era."), + }; info!("assigned_edges: {:?}", assigned_edges); From 1bffc10dd350a8fed6b3a9f0ebf9a56207888eab Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 18 Aug 2023 15:27:03 +0200 Subject: [PATCH 261/544] Decrease pallet-ddc-accounts logs severity --- pallets/ddc-accounts/src/lib.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 92c9979fc..ca12b1ffd 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -98,7 +98,7 @@ impl current_era { true } else { @@ -175,7 +175,7 @@ pub mod pallet { #[pallet::getter(fn bonded)] pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; - /// Map from all (unlocked) "controller" accounts to the info regarding the staking. + /// Map from all (unlocked) "controller" accounts to the debug regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = @@ -431,7 +431,7 @@ pub mod pallet { // Note: bonding for extra era to allow for accounting let era = Self::get_current_era() + T::BondingDuration::get(); - log::info!("Era for the unbond: {:?}", era); + log::debug!("Era for the unbond: {:?}", era); if let Some(mut chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) @@ -471,27 +471,27 @@ pub mod pallet { let (stash, old_total) = (ledger.stash.clone(), ledger.total); let current_era = Self::get_current_era(); ledger = ledger.consolidate_unlocked(current_era); - log::info!("Current era: {:?}", current_era); + log::debug!("Current era: {:?}", current_era); if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() { - log::info!("Killing stash"); + log::debug!("Killing stash"); // This account must have called `unbond()` with some value that caused the active // portion to fall below existential deposit + will have no more unlocking chunks // left. We can now safely remove all accounts-related information. Self::kill_stash(&stash)?; } else { - log::info!("Updating ledger"); + log::debug!("Updating ledger"); // This was the consequence of a partial unbond. just update the ledger and move on. Self::update_ledger(&controller, &ledger); }; - log::info!("Current total: {:?}", ledger.total); - log::info!("Old total: {:?}", old_total); + log::debug!("Current total: {:?}", ledger.total); + log::debug!("Old total: {:?}", old_total); // `old_total` should never be less than the new total because // `consolidate_unlocked` strictly subtracts balance. if ledger.total < old_total { - log::info!("Preparing for transfer"); + log::debug!("Preparing for transfer"); // Already checked that this won't overflow by entry condition. let value = old_total - ledger.total; @@ -579,7 +579,7 @@ pub mod pallet { ledger.total -= amount; ledger.active -= amount; total_charged += amount; - log::info!("Ledger updated state: {:?}", &ledger); + log::debug!("Ledger updated state: {:?}", &ledger); Self::update_ledger(&content_owner, &ledger); } else { let diff = amount - ledger.active; @@ -587,15 +587,15 @@ pub mod pallet { ledger.total -= ledger.active; ledger.active = BalanceOf::::zero(); let (ledger, charged) = ledger.charge_unlocking(diff); - log::info!("Ledger updated state: {:?}", &ledger); + log::debug!("Ledger updated state: {:?}", &ledger); Self::update_ledger(&content_owner, &ledger); total_charged += charged; } } - log::info!("Total charged: {:?}", &total_charged); + log::debug!("Total charged: {:?}", &total_charged); Self::deposit_event(Event::::Charged(total_charged)); - log::info!("Deposit event executed"); + log::debug!("Deposit event executed"); Ok(()) } From c560fe7adf7d1e4ea0ab8d85cb7f650c0d0c3d66 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 18 Aug 2023 15:30:33 +0200 Subject: [PATCH 262/544] decrease pallet-ddc-validator logs severity to debug --- pallets/ddc-validator/src/dac.rs | 26 ++++++++++++------------ pallets/ddc-validator/src/lib.rs | 35 ++++++++++++++++---------------- pallets/ddc-validator/src/shm.rs | 9 ++++---- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index d1fe5021b..dab51abe8 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -5,7 +5,7 @@ use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; use lite_json::{json::JsonValue, json_parser::parse_json}; -use log::info; +use log::debug; use serde_json::{Map, Value}; use sp_runtime::{ generic::Era, @@ -394,19 +394,19 @@ fn get_file_request_url(data_provider_url: &String) -> String { } pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec { - log::info!("fetch_file_request | url: {:?}", url); + log::debug!("fetch_file_request | url: {:?}", url); let response: FileRequestWrapper = http_get_json(&url).unwrap(); - log::info!("response.json: {:?}", response.json); + log::debug!("response.json: {:?}", response.json); let map: Vec = serde_json::from_str(response.json.as_str()).unwrap(); - // log::info!("response.json: {:?}", response.json); + // log::debug!("response.json: {:?}", response.json); map } pub(crate) fn fetch_file_request(url: &String) -> FileRequest { - log::info!("fetch_file_request | url: {:?}", url); + log::debug!("fetch_file_request | url: {:?}", url); let response: FileRequestWrapper = http_get_json(&url).unwrap(); - log::info!("response.json: {:?}", response.json); + log::debug!("response.json: {:?}", response.json); let map: FileRequest = serde_json::from_str(response.json.as_str()).unwrap(); @@ -418,17 +418,17 @@ pub(crate) fn fetch_data( era: EraIndex, cdn_node: &T::AccountId, ) -> (BytesSent, BytesReceived) { - log::info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + log::debug!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); - log::info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + log::debug!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::new(bytes_sent_res); // Todo: handle the error let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); - log::info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + log::debug!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::new(bytes_received_res); (bytes_sent, bytes_received) @@ -438,17 +438,17 @@ pub(crate) fn fetch_data1( data_provider_url: &String, era: EraIndex, ) -> (Vec, Vec) { - log::info!("[DAC Validator] DAC Validator is running. Current era is {}", era); + log::debug!("[DAC Validator] DAC Validator is running. Current era is {}", era); // Todo: handle the error let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); - log::info!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); + log::debug!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); let bytes_sent = BytesSent::get_all(bytes_sent_res); // Todo: handle the error let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); - log::info!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); + log::debug!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); let bytes_received = BytesReceived::get_all(bytes_received_res); (bytes_sent, bytes_received) @@ -503,7 +503,7 @@ pub(crate) fn http_get_json(url: &str) -> crate::ResultSt // } fn http_get_request(http_url: &str) -> Result, http::Error> { - // log::info!("[DAC Validator] Sending request to: {:?}", http_url); + // log::debug!("[DAC Validator] Sending request to: {:?}", http_url); // Initiate an external HTTP GET request. This is using high-level wrappers from // `sp_runtime`. diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 019d0db9d..8ab55ff2d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -46,7 +46,6 @@ pub use frame_system::{ pallet_prelude::*, }; pub use lite_json::json::JsonValue; -use log::info; pub use pallet::*; pub use pallet_ddc_accounts::{self as ddc_accounts, BucketsDetails}; pub use pallet_ddc_staking::{self as ddc_staking}; @@ -381,7 +380,7 @@ pub mod pallet { } last_validated_era_storage.set(¤t_ddc_era); - log::info!("🔎 DDC validation complete for {} era.", current_ddc_era); + log::debug!("🔎 DDC validation complete for {} era.", current_ddc_era); } } @@ -496,7 +495,7 @@ pub mod pallet { paying_accounts: Vec>>, ) -> DispatchResult { let controller = ensure_signed(origin)?; - log::info!("Controller is {:?}", controller); + log::debug!("Controller is {:?}", controller); let era = Self::get_current_era(); @@ -750,7 +749,7 @@ pub mod pallet { ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; let mock_data_url = Self::get_mock_data_url(); let data_provider_url = Self::get_data_provider_url(); - info!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); + log::debug!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); // let signer = Self::get_signer().unwrap(); // let validator = signer.get_any_account().unwrap().id; @@ -759,20 +758,20 @@ pub mod pallet { None => return Err("No validator public key found."), }; - info!("validator: {:?}", validator); + log::debug!("validator: {:?}", validator); let assigned_edges = match Self::assignments(current_ddc_era - 1, validator.clone()) { Some(edges) => edges, None => return Err("No assignments for the previous era."), }; - info!("assigned_edges: {:?}", assigned_edges); + log::debug!("assigned_edges: {:?}", assigned_edges); // Calculate CDN nodes reward points from validation decision aggregates let mut cdn_nodes_reward_points: Vec<(T::AccountId, u64)> = vec![]; for assigned_edge in assigned_edges.iter() { - info!("assigned edge: {:?}", assigned_edge); + log::debug!("assigned edge: {:?}", assigned_edge); // form url for each node let edge_url = format!( @@ -782,10 +781,10 @@ pub mod pallet { current_ddc_era - 1, utils::account_to_string::(assigned_edge.clone()) ); - info!("edge url: {:?}", edge_url); + log::debug!("edge url: {:?}", edge_url); let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); - info!("node aggregates: {:?}", node_aggregates); + log::debug!("node aggregates: {:?}", node_aggregates); // No data for node if (node_aggregates.len() == 0) { @@ -793,7 +792,7 @@ pub mod pallet { } let request_ids = &node_aggregates[0].request_ids; - info!("request_ids: {:?}", request_ids); + log::debug!("request_ids: {:?}", request_ids); // Store bucket payments let payments_per_bucket = &mut Vec::new(); @@ -808,7 +807,7 @@ pub mod pallet { let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&requests); let is_valid = Self::is_valid(bytes_sent, bytes_received); - info!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); + log::debug!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); let payload = serde_json::to_string(&requests).unwrap(); let decision = ValidationDecision { @@ -823,12 +822,12 @@ pub mod pallet { }, }; - info!("decision to be encoded: {:?}", decision); + log::debug!("decision to be encoded: {:?}", decision); let serialized_decision = serde_json::to_string(&decision).unwrap(); let encoded_decision = shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); - info!("encoded decision: {:?}", encoded_decision); + log::debug!("encoded decision: {:?}", encoded_decision); let validator_str = utils::account_to_string::(validator.clone()); let edge_str = utils::account_to_string::(assigned_edge.clone()); @@ -849,7 +848,7 @@ pub mod pallet { } if let Ok(res) = response.clone() { - info!("shm res: {:?}", res.to_string()); + log::debug!("shm res: {:?}", res.to_string()); } if let Ok(res) = response { @@ -863,10 +862,10 @@ pub mod pallet { quorum, ); - log::info!("get_intermediate_decisions result: {:?}", validations_res); + log::debug!("get_intermediate_decisions result: {:?}", validations_res); if validations_res.len() == QUORUM_SIZE { - log::info!("payments per bucket: {:?}", payments_per_bucket); + log::debug!("payments per bucket: {:?}", payments_per_bucket); let mut payments: BTreeMap< u128, @@ -890,7 +889,7 @@ pub mod pallet { for (_, bucket_info) in payments { final_payments.push(bucket_info); } - log::info!("final payments: {:?}", final_payments); + log::debug!("final payments: {:?}", final_payments); // Store CDN node reward points on-chain let signer: Signer = Signer::<_, _>::any_account(); @@ -917,7 +916,7 @@ pub mod pallet { validation_decision: final_res.clone(), }); - log::info!("final_res: {:?}", final_res); + log::debug!("final_res: {:?}", final_res); cdn_nodes_reward_points.push(( utils::string_to_account::(final_res.edge), diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 72c293745..2d557d37d 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -12,7 +12,6 @@ use crate::{dac, utils, ValidationDecision}; use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use base64::prelude::*; use lite_json::json::JsonValue; -use log::info; use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; use sp_std::prelude::*; @@ -74,14 +73,14 @@ pub fn share_intermediate_validation_result( let unescaped_json = utils::unescape(&json_str); let url_encoded_json = utils::url_encode(&unescaped_json); - log::info!("json_str: {:?}", json_str); + log::debug!("json_str: {:?}", json_str); let url = format!( "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", shared_memory_webdis_url, validator, cdn_node, era, url_encoded_json, ); - log::info!("share_intermediate_validation_result url: {:?}", url); + log::debug!("share_intermediate_validation_result url: {:?}", url); let request = http::Request::get(url.as_str()); let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; @@ -95,7 +94,7 @@ pub fn share_intermediate_validation_result( http::Error::Unknown })?; - log::info!("body_str: {:?}", body_str); + log::debug!("body_str: {:?}", body_str); let json = lite_json::parse_json(body_str).map_err(|_| { log::warn!("No JSON body"); @@ -138,7 +137,7 @@ pub(crate) fn decode_intermediate_decisions( let data_str = String::from_utf8_lossy(&data); let data_trimmed = data_str.trim_end_matches('\0'); - info!("data_str: {:?}", data_trimmed); + log::debug!("data_str: {:?}", data_trimmed); let decoded_decision: ValidationDecision = serde_json::from_str(&data_trimmed).unwrap(); From 7619421748c5e23dbf1d3a6b13a4d047aacf8785 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 18 Aug 2023 15:45:46 +0200 Subject: [PATCH 263/544] fix remaining conflicts not smotted by git --- pallets/ddc-staking/src/lib.rs | 24 +----------------------- pallets/ddc-validator/src/lib.rs | 19 +++++++++++++------ runtime/cere-dev/src/lib.rs | 7 ------- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 6f45e0f35..1630df783 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -240,7 +240,6 @@ pub mod pallet { type DefaultStorageChillDelay: Get; type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type Event: From> + IsType<::Event>; /// Number of eras that staked funds must remain bonded for. #[pallet::constant] type BondingDuration: Get; @@ -898,6 +897,7 @@ pub mod pallet { >::set(Some(price_per_byte)); Ok(()) } + } impl Pallet { pub fn do_payout_stakers(era: EraIndex) -> DispatchResult { @@ -1063,28 +1063,6 @@ pub mod pallet { Storages::::take(who).is_some() } - /// This function will add a storage network participant to the `Storages` storage map. - /// - /// If the storage network participant already exists, their cluster will be updated. - /// - /// NOTE: you must ALWAYS use this function to add a storage network participant to the - /// system. Any access to `Storages` outside of this function is almost certainly - /// wrong. - pub fn do_add_storage(who: &T::AccountId, cluster: ClusterId) { - Storages::::insert(who, cluster); - } - - /// This function will remove a storage network participant from the `Storages` map. - /// - /// Returns true if `who` was removed from `Storages`, otherwise false. - /// - /// NOTE: you must ALWAYS use this function to remove a storage network participant from the - /// system. Any access to `Storages` outside of this function is almost certainly - /// wrong. - pub fn do_remove_storage(who: &T::AccountId) -> bool { - Storages::::take(who).is_some() - } - /// Reset the chilling era for a controller. pub fn reset_chilling(controller: &T::AccountId) { Ledger::::mutate(&controller, |maybe_ledger| { diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 8ab55ff2d..21ee1d199 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -80,8 +80,8 @@ const ENABLE_DDC_VALIDATION_KEY: &[u8; 21] = b"enable-ddc-validation"; pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); -pub const TIME_START_MS: u128 = 1_672_531_200_000; -pub const ERA_DURATION_MS: u128 = 120_000; +pub const DDC_ERA_START_MS: u128 = 1_672_531_200_000; +pub const DDC_ERA_DURATION_MS: u128 = 120_000; pub const ERA_IN_BLOCKS: u8 = 20; pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and adjusted @@ -634,7 +634,7 @@ pub mod pallet { result } - fn assign(quorum_size: usize, era: EraIndex) { + fn assign(quorum_size: usize, era: EraIndex) -> Result<(), AssignmentError> { let validators: Vec = OffchainWorkerKeys::::iter_keys().collect(); log::debug!("Current validators: {:?}.", validators); @@ -744,6 +744,13 @@ pub mod pallet { } } + fn get_current_era() -> EraIndex { + ((::TimeProvider::now().as_millis() - DDC_ERA_START_MS) / + DDC_ERA_DURATION_MS) + .try_into() + .unwrap() + } + fn validate_edges() -> Result<(), &'static str> { let current_ddc_era = ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; @@ -787,7 +794,7 @@ pub mod pallet { log::debug!("node aggregates: {:?}", node_aggregates); // No data for node - if (node_aggregates.len() == 0) { + if node_aggregates.len() == 0 { continue } @@ -911,7 +918,7 @@ pub mod pallet { let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_era - 1, + era: current_ddc_era - 1, cdn_node: utils::string_to_account::(edge.clone()), validation_decision: final_res.clone(), }); @@ -931,7 +938,7 @@ pub mod pallet { if cdn_nodes_reward_points.len() > 0 { let _tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { - era: current_era - 1, + era: current_ddc_era - 1, stakers_points: cdn_nodes_reward_points.clone(), }); } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 05f57249f..11be6ce59 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1324,12 +1324,6 @@ parameter_types! { pub const DefaultStorageChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era } -parameter_types! { - pub const DefaultEdgeBondSize: Balance = 100 * DOLLARS; - pub const DefaultEdgeChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era - pub const DefaultStorageBondSize: Balance = 100 * DOLLARS; - pub const DefaultStorageChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era -} impl pallet_ddc_staking::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; @@ -1338,7 +1332,6 @@ impl pallet_ddc_staking::Config for Runtime { type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; - type Event = Event; type TimeProvider = pallet_timestamp::Pallet; type StakersPayoutSource = Ddc_Accounts_Pallet_Id; type UnixTime = Timestamp; From 362cee76cd6b8511401cdbad28bd8d53af555a11 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 21 Aug 2023 17:43:36 +0200 Subject: [PATCH 264/544] fix tests --- pallets/ddc-staking/src/mock.rs | 1 + pallets/ddc-validator/src/mock.rs | 1 + pallets/ddc-validator/src/tests.rs | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index c82675b73..88b696b81 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -107,6 +107,7 @@ impl crate::pallet::Config for Test { type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; type UnixTime = Timestamp; + type TimeProvider = Timestamp; type WeightInfo = (); type StakersPayoutSource = DdcAccountsPalletId; } diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index c398c2ac8..77e1f0718 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -273,6 +273,7 @@ impl pallet_ddc_staking::Config for Test { type RuntimeEvent = RuntimeEvent; type StakersPayoutSource = DdcAccountsPalletId; type UnixTime = Timestamp; + type TimeProvider = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index ab3cbad39..4d9b0bdd7 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -116,13 +116,13 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { System::set_block_number(era_block_number); // required for randomness Timestamp::set_timestamp( - (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, + (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, ); DdcStaking::on_finalize(era_block_number - 1); // set DDC era counter DdcValidator::on_initialize(era_block_number - 1); // make assignments Timestamp::set_timestamp( - (TIME_START_MS + ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64, + (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64, ); DdcStaking::on_finalize(era_block_number + 1); // inc DDC era counter StorageValueRef::persistent(ENABLE_DDC_VALIDATION_KEY).set(&true); // enable validation From 293cfd0387f9982af3e262f0b59dda000c382229 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 22 Aug 2023 21:15:03 +0200 Subject: [PATCH 265/544] update log info and debug --- pallets/ddc-staking/src/lib.rs | 8 ++++---- pallets/ddc-validator/src/dac.rs | 1 - pallets/ddc-validator/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 1630df783..ad5913c15 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -920,7 +920,7 @@ pub mod pallet { Ok(value) => value, Err(_) => Err(Error::::BudgetOverflow)?, }; - log::info!( + log::debug!( "Will payout to DDC stakers for era {:?} from account {:?} with total budget {:?} \ , there are {:?} stakers earned {:?} reward points with price per byte {:?}", era, @@ -935,7 +935,7 @@ pub mod pallet { for (stash, points) in era_reward_points.clone().individual { let part = Perbill::from_rational(points, era_reward_points.total); let reward: BalanceOf = part * payout_budget; - log::info!( + log::debug!( "Rewarding {:?} with {:?} points, its part is {:?}, reward size {:?}, balance \ on payout source account {:?}", stash, @@ -953,7 +953,7 @@ pub mod pallet { Rewards::::mutate(&stash, |current_balance| { *current_balance += reward; }); - log::info!("Total rewards to be inserted: {:?}", Self::rewards(&stash)); + log::debug!("Total rewards to be inserted: {:?}", Self::rewards(&stash)); PaidErasPerNode::::mutate(&stash, |current_rewards| { let rewards = EraRewardsPaid { era, reward }; current_rewards.push(rewards); @@ -964,7 +964,7 @@ pub mod pallet { era_reward_points.clone(), price_per_byte, )); - log::info!("Payout event executed"); + log::debug!("Payout event executed"); log::debug!( "Balance left on payout source account {:?}", diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index dab51abe8..8910ea70f 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -5,7 +5,6 @@ use alloc::{format, string::String}; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; use lite_json::{json::JsonValue, json_parser::parse_json}; -use log::debug; use serde_json::{Map, Value}; use sp_runtime::{ generic::Era, diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 21ee1d199..d480a88b0 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -380,7 +380,7 @@ pub mod pallet { } last_validated_era_storage.set(¤t_ddc_era); - log::debug!("🔎 DDC validation complete for {} era.", current_ddc_era); + log::info!("🔎 DDC validation complete for {} era.", current_ddc_era); } } From 834041d44b91625eb060e1e8730c353d045add7e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 09:59:47 +0200 Subject: [PATCH 266/544] use current_era from ddc_staking --- pallets/ddc-accounts/Cargo.toml | 1 + pallets/ddc-accounts/src/lib.rs | 51 ++++++++++++++++---------------- pallets/ddc-staking/src/lib.rs | 10 +------ pallets/ddc-validator/src/lib.rs | 17 +++-------- 4 files changed, 31 insertions(+), 48 deletions(-) diff --git a/pallets/ddc-accounts/Cargo.toml b/pallets/ddc-accounts/Cargo.toml index 869e758e6..89f3de545 100644 --- a/pallets/ddc-accounts/Cargo.toml +++ b/pallets/ddc-accounts/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index ca12b1ffd..b4e4ddc6d 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -8,21 +8,17 @@ use frame_support::{ traits::{Currency, DefensiveSaturating, ExistenceRequirement, UnixTime}, BoundedVec, PalletId, }; +pub use pallet_ddc_staking::{self as ddc_staking}; use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, RuntimeDebug, SaturatedConversion, }; - use sp_staking::EraIndex; use sp_std::prelude::*; pub use pallet::*; -pub const TIME_START_MS: u128 = 1_672_531_200_000; -pub const ERA_DURATION_MS: u128 = 120_000; -pub const ERA_IN_BLOCKS: u8 = 20; - /// The balance type of this pallet. pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -158,7 +154,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + ddc_staking::Config { /// The accounts's pallet id, used for deriving its sovereign account ID. #[pallet::constant] type PalletId: Get; @@ -245,9 +241,9 @@ pub mod pallet { impl GenesisBuild for GenesisConfig { fn build(&self) { let account_id = >::account_id(); - let min = T::Currency::minimum_balance(); - if T::Currency::free_balance(&account_id) < min { - let _ = T::Currency::make_free_balance_be(&account_id, min); + let min = ::Currency::minimum_balance(); + if ::Currency::free_balance(&account_id) < min { + let _ = ::Currency::make_free_balance_be(&account_id, min); } } } @@ -336,7 +332,7 @@ pub mod pallet { } // Reject a deposit which is considered to be _dust_. - if value < T::Currency::minimum_balance() { + if value < ::Currency::minimum_balance() { Err(Error::::InsufficientDeposit)? } @@ -344,7 +340,7 @@ pub mod pallet { >::insert(&stash, &controller); - let stash_balance = T::Currency::free_balance(&stash); + let stash_balance = ::Currency::free_balance(&stash); let value = value.min(stash_balance); Self::deposit_event(Event::::Deposited(stash.clone(), value)); let item = AccountsLedger { @@ -373,13 +369,13 @@ pub mod pallet { let controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - let stash_balance = T::Currency::free_balance(&stash); + let stash_balance = ::Currency::free_balance(&stash); let extra = stash_balance.min(max_additional); ledger.total += extra; ledger.active += extra; // Last check: the new active amount of ledger must be more than ED. ensure!( - ledger.active >= T::Currency::minimum_balance(), + ledger.active >= ::Currency::minimum_balance(), Error::::InsufficientDeposit ); @@ -424,13 +420,15 @@ pub mod pallet { ledger.active -= value; // Avoid there being a dust balance left in the accounts system. - if ledger.active < T::Currency::minimum_balance() { + if ledger.active < ::Currency::minimum_balance() { value += ledger.active; ledger.active = Zero::zero(); } + let current_era = + ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; // Note: bonding for extra era to allow for accounting - let era = Self::get_current_era() + T::BondingDuration::get(); + let era = current_era + ::BondingDuration::get(); log::debug!("Era for the unbond: {:?}", era); if let Some(mut chunk) = @@ -469,11 +467,14 @@ pub mod pallet { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); - let current_era = Self::get_current_era(); + let current_era = + ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; ledger = ledger.consolidate_unlocked(current_era); log::debug!("Current era: {:?}", current_era); - if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() { + if ledger.unlocking.is_empty() && + ledger.active < ::Currency::minimum_balance() + { log::debug!("Killing stash"); // This account must have called `unbond()` with some value that caused the active // portion to fall below existential deposit + will have no more unlocking chunks @@ -497,7 +498,12 @@ pub mod pallet { let account_id = Self::account_id(); - T::Currency::transfer(&account_id, &stash, value, ExistenceRequirement::KeepAlive)?; + ::Currency::transfer( + &account_id, + &stash, + value, + ExistenceRequirement::KeepAlive, + )?; Self::deposit_event(Event::::Withdrawn(stash, value)); } @@ -519,7 +525,7 @@ pub mod pallet { ) -> DispatchResult { let account_id = Self::account_id(); - T::Currency::transfer( + ::Currency::transfer( stash, &account_id, ledger.total, @@ -555,13 +561,6 @@ pub mod pallet { Ok(()) } - // Get the current era. - fn get_current_era() -> EraIndex { - ((T::TimeProvider::now().as_millis() - TIME_START_MS) / ERA_DURATION_MS) - .try_into() - .unwrap() - } - // Charge payments from content owners pub fn charge_payments_new( paying_accounts: Vec>>, diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ad5913c15..e2ab974fa 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -845,7 +845,7 @@ pub mod pallet { #[pallet::weight(100_000)] pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { ensure_signed(origin)?; - let current_era = Self::get_current_era(); + let current_era = Self::current_era().ok_or("DDC era not set")?; ensure!(!Self::paideras(era), Error::::DoubleSpendRewards); @@ -1083,13 +1083,5 @@ pub mod pallet { } }); } - - // Get the current era; Shall we start era count from 0 or from 1? - fn get_current_era() -> EraIndex { - ((::TimeProvider::now().as_millis() - DDC_ERA_START_MS) / - DDC_ERA_DURATION_MS) - .try_into() - .unwrap() - } } } diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index d480a88b0..e9a00b0bb 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -80,9 +80,6 @@ const ENABLE_DDC_VALIDATION_KEY: &[u8; 21] = b"enable-ddc-validation"; pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); -pub const DDC_ERA_START_MS: u128 = 1_672_531_200_000; -pub const DDC_ERA_DURATION_MS: u128 = 120_000; -pub const ERA_IN_BLOCKS: u8 = 20; pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and adjusted /// Offchain local storage key that holds the last era in which the validator completed its @@ -497,7 +494,8 @@ pub mod pallet { let controller = ensure_signed(origin)?; log::debug!("Controller is {:?}", controller); - let era = Self::get_current_era(); + let current_era = + ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; ensure!( OffchainWorkerKeys::::contains_key(&controller), @@ -505,14 +503,14 @@ pub mod pallet { ); ensure!( - !Self::content_owners_charged(era, &controller), + !Self::content_owners_charged(current_era, &controller), Error::::ContentOwnersDoubleSpend ); let pricing: u128 = >::pricing().unwrap(); >::charge_payments_new(paying_accounts, pricing); - EraContentOwnersCharged::::insert(era, controller, true); + EraContentOwnersCharged::::insert(current_era, controller, true); Ok(()) } @@ -744,13 +742,6 @@ pub mod pallet { } } - fn get_current_era() -> EraIndex { - ((::TimeProvider::now().as_millis() - DDC_ERA_START_MS) / - DDC_ERA_DURATION_MS) - .try_into() - .unwrap() - } - fn validate_edges() -> Result<(), &'static str> { let current_ddc_era = ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; From 7677a5865eb8614a1e881a3908973228115e2c0b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 10:08:32 +0200 Subject: [PATCH 267/544] change hash type to Identity for accountId --- pallets/ddc-accounts/src/lib.rs | 4 ++-- pallets/ddc-staking/src/lib.rs | 24 +++++++++--------------- pallets/ddc-validator/src/lib.rs | 13 ++++++------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index b4e4ddc6d..526b7295c 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -169,13 +169,13 @@ pub mod pallet { /// Map from all locked "stash" accounts to the controller account. #[pallet::storage] #[pallet::getter(fn bonded)] - pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + pub type Bonded = StorageMap<_, Identity, T::AccountId, T::AccountId>; /// Map from all (unlocked) "controller" accounts to the debug regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = - StorageMap<_, Blake2_128Concat, T::AccountId, AccountsLedger>>; + StorageMap<_, Identity, T::AccountId, AccountsLedger>>; #[pallet::type_value] pub fn DefaultBucketCount() -> u128 { diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index e2ab974fa..2d9dd66a6 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -258,7 +258,7 @@ pub mod pallet { /// Map from all locked "stash" accounts to the controller account. #[pallet::storage] #[pallet::getter(fn bonded)] - pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + pub type Bonded = StorageMap<_, Identity, T::AccountId, T::AccountId>; /// DDC clusters staking settings. #[pallet::storage] @@ -270,36 +270,30 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = - StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger>>; + StorageMap<_, Identity, T::AccountId, StakingLedger>>; /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to /// participate into. #[pallet::storage] #[pallet::getter(fn edges)] - pub type Edges = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; + pub type Edges = StorageMap<_, Identity, T::AccountId, ClusterId>; /// The map of (wannabe) storage network participants stash keys to the DDC cluster ID they wish /// to participate into.. #[pallet::storage] #[pallet::getter(fn storages)] - pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; + pub type Storages = StorageMap<_, Identity, T::AccountId, ClusterId>; /// Map from all "stash" accounts to the paid out rewards #[pallet::storage] #[pallet::getter(fn rewards)] - pub type Rewards = - StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf, ValueQuery>; + pub type Rewards = StorageMap<_, Identity, T::AccountId, BalanceOf, ValueQuery>; /// Map from all "stash" accounts to the paid out rewards #[pallet::storage] #[pallet::getter(fn paideraspernode)] - pub type PaidErasPerNode = StorageMap< - _, - Blake2_128Concat, - T::AccountId, - Vec>>, - ValueQuery, - >; + pub type PaidErasPerNode = + StorageMap<_, Identity, T::AccountId, Vec>>, ValueQuery>; // Map to check if validation decision was performed for the era #[pallet::storage] @@ -310,7 +304,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn contentownerscharged)] pub(super) type EraContentOwnersCharged = - StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + StorageDoubleMap<_, Identity, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; /// The current era index. /// @@ -334,7 +328,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn eras_edges_reward_points_per_node)] pub type ErasEdgesRewardPointsPerNode = - StorageMap<_, Twox64Concat, T::AccountId, Vec, ValueQuery>; + StorageMap<_, Identity, T::AccountId, Vec, ValueQuery>; /// Price per byte of the bucket traffic in smallest units of the currency. #[pallet::storage] diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index e9a00b0bb..f9ce7da87 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -222,13 +222,13 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn assignments)] pub(super) type Assignments = - StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, Vec>; + StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, Vec>; // Map to check if validation decision was performed for the era #[pallet::storage] #[pallet::getter(fn content_owners_charged)] pub(super) type EraContentOwnersCharged = - StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, bool, ValueQuery>; /// A signal to start a process on all the validators. #[pallet::storage] @@ -239,19 +239,19 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn validation_decisions)] pub type ValidationDecisions = - StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, ValidationDecision>; + StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, ValidationDecision>; // Map to check if validation decision was performed for the era #[pallet::storage] #[pallet::getter(fn validation_decision_set_for_node)] pub(super) type ValidationDecisionSetForNode = - StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, bool, ValueQuery>; // Map to check if reward points were set for the era #[pallet::storage] #[pallet::getter(fn reward_points_set_for_node)] pub(super) type RewardPointsSetForNode = - StorageDoubleMap<_, Twox64Concat, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; + StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, bool, ValueQuery>; /// The last era for which the tasks assignment produced. #[pallet::storage] @@ -261,8 +261,7 @@ pub mod pallet { /// The mapping of controller accounts to OCW public keys #[pallet::storage] #[pallet::getter(fn ocw_keys)] - pub type OffchainWorkerKeys = - StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + pub type OffchainWorkerKeys = StorageMap<_, Identity, T::AccountId, T::AccountId>; #[pallet::error] pub enum Error { From b87f620e0b986dcf01ea36a0f9e115cebbebfb4e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 10:31:30 +0200 Subject: [PATCH 268/544] add missing error types and remove unwrap from exstrinsics --- pallets/ddc-accounts/src/lib.rs | 8 +++++--- pallets/ddc-staking/src/lib.rs | 5 ++++- pallets/ddc-validator/src/lib.rs | 13 +++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 526b7295c..773f53126 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -225,6 +225,8 @@ pub mod pallet { NoMoreChunks, /// Internal state has become somehow corrupted and the operation cannot continue. BadState, + /// Current era not set + DDCEraNotSet, } #[pallet::genesis_config] @@ -425,8 +427,8 @@ pub mod pallet { ledger.active = Zero::zero(); } - let current_era = - ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; + let current_era = ddc_staking::pallet::Pallet::::current_era() + .ok_or(Error::::DDCEraNotSet)?; // Note: bonding for extra era to allow for accounting let era = current_era + ::BondingDuration::get(); log::debug!("Era for the unbond: {:?}", era); @@ -468,7 +470,7 @@ pub mod pallet { let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); let current_era = - ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; + ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ledger = ledger.consolidate_unlocked(current_era); log::debug!("Current era: {:?}", current_era); diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 2d9dd66a6..64aa27968 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -463,6 +463,7 @@ pub mod pallet { DoubleSpendRewards, PricingNotSet, BudgetOverflow, + DDCEraNotSet, } #[pallet::hooks] @@ -839,10 +840,12 @@ pub mod pallet { #[pallet::weight(100_000)] pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { ensure_signed(origin)?; - let current_era = Self::current_era().ok_or("DDC era not set")?; + let current_era = Self::current_era().ok_or(Error::::DDCEraNotSet)?; + // Makes sure this era hasn't been paid out yet ensure!(!Self::paideras(era), Error::::DoubleSpendRewards); + // This should be adjusted based on the finality of validation ensure!(current_era >= era + 2, Error::::EraNotValidated); PaidEras::::insert(era, true); diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index f9ce7da87..a63706e2a 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -265,11 +265,13 @@ pub mod pallet { #[pallet::error] pub enum Error { + DDCEraNotSet, NotController, OCWKeyNotRegistered, ContentOwnersDoubleSpend, ValidationDecisionAlreadySet, NodeNotActive, + PricingNotSet, } #[pallet::event] @@ -494,7 +496,7 @@ pub mod pallet { log::debug!("Controller is {:?}", controller); let current_era = - ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; + ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ensure!( OffchainWorkerKeys::::contains_key(&controller), @@ -506,12 +508,11 @@ pub mod pallet { Error::::ContentOwnersDoubleSpend ); - let pricing: u128 = >::pricing().unwrap(); - >::charge_payments_new(paying_accounts, pricing); - + let pricing: u128 = + >::pricing().ok_or(Error::::PricingNotSet)?; EraContentOwnersCharged::::insert(current_era, controller, true); - Ok(()) + >::charge_payments_new(paying_accounts, pricing) } #[pallet::weight(100_000)] @@ -525,7 +526,7 @@ pub mod pallet { pub fn set_ocw_key(origin: OriginFor, ocw_pub: T::AccountId) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = staking::Ledger::::get(&controller).ok_or(Error::::NotController)?; - let era = staking::Pallet::::current_era().unwrap(); + let era = staking::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ensure!( staking::ErasStakers::::contains_key(era, &ledger.stash), From 52850086f9a5f04f4f2b72967b7b9feb270e9a92 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 15:26:39 +0200 Subject: [PATCH 269/544] remove type TimeProvider --- Cargo.lock | 1 + pallets/ddc-accounts/src/lib.rs | 1 - pallets/ddc-staking/src/lib.rs | 2 -- pallets/ddc-staking/src/mock.rs | 1 - pallets/ddc-validator/src/lib.rs | 1 - pallets/ddc-validator/src/mock.rs | 3 --- runtime/cere-dev/src/lib.rs | 3 --- 7 files changed, 1 insertion(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dbbcfb847..3a7808820 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4833,6 +4833,7 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-ddc-staking", "parity-scale-codec", "scale-info", "sp-io", diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 773f53126..2cb567438 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -163,7 +163,6 @@ pub mod pallet { /// Number of eras that staked funds must remain bonded for. #[pallet::constant] type BondingDuration: Get; - type TimeProvider: UnixTime; } /// Map from all locked "stash" accounts to the controller account. diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 64aa27968..224077247 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -251,8 +251,6 @@ pub mod pallet { /// Time used for computing era index. It is guaranteed to start being called from the first /// `on_finalize`. type UnixTime: UnixTime; - - type TimeProvider: UnixTime; } /// Map from all locked "stash" accounts to the controller account. diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 88b696b81..c82675b73 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -107,7 +107,6 @@ impl crate::pallet::Config for Test { type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; type UnixTime = Timestamp; - type TimeProvider = Timestamp; type WeightInfo = (); type StakersPayoutSource = DdcAccountsPalletId; } diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index a63706e2a..c29ea49cf 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -200,7 +200,6 @@ pub mod pallet { type RuntimeCall: From>; type AuthorityId: AppCrypto; - type TimeProvider: UnixTime; /// Number of validators expected to produce an individual validation decision to form a /// consensus. Tasks assignment procedure use this value to determine the number of diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 77e1f0718..c79fc5b0e 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -253,7 +253,6 @@ impl pallet_ddc_accounts::Config for Test { type Currency = Balances; type RuntimeEvent = RuntimeEvent; type PalletId = DdcAccountsPalletId; - type TimeProvider = pallet_timestamp::Pallet; } parameter_types! { @@ -273,7 +272,6 @@ impl pallet_ddc_staking::Config for Test { type RuntimeEvent = RuntimeEvent; type StakersPayoutSource = DdcAccountsPalletId; type UnixTime = Timestamp; - type TimeProvider = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } @@ -288,7 +286,6 @@ impl pallet_ddc_validator::Config for Test { type Randomness = RandomnessCollectiveFlip; type RuntimeCall = RuntimeCall; type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; - type TimeProvider = pallet_timestamp::Pallet; type ValidationThreshold = ValidationThreshold; type ValidatorsMax = (); } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 11be6ce59..803f9d3bf 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1332,7 +1332,6 @@ impl pallet_ddc_staking::Config for Runtime { type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; - type TimeProvider = pallet_timestamp::Pallet; type StakersPayoutSource = Ddc_Accounts_Pallet_Id; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; @@ -1347,7 +1346,6 @@ impl pallet_ddc_accounts::Config for Runtime { type Currency = Balances; type PalletId = Ddc_Accounts_Pallet_Id; type RuntimeEvent = RuntimeEvent; - type TimeProvider = pallet_timestamp::Pallet; } parameter_types! { @@ -1362,7 +1360,6 @@ impl pallet_ddc_validator::Config for Runtime { type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; - type TimeProvider = pallet_timestamp::Pallet; type ValidationThreshold = ValidationThreshold; type ValidatorsMax = ValidatorsMax; } From af8508f47fc9c43ddb68b152250fc50e41f1d1e3 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 15:33:23 +0200 Subject: [PATCH 270/544] remove deprecated method and rename charge_payments to charge_content_owners --- pallets/ddc-accounts/src/lib.rs | 36 +------------------------------- pallets/ddc-validator/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 2cb567438..75a9e2ba2 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -251,40 +251,6 @@ pub mod pallet { #[pallet::call] impl Pallet { - #[pallet::weight(10_000)] - pub fn charge_payments( - origin: OriginFor, - paying_accounts: Vec>>, - ) -> DispatchResult { - let validator = ensure_signed(origin)?; - let mut total_charged = BalanceOf::::zero(); - - for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); - let content_owner = bucket.owner_id; - let amount = bucket_details.amount; - - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; - if ledger.active >= amount { - ledger.total -= amount; - ledger.active -= amount; - total_charged += amount; - Self::update_ledger(&content_owner, &ledger); - } else { - let diff = amount - ledger.active; - total_charged += ledger.active; - ledger.total -= ledger.active; - ledger.active = BalanceOf::::zero(); - let (ledger, charged) = ledger.charge_unlocking(diff); - Self::update_ledger(&content_owner, &ledger); - total_charged += charged; - } - } - Self::deposit_event(Event::::Charged(total_charged)); - - Ok(()) - } - #[pallet::weight(10_000)] pub fn create_bucket( origin: OriginFor, @@ -563,7 +529,7 @@ pub mod pallet { } // Charge payments from content owners - pub fn charge_payments_new( + pub fn charge_content_owners( paying_accounts: Vec>>, pricing: u128, ) -> DispatchResult { diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index c29ea49cf..961110cd2 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -511,7 +511,7 @@ pub mod pallet { >::pricing().ok_or(Error::::PricingNotSet)?; EraContentOwnersCharged::::insert(current_era, controller, true); - >::charge_payments_new(paying_accounts, pricing) + >::charge_content_owners(paying_accounts, pricing) } #[pallet::weight(100_000)] From 7c4f5bd7564035dd0c3f1e1d1bf48deed25fb34c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 15:34:43 +0200 Subject: [PATCH 271/544] remove obsolete method; payout_cdn_owners can be called directly from ddc-staking --- pallets/ddc-validator/src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 961110cd2..4ae5764bc 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -511,14 +511,7 @@ pub mod pallet { >::pricing().ok_or(Error::::PricingNotSet)?; EraContentOwnersCharged::::insert(current_era, controller, true); - >::charge_content_owners(paying_accounts, pricing) - } - - #[pallet::weight(100_000)] - pub fn payout_cdn_owners(origin: OriginFor, era: EraIndex) -> DispatchResult { - ensure_signed(origin)?; - - >::do_payout_stakers(era) + >::charge_content_owners(paying_accounts, pricing) } #[pallet::weight(100_000)] From 3064fcaecc10984dbbef7deb55f9e1edc47f0206 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 23 Aug 2023 15:36:08 +0200 Subject: [PATCH 272/544] remove obsolete method set_era_reward_points --- pallets/ddc-staking/src/lib.rs | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 224077247..cf065f122 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -850,39 +850,6 @@ pub mod pallet { Self::do_payout_stakers(era) } - /// Set reward points for CDN participants at the given era. - /// - /// The dispatch origin for this call must be _Signed_ by the validator. - /// - /// `stakers_points` is a vector of (stash account ID, reward points) pairs. The rewards - /// distribution will be based on total reward points, with each CDN participant receiving a - /// proportionate reward based on their individual reward points. - /// - /// See also [`ErasEdgesRewardPoints`]. - #[pallet::weight(100_000)] - pub fn set_era_reward_points( - origin: OriginFor, - era: EraIndex, - stakers_points: Vec<(T::AccountId, u64)>, - ) -> DispatchResult { - ensure_signed(origin)?; - - // ToDo: ensure origin is a validator eligible to set rewards - - // Check that a staker mentioned only once, fail with an error otherwise. - let unique_stakers_count = - stakers_points.iter().map(|(staker, _)| staker).collect::>().len(); - if unique_stakers_count != stakers_points.len() { - Err(Error::::DuplicateRewardPoints)? - } - - // ToDo: check that all accounts had an active stake at the era - - Self::reward_by_ids(era, stakers_points); - - Ok(()) - } - /// Set price per byte of the bucket traffic in smallest units of the currency. /// /// The dispatch origin for this call must be _Root_. From a047427c2e7ce8dc450fc916dc7815b7e87178cb Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 10:36:44 +0200 Subject: [PATCH 273/544] fix comments for errors and exstrinsics --- pallets/ddc-accounts/src/lib.rs | 4 +-- pallets/ddc-staking/src/lib.rs | 30 ++++++++++++------- pallets/ddc-validator/src/lib.rs | 51 ++++++++++++++++---------------- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 75a9e2ba2..9e892a90e 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -185,7 +185,7 @@ pub mod pallet { pub type BucketsCount = StorageValue>; - /// Map from all locked accounts and their buckets to the bucket structure + /// Map from bucket ID to to the bucket structure #[pallet::storage] #[pallet::getter(fn buckets)] pub type Buckets = @@ -224,7 +224,7 @@ pub mod pallet { NoMoreChunks, /// Internal state has become somehow corrupted and the operation cannot continue. BadState, - /// Current era not set + /// Current era not set during runtime DDCEraNotSet, } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index cf065f122..4f1482181 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -88,7 +88,7 @@ pub struct EraRewardPoints { pub individual: BTreeMap, } -/// Reward points of an era. Used to split era total payout between stakers. +/// Reward points for particular era. To be used in a mapping. #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] pub struct EraRewardPointsPerNode { /// Era points accrued @@ -282,28 +282,28 @@ pub mod pallet { #[pallet::getter(fn storages)] pub type Storages = StorageMap<_, Identity, T::AccountId, ClusterId>; - /// Map from all "stash" accounts to the paid out rewards + /// Map from all "stash" accounts to the total paid out rewards + /// + /// P.S. Not part of Mainnet #[pallet::storage] #[pallet::getter(fn rewards)] pub type Rewards = StorageMap<_, Identity, T::AccountId, BalanceOf, ValueQuery>; - /// Map from all "stash" accounts to the paid out rewards + /// Map from all "stash" accounts to the paid out rewards per era + /// + /// P.S. Not part of Mainnet #[pallet::storage] #[pallet::getter(fn paideraspernode)] pub type PaidErasPerNode = StorageMap<_, Identity, T::AccountId, Vec>>, ValueQuery>; - // Map to check if validation decision was performed for the era + /// Map to check if CDN participants received payments for specific era + /// + /// Used to avoid double-spend in method [payout_stakers] #[pallet::storage] #[pallet::getter(fn paideras)] pub(super) type PaidEras = StorageMap<_, Twox64Concat, EraIndex, bool, ValueQuery>; - // Map to check if validation decision was performed for the era - #[pallet::storage] - #[pallet::getter(fn contentownerscharged)] - pub(super) type EraContentOwnersCharged = - StorageDoubleMap<_, Identity, EraIndex, Twox64Concat, T::AccountId, bool, ValueQuery>; - /// The current era index. /// /// This is the latest planned era, depending on how the Session pallet queues the validator @@ -313,6 +313,7 @@ pub mod pallet { pub type CurrentEra = StorageValue<_, EraIndex>; /// The reward each CDN participant earned in the era. + /// Mapping from Era to vector of CDN participants and respective rewards /// /// See also [`pallet_staking::ErasRewardPoints`]. #[pallet::storage] @@ -321,8 +322,9 @@ pub mod pallet { StorageMap<_, Twox64Concat, EraIndex, EraRewardPoints, ValueQuery>; /// The reward each CDN participant earned in the era. + /// Mapping from each CDN participant to vector of eras and rewards /// - /// See also [`pallet_staking::ErasRewardPoints`]. + /// P.S. Not part of Mainnet #[pallet::storage] #[pallet::getter(fn eras_edges_reward_points_per_node)] pub type ErasEdgesRewardPointsPerNode = @@ -456,11 +458,17 @@ pub mod pallet { AlreadyInRole, /// Action is allowed at some point of time in future not reached yet. TooEarly, + /// We are not yet sure that era has been valdiated by this time EraNotValidated, + /// Attempt to assign reward point for some era more than once DuplicateRewardPoints, + /// Attempt to double spend the assigned rewards per era DoubleSpendRewards, + /// Pricing has not been set by sudo PricingNotSet, + /// Payout amount overflows BudgetOverflow, + /// Current era not set during runtime DDCEraNotSet, } diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 4ae5764bc..c29112c98 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -223,7 +223,8 @@ pub mod pallet { pub(super) type Assignments = StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, Vec>; - // Map to check if validation decision was performed for the era + /// Map to from era and account ID to bool indicateing that a particular content owner was + /// charged for the era #[pallet::storage] #[pallet::getter(fn content_owners_charged)] pub(super) type EraContentOwnersCharged = @@ -264,13 +265,20 @@ pub mod pallet { #[pallet::error] pub enum Error { - DDCEraNotSet, + /// Caller is not controller of validator node NotController, + /// OCW key has not been registered by validator OCWKeyNotRegistered, + /// Attempt to charge content owners twice ContentOwnersDoubleSpend, + /// Validation decision has been already set for CDN node for some era ValidationDecisionAlreadySet, + /// Node is not participating in the network NodeNotActive, + /// Pricing has not been set by sudo PricingNotSet, + /// Current era not set during runtime + DDCEraNotSet, } #[pallet::event] @@ -398,6 +406,10 @@ pub mod pallet { } /// Set validation decision for a given CDN node in an era. + /// + /// Only registered validator keys can call this exstrinsic. + /// Validation decision can be set only once per era per CDN node. + /// CDN node should be active. #[pallet::weight(10_000)] pub fn set_validation_decision( origin: OriginFor, @@ -438,14 +450,13 @@ pub mod pallet { /// Set reward points for CDN participants at the given era. /// - /// ToDo: remove it when the off-chain worker will be able to set reward points using the - /// same call defined in `pallet-ddc-staking`. + /// Only registered validator keys can call this exstrinsic. + /// Reward points can be set only once per era per CDN node. + /// CDN node should be active. /// /// `stakers_points` is a vector of (stash account ID, reward points) pairs. The rewards /// distribution will be based on total reward points, with each CDN participant receiving a /// proportionate reward based on their individual reward points. - /// - /// See also [`pallet_ddc_staking::ErasEdgesRewardPoints`]. #[pallet::weight(100_000)] pub fn set_era_reward_points( origin: OriginFor, @@ -462,9 +473,7 @@ pub mod pallet { >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { if !Self::reward_points_set_for_node(era, &staker) { - // check if rewards were not yet set for era for node if >::contains_key(&staker) { - // check if node is active *era_rewards.individual.entry(staker.clone()).or_default() += points; era_rewards.total += points; >::mutate( @@ -486,30 +495,34 @@ pub mod pallet { Ok(()) } + /// Exstrinsic deducts balances of content owners + /// + /// Only registered validator keys can call this exstrinsic. + /// Reward points can be set only once per era per validator. #[pallet::weight(100_000)] pub fn charge_payments_content_owners( origin: OriginFor, paying_accounts: Vec>>, ) -> DispatchResult { - let controller = ensure_signed(origin)?; - log::debug!("Controller is {:?}", controller); + let validator_ocw = ensure_signed(origin)?; + log::debug!("validator is {:?}", validator_ocw); let current_era = ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ensure!( - OffchainWorkerKeys::::contains_key(&controller), + OffchainWorkerKeys::::contains_key(&validator_ocw), Error::::OCWKeyNotRegistered ); ensure!( - !Self::content_owners_charged(current_era, &controller), + !Self::content_owners_charged(current_era, &validator_ocw), Error::::ContentOwnersDoubleSpend ); let pricing: u128 = >::pricing().ok_or(Error::::PricingNotSet)?; - EraContentOwnersCharged::::insert(current_era, controller, true); + EraContentOwnersCharged::::insert(current_era, validator_ocw, true); >::charge_content_owners(paying_accounts, pricing) } @@ -565,18 +578,6 @@ pub mod pallet { Ok(signer) } - fn validate(bytes_sent: &dac::BytesSent, bytes_received: &dac::BytesReceived) -> bool { - let percentage_difference = 1f32 - (bytes_received.sum as f32 / bytes_sent.sum as f32); - - return if percentage_difference >= 0.0 && - (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 - { - true - } else { - false - } - } - fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool { if bytes_sent == bytes_received { return true From 9b37895a531179a1ea2b9d857ae7540068749bc1 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 13:28:22 +0200 Subject: [PATCH 274/544] rename ocw key to validator key & some formatting --- pallets/ddc-validator/src/lib.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index c29112c98..f8eb7f6cb 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -268,7 +268,7 @@ pub mod pallet { /// Caller is not controller of validator node NotController, /// OCW key has not been registered by validator - OCWKeyNotRegistered, + DDCValidatorKeyNotRegistered, /// Attempt to charge content owners twice ContentOwnersDoubleSpend, /// Validation decision has been already set for CDN node for some era @@ -316,7 +316,7 @@ pub mod pallet { }; log::debug!("Current DDC era: {:?}.", current_ddc_era); - // Produce an assignment for the next era if it's not produced yet. + // Skip assignment if already exists for current era match Self::last_managed_era() { Some(last_managed_era) if current_ddc_era < last_managed_era => return Weight::from_ref_time(0), @@ -331,7 +331,7 @@ pub mod pallet { Weight::from_ref_time(0) } - fn offchain_worker(block_number: T::BlockNumber) { + fn offchain_worker(_block_number: T::BlockNumber) { // Skip if not a validator. if !sp_io::offchain::is_validator() { return @@ -421,7 +421,7 @@ pub mod pallet { ensure!( OffchainWorkerKeys::::contains_key(&controller), - Error::::OCWKeyNotRegistered + Error::::DDCValidatorKeyNotRegistered ); ensure!( @@ -467,7 +467,7 @@ pub mod pallet { ensure!( OffchainWorkerKeys::::contains_key(&controller), - Error::::OCWKeyNotRegistered + Error::::DDCValidatorKeyNotRegistered ); >::mutate(era, |era_rewards| { @@ -512,9 +512,11 @@ pub mod pallet { ensure!( OffchainWorkerKeys::::contains_key(&validator_ocw), - Error::::OCWKeyNotRegistered + Error::::DDCValidatorKeyNotRegistered ); + // ToDo check that key is in active validator set + ensure!( !Self::content_owners_charged(current_era, &validator_ocw), Error::::ContentOwnersDoubleSpend @@ -528,14 +530,13 @@ pub mod pallet { } #[pallet::weight(100_000)] - pub fn set_ocw_key(origin: OriginFor, ocw_pub: T::AccountId) -> DispatchResult { + pub fn set_validator_key(origin: OriginFor, ocw_pub: T::AccountId) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = staking::Ledger::::get(&controller).ok_or(Error::::NotController)?; - let era = staking::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ensure!( - staking::ErasStakers::::contains_key(era, &ledger.stash), - Error::::NotController + staking::Validators::::contains_key(&ledger.stash), + Error::::NotController // ToDo change error type ); OffchainWorkerKeys::::insert(ocw_pub, controller); From 08a1d88e64e6e9ebe391613c93a4fb3c84401f4a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 13:52:54 +0200 Subject: [PATCH 275/544] add another safety check to verify that stash key belonging to validator who registered the ddc validator key is in the active set --- pallets/ddc-validator/src/lib.rs | 69 +++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index f8eb7f6cb..2fca6f69e 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -82,13 +82,7 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and adjusted -/// Offchain local storage key that holds the last era in which the validator completed its -/// assignment. -const LAST_VALIDATED_ERA_LOCK_KEY: &[u8; 45] = b"pallet-ddc-validator::last-validated-era-lock"; -const LAST_VALIDATED_ERA_STORAGE_KEY: &[u8; 48] = - b"pallet-ddc-validator::last-validated-era-storage"; /// Webdis in experimental cluster connected to Redis in dev. -// pub const DEFAULT_DATA_PROVIDER_URL: &str = "https://dev-dac-redis.network-dev.aws.cere.io"; pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; // pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; @@ -258,15 +252,17 @@ pub mod pallet { #[pallet::getter(fn last_managed_era)] pub type LastManagedEra = StorageValue<_, EraIndex>; - /// The mapping of controller accounts to OCW public keys + /// The mapping of ddc validator keys to validator stash keys #[pallet::storage] - #[pallet::getter(fn ocw_keys)] + #[pallet::getter(fn get_stash_for_ddc_validator)] pub type OffchainWorkerKeys = StorageMap<_, Identity, T::AccountId, T::AccountId>; #[pallet::error] pub enum Error { /// Caller is not controller of validator node NotController, + /// Checked stash is not an active validator + NotValidatorStash, /// OCW key has not been registered by validator DDCValidatorKeyNotRegistered, /// Attempt to charge content owners twice @@ -408,6 +404,7 @@ pub mod pallet { /// Set validation decision for a given CDN node in an era. /// /// Only registered validator keys can call this exstrinsic. + /// Validator should be in the active set. /// Validation decision can be set only once per era per CDN node. /// CDN node should be active. #[pallet::weight(10_000)] @@ -417,13 +414,20 @@ pub mod pallet { cdn_node: T::AccountId, validation_decision: ValidationDecision, ) -> DispatchResult { - let controller = ensure_signed(origin)?; + let ddc_valitor_key = ensure_signed(origin)?; ensure!( - OffchainWorkerKeys::::contains_key(&controller), + OffchainWorkerKeys::::contains_key(&ddc_valitor_key), Error::::DDCValidatorKeyNotRegistered ); + ensure!( + staking::Validators::::contains_key(Self::get_stash_for_ddc_validator( + &ddc_valitor_key).unwrap() + ), + Error::::NotValidatorStash + ); + ensure!( !Self::validation_decision_set_for_node(era, &cdn_node), Error::::ValidationDecisionAlreadySet @@ -433,7 +437,6 @@ pub mod pallet { >::contains_key(&cdn_node), Error::::NodeNotActive ); - // ToDo: check if the era is current - 1. ValidationDecisions::::insert(era, cdn_node.clone(), validation_decision.clone()); @@ -451,6 +454,7 @@ pub mod pallet { /// Set reward points for CDN participants at the given era. /// /// Only registered validator keys can call this exstrinsic. + /// Validator should be in the active set. /// Reward points can be set only once per era per CDN node. /// CDN node should be active. /// @@ -463,13 +467,20 @@ pub mod pallet { era: EraIndex, stakers_points: Vec<(T::AccountId, u64)>, ) -> DispatchResult { - let controller = ensure_signed(origin)?; + let ddc_valitor_key = ensure_signed(origin)?; ensure!( - OffchainWorkerKeys::::contains_key(&controller), + OffchainWorkerKeys::::contains_key(&ddc_valitor_key), Error::::DDCValidatorKeyNotRegistered ); + ensure!( + staking::Validators::::contains_key(Self::get_stash_for_ddc_validator( + &ddc_valitor_key).unwrap() + ), + Error::::NotValidatorStash + ); + >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { if !Self::reward_points_set_for_node(era, &staker) { @@ -504,42 +515,54 @@ pub mod pallet { origin: OriginFor, paying_accounts: Vec>>, ) -> DispatchResult { - let validator_ocw = ensure_signed(origin)?; - log::debug!("validator is {:?}", validator_ocw); + let ddc_valitor_key = ensure_signed(origin)?; + log::debug!("validator is {:?}", &ddc_valitor_key); let current_era = ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ensure!( - OffchainWorkerKeys::::contains_key(&validator_ocw), + OffchainWorkerKeys::::contains_key(&ddc_valitor_key), Error::::DDCValidatorKeyNotRegistered ); - // ToDo check that key is in active validator set + ensure!( + staking::Validators::::contains_key(Self::get_stash_for_ddc_validator( + &ddc_valitor_key).unwrap() + ), + Error::::NotValidatorStash + ); ensure!( - !Self::content_owners_charged(current_era, &validator_ocw), + !Self::content_owners_charged(current_era, &ddc_valitor_key), Error::::ContentOwnersDoubleSpend ); let pricing: u128 = >::pricing().ok_or(Error::::PricingNotSet)?; - EraContentOwnersCharged::::insert(current_era, validator_ocw, true); + EraContentOwnersCharged::::insert(current_era, ddc_valitor_key, true); >::charge_content_owners(paying_accounts, pricing) } + /// Exstrinsic registers a ddc validator key for future use + /// + /// Only controller of validator can call this exstrinsic + /// Validator has to be in the active set #[pallet::weight(100_000)] - pub fn set_validator_key(origin: OriginFor, ocw_pub: T::AccountId) -> DispatchResult { + pub fn set_validator_key( + origin: OriginFor, + ddc_validator_pub: T::AccountId, + ) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = staking::Ledger::::get(&controller).ok_or(Error::::NotController)?; ensure!( staking::Validators::::contains_key(&ledger.stash), - Error::::NotController // ToDo change error type + Error::::NotValidatorStash ); - OffchainWorkerKeys::::insert(ocw_pub, controller); + OffchainWorkerKeys::::insert(ddc_validator_pub, &ledger.stash); Ok(()) } } @@ -901,7 +924,7 @@ pub mod pallet { let signer = Self::get_signer().unwrap(); - let tx_res = + let _tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { era: current_ddc_era - 1, cdn_node: utils::string_to_account::(edge.clone()), From 955b116672b16dbb6e13d5272de8003fc5210e56 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 13:58:55 +0200 Subject: [PATCH 276/544] simplify do_payout_stakers --- pallets/ddc-staking/src/lib.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 4f1482181..ab96cd6ae 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -871,8 +871,7 @@ pub mod pallet { impl Pallet { pub fn do_payout_stakers(era: EraIndex) -> DispatchResult { - // ToDo: check that the era is finished - // ToDo: check reward points are set + // ToDo: check that validation is finalised for era let era_reward_points: EraRewardPoints = >::get(&era); @@ -885,32 +884,18 @@ pub mod pallet { // An account we withdraw the funds from and the amount of funds to withdraw. let payout_source_account: T::AccountId = T::StakersPayoutSource::get().into_account_truncating(); - let payout_budget: BalanceOf = - match (price_per_byte * era_reward_points.total as u128).try_into() { - Ok(value) => value, - Err(_) => Err(Error::::BudgetOverflow)?, - }; - log::debug!( - "Will payout to DDC stakers for era {:?} from account {:?} with total budget {:?} \ - , there are {:?} stakers earned {:?} reward points with price per byte {:?}", - era, - payout_source_account, - payout_budget, - era_reward_points.individual.len(), - era_reward_points.total, - price_per_byte, - ); // Transfer a part of the budget to each CDN participant rewarded this era. for (stash, points) in era_reward_points.clone().individual { - let part = Perbill::from_rational(points, era_reward_points.total); - let reward: BalanceOf = part * payout_budget; + let reward: BalanceOf = match (points as u128 * price_per_byte).try_into() { + Ok(value) => value, + Err(_) => Err(Error::::BudgetOverflow)?, + }; log::debug!( - "Rewarding {:?} with {:?} points, its part is {:?}, reward size {:?}, balance \ + "Rewarding {:?} with {:?} points, reward size {:?}, balance \ on payout source account {:?}", stash, points, - part, reward, T::Currency::free_balance(&payout_source_account) ); From 4392557407c1dfffc180cd7c04b23bc2eb092b1d Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 22:35:04 +0200 Subject: [PATCH 277/544] update validator tests --- pallets/ddc-staking/src/lib.rs | 4 ++-- pallets/ddc-validator/src/tests.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ab96cd6ae..0fa560a08 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -59,10 +59,10 @@ pub use pallet::*; /// /// If you are changing this, check `on_finalize` hook to ensure `CurrentEra` is capable to hold the /// value with the new era duration. -const DDC_ERA_DURATION_MS: u128 = 120_000; +pub const DDC_ERA_DURATION_MS: u128 = 120_000; /// 2023-01-01 00:00:00 UTC -const DDC_ERA_START_MS: u128 = 1_672_531_200_000; +pub const DDC_ERA_START_MS: u128 = 1_672_531_200_000; const DDC_STAKING_ID: LockIdentifier = *b"ddcstake"; // DDC maintainer's stake /// Counter for the number of "reward" points earned by a given staker. diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 4d9b0bdd7..745deb3f8 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -2,6 +2,7 @@ use super::*; use crate::mock::{Timestamp, *}; use codec::Decode; use pallet_ddc_accounts::BucketsDetails; +use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; use sp_runtime::offchain::storage::StorageValueRef; @@ -112,7 +113,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { } t.execute_with(|| { - let era_block_number = ERA_IN_BLOCKS as u32 * era_to_validate; + let era_block_number = 20 as u32 * era_to_validate; System::set_block_number(era_block_number); // required for randomness Timestamp::set_timestamp( @@ -152,7 +153,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { assert!(tx.signature.is_some()); assert_eq!( tx.call, - crate::mock::RuntimeCall::DdcValidator(crate::Call::payout_cdn_owners { + crate::mock::RuntimeCall::DdcStaking(pallet_ddc_staking::Call::payout_stakers { era: era_to_validate + 1 }) ); From 6c45c94cd5b3e9b3858aa1ea937ce7d0dc5ea565 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 22:37:59 +0200 Subject: [PATCH 278/544] use snake_case for getters --- pallets/ddc-staking/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 0fa560a08..134d45a78 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -293,7 +293,7 @@ pub mod pallet { /// /// P.S. Not part of Mainnet #[pallet::storage] - #[pallet::getter(fn paideraspernode)] + #[pallet::getter(fn paid_eras_per_node)] pub type PaidErasPerNode = StorageMap<_, Identity, T::AccountId, Vec>>, ValueQuery>; @@ -301,7 +301,7 @@ pub mod pallet { /// /// Used to avoid double-spend in method [payout_stakers] #[pallet::storage] - #[pallet::getter(fn paideras)] + #[pallet::getter(fn paid_eras)] pub(super) type PaidEras = StorageMap<_, Twox64Concat, EraIndex, bool, ValueQuery>; /// The current era index. @@ -849,7 +849,7 @@ pub mod pallet { let current_era = Self::current_era().ok_or(Error::::DDCEraNotSet)?; // Makes sure this era hasn't been paid out yet - ensure!(!Self::paideras(era), Error::::DoubleSpendRewards); + ensure!(!Self::paid_eras(era), Error::::DoubleSpendRewards); // This should be adjusted based on the finality of validation ensure!(current_era >= era + 2, Error::::EraNotValidated); From db88c54eb521cc13bc574a8c5214828706d75c85 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 24 Aug 2023 22:43:58 +0200 Subject: [PATCH 279/544] deposit events should be placed in the end of an exstrinsic as they are not reversible --- pallets/ddc-accounts/src/lib.rs | 11 ++++------- pallets/ddc-staking/src/lib.rs | 4 ++-- pallets/ddc-validator/src/lib.rs | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 9e892a90e..1f24c4449 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -53,12 +53,6 @@ pub struct BucketsDetails { pub amount: Balance, } -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct ReceiverDetails { - cdn_owner: AccountId, - amount: Balance, -} - #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct AccountsLedger { /// The stash account whose balance is actually locked and can be used for CDN usage. @@ -251,6 +245,9 @@ pub mod pallet { #[pallet::call] impl Pallet { + /// Create new bucket with provided public availability & reserved resources + /// + /// Anyone can create a bucket #[pallet::weight(10_000)] pub fn create_bucket( origin: OriginFor, @@ -309,7 +306,6 @@ pub mod pallet { let stash_balance = ::Currency::free_balance(&stash); let value = value.min(stash_balance); - Self::deposit_event(Event::::Deposited(stash.clone(), value)); let item = AccountsLedger { stash: stash.clone(), total: value, @@ -317,6 +313,7 @@ pub mod pallet { unlocking: Default::default(), }; Self::update_ledger_and_deposit(&stash, &controller, &item)?; + Self::deposit_event(Event::::Deposited(stash.clone(), value)); Ok(()) } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 134d45a78..f355c3d8a 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -528,15 +528,15 @@ pub mod pallet { let stash_balance = T::Currency::free_balance(&stash); let value = value.min(stash_balance); - Self::deposit_event(Event::::Bonded(stash.clone(), value)); let item = StakingLedger { - stash, + stash: stash.clone(), total: value, active: value, chilling: Default::default(), unlocking: Default::default(), }; Self::update_ledger(&controller, &item); + Self::deposit_event(Event::::Bonded(stash, value)); Ok(()) } diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 2fca6f69e..3658306da 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -422,8 +422,8 @@ pub mod pallet { ); ensure!( - staking::Validators::::contains_key(Self::get_stash_for_ddc_validator( - &ddc_valitor_key).unwrap() + staking::Validators::::contains_key( + Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap() ), Error::::NotValidatorStash ); @@ -440,14 +440,14 @@ pub mod pallet { ValidationDecisions::::insert(era, cdn_node.clone(), validation_decision.clone()); + ValidationDecisionSetForNode::::insert(era, cdn_node.clone(), true); + Self::deposit_event(Event::::ValidationDecision( era, - cdn_node.clone(), + cdn_node, validation_decision, )); - ValidationDecisionSetForNode::::insert(era, cdn_node, true); - Ok(()) } @@ -475,8 +475,8 @@ pub mod pallet { ); ensure!( - staking::Validators::::contains_key(Self::get_stash_for_ddc_validator( - &ddc_valitor_key).unwrap() + staking::Validators::::contains_key( + Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap() ), Error::::NotValidatorStash ); @@ -527,8 +527,8 @@ pub mod pallet { ); ensure!( - staking::Validators::::contains_key(Self::get_stash_for_ddc_validator( - &ddc_valitor_key).unwrap() + staking::Validators::::contains_key( + Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap() ), Error::::NotValidatorStash ); @@ -546,8 +546,8 @@ pub mod pallet { } /// Exstrinsic registers a ddc validator key for future use - /// - /// Only controller of validator can call this exstrinsic + /// + /// Only controller of validator can call this exstrinsic /// Validator has to be in the active set #[pallet::weight(100_000)] pub fn set_validator_key( From e33b622d94d117ebd68e759ce9ae24b5d5785a7a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 25 Aug 2023 14:27:09 +0200 Subject: [PATCH 280/544] remove unnecessary moethds and unused imports; change naming --- pallets/ddc-accounts/src/lib.rs | 5 +- pallets/ddc-staking/src/lib.rs | 16 +- pallets/ddc-validator/src/dac.rs | 287 +---------------------------- pallets/ddc-validator/src/lib.rs | 26 +-- pallets/ddc-validator/src/shm.rs | 2 +- pallets/ddc-validator/src/utils.rs | 1 - 6 files changed, 20 insertions(+), 317 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index 1f24c4449..dc2edbbf5 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -5,7 +5,7 @@ use codec::{Decode, Encode, HasCompact}; use frame_support::{ parameter_types, - traits::{Currency, DefensiveSaturating, ExistenceRequirement, UnixTime}, + traits::{Currency, DefensiveSaturating, ExistenceRequirement}, BoundedVec, PalletId, }; pub use pallet_ddc_staking::{self as ddc_staking}; @@ -138,7 +138,6 @@ pub mod pallet { use super::*; use frame_support::{ pallet_prelude::*, sp_runtime::traits::StaticLookup, traits::LockableCurrency, - Blake2_128Concat, }; use frame_system::pallet_prelude::*; @@ -164,7 +163,7 @@ pub mod pallet { #[pallet::getter(fn bonded)] pub type Bonded = StorageMap<_, Identity, T::AccountId, T::AccountId>; - /// Map from all (unlocked) "controller" accounts to the debug regarding the staking. + /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index f355c3d8a..f192687a6 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -30,7 +30,6 @@ use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; use frame_support::{ assert_ok, - dispatch::Codec, pallet_prelude::*, parameter_types, traits::{ @@ -42,16 +41,11 @@ use frame_support::{ use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ - traits::{ - AccountIdConversion, AtLeast32BitUnsigned, CheckedSub, Saturating, StaticLookup, Zero, - }, - Perbill, RuntimeDebug, + traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, + RuntimeDebug, }; use sp_staking::EraIndex; -use sp_std::{ - collections::{btree_map::BTreeMap, btree_set::BTreeSet}, - prelude::*, -}; +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; pub use pallet::*; @@ -528,15 +522,15 @@ pub mod pallet { let stash_balance = T::Currency::free_balance(&stash); let value = value.min(stash_balance); + Self::deposit_event(Event::::Bonded(stash.clone(), value)); let item = StakingLedger { - stash: stash.clone(), + stash, total: value, active: value, chilling: Default::default(), unlocking: Default::default(), }; Self::update_ledger(&controller, &item); - Self::deposit_event(Event::::Bonded(stash, value)); Ok(()) } diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 8910ea70f..a4c81320f 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -1,19 +1,10 @@ //! A module with Data Activity Capture (DAC) interaction. use crate::{utils, DacTotalAggregates, ValidationDecision}; -use alloc::{format, string::String}; // ToDo: remove String usage +use alloc::string::String; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; -use lite_json::{json::JsonValue, json_parser::parse_json}; -use serde_json::{Map, Value}; -use sp_runtime::{ - generic::Era, - offchain::{ - http, - http::{Method, Request}, - Duration, - }, -}; +use sp_runtime::offchain::{http, Duration}; use sp_staking::EraIndex; pub use sp_std::{ collections::{btree_map::BTreeMap, btree_set::BTreeSet}, @@ -192,47 +183,6 @@ pub(crate) struct FinalDecision { #[serde(crate = "alt_serde")] pub(crate) struct FinalDecisions(BTreeMap); -impl BytesSent { - pub fn new(aggregate: RedisFtAggregate) -> BytesSent { - let data = aggregate.ft_aggregate[1].clone(); - - match data { - FtAggregate::Node(node) => - return BytesSent { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5].parse::().expect("bytesSentSum must be convertible to u32"), - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec![]; - for i in 1..aggregation.ft_aggregate.len() { - let data = aggregation.ft_aggregate[i].clone(); - match data { - FtAggregate::Node(node) => { - let node = BytesSent { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5] - .parse::() - .expect("bytesSentSum must be convertible to u32"), - }; - - res.push(node); - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - return res - } -} - #[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] pub struct BytesReceived { pub node_public_key: String, @@ -240,55 +190,12 @@ pub struct BytesReceived { pub sum: u32, } -impl BytesReceived { - pub fn new(aggregate: RedisFtAggregate) -> BytesReceived { - let data = aggregate.ft_aggregate[1].clone(); - - match data { - FtAggregate::Node(node) => - return BytesReceived { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5] - .parse::() - .expect("bytesReceivedSum must be convertible to u32"), - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - pub fn get_all(aggregation: RedisFtAggregate) -> Vec { - let mut res: Vec = vec![]; - for i in 1..aggregation.ft_aggregate.len() { - let data = aggregation.ft_aggregate[i].clone(); - match data { - FtAggregate::Node(node) => { - let node = BytesReceived { - node_public_key: node[1].clone(), - era: node[3].clone().parse::().expect("era must be convertible u32") - as EraIndex, - sum: node[5] - .parse::() - .expect("bytesReceivedSum must be convertible to u32"), - }; - - res.push(node); - }, - FtAggregate::Length(_) => panic!("[DAC Validator] Not a Node"), - } - } - - return res - } -} - fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { let mut timestamps: Vec = Vec::new(); for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { - if let Some(ack) = &chunk.ack { + if let Some(_ack) = &chunk.ack { timestamps.push(chunk.log.timestamp); } } @@ -386,12 +293,6 @@ fn is_lies_within_threshold( false } -fn get_file_request_url(data_provider_url: &String) -> String { - let res = format!("{}/JSON.GET/testddc:dac:data", data_provider_url); - - res -} - pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec { log::debug!("fetch_file_request | url: {:?}", url); let response: FileRequestWrapper = http_get_json(&url).unwrap(); @@ -412,67 +313,6 @@ pub(crate) fn fetch_file_request(url: &String) -> FileRequest { map } -pub(crate) fn fetch_data( - data_provider_url: &String, - era: EraIndex, - cdn_node: &T::AccountId, -) -> (BytesSent, BytesReceived) { - log::debug!("[DAC Validator] DAC Validator is running. Current era is {}", era); - // Todo: handle the error - let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); - let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); - log::debug!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); - let bytes_sent = BytesSent::new(bytes_sent_res); - - // Todo: handle the error - let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); - let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); - log::debug!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); - let bytes_received = BytesReceived::new(bytes_received_res); - - (bytes_sent, bytes_received) -} - -pub(crate) fn fetch_data1( - data_provider_url: &String, - era: EraIndex, -) -> (Vec, Vec) { - log::debug!("[DAC Validator] DAC Validator is running. Current era is {}", era); - // Todo: handle the error - let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); - let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).unwrap(); - log::debug!("[DAC Validator] Bytes sent sum is fetched: {:?}", bytes_sent_res); - let bytes_sent = BytesSent::get_all(bytes_sent_res); - - // Todo: handle the error - let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); - let bytes_received_res: RedisFtAggregate = http_get_json(&bytes_received_query).unwrap(); - log::debug!("[DAC Validator] Bytes received sum is fetched:: {:?}", bytes_received_res); - let bytes_received = BytesReceived::get_all(bytes_received_res); - - (bytes_sent, bytes_received) -} - -pub(crate) fn fetch_data2( - data_provider_url: &String, - era: EraIndex, -) -> Result<(String, Vec, String, Vec), ()> { - let bytes_sent_query = get_bytes_sent_query_url(data_provider_url, era); - let bytes_sent_res: RedisFtAggregate = http_get_json(&bytes_sent_query).map_err(|_| ())?; - let bytes_sent = BytesSent::get_all(bytes_sent_res); - - let bytes_received_query = get_bytes_received_query_url(data_provider_url, era); - let bytes_received_res: RedisFtAggregate = - http_get_json(&bytes_received_query).map_err(|_| ())?; - let bytes_received = BytesReceived::get_all(bytes_received_res); - - Ok((bytes_sent_query, bytes_sent, bytes_received_query, bytes_received)) -} - -fn get_bytes_received_query_url(data_provider_url: &String, era: EraIndex) -> String { - format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesReceived/AS/bytesReceivedSum", data_provider_url, era, era) -} - pub(crate) fn http_get_json(url: &str) -> crate::ResultStr { let body = http_get_request(url).map_err(|err| { log::error!("[DAC Validator] Error while getting {}: {:?}", url, err); @@ -487,20 +327,6 @@ pub(crate) fn http_get_json(url: &str) -> crate::ResultSt parsed } -// pub(crate) fn http_get_json_lite(url: &str) -> crate::ResultStr { -// let body = http_get_request(url).map_err(|err| { -// log::error!("[DAC Validator] Error while getting {}: {:?}", url, err); -// "HTTP GET error" -// })?; - -// let parsed = serde_json::from_slice(&body).map_err(|err| { -// log::warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); -// "HTTP JSON parse error" -// }); - -// parsed -// } - fn http_get_request(http_url: &str) -> Result, http::Error> { // log::debug!("[DAC Validator] Sending request to: {:?}", http_url); @@ -523,101 +349,6 @@ fn http_get_request(http_url: &str) -> Result, http::Error> { Ok(response.body().collect::>()) } -fn filter_data( - s: &Vec, - r: &Vec, - a: &T::AccountId, -) -> (BytesSent, BytesReceived) { - let ac = utils::account_to_string::(a.clone()); - - let filtered_s = &*s.into_iter().find(|bs| bs.node_public_key == ac).unwrap(); - let filtered_r = &*r.into_iter().find(|br| br.node_public_key == ac).unwrap(); - - (filtered_s.clone(), filtered_r.clone()) -} - -fn get_bytes_sent_query_url(data_provider_url: &String, era: EraIndex) -> String { - format!("{}/FT.AGGREGATE/ddc:dac:searchCommonIndex/@era:[{}%20{}]/GROUPBY/2/@nodePublicKey/@era/REDUCE/SUM/1/@bytesSent/AS/bytesSentSum", data_provider_url, era, era) -} - -pub(crate) fn fetch_aggregates( - data_provider_url: &String, - era: EraIndex, -) -> Result { - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - let url = - format!("{}/JSON.GET/ddc:dac:aggregation:nodes:{}?type=query", data_provider_url, era); - let request = http::Request::get(url.as_str()); - let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - if response.code != 200 { - log::warn!("Unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - let body = response.body().collect::>(); - let body_str = sp_std::str::from_utf8(&body).map_err(|_| { - log::warn!("No UTF-8 body"); - http::Error::Unknown - })?; - let json = lite_json::parse_json(body_str).map_err(|_| { - log::warn!("No JSON body"); - http::Error::Unknown - })?; - Ok(json) -} - -pub(crate) fn make_http_put(url: &String, payload: &String) -> Result<(), http::Error> { - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - - let request = http::Request::new(url.as_str()) - .method(Method::Put) - .body(vec![payload.as_bytes()]); - - let pending_req = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - let response = pending_req.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - - if response.code != 200 { - log::warn!("Unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - - let body = response.body().collect::>(); - let body_str = sp_std::str::from_utf8(&body).map_err(|_| { - log::warn!("No UTF-8 body"); - http::Error::Unknown - })?; - - let json = lite_json::parse_json(body_str).map_err(|_| { - log::warn!("No JSON body"); - http::Error::Unknown - })?; - - Ok(()) -} - -pub(crate) fn fetch_validators_decisions( - data_provider_url: &String, - era: EraIndex, -) -> Result { - let url = format!("{}/HGET/mock:ddc:dac:decisions_to_eras/{}", data_provider_url, era); - let wrapper: Wrapper = http_get_json(&url).unwrap(); - - Ok(wrapper) -} - -pub(crate) fn post_final_decision( - data_provider_url: &String, - era: EraIndex, - decision: FinalDecision, -) -> Result<(), http::Error> { - let url = format!("{}/HSET/mock:ddc:dac:final_decision_to_era/{}", data_provider_url, era); - - let payload_str: String = serde_json::to_string(&decision).unwrap(); - let res = make_http_put(&url, &payload_str); - - res -} - pub(crate) fn get_final_decision(decisions: Vec) -> ValidationDecision { let common_decisions = find_largest_group(decisions).unwrap(); let decision_example = common_decisions.get(0).unwrap(); @@ -639,18 +370,6 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validati final_decision } -pub(crate) fn fetch_validation_results( - data_provider_url: &String, - era: EraIndex, - edge: &String, -) -> Result, http::Error> { - let wrapper = fetch_validators_decisions(data_provider_url, 5 as EraIndex).unwrap(); // Era is mocked for now - let mut edges: EdgesToResults = serde_json::from_str(wrapper.decisions.as_str()).unwrap(); - let results = edges.0.remove(edge).unwrap(); - - Ok(results) -} - fn find_largest_group(decisions: Vec) -> Option> { let mut groups: Vec> = Vec::new(); let half = decisions.len() / 2; diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 3658306da..48c3cca32 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -80,8 +80,6 @@ const ENABLE_DDC_VALIDATION_KEY: &[u8; 21] = b"enable-ddc-validation"; pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); -pub const BYTES_TO_CERE: u64 = 1; // this should have a logic built on top and adjusted - /// Webdis in experimental cluster connected to Redis in dev. pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; // pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; @@ -442,11 +440,7 @@ pub mod pallet { ValidationDecisionSetForNode::::insert(era, cdn_node.clone(), true); - Self::deposit_event(Event::::ValidationDecision( - era, - cdn_node, - validation_decision, - )); + Self::deposit_event(Event::::ValidationDecision(era, cdn_node, validation_decision)); Ok(()) } @@ -585,10 +579,10 @@ pub mod pallet { } } - fn get_mock_data_url() -> String { + fn get_data_url() -> String { let data_url = Self::get_data_provider_url(); - let mock_url = "/JSON.GET/"; - let url = format!("{}{}", data_url, mock_url); + let json_getter = "/JSON.GET/"; + let url = format!("{}{}", data_url, json_getter); url } @@ -762,12 +756,10 @@ pub mod pallet { fn validate_edges() -> Result<(), &'static str> { let current_ddc_era = ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; - let mock_data_url = Self::get_mock_data_url(); + let data_url = Self::get_data_url(); let data_provider_url = Self::get_data_provider_url(); log::debug!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - // let signer = Self::get_signer().unwrap(); - // let validator = signer.get_any_account().unwrap().id; let validator = match Self::get_public_key() { Some(key) => key, None => return Err("No validator public key found."), @@ -791,7 +783,7 @@ pub mod pallet { // form url for each node let edge_url = format!( "{}{}{}/$.{}", - mock_data_url, + data_url, "ddc:dac:aggregation:nodes:", current_ddc_era - 1, utils::account_to_string::(assigned_edge.clone()) @@ -814,7 +806,7 @@ pub mod pallet { let requests = &mut dac::Requests::new(); for request_id in request_ids.iter() { let request_id_url = - format!("{}{}{}", mock_data_url, "ddc:dac:data:file:", request_id.clone()); + format!("{}{}{}", data_url, "ddc:dac:data:file:", request_id.clone()); let file_request = dac::fetch_file_request(&request_id_url); requests.insert(file_request.file_request_id.clone(), file_request.clone()); } @@ -866,7 +858,7 @@ pub mod pallet { log::debug!("shm res: {:?}", res.to_string()); } - if let Ok(res) = response { + if let Ok(_res) = response { let edge = utils::account_to_string::(assigned_edge.clone()); let prev_era = (current_ddc_era - 1) as EraIndex; let quorum = Self::find_validators_from_quorum(&validator, &prev_era); @@ -887,7 +879,7 @@ pub mod pallet { BucketsDetails>, > = BTreeMap::new(); for bucket in payments_per_bucket.into_iter() { - let cere_payment: u32 = (bucket.1 / BYTES_TO_CERE) as u32; + let cere_payment = bucket.1 as u32; if payments.contains_key(&bucket.0) { payments.entry(bucket.0).and_modify(|bucket_info| { bucket_info.amount += cere_payment.into() diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 2d557d37d..6989e148f 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -9,7 +9,7 @@ use alloc::{format, string::String}; pub use sp_std::collections::btree_map::BTreeMap; // ToDo: remove String usage use crate::{dac, utils, ValidationDecision}; -use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; +use alt_serde::{Deserialize, Serialize}; use base64::prelude::*; use lite_json::json::JsonValue; use sp_runtime::offchain::{http, Duration}; diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs index 709c3aa1a..5c5459b24 100644 --- a/pallets/ddc-validator/src/utils.rs +++ b/pallets/ddc-validator/src/utils.rs @@ -1,4 +1,3 @@ -use crate::dac::ValidationResult; use alloc::{format, string::String}; use codec::{Decode, Encode}; use sp_core::crypto::AccountId32; From b348217d78bc099515a3f01d5932b0b96f70461a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 25 Aug 2023 15:21:42 +0200 Subject: [PATCH 281/544] fixes base on latest comments --- .github/workflows/check.yaml | 2 +- Dockerfile | 2 +- pallets/ddc-staking/src/lib.rs | 6 +++--- pallets/ddc-validator/src/lib.rs | 24 +++++++++++++++--------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 103b2152c..1e6a57960 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -45,4 +45,4 @@ jobs: - name: Check Build for Benchmarking run: > pushd node && - cargo check --features=runtime-benchmarks --release \ No newline at end of file + cargo check --features=runtime-benchmarks --release diff --git a/Dockerfile b/Dockerfile index e054a5a11..543bc86f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,4 +78,4 @@ USER cerenetwork EXPOSE 30333 9933 9944 9615 VOLUME ["/data"] -CMD ["/usr/local/bin/cere"] \ No newline at end of file +CMD ["/usr/local/bin/cere"] diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index f192687a6..a95d5efd1 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -262,19 +262,19 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = - StorageMap<_, Identity, T::AccountId, StakingLedger>>; + StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger>>; /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to /// participate into. #[pallet::storage] #[pallet::getter(fn edges)] - pub type Edges = StorageMap<_, Identity, T::AccountId, ClusterId>; + pub type Edges = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// The map of (wannabe) storage network participants stash keys to the DDC cluster ID they wish /// to participate into.. #[pallet::storage] #[pallet::getter(fn storages)] - pub type Storages = StorageMap<_, Identity, T::AccountId, ClusterId>; + pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// Map from all "stash" accounts to the total paid out rewards /// diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 48c3cca32..6dbf95561 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -251,9 +251,14 @@ pub mod pallet { pub type LastManagedEra = StorageValue<_, EraIndex>; /// The mapping of ddc validator keys to validator stash keys + /// + /// Keys registered by validators are mapped to validator stash accounts. + /// The mapping is formed in the way that facilitates fast checking that storage contains key. + /// Similarly the validator stash is checked if he is still in the list of validators. #[pallet::storage] #[pallet::getter(fn get_stash_for_ddc_validator)] - pub type OffchainWorkerKeys = StorageMap<_, Identity, T::AccountId, T::AccountId>; + pub type DDCValidatorToStashKeys = + StorageMap<_, Identity, T::AccountId, T::AccountId>; #[pallet::error] pub enum Error { @@ -402,7 +407,6 @@ pub mod pallet { /// Set validation decision for a given CDN node in an era. /// /// Only registered validator keys can call this exstrinsic. - /// Validator should be in the active set. /// Validation decision can be set only once per era per CDN node. /// CDN node should be active. #[pallet::weight(10_000)] @@ -415,7 +419,7 @@ pub mod pallet { let ddc_valitor_key = ensure_signed(origin)?; ensure!( - OffchainWorkerKeys::::contains_key(&ddc_valitor_key), + DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), Error::::DDCValidatorKeyNotRegistered ); @@ -448,7 +452,6 @@ pub mod pallet { /// Set reward points for CDN participants at the given era. /// /// Only registered validator keys can call this exstrinsic. - /// Validator should be in the active set. /// Reward points can be set only once per era per CDN node. /// CDN node should be active. /// @@ -464,7 +467,7 @@ pub mod pallet { let ddc_valitor_key = ensure_signed(origin)?; ensure!( - OffchainWorkerKeys::::contains_key(&ddc_valitor_key), + DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), Error::::DDCValidatorKeyNotRegistered ); @@ -478,6 +481,7 @@ pub mod pallet { >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { if !Self::reward_points_set_for_node(era, &staker) { + // ToDo deal with edge case when node is chilling if >::contains_key(&staker) { *era_rewards.individual.entry(staker.clone()).or_default() += points; era_rewards.total += points; @@ -507,7 +511,9 @@ pub mod pallet { #[pallet::weight(100_000)] pub fn charge_payments_content_owners( origin: OriginFor, - paying_accounts: Vec>>, + paying_accounts: Vec>>, /* ToDo check if + * bounded vec + * should be used */ ) -> DispatchResult { let ddc_valitor_key = ensure_signed(origin)?; log::debug!("validator is {:?}", &ddc_valitor_key); @@ -516,7 +522,7 @@ pub mod pallet { ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ensure!( - OffchainWorkerKeys::::contains_key(&ddc_valitor_key), + DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), Error::::DDCValidatorKeyNotRegistered ); @@ -556,7 +562,7 @@ pub mod pallet { Error::::NotValidatorStash ); - OffchainWorkerKeys::::insert(ddc_validator_pub, &ledger.stash); + DDCValidatorToStashKeys::::insert(ddc_validator_pub, &ledger.stash); Ok(()) } } @@ -644,7 +650,7 @@ pub mod pallet { } fn assign(quorum_size: usize, era: EraIndex) -> Result<(), AssignmentError> { - let validators: Vec = OffchainWorkerKeys::::iter_keys().collect(); + let validators: Vec = DDCValidatorToStashKeys::::iter_keys().collect(); log::debug!("Current validators: {:?}.", validators); if validators.len() == 0 { From c65f551c465fa05d9f029b6da4c0b086beb34347 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 28 Aug 2023 16:10:52 +0200 Subject: [PATCH 282/544] test with one validation in quorum works correctly --- pallets/ddc-validator/src/lib.rs | 2 +- .../set-1/final-validation-decision.json | 1 + .../mock-data/set-1/validation-decision.json | 2 +- pallets/ddc-validator/src/mock.rs | 11 +--- pallets/ddc-validator/src/tests.rs | 53 ++++++++++++------- 5 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 6dbf95561..82fd69eae 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -322,7 +322,7 @@ pub mod pallet { _ => (), } - match Self::assign(3usize, current_ddc_era + 1) { + match Self::assign(1usize, current_ddc_era + 1) { Ok(_) => >::put(current_ddc_era + 1), Err(e) => log::debug!("DDC validation assignment error: {:?}.", e), } diff --git a/pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json b/pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json new file mode 100644 index 000000000..b63b98c6c --- /dev/null +++ b/pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json @@ -0,0 +1 @@ +{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[242,221,51,34,29,242,150,119,6,131,41,15,161,173,121,43,221,22,150,173,180,224,179,58,72,4,96,188,17,164,177,109],"totals":{"received":600,"sent":600,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json index 1fd502e51..d4509acb7 100644 --- a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json +++ b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json @@ -1 +1 @@ -{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[242, 221, 51, 34, 29, 242, 150, 119, 6, 131, 41, 15, 161, 173, 121, 43, 221, 22, 150, 173, 180, 224, 179, 58, 72, 4, 96, 188, 17, 164, 177, 109],"totals":{"received":600,"sent":600,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file +{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[56, 47, 100, 81, 135, 215, 168, 111, 55, 82, 203, 118, 238, 69, 174, 209, 232, 241, 187, 128, 231, 237, 139, 193, 162, 162, 91, 11, 169, 209, 27, 55],"totals":{"received":600,"sent":600,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index c79fc5b0e..00497301c 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -2,7 +2,7 @@ use crate::{self as pallet_ddc_validator, *}; use frame_election_provider_support::{onchain, SequentialPhragmen}; use frame_support::{ parameter_types, - traits::{ConstU16, ConstU64, Currency, Everything, Nothing, U128CurrencyToVote}, + traits::{Everything, Nothing, U128CurrencyToVote}, weights::Weight, PalletId, }; @@ -12,16 +12,14 @@ use pallet_session::ShouldEndSession; use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ - curve, curve::PiecewiseLinear, generic, impl_opaque_keys, - testing::{Header, TestXt, UintAuthorityId}, + testing::{TestXt, UintAuthorityId}, traits::{ BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, }, MultiSignature, Perbill, }; -use sp_staking::SessionIndex; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; type Balance = u128; @@ -96,11 +94,6 @@ parameter_types! { pub Schedule: pallet_contracts::Schedule = Default::default(); } -use contracts::Config as contractsConfig; - -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - pub struct TestWeightToFee; impl Convert for TestWeightToFee { fn convert(weight: u64) -> u128 { diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 745deb3f8..d7ebc00ae 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -30,6 +30,12 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let era_to_validate: EraIndex = 3; let cdn_node_to_validate = AccountId::from([0x1; 32]); let cdn_node_to_validate_str = utils::account_to_string::(cdn_node_to_validate.clone()); + let validator_stash = AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, + 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, + 0xdf, 0x67, + ]); + let validator_controller = AccountId::from([0xaa; 32]); { let mut state = offchain_state.write(); @@ -115,7 +121,11 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { t.execute_with(|| { let era_block_number = 20 as u32 * era_to_validate; System::set_block_number(era_block_number); // required for randomness - + DdcValidator::set_validator_key( + RuntimeOrigin::signed(validator_controller), + validator_stash, + ) + .unwrap(); Timestamp::set_timestamp( (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, ); @@ -137,42 +147,31 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); - let bucket_info1 = BucketsDetails { bucket_id: 5, amount: 100u128 }; - let bucket_info2 = BucketsDetails { bucket_id: 5, amount: 200u128 }; - let bucket_info3 = BucketsDetails { bucket_id: 5, amount: 300u128 }; + let bucket_info = BucketsDetails { bucket_id: 5, amount: 600u128 }; assert_eq!( tx.call, crate::mock::RuntimeCall::DdcValidator(crate::Call::charge_payments_content_owners { - paying_accounts: vec![bucket_info3, bucket_info1, bucket_info2,] + paying_accounts: vec![bucket_info] }) ); let tx = transactions.pop().unwrap(); let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); - assert_eq!( - tx.call, - crate::mock::RuntimeCall::DdcStaking(pallet_ddc_staking::Call::payout_stakers { - era: era_to_validate + 1 - }) - ); - let tx = transactions.pop().unwrap(); - let tx = Extrinsic::decode(&mut &*tx).unwrap(); - assert!(tx.signature.is_some()); - - let common_decision: ValidationDecision = - serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) - .unwrap(); + let common_decision: ValidationDecision = serde_json::from_slice(include_bytes!( + "./mock-data/set-1/final-validation-decision.json" + )) + .unwrap(); let common_decisions = vec![common_decision.clone()]; let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); assert_eq!( tx.call, crate::mock::RuntimeCall::DdcValidator(crate::Call::set_validation_decision { - era: era_to_validate + 1, - cdn_node: cdn_node_to_validate, + era: era_to_validate, + cdn_node: cdn_node_to_validate.clone(), validation_decision: ValidationDecision { edge: cdn_node_to_validate_str, result: true, @@ -186,5 +185,19 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { } }) ); + + let tx = transactions.pop().unwrap(); + let tx = Extrinsic::decode(&mut &*tx).unwrap(); + + let stakers_points = vec![(cdn_node_to_validate, common_decision.totals.sent)]; + + assert!(tx.signature.is_some()); + assert_eq!( + tx.call, + crate::mock::RuntimeCall::DdcValidator(crate::Call::set_era_reward_points { + era: era_to_validate, + stakers_points, + }) + ); }) } From 17762ec61a2767f6033d4b4059ec559515214446 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 29 Aug 2023 14:18:49 +0200 Subject: [PATCH 283/544] update test to 3 validators in quorum --- pallets/ddc-validator/src/lib.rs | 2 +- pallets/ddc-validator/src/tests.rs | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 82fd69eae..6dbf95561 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -322,7 +322,7 @@ pub mod pallet { _ => (), } - match Self::assign(1usize, current_ddc_era + 1) { + match Self::assign(3usize, current_ddc_era + 1) { Ok(_) => >::put(current_ddc_era + 1), Err(e) => log::debug!("DDC validation assignment error: {:?}.", e), } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index d7ebc00ae..b728f0fd1 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -30,12 +30,16 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let era_to_validate: EraIndex = 3; let cdn_node_to_validate = AccountId::from([0x1; 32]); let cdn_node_to_validate_str = utils::account_to_string::(cdn_node_to_validate.clone()); - let validator_stash = AccountId::from([ + let validator_1_stash = AccountId::from([ 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, 0xdf, 0x67, ]); - let validator_controller = AccountId::from([0xaa; 32]); + let validator_1_controller = AccountId::from([0xaa; 32]); + let validator_2_stash = AccountId::from([0xb; 32]); + let validator_2_controller = AccountId::from([0xbb; 32]); + let validator_3_stash = AccountId::from([0xc; 32]); + let validator_3_controller = AccountId::from([0xcc; 32]); { let mut state = offchain_state.write(); @@ -122,8 +126,21 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let era_block_number = 20 as u32 * era_to_validate; System::set_block_number(era_block_number); // required for randomness DdcValidator::set_validator_key( - RuntimeOrigin::signed(validator_controller), - validator_stash, + // register validator 1 + RuntimeOrigin::signed(validator_1_controller), + validator_1_stash, + ) + .unwrap(); + DdcValidator::set_validator_key( + // register validator 2 + RuntimeOrigin::signed(validator_2_controller), + validator_2_stash, + ) + .unwrap(); + DdcValidator::set_validator_key( + // register validator 3 + RuntimeOrigin::signed(validator_3_controller), + validator_3_stash, ) .unwrap(); Timestamp::set_timestamp( From fdd1009a568c3323d4eb8b1fcabeebe91e86c002 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 29 Aug 2023 14:26:11 +0200 Subject: [PATCH 284/544] revert storage map types --- pallets/ddc-staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index a95d5efd1..d2cf2b577 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -250,7 +250,7 @@ pub mod pallet { /// Map from all locked "stash" accounts to the controller account. #[pallet::storage] #[pallet::getter(fn bonded)] - pub type Bonded = StorageMap<_, Identity, T::AccountId, T::AccountId>; + pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; /// DDC clusters staking settings. #[pallet::storage] From a41b3b2441b4c31f84625c9761f9ec7f3a055daf Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 31 Aug 2023 12:42:24 +0200 Subject: [PATCH 285/544] unit tests in progress --- pallets/ddc-validator/src/lib.rs | 13 +++- pallets/ddc-validator/src/tests.rs | 97 +++++++++++++++++++++++++++++- 2 files changed, 107 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 6dbf95561..e83211846 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -922,14 +922,23 @@ pub mod pallet { let signer = Self::get_signer().unwrap(); - let _tx_res = + let tx_res = signer.send_signed_transaction(|_acct| Call::set_validation_decision { era: current_ddc_era - 1, cdn_node: utils::string_to_account::(edge.clone()), validation_decision: final_res.clone(), }); - log::debug!("final_res: {:?}", final_res); + match &tx_res { + None | Some((_, Err(()))) => return Err("Error:"), + Some((_, Ok(()))) => {}, + } + + // match tx_res.result { + // Ok(tx_res) => println!("successfull tx: {:?}", tx_res), + // Err(error) => println!("failed tx: {:?}", error), + // } + // log::debug!("final_res: {:?}", final_res); cdn_nodes_reward_points.push(( utils::string_to_account::(final_res.edge), diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index b728f0fd1..f3c069d01 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,6 +1,10 @@ use super::*; -use crate::mock::{Timestamp, *}; +use crate::{ + mock::{Timestamp, *}, + Error as ValidatorError, +}; use codec::Decode; +use frame_support::{assert_noop, assert_ok}; use pallet_ddc_accounts::BucketsDetails; use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; @@ -218,3 +222,94 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { ); }) } + +#[test] +fn send_signal_works_as_expected() { + let mut t = new_test_ext(); + + let validator_controller = AccountId::from([0xaa; 32]); + + t.execute_with(|| { + assert_eq!(DdcValidator::signal(), None); + assert_ok!(DdcValidator::send_signal(RuntimeOrigin::signed(validator_controller))); + assert_eq!(DdcValidator::signal().unwrap(), true); + }) +} + +#[test] +fn set_validation_decision_works_as_expected() { + let mut t = new_test_ext(); + + let era_to_validate: EraIndex = 3; + let cdn_node_to_validate = AccountId::from([0x1; 32]); + let not_a_cdn_node = AccountId::from([0x2; 32]); + let validator_1_stash = AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, + 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, + 0xdf, 0x67, + ]); + let validator_1_controller = AccountId::from([0xaa; 32]); + + let decision: ValidationDecision = + serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) + .unwrap(); + + sp_std::if_std! { + println!("events"); + } + + t.execute_with(|| { + System::set_block_number(1); + + assert_ok!(DdcValidator::set_validator_key( + // register validator 1 + RuntimeOrigin::signed(validator_1_controller.clone()), + validator_1_stash.clone(), + )); + + assert_noop!( + DdcValidator::set_validation_decision( + RuntimeOrigin::signed(validator_1_controller), + era_to_validate, + cdn_node_to_validate.clone(), + decision.clone(), + ), + ValidatorError::::DDCValidatorKeyNotRegistered + ); + + assert_noop!( + DdcValidator::set_validation_decision( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + not_a_cdn_node.clone(), + decision.clone() + ), + ValidatorError::::NodeNotActive + ); + + assert_ok!(DdcValidator::set_validation_decision( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + cdn_node_to_validate.clone(), + decision.clone() + )); + + assert_noop!( + DdcValidator::set_validation_decision( + RuntimeOrigin::signed(validator_1_stash), + era_to_validate, + cdn_node_to_validate.clone(), + decision.clone() + ), + ValidatorError::::ValidationDecisionAlreadySet + ); + + let evt = System::events().into_iter().map(|evt| evt.event).collect::>(); + assert_eq!(evt.len(), 1); + assert_eq!( + evt[0], + crate::Event::ValidationDecision(era_to_validate, cdn_node_to_validate, decision) + .into() + ); + }) +} From 7c4033849182f8b4f7c555cbe6b744857d4d5803 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 25 Aug 2023 18:03:26 +0200 Subject: [PATCH 286/544] - remove unused imports and methods - replace deprecated imports - remove unused macros --- node/client/src/lib.rs | 82 +------------------ pallets/chainbridge/src/lib.rs | 15 +--- .../ddc-metrics-offchain-worker/src/lib.rs | 3 +- pallets/erc20/src/lib.rs | 12 +-- pallets/erc721/src/lib.rs | 15 +--- rpc/src/lib.rs | 1 - runtime/cere-dev/src/lib.rs | 9 +- runtime/cere/src/lib.rs | 9 +- 8 files changed, 17 insertions(+), 129 deletions(-) diff --git a/node/client/src/lib.rs b/node/client/src/lib.rs index 8de68a06a..8ff812c93 100644 --- a/node/client/src/lib.rs +++ b/node/client/src/lib.rs @@ -1,15 +1,13 @@ pub use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Header, Index, Signature}; use sc_client_api::{AuxStore, Backend as BackendT, BlockchainEvents, KeyIterator, UsageProvider}; pub use sc_executor::NativeElseWasmExecutor; -use sp_api::{CallApiAt, Encode, NumberFor, ProvideRuntimeApi}; +use sp_api::{CallApiAt, NumberFor, ProvideRuntimeApi}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; use sp_consensus::BlockStatus; -use sp_core::Pair; -use sp_keyring::Sr25519Keyring; use sp_runtime::{ generic::{BlockId, SignedBlock}, traits::{BlakeTwo256, Block as BlockT}, - Justifications, OpaqueExtrinsic, + Justifications, }; use sp_storage::{ChildInfo, StorageData, StorageKey}; use std::sync::Arc; @@ -446,82 +444,6 @@ impl sp_blockchain::HeaderBackend for Client { } } -macro_rules! with_signed_payload { - { - $self:ident, - { - $extra:ident, - $client:ident, - $raw_payload:ident - }, - { - $( $setup:tt )* - }, - ( - $period:expr, - $current_block:expr, - $nonce:expr, - $tip:expr, - $call:expr, - $genesis:expr - ), - { - $( $usage:tt )* - } - } => { - match $self { - #[cfg(feature = "cere")] - Self::Cere($client) => { - use cere_runtime as runtime; - - $( $setup )* - - let $extra: runtime::SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckMortality::::from(sp_runtime::generic::Era::mortal( - $period, - $current_block, - )), - frame_system::CheckNonce::::from($nonce), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from($tip), - ); - - let $raw_payload = runtime::SignedPayload::from_raw( - $call.clone(), - $extra.clone(), - ( - (), - runtime::VERSION.spec_version, - runtime::VERSION.transaction_version, - $genesis.clone(), - $genesis, - (), - (), - (), - ), - ); - - $( $usage )* - }, - #[cfg(feature = "cere-dev")] - Self::CereDev($client) => { - use cere_dev_runtime as runtime; - - $( $setup )* - - signed_payload!($extra, $raw_payload, - ($period, $current_block, $nonce, $tip, $call, $genesis)); - - $( $usage )* - }, - } - } -} - #[allow(unused_macros)] macro_rules! signed_payload { ( diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index 512c0a9c2..1e48b4a7d 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -4,10 +4,7 @@ use codec::{Decode, Encode, EncodeLike}; use frame_support::{ decl_error, decl_event, decl_module, decl_storage, - dispatch::{ - ClassifyDispatch, DispatchClass, DispatchResult, GetDispatchInfo, Pays, PaysFee, WeighData, - Weight, - }, + dispatch::{DispatchResult, GetDispatchInfo, Pays, Weight}, ensure, traits::{EnsureOrigin, Get}, PalletId, Parameter, @@ -15,16 +12,10 @@ use frame_support::{ use frame_system::{self as system, ensure_root, ensure_signed}; use sp_core::U256; use sp_runtime::{ - traits::{ - AccountIdConversion, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, - SignedExtension, - }, - transaction_validity::{ - InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, - }, + traits::{AccountIdConversion, Dispatchable}, RuntimeDebug, }; -use sp_std::{marker::PhantomData, prelude::*}; +use sp_std::prelude::*; mod mock; mod tests; diff --git a/pallets/ddc-metrics-offchain-worker/src/lib.rs b/pallets/ddc-metrics-offchain-worker/src/lib.rs index 5c6c07892..991fdabb2 100644 --- a/pallets/ddc-metrics-offchain-worker/src/lib.rs +++ b/pallets/ddc-metrics-offchain-worker/src/lib.rs @@ -34,8 +34,7 @@ extern crate alloc; use alloc::string::String; use core::fmt::Debug; use frame_support::weights::Weight; -use scale_info::{Type, TypeInfo}; -use sp_runtime::offchain::storage::StorageRetrievalError; +use scale_info::TypeInfo; pub const BLOCK_INTERVAL: u32 = 100; // TODO: Change to 1200 later [1h]. Now - 200 [10 minutes] for testing purposes. diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index 8f861d10d..a9474ae2f 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -4,24 +4,16 @@ use pallet_chainbridge as bridge; use pallet_erc721 as erc721; -use codec::{Decode, Encode}; use frame_support::{ decl_error, decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure, traits::{Currency, EnsureOrigin, ExistenceRequirement::AllowDeath, Get}, - weights::{ClassifyDispatch, DispatchClass, Pays, PaysFee, WeighData, Weight}, }; -use frame_system::{self as system, ensure_root, ensure_signed}; +use frame_system::{self as system, ensure_signed}; use sp_arithmetic::traits::SaturatedConversion; use sp_core::U256; -use sp_runtime::{ - traits::{Bounded, DispatchInfoOf, SignedExtension, UniqueSaturatedInto}, - transaction_validity::{ - InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, - }, -}; -use sp_std::{marker::PhantomData, prelude::*}; +use sp_std::prelude::*; type ResourceId = bridge::ResourceId; diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index c0da9c7a3..c5b7244d7 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -3,22 +3,13 @@ use codec::{Decode, Encode}; use frame_support::{ - decl_error, decl_event, decl_module, decl_storage, - dispatch::{ClassifyDispatch, DispatchClass, DispatchResult, Pays, PaysFee, WeighData}, - ensure, + decl_error, decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure, traits::Get, - weights::Weight, }; use frame_system::{self as system, ensure_root, ensure_signed}; use sp_core::U256; -use sp_runtime::{ - traits::{Bounded, DispatchInfoOf, SaturatedConversion, SignedExtension}, - transaction_validity::{ - InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, - }, - RuntimeDebug, -}; -use sp_std::{marker::PhantomData, prelude::*}; +use sp_runtime::RuntimeDebug; +use sp_std::prelude::*; mod mock; mod tests; diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 9abf2af02..e8cffa484 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -11,7 +11,6 @@ use jsonrpsee::RpcModule; use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index}; use sc_client_api::AuxStore; use sc_consensus_babe::{BabeConfiguration, Epoch}; -use sc_consensus_babe_rpc::Babe; use sc_consensus_epochs::SharedEpochChanges; use sc_finality_grandpa::{ FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 1823209fc..66c8e6d18 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -22,13 +22,11 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use cere_runtime_common::{BalanceToU256, U256ToBalance}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_election_provider_support::{ - onchain, BalancingConfig, ExtendedBalance, SequentialPhragmen, VoteWeight, -}; +use frame_election_provider_support::{onchain, BalancingConfig, SequentialPhragmen, VoteWeight}; use frame_support::{ construct_runtime, + dispatch::DispatchClass, pallet_prelude::Get, parameter_types, traits::{ @@ -38,7 +36,7 @@ use frame_support::{ }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, - ConstantMultiplier, DispatchClass, IdentityFee, Weight, + ConstantMultiplier, IdentityFee, Weight, }, PalletId, RuntimeDebug, }; @@ -50,7 +48,6 @@ pub use node_primitives::{AccountId, Signature}; use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; pub use pallet_cere_ddc; pub use pallet_chainbridge; -use pallet_contracts::weights::WeightInfo; pub use pallet_ddc_metrics_offchain_worker; pub use pallet_ddc_staking; use pallet_election_provider_multi_phase::SolutionAccuracyOf; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 9145da19c..851bad201 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -22,13 +22,11 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use cere_runtime_common::{BalanceToU256, U256ToBalance}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_election_provider_support::{ - onchain, BalancingConfig, ExtendedBalance, SequentialPhragmen, VoteWeight, -}; +use frame_election_provider_support::{onchain, BalancingConfig, SequentialPhragmen, VoteWeight}; use frame_support::{ construct_runtime, + dispatch::DispatchClass, pallet_prelude::Get, parameter_types, traits::{ @@ -38,7 +36,7 @@ use frame_support::{ }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, - ConstantMultiplier, DispatchClass, IdentityFee, Weight, + ConstantMultiplier, IdentityFee, Weight, }, PalletId, RuntimeDebug, }; @@ -50,7 +48,6 @@ pub use node_primitives::{AccountId, Signature}; use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; pub use pallet_cere_ddc; pub use pallet_chainbridge; -use pallet_contracts::weights::WeightInfo; pub use pallet_ddc_metrics_offchain_worker; use pallet_election_provider_multi_phase::SolutionAccuracyOf; use pallet_grandpa::{ From a7a1e0cb4f858bd7bd4ab40cfebee8de6fd70515 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 30 Aug 2023 14:27:50 +0200 Subject: [PATCH 287/544] remove unused imports for tests; update deprecated methods for tests --- pallets/chainbridge/src/mock.rs | 6 +++--- pallets/chainbridge/src/tests.rs | 1 - pallets/ddc-metrics-offchain-worker/src/tests/mod.rs | 3 +-- .../ddc-metrics-offchain-worker/src/tests/test_runtime.rs | 3 --- pallets/ddc/src/mock.rs | 1 - pallets/erc721/src/mock.rs | 2 +- runtime/cere-dev/src/impls.rs | 5 ++++- runtime/cere/src/impls.rs | 5 ++++- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pallets/chainbridge/src/mock.rs b/pallets/chainbridge/src/mock.rs index 15a6a235b..5e22f6e92 100644 --- a/pallets/chainbridge/src/mock.rs +++ b/pallets/chainbridge/src/mock.rs @@ -3,13 +3,13 @@ use super::*; use frame_support::{ - assert_ok, ord_parameter_types, parameter_types, traits::Everything, weights::Weight, PalletId, + assert_ok, ord_parameter_types, parameter_types, traits::Everything, weights::Weight, }; use frame_system::{self as system}; use sp_core::H256; use sp_runtime::{ testing::Header, - traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, IdentityLookup}, + traits::{AccountIdConversion, BlakeTwo256, IdentityLookup}, Perbill, }; @@ -146,7 +146,7 @@ pub fn new_test_ext_initialized( // include the most recent event, but do not have to include every past event. pub fn assert_events(mut expected: Vec) { let mut actual: Vec = - system::Module::::events().iter().map(|e| e.event.clone()).collect(); + system::Pallet::::events().iter().map(|e| e.event.clone()).collect(); expected.reverse(); diff --git a/pallets/chainbridge/src/tests.rs b/pallets/chainbridge/src/tests.rs index c7b3b18a2..bd0ae5a03 100644 --- a/pallets/chainbridge/src/tests.rs +++ b/pallets/chainbridge/src/tests.rs @@ -10,7 +10,6 @@ use super::{ }; use crate::mock::new_test_ext_initialized; use frame_support::{assert_noop, assert_ok}; -use frame_system::Origin; #[test] fn derive_ids() { diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs index 6c0dbbe09..a261b10c8 100644 --- a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs +++ b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs @@ -1,6 +1,5 @@ use frame_support::traits::{Currency, OffchainWorker}; use frame_system::Config as FSC; -use pallet_contracts::{self as contracts, Config as CC}; use sp_core::offchain::{ testing, OffchainDbExt, OffchainWorkerExt, Timestamp as OCWTimestamp, TransactionPoolExt, }; @@ -285,7 +284,7 @@ fn should_run_contract() { let contract_id = deploy_contract(); let call_data = DdcMetricsOffchainWorker::encode_get_current_period_ms(); - pallet_contracts::Module::::call( + pallet_contracts::Pallet::::call( RuntimeOrigin::signed(alice.clone()), contract_id.clone(), 0, diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs b/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs index 10cee8408..7a5033b9b 100644 --- a/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs +++ b/pallets/ddc-metrics-offchain-worker/src/tests/test_runtime.rs @@ -4,7 +4,6 @@ use crate::{self as pallet_ddc_metrics_offchain_worker, *}; -use codec::{Decode, Encode}; use frame_support::{ parameter_types, traits::{ConstU32, Currency, Everything, Get, Nothing}, @@ -30,8 +29,6 @@ pub type Moment = u64; // -- Implement a contracts runtime for testing -- // Macro hack: Give names to the pallets. -use frame_system as system; -use pallet_balances as balances; use pallet_contracts as contracts; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/pallets/ddc/src/mock.rs b/pallets/ddc/src/mock.rs index 0bb912223..c514078ba 100644 --- a/pallets/ddc/src/mock.rs +++ b/pallets/ddc/src/mock.rs @@ -1,5 +1,4 @@ use crate as pallet_cere_ddc; -use crate::Module; use frame_support::{construct_runtime, parameter_types, traits::Everything}; use frame_system as system; use sp_core::H256; diff --git a/pallets/erc721/src/mock.rs b/pallets/erc721/src/mock.rs index 24ee23b92..9406619ae 100644 --- a/pallets/erc721/src/mock.rs +++ b/pallets/erc721/src/mock.rs @@ -5,7 +5,7 @@ use frame_system::{self as system}; use sp_core::{hashing::blake2_128, H256}; use sp_runtime::{ testing::Header, - traits::{BlakeTwo256, Block as BlockT, IdentityLookup}, + traits::{BlakeTwo256, IdentityLookup}, BuildStorage, Perbill, }; diff --git a/runtime/cere-dev/src/impls.rs b/runtime/cere-dev/src/impls.rs index dd38a6a1d..c576e8d31 100644 --- a/runtime/cere-dev/src/impls.rs +++ b/runtime/cere-dev/src/impls.rs @@ -36,7 +36,10 @@ mod multiplier_tests { System, TargetBlockFullness, TransactionPayment, }; use cere_dev_runtime_constants::{currency::*, time::*}; - use frame_support::weights::{DispatchClass, Weight, WeightToFee as WeightToFeeT}; + use frame_support::{ + dispatch::DispatchClass, + weights::{Weight, WeightToFee as WeightToFeeT}, + }; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_runtime::{ assert_eq_error_rate, diff --git a/runtime/cere/src/impls.rs b/runtime/cere/src/impls.rs index 9597162dc..6895f794e 100644 --- a/runtime/cere/src/impls.rs +++ b/runtime/cere/src/impls.rs @@ -36,7 +36,10 @@ mod multiplier_tests { System, TargetBlockFullness, TransactionPayment, }; use cere_runtime_constants::{currency::*, time::*}; - use frame_support::weights::{DispatchClass, Weight, WeightToFee as WeightToFeeT}; + use frame_support::{ + dispatch::DispatchClass, + weights::{Weight, WeightToFee as WeightToFeeT}, + }; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_runtime::{ assert_eq_error_rate, From 249f9ffe660331457353a6b87ee6a612137437a6 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 31 Aug 2023 17:17:55 +0600 Subject: [PATCH 288/544] Storage item for cluster managers ACL --- pallets/ddc-staking/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index d2cf2b577..38992abf8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -329,6 +329,11 @@ pub mod pallet { #[pallet::getter(fn pricing)] pub type Pricing = StorageValue<_, u128>; + /// A list of accounts allowed to become cluster managers. + #[pallet::storage] + #[pallet::getter(fn cluster_managers)] + pub type ClusterManagers = StorageValue<_, Vec, ValueQuery>; + #[pallet::genesis_config] pub struct GenesisConfig { pub edges: Vec<(T::AccountId, T::AccountId, BalanceOf, ClusterId)>, From e91505e2fd56d7ebf34f5c8b38d581061d028a0c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 1 Sep 2023 11:32:42 +0600 Subject: [PATCH 289/544] Add extrinsics to add and remove cluster managers --- pallets/ddc-staking/src/lib.rs | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 38992abf8..009315c30 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -866,6 +866,46 @@ pub mod pallet { >::set(Some(price_per_byte)); Ok(()) } + + /// Add a new account to the list of cluster managers. + /// + /// RuntimeOrigin must be Root to call this function. + #[pallet::weight(10_000)] + pub fn allow_cluster_manager( + origin: OriginFor, + grantee: ::Source, + ) -> DispatchResult { + ensure_root(origin)?; + + let grantee = T::Lookup::lookup(grantee)?; + ClusterManagers::::mutate(|grantees| { + if !grantees.contains(&grantee) { + grantees.push(grantee); + } + }); + + Ok(()) + } + + /// Remove an account from the list of cluster managers. + /// + /// RuntimeOrigin must be Root to call this function. + #[pallet::weight(10_000)] + pub fn disallow_cluster_manager( + origin: OriginFor, + revokee: ::Source, + ) -> DispatchResult { + ensure_root(origin)?; + + let revokee = T::Lookup::lookup(revokee)?; + ClusterManagers::::mutate(|grantees| { + if let Some(pos) = grantees.iter().position(|g| g == &revokee) { + grantees.remove(pos); + } + }); + + Ok(()) + } } impl Pallet { From b6137b3e5fe95a75d402210cb0d1d4d41e1f9e14 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 1 Sep 2023 11:33:08 +0600 Subject: [PATCH 290/544] A test for cluster manager ACL modifications --- pallets/ddc-staking/src/tests.rs | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 461f064d5..6d024cf64 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,7 +1,9 @@ //! Tests for the module. use super::{mock::*, *}; -use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; +use frame_support::{ + assert_noop, assert_ok, assert_storage_noop, error::BadOrigin, traits::ReservableCurrency, +}; use pallet_balances::Error as BalancesError; pub const BLOCK_TIME: u64 = 1000; @@ -176,3 +178,32 @@ fn staking_should_work() { assert_eq!(DdcStaking::edges(3), None); }); } + +#[test] +fn cluster_managers_list_can_be_managed_by_governance_only() { + ExtBuilder::default().build_and_execute(|| { + // Governance can allow an account to become cluster manager. + assert_ok!(DdcStaking::allow_cluster_manager(RuntimeOrigin::root(), 1)); + + // Repeat call does nothing. + assert_storage_noop!(assert_ok!(DdcStaking::allow_cluster_manager( + RuntimeOrigin::root(), + 1, + ))); + + // Non-governance can't allow an account to become a cluster manager. + assert_noop!(DdcStaking::allow_cluster_manager(RuntimeOrigin::signed(1), 2), BadOrigin); + + // Non-governance can't disallow an account to become a cluster manager. + assert_noop!(DdcStaking::disallow_cluster_manager(RuntimeOrigin::signed(1), 1), BadOrigin); + + // Governance can disallow an account to become a cluster manager. + assert_ok!(DdcStaking::disallow_cluster_manager(RuntimeOrigin::root(), 1)); + + // Repeat call does nothing. + assert_storage_noop!(assert_ok!(DdcStaking::disallow_cluster_manager( + RuntimeOrigin::root(), + 1, + ))); + }); +} From 2eed0bb6d0cd0e600e0c844f772e52f49db673b3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 1 Sep 2023 12:12:17 +0600 Subject: [PATCH 291/544] Benchmarks for cluster managers ACL --- pallets/ddc-staking/src/benchmarking.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 87b671426..e7a35e87f 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -105,4 +105,22 @@ benchmarks! { verify { assert!(Ledger::::contains_key(&new_controller)); } + + allow_cluster_manager { + let new_cluster_manager = create_funded_user::("cluster_manager", USER_SEED, 100); + let new_cluster_manager_lookup = T::Lookup::unlookup(new_cluster_manager.clone()); + }: _(RawOrigin::Root, new_cluster_manager_lookup) + verify { + assert!(ClusterManagers::::get().contains(&new_cluster_manager)); + } + + disallow_cluster_manager { + let new_cluster_manager = create_funded_user::("cluster_manager", USER_SEED, 100); + let new_cluster_manager_lookup = T::Lookup::unlookup(new_cluster_manager.clone()); + DdcStaking::::allow_cluster_manager(RawOrigin::Root.into(), new_cluster_manager_lookup.clone())?; + assert!(ClusterManagers::::get().contains(&new_cluster_manager)); + }: _(RawOrigin::Root, new_cluster_manager_lookup) + verify { + assert!(!ClusterManagers::::get().contains(&new_cluster_manager)); + } } From 5f1548baf7fcc100f0d3ee7071b686564cd4a97d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 1 Sep 2023 12:13:19 +0600 Subject: [PATCH 292/544] Generate weights for cluster managers ACL --- pallets/ddc-staking/src/lib.rs | 4 ++-- pallets/ddc-staking/src/weights.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 009315c30..fa05a1ade 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -870,7 +870,7 @@ pub mod pallet { /// Add a new account to the list of cluster managers. /// /// RuntimeOrigin must be Root to call this function. - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::allow_cluster_manager())] pub fn allow_cluster_manager( origin: OriginFor, grantee: ::Source, @@ -890,7 +890,7 @@ pub mod pallet { /// Remove an account from the list of cluster managers. /// /// RuntimeOrigin must be Root to call this function. - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::disallow_cluster_manager())] pub fn disallow_cluster_manager( origin: OriginFor, revokee: ::Source, diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 937eece23..acb858060 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -1,7 +1,7 @@ //! Autogenerated weights for pallet_ddc_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-04, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-09-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `e14`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 @@ -35,6 +35,8 @@ pub trait WeightInfo { fn serve() -> Weight; fn chill() -> Weight; fn set_controller() -> Weight; + fn allow_cluster_manager() -> Weight; + fn disallow_cluster_manager() -> Weight; } /// Weights for pallet_ddc_staking using the Substrate node and recommended hardware. @@ -103,6 +105,18 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } + // Storage: DdcStaking ClusterManagers (r:1 w:1) + fn allow_cluster_manager() -> Weight { + Weight::from_ref_time(11_727_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: DdcStaking ClusterManagers (r:1 w:1) + fn disallow_cluster_manager() -> Weight { + Weight::from_ref_time(18_006_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } } // For backwards compatibility and tests @@ -170,4 +184,16 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } + // Storage: DdcStaking ClusterManagers (r:1 w:1) + fn allow_cluster_manager() -> Weight { + Weight::from_ref_time(11_727_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } + // Storage: DdcStaking ClusterManagers (r:1 w:1) + fn disallow_cluster_manager() -> Weight { + Weight::from_ref_time(18_006_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } } From 8c11196417da0d75067df7d634dfa8ab4a777d73 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 1 Sep 2023 12:20:33 +0600 Subject: [PATCH 293/544] Bump cere-dev runtime `spec_version` to 48003 --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 803f9d3bf..a0de3e32f 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -131,7 +131,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48002, + spec_version: 48003, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From a95e2f507ecd3207b46d330d57811cce80a0d6fa Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 1 Sep 2023 12:23:45 +0600 Subject: [PATCH 294/544] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cef36998..db17d69ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument. It will only work on the nodes with validation and offchain workers enabled as well. - [D] Several calls for `pallet-ddc-staking` to distribute rewards. +- [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance. ### Changed From c9c0bd30992b6b6ddaebe228176d3e1e4abc020b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 1 Sep 2023 10:42:33 +0200 Subject: [PATCH 295/544] add unit tests and fix source code --- pallets/ddc-accounts/src/lib.rs | 5 +- pallets/ddc-validator/src/lib.rs | 54 +++-- pallets/ddc-validator/src/tests.rs | 333 ++++++++++++++++++++++++++--- 3 files changed, 354 insertions(+), 38 deletions(-) diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index dc2edbbf5..e988cdd0f 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -219,6 +219,8 @@ pub mod pallet { BadState, /// Current era not set during runtime DDCEraNotSet, + /// Bucket with specified id doesn't exist + BucketDoesNotExist, } #[pallet::genesis_config] @@ -532,7 +534,8 @@ pub mod pallet { let mut total_charged = BalanceOf::::zero(); for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id).unwrap(); + let bucket: Bucket = Self::buckets(bucket_details.bucket_id) + .ok_or(Error::::BucketDoesNotExist)?; let content_owner = bucket.owner_id; let amount = bucket_details.amount * pricing.saturated_into::>(); diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index e83211846..7eb36db1d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -465,6 +465,7 @@ pub mod pallet { stakers_points: Vec<(T::AccountId, u64)>, ) -> DispatchResult { let ddc_valitor_key = ensure_signed(origin)?; + let mut rewards_counter = 0; ensure!( DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), @@ -488,18 +489,21 @@ pub mod pallet { >::mutate( &staker, |current_reward_points| { - let rewards = + let rewards: ddc_staking::EraRewardPointsPerNode = ddc_staking::EraRewardPointsPerNode { era, points }; current_reward_points.push(rewards); }, ); RewardPointsSetForNode::::insert(era, staker, true); + rewards_counter += 1; } } } }); - Self::deposit_event(Event::::EraRewardPoints(era, stakers_points)); + if rewards_counter > 0 { + Self::deposit_event(Event::::EraRewardPoints(era, stakers_points)); + } Ok(()) } @@ -911,13 +915,25 @@ pub mod pallet { return Err("signing key not set") } // ToDo: replace local call by a call from `ddc-staking` pallet - let _tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = + let tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = signer.send_signed_transaction(|_account| { Call::charge_payments_content_owners { paying_accounts: final_payments.clone(), } }); + for (acc, res) in &tx_res { + match res { + Ok(()) => + log::debug!("[{:?}]: submit transaction success.", acc.id), + Err(e) => log::debug!( + "[{:?}]: submit transaction failure. Reason: {:?}", + acc.id, + e + ), + } + } + let final_res = dac::get_final_decision(validations_res); let signer = Self::get_signer().unwrap(); @@ -929,17 +945,18 @@ pub mod pallet { validation_decision: final_res.clone(), }); - match &tx_res { - None | Some((_, Err(()))) => return Err("Error:"), - Some((_, Ok(()))) => {}, + for (acc, res) in &tx_res { + match res { + Ok(()) => + log::debug!("[{:?}]: submit transaction success.", acc.id), + Err(e) => log::debug!( + "[{:?}]: submit transaction failure. Reason: {:?}", + acc.id, + e + ), + } } - // match tx_res.result { - // Ok(tx_res) => println!("successfull tx: {:?}", tx_res), - // Err(error) => println!("failed tx: {:?}", error), - // } - // log::debug!("final_res: {:?}", final_res); - cdn_nodes_reward_points.push(( utils::string_to_account::(final_res.edge), final_res.totals.sent, @@ -951,11 +968,22 @@ pub mod pallet { // ToDo: replace local call by a call from `ddc-staking` pallet if cdn_nodes_reward_points.len() > 0 { - let _tx_res = + let tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { era: current_ddc_era - 1, stakers_points: cdn_nodes_reward_points.clone(), }); + + for (acc, res) in &tx_res { + match res { + Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), + Err(e) => log::debug!( + "[{:?}]: submit transaction failure. Reason: {:?}", + acc.id, + e + ), + } + } } Ok(()) diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index f3c069d01..a2bb9963a 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -1,3 +1,5 @@ +#![cfg(test)] + use super::*; use crate::{ mock::{Timestamp, *}, @@ -5,7 +7,7 @@ use crate::{ }; use codec::Decode; use frame_support::{assert_noop, assert_ok}; -use pallet_ddc_accounts::BucketsDetails; +use pallet_ddc_accounts::{BucketsDetails, Error as AccountsError}; use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; @@ -16,6 +18,10 @@ const OCW_PUB_KEY_STR: &str = "d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1 const OCW_SEED: &str = "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; +fn last_event() -> RuntimeEvent { + System::events().pop().expect("Event expected").event.into() +} + #[test] fn it_sets_validation_decision_with_one_validator_in_quorum() { let mut t = new_test_ext(); @@ -129,24 +135,21 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { t.execute_with(|| { let era_block_number = 20 as u32 * era_to_validate; System::set_block_number(era_block_number); // required for randomness - DdcValidator::set_validator_key( + assert_ok!(DdcValidator::set_validator_key( // register validator 1 RuntimeOrigin::signed(validator_1_controller), validator_1_stash, - ) - .unwrap(); - DdcValidator::set_validator_key( + )); + assert_ok!(DdcValidator::set_validator_key( // register validator 2 RuntimeOrigin::signed(validator_2_controller), validator_2_stash, - ) - .unwrap(); - DdcValidator::set_validator_key( + )); + assert_ok!(DdcValidator::set_validator_key( // register validator 3 RuntimeOrigin::signed(validator_3_controller), validator_3_stash, - ) - .unwrap(); + )); Timestamp::set_timestamp( (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, ); @@ -249,27 +252,18 @@ fn set_validation_decision_works_as_expected() { 0xdf, 0x67, ]); let validator_1_controller = AccountId::from([0xaa; 32]); + let validator_1_not_controller = AccountId::from([0xdd; 32]); let decision: ValidationDecision = serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) .unwrap(); - sp_std::if_std! { - println!("events"); - } - t.execute_with(|| { System::set_block_number(1); - assert_ok!(DdcValidator::set_validator_key( - // register validator 1 - RuntimeOrigin::signed(validator_1_controller.clone()), - validator_1_stash.clone(), - )); - assert_noop!( DdcValidator::set_validation_decision( - RuntimeOrigin::signed(validator_1_controller), + RuntimeOrigin::signed(validator_1_controller.clone()), era_to_validate, cdn_node_to_validate.clone(), decision.clone(), @@ -277,6 +271,28 @@ fn set_validation_decision_works_as_expected() { ValidatorError::::DDCValidatorKeyNotRegistered ); + // Set a mapping from stash to not a validator + DDCValidatorToStashKeys::::insert( + validator_1_stash.clone(), + validator_1_not_controller.clone(), + ); + + assert_noop!( + DdcValidator::set_validation_decision( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + cdn_node_to_validate.clone(), + decision.clone() + ), + ValidatorError::::NotValidatorStash + ); + + assert_ok!(DdcValidator::set_validator_key( + // register validator 1 + RuntimeOrigin::signed(validator_1_controller.clone()), + validator_1_stash.clone(), + )); + assert_noop!( DdcValidator::set_validation_decision( RuntimeOrigin::signed(validator_1_stash.clone()), @@ -304,12 +320,281 @@ fn set_validation_decision_works_as_expected() { ValidatorError::::ValidationDecisionAlreadySet ); - let evt = System::events().into_iter().map(|evt| evt.event).collect::>(); - assert_eq!(evt.len(), 1); + let evt = last_event(); + assert_eq!( - evt[0], + evt, crate::Event::ValidationDecision(era_to_validate, cdn_node_to_validate, decision) .into() ); }) } + +#[test] +fn set_era_reward_points_works_as_expected() { + let mut t = new_test_ext(); + + let era_to_validate: EraIndex = 3; + let cdn_node_to_validate = AccountId::from([0x1; 32]); + let not_a_cdn_node = AccountId::from([0x2; 32]); + let validator_1_stash = AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, + 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, + 0xdf, 0x67, + ]); + let validator_1_controller = AccountId::from([0xaa; 32]); + let validator_1_not_controller = AccountId::from([0xdd; 32]); + + let decision: ValidationDecision = + serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) + .unwrap(); + + let stakers_points = vec![(cdn_node_to_validate.clone(), decision.totals.sent)]; + let fake_stakers_points = vec![(not_a_cdn_node.clone(), decision.totals.sent)]; + + t.execute_with(|| { + System::set_block_number(1); + + assert_noop!( + DdcValidator::set_era_reward_points( + RuntimeOrigin::signed(validator_1_controller.clone()), + era_to_validate, + stakers_points.clone(), + ), + ValidatorError::::DDCValidatorKeyNotRegistered + ); + + // Set a mapping from stash to not a validator + DDCValidatorToStashKeys::::insert( + validator_1_stash.clone(), + validator_1_not_controller.clone(), + ); + + assert_noop!( + DdcValidator::set_era_reward_points( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + stakers_points.clone() + ), + ValidatorError::::NotValidatorStash + ); + + assert_ok!(DdcValidator::set_validator_key( + // register validator 1 + RuntimeOrigin::signed(validator_1_controller), + validator_1_stash.clone(), + )); + + // attempting to set era reward points for account, which is not an active CDN node + assert_ok!(DdcValidator::set_era_reward_points( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + fake_stakers_points.clone() + )); + + // rewards points should not be set + assert_eq!( + DdcValidator::reward_points_set_for_node(era_to_validate, not_a_cdn_node), + false + ); + + assert_ok!(DdcValidator::set_era_reward_points( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + stakers_points.clone() + )); + + let reward_points = ddc_staking::pallet::ErasEdgesRewardPointsPerNode::::get( + cdn_node_to_validate.clone(), + ); + + assert_eq!(reward_points.len(), 1); + + // Second run will still pass, but state will not change, as for specified node era points + // were set already + assert_ok!(DdcValidator::set_era_reward_points( + RuntimeOrigin::signed(validator_1_stash.clone()), + era_to_validate, + stakers_points.clone() + )); + + let reward_points_update_attempt = + ddc_staking::pallet::ErasEdgesRewardPointsPerNode::::get( + cdn_node_to_validate.clone(), + ); + + assert_eq!(reward_points_update_attempt.len(), 1); + + assert_eq!( + DdcValidator::reward_points_set_for_node(era_to_validate, cdn_node_to_validate), + true + ); + + assert_eq!(System::events().len(), 1); + let evt = System::events().pop().expect("Event expected").event; + + assert_eq!(evt, crate::Event::EraRewardPoints(era_to_validate, stakers_points).into()); + }) +} + +#[test] +fn charge_payments_content_owners_works_as_expected() { + let mut t = new_test_ext(); + + let era_to_validate: EraIndex = 3; + let validator_1_stash = AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, + 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, + 0xdf, 0x67, + ]); + let validator_1_controller = AccountId::from([0xaa; 32]); + let validator_1_not_controller = AccountId::from([0xdd; 32]); + + let bucket_info = BucketsDetails { bucket_id: 5, amount: 600u128 }; + + t.execute_with(|| { + System::set_block_number(1); + + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_controller.clone()), + vec![bucket_info.clone()], + ), + ValidatorError::::DDCEraNotSet + ); + + let era_block_number = 20 as u32 * era_to_validate; + System::set_block_number(era_block_number); + Timestamp::set_timestamp( + (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, + ); + DdcStaking::on_finalize(era_block_number - 1); + + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + ), + ValidatorError::::DDCValidatorKeyNotRegistered + ); + + // Set a mapping from stash to not a validator + DDCValidatorToStashKeys::::insert( + validator_1_stash.clone(), + validator_1_not_controller.clone(), + ); + + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + ), + ValidatorError::::NotValidatorStash + ); + + assert_ok!(DdcValidator::set_validator_key( + // register validator 1 + RuntimeOrigin::signed(validator_1_controller.clone()), + validator_1_stash.clone(), + )); + + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + ), + ValidatorError::::PricingNotSet + ); + + ddc_staking::Pricing::::set(Some(1)); // set CERE token per byte / reward + + // No buckets were created at this point + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + ), + AccountsError::::BucketDoesNotExist + ); + + // Create buckets + for range in 1..6 { + assert_ok!(ddc_accounts::Pallet::::create_bucket( + RuntimeOrigin::signed(validator_1_stash.clone()), + true, + range + )); + } + + // Account to charge payments from is not created + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + ), + AccountsError::::NotController + ); + + // Deposit funds for account + assert_ok!(ddc_accounts::Pallet::::deposit( + RuntimeOrigin::signed(validator_1_stash.clone()), + validator_1_stash.clone(), + 1_000, + )); + + assert_ok!(DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + )); + + // Should not be able to charge account twice by the same validator during one era + assert_noop!( + DdcValidator::charge_payments_content_owners( + RuntimeOrigin::signed(validator_1_stash.clone()), + vec![bucket_info.clone()] + ), + ValidatorError::::ContentOwnersDoubleSpend + ); + + let last_evt = System::events().pop().expect("Event expected").event; + assert_eq!(last_evt, ddc_accounts::Event::Charged(bucket_info.amount).into()); + }) +} + +#[test] +fn set_validator_key_works_as_expected() { + let mut t = new_test_ext(); + + let validator_1_stash = AccountId::from([ + 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, + 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, + 0xdf, 0x67, + ]); + let validator_1_controller: AccountId32 = AccountId::from([0xaa; 32]); + + t.execute_with(|| { + assert_noop!( + DdcValidator::set_validator_key( + RuntimeOrigin::signed(validator_1_stash.clone()), + validator_1_stash.clone(), + ), + ValidatorError::::NotController + ); + + assert_ok!(DdcValidator::set_validator_key( + RuntimeOrigin::signed(validator_1_controller.clone()), + validator_1_stash.clone(), + )); + + staking::Validators::::remove(validator_1_stash.clone()); + + // If stash is not a validator anymore, action will fail + assert_noop!( + DdcValidator::set_validator_key( + RuntimeOrigin::signed(validator_1_controller), + validator_1_stash, + ), + ValidatorError::::NotValidatorStash + ); + }) +} From e7628d7941907038b71dba0ac0651fa5ced9cd6d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 4 Sep 2023 11:56:55 +0600 Subject: [PATCH 296/544] Remove toolchain argument from cargo fmt commands --- .github/workflows/check.yaml | 2 +- .vscode/settings.json | 5 +---- scripts/pre-commit.sh | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 1e6a57960..b4b77700e 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -36,7 +36,7 @@ jobs: - name: Check Format run: | - cargo +nightly fmt -- --check + cargo fmt -- --check - name: Check Build run: | diff --git a/.vscode/settings.json b/.vscode/settings.json index 003fc3624..0196fd738 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,8 +2,5 @@ "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer", "editor.formatOnSave": true - }, - "rust-analyzer.rustfmt.extraArgs": [ - "+nightly" - ] + } } \ No newline at end of file diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index d84399d28..4106624b8 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -1,8 +1,8 @@ #!/bin/sh # Prevent committing badly formatted code -cargo +nightly fmt -- --check +cargo fmt -- --check if [ $? -ne 0 ]; then - echo "Run \`cargo +nightly fmt\` to fix formatting issues before committing." + echo "Run \`cargo fmt\` to fix formatting issues before committing." exit 1 fi From f69abcc2c919ed0efaccfd20744938e0416f2bac Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 4 Sep 2023 10:42:27 +0200 Subject: [PATCH 297/544] resolve comments --- pallets/ddc-validator/src/lib.rs | 53 ++++++++++++++---------------- pallets/ddc-validator/src/tests.rs | 5 ++- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 7eb36db1d..a4a5fd7e5 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -922,16 +922,15 @@ pub mod pallet { } }); - for (acc, res) in &tx_res { - match res { - Ok(()) => - log::debug!("[{:?}]: submit transaction success.", acc.id), - Err(e) => log::debug!( - "[{:?}]: submit transaction failure. Reason: {:?}", - acc.id, - e - ), - } + let (acc, res) = &tx_res.unwrap(); + + match res { + Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), + Err(e) => log::debug!( + "[{:?}]: submit transaction failure. Reason: {:?}", + acc.id, + e + ), } let final_res = dac::get_final_decision(validations_res); @@ -945,16 +944,15 @@ pub mod pallet { validation_decision: final_res.clone(), }); - for (acc, res) in &tx_res { - match res { - Ok(()) => - log::debug!("[{:?}]: submit transaction success.", acc.id), - Err(e) => log::debug!( - "[{:?}]: submit transaction failure. Reason: {:?}", - acc.id, - e - ), - } + let (acc, res) = &tx_res.unwrap(); + + match res { + Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), + Err(e) => log::debug!( + "[{:?}]: submit transaction failure. Reason: {:?}", + acc.id, + e + ), } cdn_nodes_reward_points.push(( @@ -974,15 +972,12 @@ pub mod pallet { stakers_points: cdn_nodes_reward_points.clone(), }); - for (acc, res) in &tx_res { - match res { - Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), - Err(e) => log::debug!( - "[{:?}]: submit transaction failure. Reason: {:?}", - acc.id, - e - ), - } + let (acc, res) = &tx_res.unwrap(); + + match res { + Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), + Err(e) => + log::debug!("[{:?}]: submit transaction failure. Reason: {:?}", acc.id, e), } } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index a2bb9963a..c2c470056 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -235,7 +235,10 @@ fn send_signal_works_as_expected() { t.execute_with(|| { assert_eq!(DdcValidator::signal(), None); assert_ok!(DdcValidator::send_signal(RuntimeOrigin::signed(validator_controller))); - assert_eq!(DdcValidator::signal().unwrap(), true); + assert_eq!(DdcValidator::signal(), Some(true)); + DdcValidator::on_initialize(2); + System::set_block_number(2); + assert_eq!(DdcValidator::signal(), Some(false)); }) } From 39d8e69f3e19e2ed10cec86317e20cac0bbc9825 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 4 Sep 2023 15:32:20 +0200 Subject: [PATCH 298/544] fix match for tx_res --- pallets/ddc-validator/src/lib.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index a4a5fd7e5..afe90a719 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -922,15 +922,15 @@ pub mod pallet { } }); - let (acc, res) = &tx_res.unwrap(); - - match res { - Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), - Err(e) => log::debug!( + match tx_res { + Some((acc, Ok(()))) => + log::debug!("[{:?}]: submit transaction success.", acc.id), + Some((acc, Err(e))) => log::debug!( "[{:?}]: submit transaction failure. Reason: {:?}", acc.id, e ), + None => log::debug!("submit transaction failure."), } let final_res = dac::get_final_decision(validations_res); @@ -944,15 +944,15 @@ pub mod pallet { validation_decision: final_res.clone(), }); - let (acc, res) = &tx_res.unwrap(); - - match res { - Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), - Err(e) => log::debug!( + match tx_res { + Some((acc, Ok(()))) => + log::debug!("[{:?}]: submit transaction success.", acc.id), + Some((acc, Err(e))) => log::debug!( "[{:?}]: submit transaction failure. Reason: {:?}", acc.id, e ), + None => log::debug!("submit transaction failure."), } cdn_nodes_reward_points.push(( @@ -972,12 +972,12 @@ pub mod pallet { stakers_points: cdn_nodes_reward_points.clone(), }); - let (acc, res) = &tx_res.unwrap(); - - match res { - Ok(()) => log::debug!("[{:?}]: submit transaction success.", acc.id), - Err(e) => + match tx_res { + Some((acc, Ok(()))) => + log::debug!("[{:?}]: submit transaction success.", acc.id), + Some((acc, Err(e))) => log::debug!("[{:?}]: submit transaction failure. Reason: {:?}", acc.id, e), + None => log::debug!("submit transaction failure."), } } From 684df85595c522b5c1e9351f49d6855f6d55fccf Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 6 Sep 2023 18:12:22 +0600 Subject: [PATCH 299/544] Fix runtime loading from file for cere-dev chains --- cli/src/command.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 0c86611fb..d5fb49bea 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -43,11 +43,14 @@ impl SubstrateCli for Cli { "local" => Box::new(cere_service::chain_spec::cere_dev_local_testnet_config()?), path => { let path = std::path::PathBuf::from(path); + let chain_spec = + Box::new(cere_service::CereChainSpec::from_json_file(path.clone())?) + as Box; - if self.run.force_cere_dev { + if self.run.force_cere_dev || chain_spec.is_cere_dev() { Box::new(cere_service::CereDevChainSpec::from_json_file(path)?) } else { - Box::new(cere_service::CereChainSpec::from_json_file(path)?) + chain_spec } }, }) From e9a2855f1d49aa51b533e05117109d56aad1078d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 4 Sep 2023 17:38:30 +0600 Subject: [PATCH 300/544] Basic zombienet config with two nodes --- zombienet/0000-block-building/block-building.toml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 zombienet/0000-block-building/block-building.toml diff --git a/zombienet/0000-block-building/block-building.toml b/zombienet/0000-block-building/block-building.toml new file mode 100644 index 000000000..b9d662117 --- /dev/null +++ b/zombienet/0000-block-building/block-building.toml @@ -0,0 +1,9 @@ +[relaychain] +default_command = "./target/release/cere" +chain = "local" + + [[relaychain.nodes]] + name = "alice" + + [[relaychain.nodes]] + name = "bob" From 5adda15c6efe4c10111caae1a1503157a8241d31 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 4 Sep 2023 17:39:40 +0600 Subject: [PATCH 301/544] Zombienet block building and balance transfer test --- .../0000-block-building/block-building.zndsl | 17 ++++++ .../transaction-gets-finalized.js | 59 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 zombienet/0000-block-building/block-building.zndsl create mode 100644 zombienet/0000-block-building/transaction-gets-finalized.js diff --git a/zombienet/0000-block-building/block-building.zndsl b/zombienet/0000-block-building/block-building.zndsl new file mode 100644 index 000000000..7bed0649f --- /dev/null +++ b/zombienet/0000-block-building/block-building.zndsl @@ -0,0 +1,17 @@ +Description: Block building +Network: ./block-building.toml +Creds: config + +alice: reports node_roles is 4 +bob: reports node_roles is 4 + +alice: reports peers count is at least 1 +bob: reports peers count is at least 1 + +alice: reports block height is at least 5 within 30 seconds +bob: reports block height is at least 5 within 30 seconds + +alice: count of log lines containing "error" is 0 within 2 seconds +bob: count of log lines containing "error" is 0 within 2 seconds + +alice: js-script ./transaction-gets-finalized.js within 30 seconds diff --git a/zombienet/0000-block-building/transaction-gets-finalized.js b/zombienet/0000-block-building/transaction-gets-finalized.js new file mode 100644 index 000000000..2533ef8b8 --- /dev/null +++ b/zombienet/0000-block-building/transaction-gets-finalized.js @@ -0,0 +1,59 @@ +// based on: https://github.com/paritytech/polkadot-sdk/blob/91deee7a1dba52e5e73d1a97d9fd5b8ad1e916a4/substrate/zombienet/0000-block-building/transaction-gets-finalized.js + +const assert = require('assert'); + +async function run(nodeName, networkInfo) { + const { wsUri, userDefinedTypes } = networkInfo.nodesByName[nodeName]; + const api = await zombie.connect(wsUri, userDefinedTypes); + + // Construct the keyring after the API (crypto has an async init) + const keyring = new zombie.Keyring({ type: 'sr25519' }); + + // Add Alice to our keyring with a hard-derivation path (empty phrase, so uses dev) + const alice = keyring.addFromUri('//Alice'); + const bob = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'; + + // Create a extrinsic, transferring 10^10 units to Bob + const transfer = api.tx.balances.transfer(bob, 10n ** 10n); + + let transaction_success_event = false; + try { + await new Promise(async (resolve, reject) => { + const unsubscribe = await transfer + .signAndSend(alice, { nonce: -1 }, ({ events = [], status }) => { + console.log('Transaction status:', status.type); + + if (status.isInBlock) { + console.log('Included at block hash', status.asInBlock.toHex()); + console.log('Events:'); + + events.forEach(({ event: { data, method, section }, phase }) => { + console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString()); + + if (section == 'system' && method == 'ExtrinsicSuccess') { + transaction_success_event = true; + } + }); + } else if (status.isFinalized) { + console.log('Finalized block hash', status.asFinalized.toHex()); + unsubscribe(); + if (transaction_success_event) { + resolve(); + } else { + reject('ExtrinsicSuccess has not been seen'); + } + } else if (status.isError) { + unsubscribe(); + reject('Transaction status.isError'); + } + + }); + }); + } catch (error) { + assert.fail('Transfer promise failed, error: ' + error); + } + + assert.ok('test passed'); +} + +module.exports = { run } From 98548673e41be1c9675fdd29f8be173ee5461d2b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 7 Sep 2023 12:54:58 +0600 Subject: [PATCH 302/544] Zombienet config for DDC validation development --- .../0001-ddc-validation/ddc-validation.toml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 zombienet/0001-ddc-validation/ddc-validation.toml diff --git a/zombienet/0001-ddc-validation/ddc-validation.toml b/zombienet/0001-ddc-validation/ddc-validation.toml new file mode 100644 index 000000000..6a3fb41e2 --- /dev/null +++ b/zombienet/0001-ddc-validation/ddc-validation.toml @@ -0,0 +1,23 @@ +[relaychain] +default_command = "./target/release/cere" +default_args = ["--enable-ddc-validation"] +chain = "local" + + [[relaychain.nodes]] + name = "alice" + + [[relaychain.nodes]] + name = "bob" + + [[relaychain.nodes]] + name = "charlie" + + [[relaychain.nodes]] + name = "dave" + + [[relaychain.nodes]] + name = "eve" + + [[relaychain.nodes]] + name = "ferdie" + validator = false From bb74e5c249c2c55b223721e308ba0da9f12f8a8d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 7 Sep 2023 14:10:57 +0600 Subject: [PATCH 303/544] Add `zombienet` section to the README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index f2493a607..951ac8f42 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,28 @@ Start Bob's node: > - Alice//stash > - Bob//stash +### Zombienet + +Zombienet is a cli tool to easily spawn ephemeral networks and perform tests against them. Its installation and usage guide is available [here](https://github.com/paritytech/zombienet#usage). + +The following scenarios expect the node binary available at `./target/release/cere`. + +#### Test block building + +Spawn 2 nodes network and test if it produces blocks and finalized transaction. + +```console +zombienet -p native test zombienet/0000-block-building/block-building.zndsl +``` + +#### Spawn 5 DDC validation nodes + +The following command spawns 5 validator nodes with DDC validation enabled as well as 1 non-validator node to check it is not affected. + +```console +zombienet -p native test zombienet/0001-ddc-validation/ddc-validation.toml +``` + ### Runtimes The node supports 2 runtimes. From 1f1927ebc8d6fc7b1e7f3ce33488c3abe4250f2b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 7 Sep 2023 14:24:59 +0600 Subject: [PATCH 304/544] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db17d69ad..4e09b33f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument. It will only work on the nodes with validation and offchain workers enabled as well. - [D] Several calls for `pallet-ddc-staking` to distribute rewards. - [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance. +- [Zombienet](https://github.com/paritytech/zombienet) configurations to test block building and spawn a network for DDC validation debugging. ### Changed From a2e368a7a78f338c6c54a2cb48916d642a5478f2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 8 Sep 2023 18:50:44 +0600 Subject: [PATCH 305/544] Add DAC DataModel URL CLI parameter --- cli/src/cli.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index b60cea5b2..aeae79cff 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -18,6 +18,10 @@ pub struct RunCmd { #[clap(long)] pub enable_ddc_validation: bool, + /// DAC DataModel HTTP endpoint to retrieve DDC activity data for validation. + #[clap(long)] + pub dac_url: String, + /// Force using Cere Dev runtime. #[clap(long = "force-cere-dev")] pub force_cere_dev: bool, From ab47e18a18d43adfa3d37da6d6ebc4af17643844 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 8 Sep 2023 18:52:13 +0600 Subject: [PATCH 306/544] Write provided DAC URL to the offchain storage --- cli/src/command.rs | 1 + node/service/src/lib.rs | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index d5fb49bea..9865ccf85 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -249,6 +249,7 @@ pub fn run() -> sc_cli::Result<()> { config, cli.run.no_hardware_benchmarks, cli.run.enable_ddc_validation, + cli.run.dac_url, ) .map(|full| full.task_manager) .map_err(Error::Service) diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 3f6ffa118..692ed9598 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -271,6 +271,7 @@ pub fn build_full( config: Configuration, disable_hardware_benchmarks: bool, enable_ddc_validation: bool, + dac_url: String, ) -> Result, ServiceError> { #[cfg(feature = "cere-dev-native")] if config.chain_spec.is_cere_dev() { @@ -278,6 +279,7 @@ pub fn build_full( config, disable_hardware_benchmarks, enable_ddc_validation, + dac_url, |_, _| (), ) .map(|full| full.with_client(Client::CereDev)) @@ -289,6 +291,7 @@ pub fn build_full( config, disable_hardware_benchmarks, enable_ddc_validation, + dac_url, |_, _| (), ) .map(|full| full.with_client(Client::Cere)) @@ -323,6 +326,7 @@ pub fn new_full( mut config: Configuration, disable_hardware_benchmarks: bool, enable_ddc_validation: bool, + dac_url: String, with_startup_data: impl FnOnce( &sc_consensus_babe::BabeBlockImport< Block, @@ -352,15 +356,17 @@ where let basics = new_partial_basics::(&config)?; - basics + let mut offchain_storage = basics .backend .offchain_storage() - .expect("no off-chain storage, DDC validation is not possible") - .set( - sp_core::offchain::STORAGE_PREFIX, - b"enable-ddc-validation", - if enable_ddc_validation { &[1] } else { &[0] }, - ); + .expect("no off-chain storage, DDC validation is not possible"); + + offchain_storage.set( + sp_core::offchain::STORAGE_PREFIX, + b"enable-ddc-validation", + if enable_ddc_validation { &[1] } else { &[0] }, + ); + offchain_storage.set(sp_core::offchain::STORAGE_PREFIX, b"dac-url", dac_url.as_bytes()); let sc_service::PartialComponents { client, From 670ea6fbdbf4eed29757f0718ac8aeb531199031 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 8 Sep 2023 18:54:42 +0600 Subject: [PATCH 307/544] Update key where the validation reads DAC URL --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 6dbf95561..473695839 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -83,7 +83,7 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); /// Webdis in experimental cluster connected to Redis in dev. pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; // pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; -pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; +pub const DATA_PROVIDER_URL_KEY: &[u8; 7] = b"dac-url"; pub const QUORUM_SIZE: usize = 1; #[derive(Debug)] From 3cb4cc7db2a10cba42a03d416e123212d110b2a6 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 8 Sep 2023 18:57:44 +0600 Subject: [PATCH 308/544] Pass DAC URL to ddc-validation zombienet --- zombienet/0001-ddc-validation/ddc-validation.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zombienet/0001-ddc-validation/ddc-validation.toml b/zombienet/0001-ddc-validation/ddc-validation.toml index 6a3fb41e2..64b4111ed 100644 --- a/zombienet/0001-ddc-validation/ddc-validation.toml +++ b/zombienet/0001-ddc-validation/ddc-validation.toml @@ -1,6 +1,6 @@ [relaychain] default_command = "./target/release/cere" -default_args = ["--enable-ddc-validation"] +default_args = ["--enable-ddc-validation --dac-url {{DAC_URL}}"] chain = "local" [[relaychain.nodes]] From 1a4a745f62f0b8c1a33a34387fa20694b8c95b05 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 8 Sep 2023 19:01:23 +0600 Subject: [PATCH 309/544] Add DAC URL to zombienet usage guide --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 951ac8f42..07d0962c9 100644 --- a/README.md +++ b/README.md @@ -133,9 +133,10 @@ zombienet -p native test zombienet/0000-block-building/block-building.zndsl #### Spawn 5 DDC validation nodes -The following command spawns 5 validator nodes with DDC validation enabled as well as 1 non-validator node to check it is not affected. +The following command spawns 5 validator nodes with DDC validation enabled as well as 1 non-validator node to check it is not affected. Set `DAC_URL` environment variable with an address to [webdis](https://webd.is/) which will proxy validator's requests for DDC activity data to DAC DataModel Redis. ```console +export DAC_URL=http://localhost:7379/ zombienet -p native test zombienet/0001-ddc-validation/ddc-validation.toml ``` From 7a8ff85a4f1dd983940f56c15361d58bb8758d9e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 8 Sep 2023 19:03:24 +0600 Subject: [PATCH 310/544] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e09b33f0..85f6b0c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument. It will only work on the nodes with validation and offchain workers enabled as well. +- [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument and `--dac-url` argument to specify DAC endpoint. It will only work on the nodes with validation and offchain workers enabled as well. - [D] Several calls for `pallet-ddc-staking` to distribute rewards. - [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance. - [Zombienet](https://github.com/paritytech/zombienet) configurations to test block building and spawn a network for DDC validation debugging. From a41c56baab4edc8bccf57b0b4523a19158d9d5b5 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 19 Sep 2023 10:52:44 +0200 Subject: [PATCH 311/544] account only for read logs/acks during validation --- pallets/ddc-validator/src/dac.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index a4c81320f..5eee856e2 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -216,10 +216,13 @@ pub fn get_acknowledged_bytes_bucket<'a>( let mut total_bytes_received = 0u64; let bucket_id = file_request.bucket_id; for (_, chunk) in &file_request.chunks { - if let Some(ack) = &chunk.ack { - total_bytes_received += ack.bytes_received; - } else { - total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + // Only check reads + if chunk.log.log_type == 1u64 { + if let Some(ack) = &chunk.ack { + total_bytes_received += ack.bytes_received; + } else { + total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + } } } acknowledged_bytes_by_bucket.push((bucket_id, total_bytes_received)); From 99e61a50c79ece301906970f2367c8259cfd14d4 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 13:54:42 +0600 Subject: [PATCH 312/544] Require all or none of DAC-related CLI parameters --- cli/src/cli.rs | 6 +++--- node/service/src/lib.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index aeae79cff..c904f01ea 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -15,12 +15,12 @@ pub struct RunCmd { /// Enable DDC validation (disabled by default). Works only on validator nodes with enabled /// offchain workers. - #[clap(long)] + #[clap(long, requires = "dac-url")] pub enable_ddc_validation: bool, /// DAC DataModel HTTP endpoint to retrieve DDC activity data for validation. - #[clap(long)] - pub dac_url: String, + #[clap(long, requires = "enable-ddc-validation")] + pub dac_url: Option, /// Force using Cere Dev runtime. #[clap(long = "force-cere-dev")] diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 692ed9598..6988b5641 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -271,7 +271,7 @@ pub fn build_full( config: Configuration, disable_hardware_benchmarks: bool, enable_ddc_validation: bool, - dac_url: String, + dac_url: Option, ) -> Result, ServiceError> { #[cfg(feature = "cere-dev-native")] if config.chain_spec.is_cere_dev() { @@ -326,7 +326,7 @@ pub fn new_full( mut config: Configuration, disable_hardware_benchmarks: bool, enable_ddc_validation: bool, - dac_url: String, + dac_url: Option, with_startup_data: impl FnOnce( &sc_consensus_babe::BabeBlockImport< Block, @@ -366,7 +366,9 @@ where b"enable-ddc-validation", if enable_ddc_validation { &[1] } else { &[0] }, ); - offchain_storage.set(sp_core::offchain::STORAGE_PREFIX, b"dac-url", dac_url.as_bytes()); + if let Some(dac_url) = dac_url { + offchain_storage.set(sp_core::offchain::STORAGE_PREFIX, b"dac-url", dac_url.as_bytes()); + }; let sc_service::PartialComponents { client, From 996cdf2e91d96fa8ddc48456cae0b233c4a56165 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 21 Sep 2023 10:43:49 +0200 Subject: [PATCH 313/544] fix redundant event deposited for set_era_reward_points; fix not working last_validated_era local storage key --- pallets/ddc-validator/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 6dbf95561..f3fdc5233 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -73,6 +73,8 @@ type ResultStr = Result; /// Offchain local storage key that holds the last era in which the validator completed its /// assignment. const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; +/// Offchain local storage that holds the validation lock +const VALIDATION_LOCK: &[u8; 40] = b"pallet-ddc-validator::validation_lock"; /// Local storage key that holds the flag to enable DDC validation. Set it to true (0x01) to enable /// DDC validation, set it to false (0x00) or delete the key to disable it. @@ -344,8 +346,7 @@ pub mod pallet { let mut should_validate_because_new_era = true; - let mut validation_lock = - StorageLock::::new(LAST_VALIDATED_ERA_KEY); + let mut validation_lock = StorageLock::::new(VALIDATION_LOCK); // Skip if the validation is already in progress. if validation_lock.try_lock().is_err() { @@ -382,7 +383,6 @@ pub mod pallet { log::warn!("🔎 DDC validation failed. {}", e); return } - last_validated_era_storage.set(¤t_ddc_era); log::info!("🔎 DDC validation complete for {} era.", current_ddc_era); } @@ -478,6 +478,8 @@ pub mod pallet { Error::::NotValidatorStash ); + let mut rewards_counter = 0; + >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.clone().into_iter() { if !Self::reward_points_set_for_node(era, &staker) { @@ -494,12 +496,15 @@ pub mod pallet { }, ); RewardPointsSetForNode::::insert(era, staker, true); + rewards_counter += 1; } } } }); - Self::deposit_event(Event::::EraRewardPoints(era, stakers_points)); + if rewards_counter > 0 { + Self::deposit_event(Event::::EraRewardPoints(era, stakers_points)); + } Ok(()) } From 6ae85044c9372b963d479b51cef434c9479d4140 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 15:36:28 +0600 Subject: [PATCH 314/544] Add URL validator to DAC URL CLI parameter --- Cargo.lock | 5 +++-- cli/Cargo.toml | 1 + cli/src/cli.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a7808820..34121abb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -742,6 +742,7 @@ dependencies = [ "sc-service", "substrate-build-script-utils", "try-runtime-cli", + "url", ] [[package]] @@ -9639,9 +9640,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna 0.4.0", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 460371d3c..77f4d290d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -17,6 +17,7 @@ sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrat sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.30" } +url = "2.4.1" # Local cere-service = { path = "../node/service", default-features = false, optional = true } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index c904f01ea..880033ecf 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -19,7 +19,7 @@ pub struct RunCmd { pub enable_ddc_validation: bool, /// DAC DataModel HTTP endpoint to retrieve DDC activity data for validation. - #[clap(long, requires = "enable-ddc-validation")] + #[clap(long, requires = "enable-ddc-validation", validator = url::Url::parse)] pub dac_url: Option, /// Force using Cere Dev runtime. From 1595cdf6216003fa6ed75478b1374626fe012a86 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 17:22:21 +0600 Subject: [PATCH 315/544] Camel case name for `ddc-accounts` pallet ID --- runtime/cere-dev/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 38741473a..6a26d5836 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1329,19 +1329,19 @@ impl pallet_ddc_staking::Config for Runtime { type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; - type StakersPayoutSource = Ddc_Accounts_Pallet_Id; + type StakersPayoutSource = DdcAccountsPalletId; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } parameter_types! { - pub const Ddc_Accounts_Pallet_Id: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake + pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake } impl pallet_ddc_accounts::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; - type PalletId = Ddc_Accounts_Pallet_Id; + type PalletId = DdcAccountsPalletId; type RuntimeEvent = RuntimeEvent; } From 031c58d0f089a2e112d982dbb31d29e064e5b587 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 21 Sep 2023 16:37:59 +0200 Subject: [PATCH 316/544] update impementation accroding to comments #1 --- pallets/ddc-validator/src/dac.rs | 16 +++++++++------- pallets/ddc-validator/src/lib.rs | 22 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 5eee856e2..8800f64af 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -1,6 +1,6 @@ //! A module with Data Activity Capture (DAC) interaction. -use crate::{utils, DacTotalAggregates, ValidationDecision}; +use crate::{utils, DacTotalAggregates, LogType, ValidationDecision}; use alloc::string::String; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; @@ -217,12 +217,14 @@ pub fn get_acknowledged_bytes_bucket<'a>( let bucket_id = file_request.bucket_id; for (_, chunk) in &file_request.chunks { // Only check reads - if chunk.log.log_type == 1u64 { - if let Some(ack) = &chunk.ack { - total_bytes_received += ack.bytes_received; - } else { - total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); - } + match chunk.log.log_type.try_into() { + Ok(LogType::Read) => + if let Some(ack) = &chunk.ack { + total_bytes_received += ack.bytes_received; + } else { + total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + }, + _ => (), } } acknowledged_bytes_by_bucket.push((bucket_id, total_bytes_received)); diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index f3fdc5233..120772502 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -74,7 +74,7 @@ type ResultStr = Result; /// assignment. const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; /// Offchain local storage that holds the validation lock -const VALIDATION_LOCK: &[u8; 40] = b"pallet-ddc-validator::validation_lock"; +const VALIDATION_LOCK: &[u8; 37] = b"pallet-ddc-validator::validation_lock"; /// Local storage key that holds the flag to enable DDC validation. Set it to true (0x01) to enable /// DDC validation, set it to false (0x00) or delete the key to disable it. @@ -88,6 +88,26 @@ pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url"; pub const QUORUM_SIZE: usize = 1; +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub enum LogType { + Write = 1, + Read = 2, + Query = 3, +} + +impl TryFrom for LogType { + type Error = &'static str; + + fn try_from(v: u64) -> Result { + match v { + x if x == LogType::Write as u64 => Ok(LogType::Write), + x if x == LogType::Read as u64 => Ok(LogType::Read), + x if x == LogType::Query as u64 => Ok(LogType::Query), + _ => Err("Invalid value to for log type"), + } + } +} + #[derive(Debug)] pub enum AssignmentError { NoValidators, From dd27cc2b07f243ceca51b98ae80d11bf69d545cb Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 21 Sep 2023 16:42:46 +0200 Subject: [PATCH 317/544] fix logtype enum --- pallets/ddc-validator/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 120772502..d33277dab 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -90,8 +90,8 @@ pub const QUORUM_SIZE: usize = 1; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub enum LogType { - Write = 1, - Read = 2, + Read = 1, + Write = 2, Query = 3, } From a275de7982ff2c4392695ee31f3f6f45edbbd393 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 18:31:53 +0600 Subject: [PATCH 318/544] Launch `check` workflow on push to all branches --- .github/workflows/check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index b4b77700e..88fc4b76e 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -4,7 +4,7 @@ name: Check Set-Up & Build on: # Triggers the workflow on push or pull request events but only for the master branch push: - branches: [ master ] + branches: [ '**' ] pull_request: branches: [ master ] From 495f90a16eb4b2f971ac8633623ce45af6a85ba5 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 18:32:49 +0600 Subject: [PATCH 319/544] Disable check workflow on a pull request to master --- .github/workflows/check.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 88fc4b76e..f170e84c4 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -5,8 +5,6 @@ on: # Triggers the workflow on push or pull request events but only for the master branch push: branches: [ '**' ] - pull_request: - branches: [ master ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From 546ec270c87b002019993be36d8fe754d0a6e094 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 18:37:05 +0600 Subject: [PATCH 320/544] Run `check.yaml` workflow on `ubuntu-22.04` --- .github/workflows/check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index f170e84c4..88876a208 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -13,7 +13,7 @@ on: jobs: check: # The type of runner that the job will run on - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 # Steps represent a sequence of tasks that will be executed as part of the job steps: From 1936c1a90d138d1661a3af6836cc214a2094800c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 18:38:03 +0600 Subject: [PATCH 321/544] Update actions/checkout to v4 --- .github/workflows/check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 88876a208..5874103dc 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -18,7 +18,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set-Up run: sudo apt install -y git clang curl libssl-dev llvm libudev-dev From d8b326acb9bf86c56eb8b6115689cd7c98c29943 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 18:39:19 +0600 Subject: [PATCH 322/544] Simplify Rust setup for `check.yaml` workflow --- .github/workflows/check.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 5874103dc..95fcab1ad 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -23,14 +23,10 @@ jobs: - name: Set-Up run: sudo apt install -y git clang curl libssl-dev llvm libudev-dev - - name: Install Rustup + - name: Install Rust run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - source ~/.cargo/env - rustup default stable - rustup update nightly - rustup update stable - rustup component add rustfmt --toolchain nightly + rustup update stable --no-self-update + rustup target add wasm32-unknown-unknown - name: Check Format run: | From 95ff7568b94ecaecea17267de72baa26165814b3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 18:41:02 +0600 Subject: [PATCH 323/544] Use build cache in `check.yaml` workflow --- .github/workflows/check.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 95fcab1ad..b43e4c05c 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -32,6 +32,9 @@ jobs: run: | cargo fmt -- --check + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Check Build run: | SKIP_WASM_BUILD=1 cargo check --release From 483fe8f1f5b28a995e40429ed3a9ad95063214b7 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 22 Sep 2023 17:09:13 +0200 Subject: [PATCH 324/544] fix tests and naming --- pallets/ddc-validator/src/dac.rs | 4 ++-- pallets/ddc-validator/src/lib.rs | 12 ++++++------ pallets/ddc-validator/src/tests.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 8800f64af..b9c34e5dc 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -1,6 +1,6 @@ //! A module with Data Activity Capture (DAC) interaction. -use crate::{utils, DacTotalAggregates, LogType, ValidationDecision}; +use crate::{opCode, utils, DacTotalAggregates, ValidationDecision}; use alloc::string::String; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; @@ -218,7 +218,7 @@ pub fn get_acknowledged_bytes_bucket<'a>( for (_, chunk) in &file_request.chunks { // Only check reads match chunk.log.log_type.try_into() { - Ok(LogType::Read) => + Ok(opCode::Read) => if let Some(ack) = &chunk.ack { total_bytes_received += ack.bytes_received; } else { diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index d33277dab..15dfb6c2a 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -89,20 +89,20 @@ pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url" pub const QUORUM_SIZE: usize = 1; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub enum LogType { +pub enum opCode { Read = 1, Write = 2, - Query = 3, + Search = 3, } -impl TryFrom for LogType { +impl TryFrom for opCode { type Error = &'static str; fn try_from(v: u64) -> Result { match v { - x if x == LogType::Write as u64 => Ok(LogType::Write), - x if x == LogType::Read as u64 => Ok(LogType::Read), - x if x == LogType::Query as u64 => Ok(LogType::Query), + x if x == opCode::Write as u64 => Ok(opCode::Write), + x if x == opCode::Read as u64 => Ok(opCode::Read), + x if x == opCode::Query as u64 => Ok(opCode::Query), _ => Err("Invalid value to for log type"), } } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index b728f0fd1..d7e0b7bd8 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -164,7 +164,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert!(tx.signature.is_some()); - let bucket_info = BucketsDetails { bucket_id: 5, amount: 600u128 }; + let bucket_info = BucketsDetails { bucket_id: 5, amount: 400u128 }; assert_eq!( tx.call, From c38f3d0c46bb0df403875b38bb329d9e3e2011a3 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 22 Sep 2023 18:12:49 +0200 Subject: [PATCH 325/544] fix bug --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 15dfb6c2a..77070736e 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -102,7 +102,7 @@ impl TryFrom for opCode { match v { x if x == opCode::Write as u64 => Ok(opCode::Write), x if x == opCode::Read as u64 => Ok(opCode::Read), - x if x == opCode::Query as u64 => Ok(opCode::Query), + x if x == opCode::Search as u64 => Ok(opCode::Search), _ => Err("Invalid value to for log type"), } } From 35d1b867ffb43b4be38c4fa12599a335adefbd10 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 25 Sep 2023 12:02:45 +0600 Subject: [PATCH 326/544] Update linux dependencies setup list --- .github/workflows/check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index b43e4c05c..db63d8d96 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -20,8 +20,8 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 - - name: Set-Up - run: sudo apt install -y git clang curl libssl-dev llvm libudev-dev + - name: Install linux dependencies + run: sudo apt install -y clang libssl-dev llvm libudev-dev protobuf-compiler - name: Install Rust run: | From 5dd35bfa417a7c2ebf9ab0507f598ae4fe18a4ec Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 25 Sep 2023 11:06:43 +0200 Subject: [PATCH 327/544] fix formatting --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 77070736e..a69c66db7 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -95,7 +95,7 @@ pub enum opCode { Search = 3, } -impl TryFrom for opCode { +impl TryFrom for OpCode { type Error = &'static str; fn try_from(v: u64) -> Result { From 6be0468ff2bedcac8829657885a65fe1a16055d3 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 25 Sep 2023 12:30:59 +0200 Subject: [PATCH 328/544] fix formatting --- pallets/ddc-validator/src/dac.rs | 4 ++-- pallets/ddc-validator/src/lib.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index b9c34e5dc..024a5adf6 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -1,6 +1,6 @@ //! A module with Data Activity Capture (DAC) interaction. -use crate::{opCode, utils, DacTotalAggregates, ValidationDecision}; +use crate::{utils, DacTotalAggregates, OpCode, ValidationDecision}; use alloc::string::String; // ToDo: remove String usage use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; use codec::{Decode, Encode}; @@ -218,7 +218,7 @@ pub fn get_acknowledged_bytes_bucket<'a>( for (_, chunk) in &file_request.chunks { // Only check reads match chunk.log.log_type.try_into() { - Ok(opCode::Read) => + Ok(OpCode::Read) => if let Some(ack) = &chunk.ack { total_bytes_received += ack.bytes_received; } else { diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index a69c66db7..b7a5a9c4d 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -89,7 +89,7 @@ pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url" pub const QUORUM_SIZE: usize = 1; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub enum opCode { +pub enum OpCode { Read = 1, Write = 2, Search = 3, @@ -100,9 +100,9 @@ impl TryFrom for OpCode { fn try_from(v: u64) -> Result { match v { - x if x == opCode::Write as u64 => Ok(opCode::Write), - x if x == opCode::Read as u64 => Ok(opCode::Read), - x if x == opCode::Search as u64 => Ok(opCode::Search), + x if x == OpCode::Write as u64 => Ok(OpCode::Write), + x if x == OpCode::Read as u64 => Ok(OpCode::Read), + x if x == OpCode::Search as u64 => Ok(OpCode::Search), _ => Err("Invalid value to for log type"), } } From 2f6d8b82b2c859bb592b77a590374ce3097cff53 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 26 Sep 2023 07:33:47 +0200 Subject: [PATCH 329/544] only consider read chunks to form validation decision --- pallets/ddc-validator/src/dac.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index 024a5adf6..c23b98588 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -240,12 +240,17 @@ pub fn get_served_bytes_sum(file_requests: &Requests) -> (u64, u64) { for (_, file_request) in file_requests { for (_, chunk) in &file_request.chunks { - total_bytes_sent += chunk.log.bytes_sent; + match chunk.log.log_type.try_into() { + Ok(OpCode::Read) => { + total_bytes_sent += chunk.log.bytes_sent; - if let Some(ack) = &chunk.ack { - total_bytes_received += ack.bytes_received; - } else { - total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + if let Some(ack) = &chunk.ack { + total_bytes_received += ack.bytes_received; + } else { + total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); + } + }, + _ => (), } } } From 9c80f86288e275c8a91ae4bbe37ca555e6c1215a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 26 Sep 2023 09:16:59 +0200 Subject: [PATCH 330/544] update expected validation results for tests --- .../ddc-validator/src/mock-data/set-1/validation-decision.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json index d4509acb7..de8eec3a7 100644 --- a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json +++ b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json @@ -1 +1 @@ -{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[56, 47, 100, 81, 135, 215, 168, 111, 55, 82, 203, 118, 238, 69, 174, 209, 232, 241, 187, 128, 231, 237, 139, 193, 162, 162, 91, 11, 169, 209, 27, 55],"totals":{"received":600,"sent":600,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file +{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[56, 47, 100, 81, 135, 215, 168, 111, 55, 82, 203, 118, 238, 69, 174, 209, 232, 241, 187, 128, 231, 237, 139, 193, 162, 162, 91, 11, 169, 209, 27, 55],"totals":{"received":400,"sent":400,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file From 27776616874d3f3a452df420662d7fbc66270bb9 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 25 Sep 2023 17:58:29 +0200 Subject: [PATCH 331/544] Update gov related constants --- node/service/src/chain_spec.rs | 2 +- runtime/cere-dev/src/lib.rs | 8 ++++---- runtime/cere/src/lib.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 2588a9a3d..412649e65 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -160,7 +160,7 @@ pub fn cere_dev_genesis( let num_endowed_accounts = endowed_accounts.len(); - const ENDOWMENT: Balance = 10_000_000 * TEST_UNITS; + const ENDOWMENT: Balance = 10_000_000_000 * TEST_UNITS; const STASH: Balance = ENDOWMENT / 1000; cere_dev::GenesisConfig { diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 6a26d5836..848e96ddc 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -800,11 +800,11 @@ impl pallet_collective::Config for Runtime { } parameter_types! { - pub const CandidacyBond: Balance = 100 * DOLLARS; + pub const CandidacyBond: Balance = 500_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); pub const VotingBondFactor: Balance = 1 * DOLLARS; - pub const TermDuration: BlockNumber = 7 * DAYS; + pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; @@ -879,8 +879,8 @@ parameter_types! { pub const Burn: Permill = Permill::from_percent(0); pub const TipCountdown: BlockNumber = 1 * DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); - pub const TipReportDepositBase: Balance = 1 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * CENTS; + pub const TipReportDepositBase: Balance = 5_000_000 * DOLLARS; + pub const DataDepositPerByte: Balance = 1 * DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 851bad201..dc19d78f1 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -798,11 +798,11 @@ impl pallet_collective::Config for Runtime { } parameter_types! { - pub const CandidacyBond: Balance = 100 * DOLLARS; + pub const CandidacyBond: Balance = 500_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); pub const VotingBondFactor: Balance = 1 * DOLLARS; - pub const TermDuration: BlockNumber = 7 * DAYS; + pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; @@ -877,8 +877,8 @@ parameter_types! { pub const Burn: Permill = Permill::from_percent(0); pub const TipCountdown: BlockNumber = 1 * DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); - pub const TipReportDepositBase: Balance = 1 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * CENTS; + pub const TipReportDepositBase: Balance = 5_000_000 * DOLLARS; + pub const DataDepositPerByte: Balance = 1 * DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; From e4e88777a73a21e8fa9297daee39dd33fe1ee38b Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 26 Sep 2023 11:05:28 +0200 Subject: [PATCH 332/544] Increase minimal proposal deposit --- runtime/cere-dev/src/lib.rs | 2 +- runtime/cere/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 848e96ddc..7ae0c2675 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -724,7 +724,7 @@ parameter_types! { pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; - pub const MinimumDeposit: Balance = 5000 * DOLLARS; + pub const MinimumDeposit: Balance = 5_000_000 * DOLLARS; pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index dc19d78f1..3b884d962 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -722,7 +722,7 @@ parameter_types! { pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; - pub const MinimumDeposit: Balance = 5000 * DOLLARS; + pub const MinimumDeposit: Balance = 5_000_000 * DOLLARS; pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; From 4cb43ac549e9e742a3c71134747ee0a46a550355 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Wed, 27 Sep 2023 11:20:35 +0200 Subject: [PATCH 333/544] Update treasury and bounties proposal minimal bond --- runtime/cere-dev/src/lib.rs | 4 ++-- runtime/cere/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 7ae0c2675..00ea9aed4 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -874,7 +874,7 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 100 * DOLLARS; + pub const ProposalBondMinimum: Balance = 5_000_000 * DOLLARS; pub const SpendPeriod: BlockNumber = 1 * DAYS; pub const Burn: Permill = Permill::from_percent(0); pub const TipCountdown: BlockNumber = 1 * DAYS; @@ -914,7 +914,7 @@ impl pallet_treasury::Config for Runtime { parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 10 * DOLLARS; - pub const BountyDepositBase: Balance = 1 * DOLLARS; + pub const BountyDepositBase: Balance = 5_000_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); pub const CuratorDepositMin: Balance = 1 * DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 3b884d962..0327cfa1b 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -872,7 +872,7 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 100 * DOLLARS; + pub const ProposalBondMinimum: Balance = 5_000_000 * DOLLARS; pub const SpendPeriod: BlockNumber = 1 * DAYS; pub const Burn: Permill = Permill::from_percent(0); pub const TipCountdown: BlockNumber = 1 * DAYS; @@ -912,7 +912,7 @@ impl pallet_treasury::Config for Runtime { parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 10 * DOLLARS; - pub const BountyDepositBase: Balance = 1 * DOLLARS; + pub const BountyDepositBase: Balance = 5_000_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); pub const CuratorDepositMin: Balance = 1 * DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; From d7aa2a76bed14df62ecf5240c72b6581dd16551a Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Thu, 28 Sep 2023 13:02:25 +0200 Subject: [PATCH 334/544] Update spec version --- runtime/cere-dev/src/lib.rs | 2 +- runtime/cere/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 00ea9aed4..13752e72f 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -128,7 +128,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48003, + spec_version: 48005, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 0327cfa1b..c27c8e8e6 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -125,7 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48001, + spec_version: 48005, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From 59b38b26575bffa1bdde04d66758323078e5d361 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 29 Sep 2023 23:16:47 +0200 Subject: [PATCH 335/544] feat(pallet-nodes): basic abstractions for nodes are added --- Cargo.lock | 20 +++ Cargo.toml | 1 + pallets/ddc-nodes/Cargo.toml | 36 +++++ pallets/ddc-nodes/src/lib.rs | 259 +++++++++++++++++++++++++++++++++++ runtime/cere-dev/Cargo.toml | 2 + runtime/cere-dev/src/lib.rs | 4 + 6 files changed, 322 insertions(+) create mode 100644 pallets/ddc-nodes/Cargo.toml create mode 100644 pallets/ddc-nodes/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 34121abb6..4984b5c8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -812,6 +812,7 @@ dependencies = [ "pallet-contracts-rpc-runtime-api", "pallet-ddc-accounts", "pallet-ddc-metrics-offchain-worker", + "pallet-ddc-nodes", "pallet-ddc-staking", "pallet-ddc-validator", "pallet-democracy", @@ -4870,6 +4871,25 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-ddc-nodes" +version = "4.8.1" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "sp-tracing", + "substrate-test-utils", +] + [[package]] name = "pallet-ddc-staking" version = "4.8.1" diff --git a/Cargo.toml b/Cargo.toml index 7c63183c3..b7a61035b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ members = [ "pallets/ddc-metrics-offchain-worker", "pallets/ddc-validator", "pallets/ddc-accounts", + "pallets/ddc-nodes", ] [profile.release] diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml new file mode 100644 index 000000000..f6999d2c3 --- /dev/null +++ b/pallets/ddc-nodes/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "pallet-ddc-nodes" +version = "4.8.1" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +[dev-dependencies] +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", +] +runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs new file mode 100644 index 000000000..c34aa3f27 --- /dev/null +++ b/pallets/ddc-nodes/src/lib.rs @@ -0,0 +1,259 @@ +//! # DDC Nodes Pallet +//! +//! The DDC Nodes pallet is used to manage nodes in DDC Cluster +//! +//! - [`Config`] +//! - [`Call`] +//! - [`Pallet`] +//! +//! ## GenesisConfig +//! +//! The DDC Nodes pallet depends on the [`GenesisConfig`]. The +//! `GenesisConfig` is optional and allow to set some initial nodes in DDC. + +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +// #[cfg(feature = "runtime-benchmarks")] +// pub mod benchmarking; +// #[cfg(any(feature = "runtime-benchmarks", test))] +// pub mod testing_utils; + +// #[cfg(test)] +// pub(crate) mod mock; +// #[cfg(test)] +// mod tests; + +// pub mod weights; +// use crate::weights::WeightInfo; + +use codec::{Decode, Encode, HasCompact}; +use frame_support::{pallet_prelude::*, BoundedVec, PalletId}; +use frame_system::pallet_prelude::*; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; +use sp_std::prelude::*; + +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config {} + + // #[pallet::genesis_config] + // pub struct GenesisConfig { + + // } + + // #[cfg(feature = "std")] + // impl Default for GenesisConfig { + // fn default() -> Self { + // GenesisConfig {} + // } + // } + + // #[pallet::genesis_build] + // impl GenesisBuild for GenesisConfig { + // fn build(&self) {} + // } + + // #[pallet::event] + // #[pallet::generate_deposit(pub(crate) fn deposit_event)] + // pub enum Event { + + // } + + // #[pallet::error] + // pub enum Error { + + // } + + /// Map from all (unlocked) "controller" accounts to the info regarding the staking. + #[pallet::storage] + #[pallet::getter(fn storage_nodes)] + pub type StorageNodes = + StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; + + #[pallet::storage] + #[pallet::getter(fn cdn_nodes)] + pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; + + type StorageNodePubKey = sp_runtime::AccountId32; + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct StorageNode { + key: StorageNodePubKey, + status: u8, + props: StorageProps, + } + + impl StorageNode { + fn from_params(params: StorageParams) -> StorageNode { + StorageNode { + key: params.pub_key, + status: 1, + props: StorageProps { capacity: params.capacity }, + } + } + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct StorageProps { + capacity: u32, + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct StorageParams { + pub_key: StorageNodePubKey, + capacity: u32, + } + + type CDNNodePubKey = sp_runtime::AccountId32; + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct CDNNode { + key: CDNNodePubKey, + status: u8, + props: CDNProps, + } + + impl CDNNode { + fn from_params(params: CDNParams) -> CDNNode { + CDNNode { + key: params.pub_key, + status: 1, + props: CDNProps { url: params.url, location: params.location }, + } + } + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct CDNProps { + url: Vec, + location: [u8; 2], + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct CDNParams { + pub_key: CDNNodePubKey, + url: Vec, + location: [u8; 2], + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub enum NodeParams { + StorageParams(StorageParams), + CDNParams(CDNParams), + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub enum Node { + Storage(StorageNode), + CDN(CDNNode), + } + + #[derive(Debug, PartialEq)] + pub enum NodePubKey<'a> { + StoragePubKey(&'a StorageNodePubKey), + CDNPubKey(&'a CDNNodePubKey), + } + + #[derive(Debug, PartialEq)] + pub enum NodeProps<'a> { + StorageProps(&'a StorageProps), + CDNProps(&'a CDNProps), + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub enum NodeType { + Storage = 1, + CDN = 2, + } + + pub trait NodeTrait { + fn get_key<'a>(&'a self) -> NodePubKey<'a>; + fn get_props<'a>(&'a self) -> NodeProps<'a>; + } + + impl NodeTrait for StorageNode { + fn get_key<'a>(&'a self) -> NodePubKey<'a> { + NodePubKey::StoragePubKey(&self.key) + } + fn get_props<'a>(&'a self) -> NodeProps<'a> { + NodeProps::StorageProps(&self.props) + } + } + + impl NodeTrait for CDNNode { + fn get_key<'a>(&'a self) -> NodePubKey<'a> { + NodePubKey::CDNPubKey(&self.key) + } + fn get_props<'a>(&'a self) -> NodeProps<'a> { + NodeProps::CDNProps(&self.props) + } + } + + impl NodeTrait for Node { + fn get_key<'a>(&'a self) -> NodePubKey<'a> { + match &self { + Node::Storage(node) => node.get_key(), + Node::CDN(node) => node.get_key(), + } + } + + fn get_props<'a>(&'a self) -> NodeProps<'a> { + match &self { + Node::Storage(node) => node.get_props(), + Node::CDN(node) => node.get_props(), + } + } + } + + impl From for u8 { + fn from(node_type: NodeType) -> Self { + match node_type { + NodeType::Storage => 1, + NodeType::CDN => 2, + } + } + } + + impl TryFrom for NodeType { + type Error = (); + + fn try_from(value: u8) -> Result { + match value { + 1 => Ok(NodeType::Storage), + 2 => Ok(NodeType::CDN), + _ => Err(()), + } + } + } + + #[pallet::call] + impl Pallet { + #[pallet::weight(10_000)] + pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { + let _node_provider = ensure_signed(origin)?; + + match node_params { + NodeParams::StorageParams(storage_params) => { + let storage_node = StorageNode::from_params(storage_params); + StorageNodes::::insert(storage_node.key.clone(), storage_node); + }, + NodeParams::CDNParams(cdn_params) => { + let cdn_node = CDNNode::from_params(cdn_params); + CDNNodes::::insert(cdn_node.key.clone(), cdn_node); + }, + } + + Ok(()) + } + } +} diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 2a23b4c9f..35ac65486 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -104,6 +104,7 @@ pallet-ddc-validator = { version = "0.1.0", default-features = false, path = ".. pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -185,6 +186,7 @@ std = [ "cere-dev-runtime-constants/std", "pallet-ddc-validator/std", "pallet-ddc-accounts/std", + "pallet-ddc-nodes/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 13752e72f..26c1a1448 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -50,6 +50,7 @@ pub use pallet_cere_ddc; pub use pallet_chainbridge; pub use pallet_ddc_accounts; pub use pallet_ddc_metrics_offchain_worker; +pub use pallet_ddc_nodes; pub use pallet_ddc_staking; use pallet_election_provider_multi_phase::SolutionAccuracyOf; use pallet_grandpa::{ @@ -1361,6 +1362,8 @@ impl pallet_ddc_validator::Config for Runtime { type ValidatorsMax = ValidatorsMax; } +impl pallet_ddc_nodes::Config for Runtime {} + construct_runtime!( pub enum Runtime where Block = Block, @@ -1415,6 +1418,7 @@ construct_runtime!( DdcStaking: pallet_ddc_staking, DdcValidator: pallet_ddc_validator, DdcAccounts: pallet_ddc_accounts, + DdcNode: pallet_ddc_nodes, } ); From 14003ea6f253f5368ae66bb16575f9ca3b261254 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 2 Oct 2023 16:36:16 +0200 Subject: [PATCH 336/544] refactor: renaming generic node params and props --- pallets/ddc-nodes/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index c34aa3f27..cbe57e479 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -91,26 +91,26 @@ pub mod pallet { pub struct StorageNode { key: StorageNodePubKey, status: u8, - props: StorageProps, + props: StorageNodeProps, } impl StorageNode { - fn from_params(params: StorageParams) -> StorageNode { + fn from_params(params: StorageNodeParams) -> StorageNode { StorageNode { key: params.pub_key, status: 1, - props: StorageProps { capacity: params.capacity }, + props: StorageNodeProps { capacity: params.capacity }, } } } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct StorageProps { + pub struct StorageNodeProps { capacity: u32, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct StorageParams { + pub struct StorageNodeParams { pub_key: StorageNodePubKey, capacity: u32, } @@ -120,27 +120,27 @@ pub mod pallet { pub struct CDNNode { key: CDNNodePubKey, status: u8, - props: CDNProps, + props: CDNNodeProps, } impl CDNNode { - fn from_params(params: CDNParams) -> CDNNode { + fn from_params(params: CDNNodeParams) -> CDNNode { CDNNode { key: params.pub_key, status: 1, - props: CDNProps { url: params.url, location: params.location }, + props: CDNNodeProps { url: params.url, location: params.location }, } } } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct CDNProps { + pub struct CDNNodeProps { url: Vec, location: [u8; 2], } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct CDNParams { + pub struct CDNNodeParams { pub_key: CDNNodePubKey, url: Vec, location: [u8; 2], @@ -148,8 +148,8 @@ pub mod pallet { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeParams { - StorageParams(StorageParams), - CDNParams(CDNParams), + StorageParams(StorageNodeParams), + CDNParams(CDNNodeParams), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -166,8 +166,8 @@ pub mod pallet { #[derive(Debug, PartialEq)] pub enum NodeProps<'a> { - StorageProps(&'a StorageProps), - CDNProps(&'a CDNProps), + StorageProps(&'a StorageNodeProps), + CDNProps(&'a CDNNodeProps), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] From 9e793a0fc78eec2cc7c8c7dd55ce85e37a40a2ea Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 2 Oct 2023 19:09:00 +0200 Subject: [PATCH 337/544] feat: basic clusters pallet --- Cargo.lock | 20 +++++++ Cargo.toml | 1 + pallets/ddc-clusters/Cargo.toml | 37 +++++++++++++ pallets/ddc-clusters/src/lib.rs | 94 +++++++++++++++++++++++++++++++++ pallets/ddc-nodes/src/lib.rs | 83 ++++++++++++++--------------- runtime/cere-dev/Cargo.toml | 1 + runtime/cere-dev/src/lib.rs | 12 ++++- 7 files changed, 203 insertions(+), 45 deletions(-) create mode 100644 pallets/ddc-clusters/Cargo.toml create mode 100644 pallets/ddc-clusters/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 4984b5c8e..d9d6e9b98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -811,6 +811,7 @@ dependencies = [ "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", "pallet-ddc-accounts", + "pallet-ddc-clusters", "pallet-ddc-metrics-offchain-worker", "pallet-ddc-nodes", "pallet-ddc-staking", @@ -4845,6 +4846,25 @@ dependencies = [ "substrate-test-utils", ] +[[package]] +name = "pallet-ddc-clusters" +version = "4.8.1" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "sp-tracing", + "substrate-test-utils", +] + [[package]] name = "pallet-ddc-metrics-offchain-worker" version = "4.8.1" diff --git a/Cargo.toml b/Cargo.toml index b7a61035b..9bfa3cfa5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ members = [ "pallets/ddc-validator", "pallets/ddc-accounts", "pallets/ddc-nodes", + "pallets/ddc-clusters", ] [profile.release] diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml new file mode 100644 index 000000000..a305d15cc --- /dev/null +++ b/pallets/ddc-clusters/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "pallet-ddc-clusters" +version = "4.8.1" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } + +[dev-dependencies] +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", +] +runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs new file mode 100644 index 000000000..0c61056c4 --- /dev/null +++ b/pallets/ddc-clusters/src/lib.rs @@ -0,0 +1,94 @@ +//! # DDC Nodes Pallet +//! +//! The DDC Clusters pallet is used to manage DDC Clusters +//! +//! - [`Config`] +//! - [`Call`] +//! - [`Pallet`] +//! +//! ## GenesisConfig +//! +//! The DDC Clusters pallet depends on the [`GenesisConfig`]. The +//! `GenesisConfig` is optional and allow to set some initial nodes in DDC. + +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; +pub use pallet::*; +use scale_info::TypeInfo; +use sp_core::hash::H160; +use sp_runtime::RuntimeDebug; +use sp_std::prelude::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + ClusterCreated(ClusterId), + } + + #[pallet::error] + pub enum Error { + ClusterAlreadyExists, + } + + /// Map from all (unlocked) "controller" accounts to the info regarding the staking. + #[pallet::storage] + #[pallet::getter(fn storage_nodes)] + pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; + + type ClusterId = H160; + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct Cluster { + id: ClusterId, + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub struct ClusterParams { + id: ClusterId, + } + + impl Cluster { + fn from_params(params: ClusterParams) -> Cluster { + Cluster { id: params.id } + } + } + + #[pallet::call] + impl Pallet { + #[pallet::weight(10_000)] + pub fn create_cluster( + origin: OriginFor, + cluster_params: ClusterParams, + ) -> DispatchResult { + let _cluster_manager = ensure_signed(origin)?; + + let cluster = Cluster::from_params(cluster_params); + let cluster_id = cluster.id.clone(); + + ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); + + Clusters::::insert(cluster_id.clone(), cluster); + Self::deposit_event(Event::::ClusterCreated(cluster_id)); + + Ok(()) + } + } +} diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index cbe57e479..6c87f6cb3 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -14,21 +14,8 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] -// #[cfg(feature = "runtime-benchmarks")] -// pub mod benchmarking; -// #[cfg(any(feature = "runtime-benchmarks", test))] -// pub mod testing_utils; - -// #[cfg(test)] -// pub(crate) mod mock; -// #[cfg(test)] -// mod tests; - -// pub mod weights; -// use crate::weights::WeightInfo; - -use codec::{Decode, Encode, HasCompact}; -use frame_support::{pallet_prelude::*, BoundedVec, PalletId}; +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -46,35 +33,20 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config {} - - // #[pallet::genesis_config] - // pub struct GenesisConfig { - - // } - - // #[cfg(feature = "std")] - // impl Default for GenesisConfig { - // fn default() -> Self { - // GenesisConfig {} - // } - // } - - // #[pallet::genesis_build] - // impl GenesisBuild for GenesisConfig { - // fn build(&self) {} - // } - - // #[pallet::event] - // #[pallet::generate_deposit(pub(crate) fn deposit_event)] - // pub enum Event { - - // } + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } - // #[pallet::error] - // pub enum Error { + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + NodeCreated(NodeType, OwnableNodePubKey), + } - // } + #[pallet::error] + pub enum Error { + NodeAlreadyExists, + } /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] @@ -164,6 +136,12 @@ pub mod pallet { CDNPubKey(&'a CDNNodePubKey), } + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub enum OwnableNodePubKey { + StoragePubKey(StorageNodePubKey), + CDNPubKey(CDNNodePubKey), + } + #[derive(Debug, PartialEq)] pub enum NodeProps<'a> { StorageProps(&'a StorageNodeProps), @@ -245,11 +223,30 @@ pub mod pallet { match node_params { NodeParams::StorageParams(storage_params) => { let storage_node = StorageNode::from_params(storage_params); - StorageNodes::::insert(storage_node.key.clone(), storage_node); + let node_key = storage_node.key.clone(); + + ensure!( + !StorageNodes::::contains_key(&node_key), + Error::::NodeAlreadyExists + ); + + StorageNodes::::insert(node_key.clone(), storage_node); + Self::deposit_event(Event::::NodeCreated( + NodeType::Storage, + OwnableNodePubKey::StoragePubKey(node_key), + )); }, NodeParams::CDNParams(cdn_params) => { let cdn_node = CDNNode::from_params(cdn_params); + let node_key = cdn_node.key.clone(); + + ensure!(!CDNNodes::::contains_key(&node_key), Error::::NodeAlreadyExists); + CDNNodes::::insert(cdn_node.key.clone(), cdn_node); + Self::deposit_event(Event::::NodeCreated( + NodeType::CDN, + OwnableNodePubKey::CDNPubKey(node_key), + )); }, } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 35ac65486..a770756e9 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -105,6 +105,7 @@ pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pal pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 26c1a1448..a2bd98d21 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -49,6 +49,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; pub use pallet_cere_ddc; pub use pallet_chainbridge; pub use pallet_ddc_accounts; +pub use pallet_ddc_clusters; pub use pallet_ddc_metrics_offchain_worker; pub use pallet_ddc_nodes; pub use pallet_ddc_staking; @@ -1362,7 +1363,13 @@ impl pallet_ddc_validator::Config for Runtime { type ValidatorsMax = ValidatorsMax; } -impl pallet_ddc_nodes::Config for Runtime {} +impl pallet_ddc_nodes::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +impl pallet_ddc_clusters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} construct_runtime!( pub enum Runtime where @@ -1418,7 +1425,8 @@ construct_runtime!( DdcStaking: pallet_ddc_staking, DdcValidator: pallet_ddc_validator, DdcAccounts: pallet_ddc_accounts, - DdcNode: pallet_ddc_nodes, + DdcNodes: pallet_ddc_nodes, + DdcClusters: pallet_ddc_clusters } ); From 6c6702f05bd69cdbe51da2dac588d58d7f9d42c5 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 2 Oct 2023 21:40:07 +0200 Subject: [PATCH 338/544] feat(pallet-ddc-nodes): using generic Node type in pallet calls --- pallets/ddc-nodes/src/lib.rs | 152 ++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 67 deletions(-) diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 6c87f6cb3..e2c3c6bdc 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -40,12 +40,13 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - NodeCreated(NodeType, OwnableNodePubKey), + NodeCreated(NodeType), } #[pallet::error] pub enum Error { NodeAlreadyExists, + InvalidNodeParams, } /// Map from all (unlocked) "controller" accounts to the info regarding the staking. @@ -66,16 +67,6 @@ pub mod pallet { props: StorageNodeProps, } - impl StorageNode { - fn from_params(params: StorageNodeParams) -> StorageNode { - StorageNode { - key: params.pub_key, - status: 1, - props: StorageNodeProps { capacity: params.capacity }, - } - } - } - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeProps { capacity: u32, @@ -95,16 +86,6 @@ pub mod pallet { props: CDNNodeProps, } - impl CDNNode { - fn from_params(params: CDNNodeParams) -> CDNNode { - CDNNode { - key: params.pub_key, - status: 1, - props: CDNNodeProps { url: params.url, location: params.location }, - } - } - } - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeProps { url: Vec, @@ -118,19 +99,19 @@ pub mod pallet { location: [u8; 2], } - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum NodeParams { - StorageParams(StorageNodeParams), - CDNParams(CDNNodeParams), - } - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum Node { Storage(StorageNode), CDN(CDNNode), } - #[derive(Debug, PartialEq)] + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub enum NodeParams { + StorageParams(StorageNodeParams), + CDNParams(CDNNodeParams), + } + + #[derive(Clone, RuntimeDebug, PartialEq)] pub enum NodePubKey<'a> { StoragePubKey(&'a StorageNodePubKey), CDNPubKey(&'a CDNNodePubKey), @@ -142,7 +123,7 @@ pub mod pallet { CDNPubKey(CDNNodePubKey), } - #[derive(Debug, PartialEq)] + #[derive(Clone, RuntimeDebug, PartialEq)] pub enum NodeProps<'a> { StorageProps(&'a StorageNodeProps), CDNProps(&'a CDNNodeProps), @@ -155,42 +136,81 @@ pub mod pallet { } pub trait NodeTrait { - fn get_key<'a>(&'a self) -> NodePubKey<'a>; + fn get_pub_key<'a>(&'a self) -> NodePubKey<'a>; fn get_props<'a>(&'a self) -> NodeProps<'a>; + fn get_type(&self) -> NodeType; + fn from_params(params: NodeParams) -> Result>; } impl NodeTrait for StorageNode { - fn get_key<'a>(&'a self) -> NodePubKey<'a> { + fn get_pub_key<'a>(&'a self) -> NodePubKey<'a> { NodePubKey::StoragePubKey(&self.key) } fn get_props<'a>(&'a self) -> NodeProps<'a> { NodeProps::StorageProps(&self.props) } + fn get_type(&self) -> NodeType { + NodeType::Storage + } + fn from_params(params: NodeParams) -> Result> { + match params { + NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode { + key: params.pub_key, + status: 1, + props: StorageNodeProps { capacity: params.capacity }, + })), + _ => Err(Error::::NodeAlreadyExists), + } + } } impl NodeTrait for CDNNode { - fn get_key<'a>(&'a self) -> NodePubKey<'a> { + fn get_pub_key<'a>(&'a self) -> NodePubKey<'a> { NodePubKey::CDNPubKey(&self.key) } fn get_props<'a>(&'a self) -> NodeProps<'a> { NodeProps::CDNProps(&self.props) } + fn get_type(&self) -> NodeType { + NodeType::CDN + } + fn from_params(params: NodeParams) -> Result> { + match params { + NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode { + key: params.pub_key, + status: 1, + props: CDNNodeProps { url: params.url, location: params.location }, + })), + _ => Err(Error::::NodeAlreadyExists), + } + } } impl NodeTrait for Node { - fn get_key<'a>(&'a self) -> NodePubKey<'a> { + fn get_pub_key<'a>(&'a self) -> NodePubKey<'a> { match &self { - Node::Storage(node) => node.get_key(), - Node::CDN(node) => node.get_key(), + Node::Storage(node) => node.get_pub_key(), + Node::CDN(node) => node.get_pub_key(), } } - fn get_props<'a>(&'a self) -> NodeProps<'a> { match &self { Node::Storage(node) => node.get_props(), Node::CDN(node) => node.get_props(), } } + fn get_type(&self) -> NodeType { + match &self { + Node::Storage(node) => node.get_type(), + Node::CDN(node) => node.get_type(), + } + } + fn from_params(params: NodeParams) -> Result> { + match params { + NodeParams::StorageParams(_) => StorageNode::from_params(params), + NodeParams::CDNParams(_) => CDNNode::from_params(params), + } + } } impl From for u8 { @@ -204,7 +224,6 @@ pub mod pallet { impl TryFrom for NodeType { type Error = (); - fn try_from(value: u8) -> Result { match value { 1 => Ok(NodeType::Storage), @@ -214,42 +233,41 @@ pub mod pallet { } } - #[pallet::call] - impl Pallet { - #[pallet::weight(10_000)] - pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { - let _node_provider = ensure_signed(origin)?; - - match node_params { - NodeParams::StorageParams(storage_params) => { - let storage_node = StorageNode::from_params(storage_params); - let node_key = storage_node.key.clone(); - - ensure!( - !StorageNodes::::contains_key(&node_key), - Error::::NodeAlreadyExists - ); + pub trait NodeRepositoryTrait { + fn save(node: Node) -> Result<(), pallet::Error>; + } - StorageNodes::::insert(node_key.clone(), storage_node); - Self::deposit_event(Event::::NodeCreated( - NodeType::Storage, - OwnableNodePubKey::StoragePubKey(node_key), - )); + struct NodeRepository; + impl NodeRepositoryTrait for NodeRepository { + fn save(node: Node) -> Result<(), pallet::Error> { + match node { + Node::Storage(storage_node) => { + if StorageNodes::::contains_key(&storage_node.key) { + return Err(Error::::NodeAlreadyExists) + } + StorageNodes::::insert(storage_node.key.clone(), storage_node); + Ok(()) }, - NodeParams::CDNParams(cdn_params) => { - let cdn_node = CDNNode::from_params(cdn_params); - let node_key = cdn_node.key.clone(); - - ensure!(!CDNNodes::::contains_key(&node_key), Error::::NodeAlreadyExists); - + Node::CDN(cdn_node) => { + if CDNNodes::::contains_key(&cdn_node.key) { + return Err(Error::::NodeAlreadyExists) + } CDNNodes::::insert(cdn_node.key.clone(), cdn_node); - Self::deposit_event(Event::::NodeCreated( - NodeType::CDN, - OwnableNodePubKey::CDNPubKey(node_key), - )); + Ok(()) }, } + } + } + #[pallet::call] + impl Pallet { + #[pallet::weight(10_000)] + pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { + let node_provider = ensure_signed(origin)?; + let node = Node::from_params::(node_params)?; + let node_type = node.get_type(); + NodeRepository::save::(node)?; + Self::deposit_event(Event::::NodeCreated(node_type)); Ok(()) } } From fc1b722d256b4a9cb37f44328d59d5844ffa2c8c Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 2 Oct 2023 22:54:44 +0200 Subject: [PATCH 339/544] feat: using ref typse for Node pub key and params --- pallets/ddc-clusters/src/lib.rs | 3 +- pallets/ddc-nodes/src/lib.rs | 82 ++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 0c61056c4..8ed0f071c 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -48,7 +48,6 @@ pub mod pallet { ClusterAlreadyExists, } - /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn storage_nodes)] pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; @@ -78,7 +77,7 @@ pub mod pallet { origin: OriginFor, cluster_params: ClusterParams, ) -> DispatchResult { - let _cluster_manager = ensure_signed(origin)?; + ensure_signed(origin)?; let cluster = Cluster::from_params(cluster_params); let cluster_id = cluster.id.clone(); diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index e2c3c6bdc..f00ef4cfd 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -40,7 +40,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - NodeCreated(NodeType), + NodeCreated(NodePubKey), } #[pallet::error] @@ -49,7 +49,6 @@ pub mod pallet { InvalidNodeParams, } - /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn storage_nodes)] pub type StorageNodes = @@ -62,7 +61,7 @@ pub mod pallet { type StorageNodePubKey = sp_runtime::AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNode { - key: StorageNodePubKey, + pub_key: StorageNodePubKey, status: u8, props: StorageNodeProps, } @@ -81,7 +80,7 @@ pub mod pallet { type CDNNodePubKey = sp_runtime::AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNode { - key: CDNNodePubKey, + pub_key: CDNNodePubKey, status: u8, props: CDNNodeProps, } @@ -111,22 +110,33 @@ pub mod pallet { CDNParams(CDNNodeParams), } - #[derive(Clone, RuntimeDebug, PartialEq)] - pub enum NodePubKey<'a> { - StoragePubKey(&'a StorageNodePubKey), - CDNPubKey(&'a CDNNodePubKey), - } - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum OwnableNodePubKey { + pub enum NodePubKey { StoragePubKey(StorageNodePubKey), CDNPubKey(CDNNodePubKey), } #[derive(Clone, RuntimeDebug, PartialEq)] - pub enum NodeProps<'a> { - StorageProps(&'a StorageNodeProps), - CDNProps(&'a CDNNodeProps), + pub enum NodePubKeyRef<'a> { + StoragePubKeyRef(&'a StorageNodePubKey), + CDNPubKeyRef(&'a CDNNodePubKey), + } + + impl<'a> NodePubKeyRef<'a> { + pub fn to_owned(&self) -> NodePubKey { + match &self { + NodePubKeyRef::StoragePubKeyRef(pub_key_ref) => + NodePubKey::StoragePubKey((**pub_key_ref).clone()), + NodePubKeyRef::CDNPubKeyRef(pub_key_ref) => + NodePubKey::CDNPubKey((**pub_key_ref).clone()), + } + } + } + + #[derive(Clone, RuntimeDebug, PartialEq)] + pub enum NodePropsRef<'a> { + StoragePropsRef(&'a StorageNodeProps), + CDNPropsRef(&'a CDNNodeProps), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -136,18 +146,18 @@ pub mod pallet { } pub trait NodeTrait { - fn get_pub_key<'a>(&'a self) -> NodePubKey<'a>; - fn get_props<'a>(&'a self) -> NodeProps<'a>; + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; + fn get_props<'a>(&'a self) -> NodePropsRef<'a>; fn get_type(&self) -> NodeType; fn from_params(params: NodeParams) -> Result>; } impl NodeTrait for StorageNode { - fn get_pub_key<'a>(&'a self) -> NodePubKey<'a> { - NodePubKey::StoragePubKey(&self.key) + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + NodePubKeyRef::StoragePubKeyRef(&self.pub_key) } - fn get_props<'a>(&'a self) -> NodeProps<'a> { - NodeProps::StorageProps(&self.props) + fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + NodePropsRef::StoragePropsRef(&self.props) } fn get_type(&self) -> NodeType { NodeType::Storage @@ -155,7 +165,7 @@ pub mod pallet { fn from_params(params: NodeParams) -> Result> { match params { NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode { - key: params.pub_key, + pub_key: params.pub_key, status: 1, props: StorageNodeProps { capacity: params.capacity }, })), @@ -165,11 +175,11 @@ pub mod pallet { } impl NodeTrait for CDNNode { - fn get_pub_key<'a>(&'a self) -> NodePubKey<'a> { - NodePubKey::CDNPubKey(&self.key) + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + NodePubKeyRef::CDNPubKeyRef(&self.pub_key) } - fn get_props<'a>(&'a self) -> NodeProps<'a> { - NodeProps::CDNProps(&self.props) + fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + NodePropsRef::CDNPropsRef(&self.props) } fn get_type(&self) -> NodeType { NodeType::CDN @@ -177,7 +187,7 @@ pub mod pallet { fn from_params(params: NodeParams) -> Result> { match params { NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode { - key: params.pub_key, + pub_key: params.pub_key, status: 1, props: CDNNodeProps { url: params.url, location: params.location }, })), @@ -187,13 +197,13 @@ pub mod pallet { } impl NodeTrait for Node { - fn get_pub_key<'a>(&'a self) -> NodePubKey<'a> { + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { match &self { Node::Storage(node) => node.get_pub_key(), Node::CDN(node) => node.get_pub_key(), } } - fn get_props<'a>(&'a self) -> NodeProps<'a> { + fn get_props<'a>(&'a self) -> NodePropsRef<'a> { match &self { Node::Storage(node) => node.get_props(), Node::CDN(node) => node.get_props(), @@ -242,17 +252,17 @@ pub mod pallet { fn save(node: Node) -> Result<(), pallet::Error> { match node { Node::Storage(storage_node) => { - if StorageNodes::::contains_key(&storage_node.key) { + if StorageNodes::::contains_key(&storage_node.pub_key) { return Err(Error::::NodeAlreadyExists) } - StorageNodes::::insert(storage_node.key.clone(), storage_node); + StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) }, Node::CDN(cdn_node) => { - if CDNNodes::::contains_key(&cdn_node.key) { + if CDNNodes::::contains_key(&cdn_node.pub_key) { return Err(Error::::NodeAlreadyExists) } - CDNNodes::::insert(cdn_node.key.clone(), cdn_node); + CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); Ok(()) }, } @@ -263,11 +273,11 @@ pub mod pallet { impl Pallet { #[pallet::weight(10_000)] pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { - let node_provider = ensure_signed(origin)?; - let node = Node::from_params::(node_params)?; - let node_type = node.get_type(); + ensure_signed(origin)?; + let node: Node = Node::from_params::(node_params)?; + let node_pub_key = node.get_pub_key().to_owned(); NodeRepository::save::(node)?; - Self::deposit_event(Event::::NodeCreated(node_type)); + Self::deposit_event(Event::::NodeCreated(node_pub_key)); Ok(()) } } From e5c6077424f12807695e3aa293213f1d171a6fd3 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 3 Oct 2023 01:08:57 +0200 Subject: [PATCH 340/544] feat: loose coupling between nodes and clusters pallets to provide access for nodes repository --- Cargo.lock | 1 + pallets/ddc-clusters/Cargo.toml | 1 + pallets/ddc-clusters/src/lib.rs | 15 ++++++++++ pallets/ddc-nodes/src/lib.rs | 51 ++++++++++++++++++++++----------- runtime/cere-dev/src/lib.rs | 1 + 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9d6e9b98..b7978f71d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4854,6 +4854,7 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-ddc-nodes", "parity-scale-codec", "scale-info", "sp-core", diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index a305d15cc..22786b2dd 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -15,6 +15,7 @@ sp-runtime = { version = "6.0.0", default-features = false, git = "https://githu sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 8ed0f071c..80555a113 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -23,6 +23,8 @@ use sp_core::hash::H160; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; +use pallet_ddc_nodes::{NodePubKey, NodeRepository}; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -35,6 +37,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type NodeRepository: NodeRepository; } #[pallet::event] @@ -89,5 +92,17 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(10_000)] + pub fn add_node( + origin: OriginFor, + cluster_id: ClusterId, + node_pub_key: NodePubKey, + ) -> DispatchResult { + ensure_signed(origin)?; + let node = T::NodeRepository::get(node_pub_key)?; + + Ok(()) + } } } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f00ef4cfd..9c901ca80 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -46,6 +46,7 @@ pub mod pallet { #[pallet::error] pub enum Error { NodeAlreadyExists, + NodeDoesNotExist, InvalidNodeParams, } @@ -245,40 +246,58 @@ pub mod pallet { pub trait NodeRepositoryTrait { fn save(node: Node) -> Result<(), pallet::Error>; + fn get(pub_key: NodePubKey) -> Result>; } - struct NodeRepository; - impl NodeRepositoryTrait for NodeRepository { - fn save(node: Node) -> Result<(), pallet::Error> { + #[pallet::call] + impl Pallet { + #[pallet::weight(10_000)] + pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { + ensure_signed(origin)?; + let node: Node = Node::from_params::(node_params)?; + let node_pub_key = node.get_pub_key().to_owned(); + Self::save(node)?; + Self::deposit_event(Event::::NodeCreated(node_pub_key)); + Ok(()) + } + } + + pub trait NodeRepository { + fn save(node: Node) -> Result<(), &'static str>; + fn get(pub_key: NodePubKey) -> Result; + } + + impl NodeRepository for Pallet { + fn save(node: Node) -> Result<(), &'static str> { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { - return Err(Error::::NodeAlreadyExists) + return Err("Node already exists") } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) }, Node::CDN(cdn_node) => { if CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err(Error::::NodeAlreadyExists) + return Err("Node already exists") } CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); Ok(()) }, } } - } - #[pallet::call] - impl Pallet { - #[pallet::weight(10_000)] - pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { - ensure_signed(origin)?; - let node: Node = Node::from_params::(node_params)?; - let node_pub_key = node.get_pub_key().to_owned(); - NodeRepository::save::(node)?; - Self::deposit_event(Event::::NodeCreated(node_pub_key)); - Ok(()) + fn get(node_pub_key: NodePubKey) -> Result { + match node_pub_key { + NodePubKey::StoragePubKey(pub_key) => match StorageNodes::::try_get(pub_key) { + Ok(node) => Ok(Node::Storage(node)), + Err(_) => Err("Node does not exist"), + }, + NodePubKey::CDNPubKey(pub_key) => match CDNNodes::::try_get(pub_key) { + Ok(node) => Ok(Node::CDN(node)), + Err(_) => Err("Node does not exist"), + }, + } } } } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index a2bd98d21..ff5778e9e 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1369,6 +1369,7 @@ impl pallet_ddc_nodes::Config for Runtime { impl pallet_ddc_clusters::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type NodeRepository = pallet_ddc_nodes::Pallet; } construct_runtime!( From 42e4362c7ab7c105fcec0e4afdd98fe9e6a08ade Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 3 Oct 2023 01:39:57 +0200 Subject: [PATCH 341/544] feat: setting cluster_id for node --- pallets/ddc-clusters/src/lib.rs | 3 ++- pallets/ddc-nodes/Cargo.toml | 1 + pallets/ddc-nodes/src/lib.rs | 36 +++++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 80555a113..4b46ae5d5 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -100,7 +100,8 @@ pub mod pallet { node_pub_key: NodePubKey, ) -> DispatchResult { ensure_signed(origin)?; - let node = T::NodeRepository::get(node_pub_key)?; + + T::NodeRepository::add_to_cluster(node_pub_key, cluster_id)?; Ok(()) } diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index f6999d2c3..d05d85bf2 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -14,6 +14,7 @@ sp-io = { version = "6.0.0", default-features = false, git = "https://github.com sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 9c901ca80..baf3a2c73 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -18,6 +18,7 @@ use codec::{Decode, Encode}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; +use sp_core::hash::H160; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; @@ -59,11 +60,14 @@ pub mod pallet { #[pallet::getter(fn cdn_nodes)] pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; + // todo: add the type to the Config + type ClusterId = H160; + type StorageNodePubKey = sp_runtime::AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNode { pub_key: StorageNodePubKey, - status: u8, + cluster_id: Option, props: StorageNodeProps, } @@ -82,7 +86,7 @@ pub mod pallet { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNode { pub_key: CDNNodePubKey, - status: u8, + cluster_id: Option, props: CDNNodeProps, } @@ -167,7 +171,7 @@ pub mod pallet { match params { NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode { pub_key: params.pub_key, - status: 1, + cluster_id: None, props: StorageNodeProps { capacity: params.capacity }, })), _ => Err(Error::::NodeAlreadyExists), @@ -189,7 +193,7 @@ pub mod pallet { match params { NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode { pub_key: params.pub_key, - status: 1, + cluster_id: None, props: CDNNodeProps { url: params.url, location: params.location }, })), _ => Err(Error::::NodeAlreadyExists), @@ -245,7 +249,7 @@ pub mod pallet { } pub trait NodeRepositoryTrait { - fn save(node: Node) -> Result<(), pallet::Error>; + fn create(node: Node) -> Result<(), pallet::Error>; fn get(pub_key: NodePubKey) -> Result>; } @@ -256,19 +260,20 @@ pub mod pallet { ensure_signed(origin)?; let node: Node = Node::from_params::(node_params)?; let node_pub_key = node.get_pub_key().to_owned(); - Self::save(node)?; + Self::create(node)?; Self::deposit_event(Event::::NodeCreated(node_pub_key)); Ok(()) } } pub trait NodeRepository { - fn save(node: Node) -> Result<(), &'static str>; + fn create(node: Node) -> Result<(), &'static str>; fn get(pub_key: NodePubKey) -> Result; + fn add_to_cluster(pub_key: NodePubKey, cluster_id: ClusterId) -> Result<(), &'static str>; } impl NodeRepository for Pallet { - fn save(node: Node) -> Result<(), &'static str> { + fn create(node: Node) -> Result<(), &'static str> { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { @@ -299,5 +304,20 @@ pub mod pallet { }, } } + + fn add_to_cluster(pub_key: NodePubKey, cluster_id: ClusterId) -> Result<(), &'static str> { + let mut node = Self::get(pub_key)?; + match node { + Node::Storage(mut storage_node) => { + storage_node.cluster_id = Some(cluster_id); + StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); + }, + Node::CDN(mut cdn_node) => { + cdn_node.cluster_id = Some(cluster_id); + CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); + }, + } + Ok(()) + } } } From 70a97946a3586dbdc1801d39150d821fd037450e Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Wed, 4 Oct 2023 20:33:36 +0200 Subject: [PATCH 342/544] fix: node type is added to external event --- pallets/ddc-nodes/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index baf3a2c73..0717dec4e 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -41,7 +41,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - NodeCreated(NodePubKey), + NodeCreated(NodeType, NodePubKey), } #[pallet::error] @@ -260,8 +260,9 @@ pub mod pallet { ensure_signed(origin)?; let node: Node = Node::from_params::(node_params)?; let node_pub_key = node.get_pub_key().to_owned(); + let node_type = node.get_type(); Self::create(node)?; - Self::deposit_event(Event::::NodeCreated(node_pub_key)); + Self::deposit_event(Event::::NodeCreated(node_type, node_pub_key)); Ok(()) } } From 23511c4e38b0f850ca1b084a22d666beddf353cc Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Wed, 4 Oct 2023 21:55:53 +0200 Subject: [PATCH 343/544] fix: using u8 type for node_type field --- pallets/ddc-nodes/src/lib.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 0717dec4e..1a6db5178 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -41,7 +41,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - NodeCreated(NodeType, NodePubKey), + NodeCreated { node_type: u8, node_pub_key: NodePubKey }, } #[pallet::error] @@ -144,12 +144,6 @@ pub mod pallet { CDNPropsRef(&'a CDNNodeProps), } - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum NodeType { - Storage = 1, - CDN = 2, - } - pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; @@ -228,6 +222,12 @@ pub mod pallet { } } + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + pub enum NodeType { + Storage = 1, + CDN = 2, + } + impl From for u8 { fn from(node_type: NodeType) -> Self { match node_type { @@ -259,10 +259,13 @@ pub mod pallet { pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { ensure_signed(origin)?; let node: Node = Node::from_params::(node_params)?; - let node_pub_key = node.get_pub_key().to_owned(); let node_type = node.get_type(); + let node_pub_key = node.get_pub_key().to_owned(); Self::create(node)?; - Self::deposit_event(Event::::NodeCreated(node_type, node_pub_key)); + Self::deposit_event(Event::::NodeCreated { + node_type: node_type.into(), + node_pub_key, + }); Ok(()) } } @@ -307,7 +310,7 @@ pub mod pallet { } fn add_to_cluster(pub_key: NodePubKey, cluster_id: ClusterId) -> Result<(), &'static str> { - let mut node = Self::get(pub_key)?; + let node = Self::get(pub_key)?; match node { Node::Storage(mut storage_node) => { storage_node.cluster_id = Some(cluster_id); From 065e651d828caf5e908538f7eec15fc8cddb7172 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 5 Oct 2023 02:19:41 +0200 Subject: [PATCH 344/544] refactor: separate modules for nodes --- pallets/ddc-clusters/src/lib.rs | 15 +- pallets/ddc-nodes/src/cdn_node.rs | 53 +++++++ pallets/ddc-nodes/src/lib.rs | 201 ++------------------------ pallets/ddc-nodes/src/node.rs | 110 ++++++++++++++ pallets/ddc-nodes/src/storage_node.rs | 50 +++++++ 5 files changed, 231 insertions(+), 198 deletions(-) create mode 100644 pallets/ddc-nodes/src/cdn_node.rs create mode 100644 pallets/ddc-nodes/src/node.rs create mode 100644 pallets/ddc-nodes/src/storage_node.rs diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 4b46ae5d5..49f7b8222 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -23,7 +23,7 @@ use sp_core::hash::H160; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; -use pallet_ddc_nodes::{NodePubKey, NodeRepository}; +use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; #[frame_support::pallet] pub mod pallet { @@ -43,7 +43,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - ClusterCreated(ClusterId), + ClusterCreated { cluster_id: ClusterId }, } #[pallet::error] @@ -59,17 +59,17 @@ pub mod pallet { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct Cluster { - id: ClusterId, + cluster_id: ClusterId, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterParams { - id: ClusterId, + cluster_id: ClusterId, } impl Cluster { fn from_params(params: ClusterParams) -> Cluster { - Cluster { id: params.id } + Cluster { cluster_id: params.cluster_id } } } @@ -83,12 +83,12 @@ pub mod pallet { ensure_signed(origin)?; let cluster = Cluster::from_params(cluster_params); - let cluster_id = cluster.id.clone(); + let cluster_id = cluster.cluster_id.clone(); ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); - Self::deposit_event(Event::::ClusterCreated(cluster_id)); + Self::deposit_event(Event::::ClusterCreated { cluster_id }); Ok(()) } @@ -101,6 +101,7 @@ pub mod pallet { ) -> DispatchResult { ensure_signed(origin)?; + let node = T::NodeRepository::get(node_pub_key.clone())?; T::NodeRepository::add_to_cluster(node_pub_key, cluster_id)?; Ok(()) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs new file mode 100644 index 000000000..c32d80b20 --- /dev/null +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -0,0 +1,53 @@ +use crate::{ + node::{Node, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, + pallet::Error, + ClusterId, Config, +}; +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; +use sp_std::prelude::*; + +pub type CDNNodePubKey = sp_runtime::AccountId32; + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct CDNNode { + pub pub_key: CDNNodePubKey, + pub cluster_id: Option, + pub props: CDNNodeProps, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct CDNNodeProps { + pub url: Vec, + pub location: [u8; 2], +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct CDNNodeParams { + pub pub_key: CDNNodePubKey, + pub url: Vec, + pub location: [u8; 2], +} + +impl NodeTrait for CDNNode { + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + NodePubKeyRef::CDNPubKeyRef(&self.pub_key) + } + fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + NodePropsRef::CDNPropsRef(&self.props) + } + fn get_type(&self) -> NodeType { + NodeType::CDN + } + fn from_params(params: NodeParams) -> Result> { + match params { + NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode { + pub_key: params.pub_key, + cluster_id: None, + props: CDNNodeProps { url: params.url, location: params.location }, + })), + _ => Err(Error::::NodeAlreadyExists), + } + } +} diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 1a6db5178..482774046 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -23,6 +23,15 @@ use sp_runtime::RuntimeDebug; use sp_std::prelude::*; pub use pallet::*; +mod cdn_node; +mod node; +mod storage_node; + +pub use crate::{ + cdn_node::{CDNNode, CDNNodePubKey}, + node::{Node, NodeParams, NodePubKey, NodeTrait}, + storage_node::{StorageNode, StorageNodePubKey}, +}; #[frame_support::pallet] pub mod pallet { @@ -61,197 +70,7 @@ pub mod pallet { pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; // todo: add the type to the Config - type ClusterId = H160; - - type StorageNodePubKey = sp_runtime::AccountId32; - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct StorageNode { - pub_key: StorageNodePubKey, - cluster_id: Option, - props: StorageNodeProps, - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct StorageNodeProps { - capacity: u32, - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct StorageNodeParams { - pub_key: StorageNodePubKey, - capacity: u32, - } - - type CDNNodePubKey = sp_runtime::AccountId32; - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct CDNNode { - pub_key: CDNNodePubKey, - cluster_id: Option, - props: CDNNodeProps, - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct CDNNodeProps { - url: Vec, - location: [u8; 2], - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct CDNNodeParams { - pub_key: CDNNodePubKey, - url: Vec, - location: [u8; 2], - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum Node { - Storage(StorageNode), - CDN(CDNNode), - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum NodeParams { - StorageParams(StorageNodeParams), - CDNParams(CDNNodeParams), - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum NodePubKey { - StoragePubKey(StorageNodePubKey), - CDNPubKey(CDNNodePubKey), - } - - #[derive(Clone, RuntimeDebug, PartialEq)] - pub enum NodePubKeyRef<'a> { - StoragePubKeyRef(&'a StorageNodePubKey), - CDNPubKeyRef(&'a CDNNodePubKey), - } - - impl<'a> NodePubKeyRef<'a> { - pub fn to_owned(&self) -> NodePubKey { - match &self { - NodePubKeyRef::StoragePubKeyRef(pub_key_ref) => - NodePubKey::StoragePubKey((**pub_key_ref).clone()), - NodePubKeyRef::CDNPubKeyRef(pub_key_ref) => - NodePubKey::CDNPubKey((**pub_key_ref).clone()), - } - } - } - - #[derive(Clone, RuntimeDebug, PartialEq)] - pub enum NodePropsRef<'a> { - StoragePropsRef(&'a StorageNodeProps), - CDNPropsRef(&'a CDNNodeProps), - } - - pub trait NodeTrait { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; - fn get_props<'a>(&'a self) -> NodePropsRef<'a>; - fn get_type(&self) -> NodeType; - fn from_params(params: NodeParams) -> Result>; - } - - impl NodeTrait for StorageNode { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - NodePubKeyRef::StoragePubKeyRef(&self.pub_key) - } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - NodePropsRef::StoragePropsRef(&self.props) - } - fn get_type(&self) -> NodeType { - NodeType::Storage - } - fn from_params(params: NodeParams) -> Result> { - match params { - NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode { - pub_key: params.pub_key, - cluster_id: None, - props: StorageNodeProps { capacity: params.capacity }, - })), - _ => Err(Error::::NodeAlreadyExists), - } - } - } - - impl NodeTrait for CDNNode { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - NodePubKeyRef::CDNPubKeyRef(&self.pub_key) - } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - NodePropsRef::CDNPropsRef(&self.props) - } - fn get_type(&self) -> NodeType { - NodeType::CDN - } - fn from_params(params: NodeParams) -> Result> { - match params { - NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode { - pub_key: params.pub_key, - cluster_id: None, - props: CDNNodeProps { url: params.url, location: params.location }, - })), - _ => Err(Error::::NodeAlreadyExists), - } - } - } - - impl NodeTrait for Node { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - match &self { - Node::Storage(node) => node.get_pub_key(), - Node::CDN(node) => node.get_pub_key(), - } - } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - match &self { - Node::Storage(node) => node.get_props(), - Node::CDN(node) => node.get_props(), - } - } - fn get_type(&self) -> NodeType { - match &self { - Node::Storage(node) => node.get_type(), - Node::CDN(node) => node.get_type(), - } - } - fn from_params(params: NodeParams) -> Result> { - match params { - NodeParams::StorageParams(_) => StorageNode::from_params(params), - NodeParams::CDNParams(_) => CDNNode::from_params(params), - } - } - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub enum NodeType { - Storage = 1, - CDN = 2, - } - - impl From for u8 { - fn from(node_type: NodeType) -> Self { - match node_type { - NodeType::Storage => 1, - NodeType::CDN => 2, - } - } - } - - impl TryFrom for NodeType { - type Error = (); - fn try_from(value: u8) -> Result { - match value { - 1 => Ok(NodeType::Storage), - 2 => Ok(NodeType::CDN), - _ => Err(()), - } - } - } - - pub trait NodeRepositoryTrait { - fn create(node: Node) -> Result<(), pallet::Error>; - fn get(pub_key: NodePubKey) -> Result>; - } + pub type ClusterId = H160; #[pallet::call] impl Pallet { diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs new file mode 100644 index 000000000..a03a07852 --- /dev/null +++ b/pallets/ddc-nodes/src/node.rs @@ -0,0 +1,110 @@ +use crate::{ + cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps, CDNNodePubKey}, + pallet::Error, + storage_node::{StorageNode, StorageNodeParams, StorageNodeProps, StorageNodePubKey}, + Config, +}; +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum Node { + Storage(StorageNode), + CDN(CDNNode), +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodeParams { + StorageParams(StorageNodeParams), + CDNParams(CDNNodeParams), +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodePubKey { + StoragePubKey(StorageNodePubKey), + CDNPubKey(CDNNodePubKey), +} + +#[derive(Clone, RuntimeDebug, PartialEq)] +pub enum NodePubKeyRef<'a> { + StoragePubKeyRef(&'a StorageNodePubKey), + CDNPubKeyRef(&'a CDNNodePubKey), +} + +impl<'a> NodePubKeyRef<'a> { + pub fn to_owned(&self) -> NodePubKey { + match &self { + NodePubKeyRef::StoragePubKeyRef(pub_key_ref) => + NodePubKey::StoragePubKey((**pub_key_ref).clone()), + NodePubKeyRef::CDNPubKeyRef(pub_key_ref) => + NodePubKey::CDNPubKey((**pub_key_ref).clone()), + } + } +} + +#[derive(Clone, RuntimeDebug, PartialEq)] +pub enum NodePropsRef<'a> { + StoragePropsRef(&'a StorageNodeProps), + CDNPropsRef(&'a CDNNodeProps), +} + +pub trait NodeTrait { + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; + fn get_props<'a>(&'a self) -> NodePropsRef<'a>; + fn get_type(&self) -> NodeType; + fn from_params(params: NodeParams) -> Result>; +} + +impl NodeTrait for Node { + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + match &self { + Node::Storage(node) => node.get_pub_key(), + Node::CDN(node) => node.get_pub_key(), + } + } + fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + match &self { + Node::Storage(node) => node.get_props(), + Node::CDN(node) => node.get_props(), + } + } + fn get_type(&self) -> NodeType { + match &self { + Node::Storage(node) => node.get_type(), + Node::CDN(node) => node.get_type(), + } + } + fn from_params(params: NodeParams) -> Result> { + match params { + NodeParams::StorageParams(_) => StorageNode::from_params(params), + NodeParams::CDNParams(_) => CDNNode::from_params(params), + } + } +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodeType { + Storage = 1, + CDN = 2, +} + +impl From for u8 { + fn from(node_type: NodeType) -> Self { + match node_type { + NodeType::Storage => 1, + NodeType::CDN => 2, + } + } +} + +impl TryFrom for NodeType { + type Error = (); + fn try_from(value: u8) -> Result { + match value { + 1 => Ok(NodeType::Storage), + 2 => Ok(NodeType::CDN), + _ => Err(()), + } + } +} diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs new file mode 100644 index 000000000..9e9ad4654 --- /dev/null +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -0,0 +1,50 @@ +use crate::{ + node::{Node, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, + pallet::Error, + ClusterId, Config, +}; +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; + +pub type StorageNodePubKey = sp_runtime::AccountId32; + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct StorageNode { + pub pub_key: StorageNodePubKey, + pub cluster_id: Option, + pub props: StorageNodeProps, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct StorageNodeProps { + pub capacity: u32, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct StorageNodeParams { + pub pub_key: StorageNodePubKey, + pub capacity: u32, +} + +impl NodeTrait for StorageNode { + fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + NodePubKeyRef::StoragePubKeyRef(&self.pub_key) + } + fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + NodePropsRef::StoragePropsRef(&self.props) + } + fn get_type(&self) -> NodeType { + NodeType::Storage + } + fn from_params(params: NodeParams) -> Result> { + match params { + NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode { + pub_key: params.pub_key, + cluster_id: None, + props: StorageNodeProps { capacity: params.capacity }, + })), + _ => Err(Error::::NodeAlreadyExists), + } + } +} From b9eb635b6d344212806edbdfd4697e7720a98eed Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 7 Oct 2023 02:05:24 +0200 Subject: [PATCH 345/544] feat: node_provider_id field is added --- pallets/ddc-clusters/src/lib.rs | 2 +- pallets/ddc-nodes/src/cdn_node.rs | 19 +++++++++----- pallets/ddc-nodes/src/lib.rs | 24 +++++++++-------- pallets/ddc-nodes/src/node.rs | 38 ++++++++++++++++++++------- pallets/ddc-nodes/src/storage_node.rs | 19 +++++++++----- 5 files changed, 67 insertions(+), 35 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 49f7b8222..8ced6b1a9 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -37,7 +37,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type NodeRepository: NodeRepository; + type NodeRepository: NodeRepository; } #[pallet::event] diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index c32d80b20..41b9cfca3 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,7 +1,7 @@ use crate::{ - node::{Node, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, + node::{Node, NodeError, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, pallet::Error, - ClusterId, Config, + ClusterId, }; use codec::{Decode, Encode}; use scale_info::TypeInfo; @@ -11,8 +11,9 @@ use sp_std::prelude::*; pub type CDNNodePubKey = sp_runtime::AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNode { +pub struct CDNNode { pub pub_key: CDNNodePubKey, + pub provider_id: ProviderId, pub cluster_id: Option, pub props: CDNNodeProps, } @@ -30,7 +31,7 @@ pub struct CDNNodeParams { pub location: [u8; 2], } -impl NodeTrait for CDNNode { +impl NodeTrait for CDNNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::CDNPubKeyRef(&self.pub_key) } @@ -40,14 +41,18 @@ impl NodeTrait for CDNNode { fn get_type(&self) -> NodeType { NodeType::CDN } - fn from_params(params: NodeParams) -> Result> { + fn from_params( + provider_id: ProviderId, + params: NodeParams, + ) -> Result, NodeError> { match params { - NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode { + NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode:: { + provider_id, pub_key: params.pub_key, cluster_id: None, props: CDNNodeProps { url: params.url, location: params.location }, })), - _ => Err(Error::::NodeAlreadyExists), + _ => Err(NodeError::InvalidCDNNodeParams), } } } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 482774046..55f043859 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -29,7 +29,7 @@ mod storage_node; pub use crate::{ cdn_node::{CDNNode, CDNNodePubKey}, - node::{Node, NodeParams, NodePubKey, NodeTrait}, + node::{Node, NodeError, NodeParams, NodePubKey, NodeTrait}, storage_node::{StorageNode, StorageNodePubKey}, }; @@ -63,11 +63,12 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn storage_nodes)] pub type StorageNodes = - StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; + StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; #[pallet::storage] #[pallet::getter(fn cdn_nodes)] - pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; + pub type CDNNodes = + StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; // todo: add the type to the Config pub type ClusterId = H160; @@ -76,8 +77,9 @@ pub mod pallet { impl Pallet { #[pallet::weight(10_000)] pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { - ensure_signed(origin)?; - let node: Node = Node::from_params::(node_params)?; + let provider_id = ensure_signed(origin)?; + let node = Node::::from_params(provider_id, node_params) + .map_err(|e| Into::>::into(NodeError::from(e)))?; let node_type = node.get_type(); let node_pub_key = node.get_pub_key().to_owned(); Self::create(node)?; @@ -89,14 +91,14 @@ pub mod pallet { } } - pub trait NodeRepository { - fn create(node: Node) -> Result<(), &'static str>; - fn get(pub_key: NodePubKey) -> Result; + pub trait NodeRepository { + fn create(node: Node) -> Result<(), &'static str>; + fn get(pub_key: NodePubKey) -> Result, &'static str>; fn add_to_cluster(pub_key: NodePubKey, cluster_id: ClusterId) -> Result<(), &'static str>; } - impl NodeRepository for Pallet { - fn create(node: Node) -> Result<(), &'static str> { + impl NodeRepository for Pallet { + fn create(node: Node) -> Result<(), &'static str> { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { @@ -115,7 +117,7 @@ pub mod pallet { } } - fn get(node_pub_key: NodePubKey) -> Result { + fn get(node_pub_key: NodePubKey) -> Result, &'static str> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => match StorageNodes::::try_get(pub_key) { Ok(node) => Ok(Node::Storage(node)), diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index a03a07852..84d123acf 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -9,9 +9,9 @@ use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum Node { - Storage(StorageNode), - CDN(CDNNode), +pub enum Node { + Storage(StorageNode), + CDN(CDNNode), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -49,14 +49,17 @@ pub enum NodePropsRef<'a> { CDNPropsRef(&'a CDNNodeProps), } -pub trait NodeTrait { +pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; fn get_type(&self) -> NodeType; - fn from_params(params: NodeParams) -> Result>; + fn from_params( + provider_id: ProviderId, + params: NodeParams, + ) -> Result, NodeError>; } -impl NodeTrait for Node { +impl NodeTrait for Node { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { match &self { Node::Storage(node) => node.get_pub_key(), @@ -75,10 +78,13 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_type(), } } - fn from_params(params: NodeParams) -> Result> { + fn from_params( + provider_id: ProviderId, + params: NodeParams, + ) -> Result, NodeError> { match params { - NodeParams::StorageParams(_) => StorageNode::from_params(params), - NodeParams::CDNParams(_) => CDNNode::from_params(params), + NodeParams::StorageParams(_) => StorageNode::from_params(provider_id, params), + NodeParams::CDNParams(_) => CDNNode::from_params(provider_id, params), } } } @@ -108,3 +114,17 @@ impl TryFrom for NodeType { } } } + +pub enum NodeError { + InvalidStorageNodeParams, + InvalidCDNNodeParams, +} + +impl From for Error { + fn from(error: NodeError) -> Self { + match error { + NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, + NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, + } + } +} diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 9e9ad4654..1afcb7f31 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,7 +1,7 @@ use crate::{ - node::{Node, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, + node::{Node, NodeError, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, pallet::Error, - ClusterId, Config, + ClusterId, }; use codec::{Decode, Encode}; use scale_info::TypeInfo; @@ -10,8 +10,9 @@ use sp_runtime::RuntimeDebug; pub type StorageNodePubKey = sp_runtime::AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct StorageNode { +pub struct StorageNode { pub pub_key: StorageNodePubKey, + pub provider_id: ProviderId, pub cluster_id: Option, pub props: StorageNodeProps, } @@ -27,7 +28,7 @@ pub struct StorageNodeParams { pub capacity: u32, } -impl NodeTrait for StorageNode { +impl NodeTrait for StorageNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::StoragePubKeyRef(&self.pub_key) } @@ -37,14 +38,18 @@ impl NodeTrait for StorageNode { fn get_type(&self) -> NodeType { NodeType::Storage } - fn from_params(params: NodeParams) -> Result> { + fn from_params( + provider_id: ProviderId, + params: NodeParams, + ) -> Result, NodeError> { match params { - NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode { + NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode:: { + provider_id, pub_key: params.pub_key, cluster_id: None, props: StorageNodeProps { capacity: params.capacity }, })), - _ => Err(Error::::NodeAlreadyExists), + _ => Err(NodeError::InvalidStorageNodeParams), } } } From 77e9d787cd394c712a66c8058d552c7542ff799a Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 7 Oct 2023 02:33:56 +0200 Subject: [PATCH 346/544] fix: unused types removed --- pallets/ddc-nodes/src/cdn_node.rs | 5 ++--- pallets/ddc-nodes/src/node.rs | 1 - pallets/ddc-nodes/src/storage_node.rs | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 41b9cfca3..e14da659a 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,14 +1,13 @@ use crate::{ node::{Node, NodeError, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, - pallet::Error, ClusterId, }; use codec::{Decode, Encode}; use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; +use sp_runtime::{AccountId32, RuntimeDebug}; use sp_std::prelude::*; -pub type CDNNodePubKey = sp_runtime::AccountId32; +pub type CDNNodePubKey = AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNode { diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 84d123acf..fe2a60f5e 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -2,7 +2,6 @@ use crate::{ cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps, CDNNodePubKey}, pallet::Error, storage_node::{StorageNode, StorageNodeParams, StorageNodeProps, StorageNodePubKey}, - Config, }; use codec::{Decode, Encode}; use scale_info::TypeInfo; diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 1afcb7f31..dea3b8591 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,13 +1,12 @@ use crate::{ node::{Node, NodeError, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, - pallet::Error, ClusterId, }; use codec::{Decode, Encode}; use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; +use sp_runtime::{AccountId32, RuntimeDebug}; -pub type StorageNodePubKey = sp_runtime::AccountId32; +pub type StorageNodePubKey = AccountId32; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNode { From fbcb9b7da432ac50bdb7e7808f2302a27c1146d9 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 7 Oct 2023 03:04:21 +0200 Subject: [PATCH 347/544] feat: getting provider_id --- pallets/ddc-nodes/src/cdn_node.rs | 7 +++++-- pallets/ddc-nodes/src/node.rs | 7 +++++++ pallets/ddc-nodes/src/storage_node.rs | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index e14da659a..8bc26e151 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -20,20 +20,23 @@ pub struct CDNNode { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeProps { pub url: Vec, - pub location: [u8; 2], + pub location: Vec, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeParams { pub pub_key: CDNNodePubKey, pub url: Vec, - pub location: [u8; 2], + pub location: Vec, } impl NodeTrait for CDNNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::CDNPubKeyRef(&self.pub_key) } + fn get_provider_id(&self) -> &ProviderId { + &self.provider_id + } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::CDNPropsRef(&self.props) } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index fe2a60f5e..bc14f9790 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -50,6 +50,7 @@ pub enum NodePropsRef<'a> { pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; + fn get_provider_id(&self) -> &ProviderId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; fn get_type(&self) -> NodeType; fn from_params( @@ -65,6 +66,12 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_pub_key(), } } + fn get_provider_id(&self) -> &ProviderId { + match &self { + Node::Storage(node) => node.get_provider_id(), + Node::CDN(node) => node.get_provider_id(), + } + } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { match &self { Node::Storage(node) => node.get_props(), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index dea3b8591..c0d967c1b 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -31,6 +31,9 @@ impl NodeTrait for StorageNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::StoragePubKeyRef(&self.pub_key) } + fn get_provider_id(&self) -> &ProviderId { + &self.provider_id + } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::StoragePropsRef(&self.props) } From e75b507babc4660acc7d1d9ea31963d276859f59 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 7 Oct 2023 03:30:31 +0200 Subject: [PATCH 348/544] feat: getting cluster id --- pallets/ddc-nodes/src/cdn_node.rs | 3 +++ pallets/ddc-nodes/src/node.rs | 8 ++++++++ pallets/ddc-nodes/src/storage_node.rs | 3 +++ 3 files changed, 14 insertions(+) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 8bc26e151..58fd59246 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -40,6 +40,9 @@ impl NodeTrait for CDNNode { fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::CDNPropsRef(&self.props) } + fn get_cluster_id(&self) -> &Option { + &self.cluster_id + } fn get_type(&self) -> NodeType { NodeType::CDN } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index bc14f9790..70359dffa 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -2,6 +2,7 @@ use crate::{ cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps, CDNNodePubKey}, pallet::Error, storage_node::{StorageNode, StorageNodeParams, StorageNodeProps, StorageNodePubKey}, + ClusterId, }; use codec::{Decode, Encode}; use scale_info::TypeInfo; @@ -52,6 +53,7 @@ pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; fn get_provider_id(&self) -> &ProviderId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; + fn get_cluster_id(&self) -> &Option; fn get_type(&self) -> NodeType; fn from_params( provider_id: ProviderId, @@ -78,6 +80,12 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_props(), } } + fn get_cluster_id(&self) -> &Option { + match &self { + Node::Storage(node) => node.get_cluster_id(), + Node::CDN(node) => node.get_cluster_id(), + } + } fn get_type(&self) -> NodeType { match &self { Node::Storage(node) => node.get_type(), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index c0d967c1b..6012ce814 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -37,6 +37,9 @@ impl NodeTrait for StorageNode { fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::StoragePropsRef(&self.props) } + fn get_cluster_id(&self) -> &Option { + &self.cluster_id + } fn get_type(&self) -> NodeType { NodeType::Storage } From 87da868b23a315b76e6a75e4b061687d677db237 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 7 Oct 2023 04:07:40 +0200 Subject: [PATCH 349/544] feat: updating cluster id for nodes --- pallets/ddc-clusters/src/lib.rs | 5 +++-- pallets/ddc-nodes/src/cdn_node.rs | 3 +++ pallets/ddc-nodes/src/lib.rs | 29 +++++++++++++++------------ pallets/ddc-nodes/src/node.rs | 7 +++++++ pallets/ddc-nodes/src/storage_node.rs | 3 +++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 8ced6b1a9..4592d7f8e 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -101,8 +101,9 @@ pub mod pallet { ) -> DispatchResult { ensure_signed(origin)?; - let node = T::NodeRepository::get(node_pub_key.clone())?; - T::NodeRepository::add_to_cluster(node_pub_key, cluster_id)?; + let mut node = T::NodeRepository::get(node_pub_key.clone())?; + node.set_cluster_id(cluster_id); + T::NodeRepository::update(node)?; Ok(()) } diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 58fd59246..d54a80dd9 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -43,6 +43,9 @@ impl NodeTrait for CDNNode { fn get_cluster_id(&self) -> &Option { &self.cluster_id } + fn set_cluster_id(&mut self, cluster_id: ClusterId) { + self.cluster_id = Some(cluster_id); + } fn get_type(&self) -> NodeType { NodeType::CDN } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 55f043859..cebeb452b 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -94,7 +94,7 @@ pub mod pallet { pub trait NodeRepository { fn create(node: Node) -> Result<(), &'static str>; fn get(pub_key: NodePubKey) -> Result, &'static str>; - fn add_to_cluster(pub_key: NodePubKey, cluster_id: ClusterId) -> Result<(), &'static str>; + fn update(node: Node) -> Result<(), &'static str>; } impl NodeRepository for Pallet { @@ -102,14 +102,14 @@ pub mod pallet { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { - return Err("Node already exists") + return Err("Storage node already exists") } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) }, Node::CDN(cdn_node) => { if CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err("Node already exists") + return Err("CDN node already exists") } CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); Ok(()) @@ -120,25 +120,28 @@ pub mod pallet { fn get(node_pub_key: NodePubKey) -> Result, &'static str> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => match StorageNodes::::try_get(pub_key) { - Ok(node) => Ok(Node::Storage(node)), - Err(_) => Err("Node does not exist"), + Ok(storage_node) => Ok(Node::Storage(storage_node)), + Err(_) => Err("Storage node does not exist"), }, NodePubKey::CDNPubKey(pub_key) => match CDNNodes::::try_get(pub_key) { - Ok(node) => Ok(Node::CDN(node)), - Err(_) => Err("Node does not exist"), + Ok(cdn_node) => Ok(Node::CDN(cdn_node)), + Err(_) => Err("CDN node does not exist"), }, } } - fn add_to_cluster(pub_key: NodePubKey, cluster_id: ClusterId) -> Result<(), &'static str> { - let node = Self::get(pub_key)?; + fn update(node: Node) -> Result<(), &'static str> { match node { - Node::Storage(mut storage_node) => { - storage_node.cluster_id = Some(cluster_id); + Node::Storage(storage_node) => { + if !StorageNodes::::contains_key(&storage_node.pub_key) { + return Err("Storage node does not exist") + } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); }, - Node::CDN(mut cdn_node) => { - cdn_node.cluster_id = Some(cluster_id); + Node::CDN(cdn_node) => { + if !CDNNodes::::contains_key(&cdn_node.pub_key) { + return Err("CDN node does not exist") + } CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); }, } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 70359dffa..40961f8ad 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -54,6 +54,7 @@ pub trait NodeTrait { fn get_provider_id(&self) -> &ProviderId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; fn get_cluster_id(&self) -> &Option; + fn set_cluster_id(&mut self, cluster_id: ClusterId); fn get_type(&self) -> NodeType; fn from_params( provider_id: ProviderId, @@ -86,6 +87,12 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_cluster_id(), } } + fn set_cluster_id(&mut self, cluster_id: ClusterId) { + match self { + Node::Storage(node) => node.set_cluster_id(cluster_id), + Node::CDN(node) => node.set_cluster_id(cluster_id), + } + } fn get_type(&self) -> NodeType { match &self { Node::Storage(node) => node.get_type(), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 6012ce814..b03629ef9 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -40,6 +40,9 @@ impl NodeTrait for StorageNode { fn get_cluster_id(&self) -> &Option { &self.cluster_id } + fn set_cluster_id(&mut self, cluster_id: ClusterId) { + self.cluster_id = Some(cluster_id); + } fn get_type(&self) -> NodeType { NodeType::Storage } From fb158d4c5de7e9ada75ff4a8f2afd627d2261e8a Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 00:36:30 +0200 Subject: [PATCH 350/544] chore: cluster and nodes split to modules --- pallets/ddc-clusters/src/cluster.rs | 61 +++++++++++++++++++++++++++ pallets/ddc-clusters/src/lib.rs | 40 ++++++------------ pallets/ddc-nodes/src/cdn_node.rs | 27 ++++++++---- pallets/ddc-nodes/src/lib.rs | 4 +- pallets/ddc-nodes/src/node.rs | 4 ++ pallets/ddc-nodes/src/storage_node.rs | 33 ++++++++++----- 6 files changed, 119 insertions(+), 50 deletions(-) create mode 100644 pallets/ddc-clusters/src/cluster.rs diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs new file mode 100644 index 000000000..c81916c74 --- /dev/null +++ b/pallets/ddc-clusters/src/cluster.rs @@ -0,0 +1,61 @@ +use crate::pallet::Error; +use codec::{Decode, Encode}; +use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; +use scale_info::TypeInfo; +use sp_core::hash::H160; +use sp_std::vec::Vec; + +pub type ClusterId = H160; +parameter_types! { + pub MaxClusterParamsLen: u16 = 2048; +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct Cluster { + pub cluster_id: ClusterId, + pub manager_id: ManagerId, + pub props: ClusterProps, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterProps { + // this is a temporal way of storing cluster parameters as a stringified json, + // should be replaced with specific properties for cluster + pub params: BoundedVec, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterParams { + pub params: Vec, +} + +impl Cluster { + pub fn from_params( + cluster_id: ClusterId, + manager_id: ManagerId, + cluster_params: ClusterParams, + ) -> Result, ClusterError> { + Ok(Cluster { + cluster_id, + manager_id, + props: ClusterProps { + params: match cluster_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(ClusterError::ClusterParamsExceedsLimit), + }, + }, + }) + } +} + +pub enum ClusterError { + ClusterParamsExceedsLimit, +} + +impl From for Error { + fn from(error: ClusterError) -> Self { + match error { + ClusterError::ClusterParamsExceedsLimit => Error::::ClusterParamsExceedsLimit, + } + } +} diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 4592d7f8e..3aa2dbf30 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -14,16 +14,15 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] -use codec::{Decode, Encode}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -pub use pallet::*; -use scale_info::TypeInfo; -use sp_core::hash::H160; -use sp_runtime::RuntimeDebug; +use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; use sp_std::prelude::*; -use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; +pub use pallet::*; +mod cluster; + +pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; #[frame_support::pallet] pub mod pallet { @@ -49,40 +48,25 @@ pub mod pallet { #[pallet::error] pub enum Error { ClusterAlreadyExists, + ClusterParamsExceedsLimit, } #[pallet::storage] #[pallet::getter(fn storage_nodes)] - pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; - - type ClusterId = H160; - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct Cluster { - cluster_id: ClusterId, - } - - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] - pub struct ClusterParams { - cluster_id: ClusterId, - } - - impl Cluster { - fn from_params(params: ClusterParams) -> Cluster { - Cluster { cluster_id: params.cluster_id } - } - } + pub type Clusters = + StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; #[pallet::call] impl Pallet { #[pallet::weight(10_000)] pub fn create_cluster( origin: OriginFor, + cluster_id: ClusterId, cluster_params: ClusterParams, ) -> DispatchResult { - ensure_signed(origin)?; - - let cluster = Cluster::from_params(cluster_params); + let manager_id = ensure_signed(origin)?; + let cluster = Cluster::from_params(cluster_id, manager_id, cluster_params) + .map_err(|e| Into::>::into(ClusterError::from(e)))?; let cluster_id = cluster.cluster_id.clone(); ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index d54a80dd9..66fef097f 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -3,11 +3,15 @@ use crate::{ ClusterId, }; use codec::{Decode, Encode}; +use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::{AccountId32, RuntimeDebug}; use sp_std::prelude::*; pub type CDNNodePubKey = AccountId32; +parameter_types! { + pub MaxCDNNodeParamsLen: u16 = 2048; +} #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNode { @@ -19,15 +23,15 @@ pub struct CDNNode { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeProps { - pub url: Vec, - pub location: Vec, + // this is a temporal way of storing node parameters as a stringified json, + // should be replaced with specific properties for this type of node once they are defined + pub params: BoundedVec, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeParams { pub pub_key: CDNNodePubKey, - pub url: Vec, - pub location: Vec, + pub params: Vec, // should be replaced with specific parameters for this type of node } impl NodeTrait for CDNNode { @@ -51,14 +55,19 @@ impl NodeTrait for CDNNode { } fn from_params( provider_id: ProviderId, - params: NodeParams, + node_params: NodeParams, ) -> Result, NodeError> { - match params { - NodeParams::CDNParams(params) => Ok(Node::CDN(CDNNode:: { + match node_params { + NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { provider_id, - pub_key: params.pub_key, + pub_key: node_params.pub_key, cluster_id: None, - props: CDNNodeProps { url: params.url, location: params.location }, + props: CDNNodeProps { + params: match node_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNNodeParamsExceedsLimit), + }, + }, })), _ => Err(NodeError::InvalidCDNNodeParams), } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index cebeb452b..6514c3349 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -14,12 +14,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] -use codec::{Decode, Encode}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -use scale_info::TypeInfo; use sp_core::hash::H160; -use sp_runtime::RuntimeDebug; use sp_std::prelude::*; pub use pallet::*; @@ -58,6 +55,7 @@ pub mod pallet { NodeAlreadyExists, NodeDoesNotExist, InvalidNodeParams, + NodeParamsExceedsLimit, } #[pallet::storage] diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 40961f8ad..19c9d4b50 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -139,6 +139,8 @@ impl TryFrom for NodeType { pub enum NodeError { InvalidStorageNodeParams, InvalidCDNNodeParams, + StorageNodeParamsExceedsLimit, + CDNNodeParamsExceedsLimit, } impl From for Error { @@ -146,6 +148,8 @@ impl From for Error { match error { NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, + NodeError::StorageNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, + NodeError::CDNNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, } } } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index b03629ef9..b40a8bade 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -3,10 +3,15 @@ use crate::{ ClusterId, }; use codec::{Decode, Encode}; +use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::{AccountId32, RuntimeDebug}; +use sp_std::prelude::Vec; pub type StorageNodePubKey = AccountId32; +parameter_types! { + pub MaxStorageNodeParamsLen: u16 = 2048; +} #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNode { @@ -18,13 +23,15 @@ pub struct StorageNode { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeProps { - pub capacity: u32, + // this is a temporal way of storing node parameters as a stringified json, + // should be replaced with specific properties for this type of node once they are defined + pub params: BoundedVec, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeParams { pub pub_key: StorageNodePubKey, - pub capacity: u32, + pub params: Vec, // should be replaced with specific parameters for this type of node } impl NodeTrait for StorageNode { @@ -48,15 +55,21 @@ impl NodeTrait for StorageNode { } fn from_params( provider_id: ProviderId, - params: NodeParams, + node_params: NodeParams, ) -> Result, NodeError> { - match params { - NodeParams::StorageParams(params) => Ok(Node::Storage(StorageNode:: { - provider_id, - pub_key: params.pub_key, - cluster_id: None, - props: StorageNodeProps { capacity: params.capacity }, - })), + match node_params { + NodeParams::StorageParams(node_params) => + Ok(Node::Storage(StorageNode:: { + provider_id, + pub_key: node_params.pub_key, + cluster_id: None, + props: StorageNodeProps { + params: match node_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), + }, + }, + })), _ => Err(NodeError::InvalidStorageNodeParams), } } From 5f2acaa5e7b04d74a0e47879e5dc996472cd80be Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 01:46:05 +0200 Subject: [PATCH 351/544] chore: adding error types for node repository --- pallets/ddc-clusters/src/cluster.rs | 2 +- pallets/ddc-clusters/src/lib.rs | 13 +++----- pallets/ddc-nodes/src/cdn_node.rs | 2 +- pallets/ddc-nodes/src/lib.rs | 46 +++++++++++++++++++-------- pallets/ddc-nodes/src/node.rs | 14 +++----- pallets/ddc-nodes/src/storage_node.rs | 2 +- 6 files changed, 44 insertions(+), 35 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index c81916c74..58144292b 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -30,7 +30,7 @@ pub struct ClusterParams { } impl Cluster { - pub fn from_params( + pub fn new( cluster_id: ClusterId, manager_id: ManagerId, cluster_params: ClusterParams, diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 3aa2dbf30..2ba887c49 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -49,6 +49,7 @@ pub mod pallet { pub enum Error { ClusterAlreadyExists, ClusterParamsExceedsLimit, + AttemptToAddNonExistentNode, } #[pallet::storage] @@ -65,15 +66,12 @@ pub mod pallet { cluster_params: ClusterParams, ) -> DispatchResult { let manager_id = ensure_signed(origin)?; - let cluster = Cluster::from_params(cluster_id, manager_id, cluster_params) + let cluster = Cluster::new(cluster_id, manager_id, cluster_params) .map_err(|e| Into::>::into(ClusterError::from(e)))?; let cluster_id = cluster.cluster_id.clone(); - ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); - Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); - Ok(()) } @@ -84,11 +82,10 @@ pub mod pallet { node_pub_key: NodePubKey, ) -> DispatchResult { ensure_signed(origin)?; - - let mut node = T::NodeRepository::get(node_pub_key.clone())?; + let mut node = T::NodeRepository::get(node_pub_key.clone()) + .map_err(|_| Error::::AttemptToAddNonExistentNode)?; node.set_cluster_id(cluster_id); - T::NodeRepository::update(node)?; - + T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; Ok(()) } } diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 66fef097f..395f4e770 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -53,7 +53,7 @@ impl NodeTrait for CDNNode { fn get_type(&self) -> NodeType { NodeType::CDN } - fn from_params( + fn new( provider_id: ProviderId, node_params: NodeParams, ) -> Result, NodeError> { diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 6514c3349..781a5403f 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -76,11 +76,11 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { let provider_id = ensure_signed(origin)?; - let node = Node::::from_params(provider_id, node_params) + let node = Node::::new(provider_id, node_params) .map_err(|e| Into::>::into(NodeError::from(e)))?; let node_type = node.get_type(); let node_pub_key = node.get_pub_key().to_owned(); - Self::create(node)?; + Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; Self::deposit_event(Event::::NodeCreated { node_type: node_type.into(), node_pub_key, @@ -90,24 +90,42 @@ pub mod pallet { } pub trait NodeRepository { - fn create(node: Node) -> Result<(), &'static str>; - fn get(pub_key: NodePubKey) -> Result, &'static str>; - fn update(node: Node) -> Result<(), &'static str>; + fn create(node: Node) -> Result<(), NodeRepositoryError>; + fn get(pub_key: NodePubKey) -> Result, NodeRepositoryError>; + fn update(node: Node) -> Result<(), NodeRepositoryError>; + } + + pub enum NodeRepositoryError { + StorageNodeAlreadyExists, + CDNNodeAlreadyExists, + StorageNodeDoesNotExist, + CDNNodeDoesNotExist, + } + + impl From for Error { + fn from(error: NodeRepositoryError) -> Self { + match error { + NodeRepositoryError::StorageNodeAlreadyExists => Error::::NodeAlreadyExists, + NodeRepositoryError::CDNNodeAlreadyExists => Error::::NodeAlreadyExists, + NodeRepositoryError::StorageNodeDoesNotExist => Error::::NodeDoesNotExist, + NodeRepositoryError::CDNNodeDoesNotExist => Error::::NodeDoesNotExist, + } + } } impl NodeRepository for Pallet { - fn create(node: Node) -> Result<(), &'static str> { + fn create(node: Node) -> Result<(), NodeRepositoryError> { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { - return Err("Storage node already exists") + return Err(NodeRepositoryError::StorageNodeAlreadyExists) } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) }, Node::CDN(cdn_node) => { if CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err("CDN node already exists") + return Err(NodeRepositoryError::CDNNodeAlreadyExists) } CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); Ok(()) @@ -115,30 +133,30 @@ pub mod pallet { } } - fn get(node_pub_key: NodePubKey) -> Result, &'static str> { + fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => match StorageNodes::::try_get(pub_key) { Ok(storage_node) => Ok(Node::Storage(storage_node)), - Err(_) => Err("Storage node does not exist"), + Err(_) => Err(NodeRepositoryError::StorageNodeDoesNotExist), }, NodePubKey::CDNPubKey(pub_key) => match CDNNodes::::try_get(pub_key) { Ok(cdn_node) => Ok(Node::CDN(cdn_node)), - Err(_) => Err("CDN node does not exist"), + Err(_) => Err(NodeRepositoryError::CDNNodeDoesNotExist), }, } } - fn update(node: Node) -> Result<(), &'static str> { + fn update(node: Node) -> Result<(), NodeRepositoryError> { match node { Node::Storage(storage_node) => { if !StorageNodes::::contains_key(&storage_node.pub_key) { - return Err("Storage node does not exist") + return Err(NodeRepositoryError::StorageNodeDoesNotExist) } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); }, Node::CDN(cdn_node) => { if !CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err("CDN node does not exist") + return Err(NodeRepositoryError::CDNNodeDoesNotExist) } CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); }, diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 19c9d4b50..6b32cb2c4 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -56,10 +56,7 @@ pub trait NodeTrait { fn get_cluster_id(&self) -> &Option; fn set_cluster_id(&mut self, cluster_id: ClusterId); fn get_type(&self) -> NodeType; - fn from_params( - provider_id: ProviderId, - params: NodeParams, - ) -> Result, NodeError>; + fn new(provider_id: ProviderId, params: NodeParams) -> Result, NodeError>; } impl NodeTrait for Node { @@ -99,13 +96,10 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_type(), } } - fn from_params( - provider_id: ProviderId, - params: NodeParams, - ) -> Result, NodeError> { + fn new(provider_id: ProviderId, params: NodeParams) -> Result, NodeError> { match params { - NodeParams::StorageParams(_) => StorageNode::from_params(provider_id, params), - NodeParams::CDNParams(_) => CDNNode::from_params(provider_id, params), + NodeParams::StorageParams(_) => StorageNode::new(provider_id, params), + NodeParams::CDNParams(_) => CDNNode::new(provider_id, params), } } } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index b40a8bade..e641d138e 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -53,7 +53,7 @@ impl NodeTrait for StorageNode { fn get_type(&self) -> NodeType { NodeType::Storage } - fn from_params( + fn new( provider_id: ProviderId, node_params: NodeParams, ) -> Result, NodeError> { From 7c65f2e02fe2cd1512c767cff2644ac49d593b4e Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 02:01:23 +0200 Subject: [PATCH 352/544] fix: checking cluster existence --- pallets/ddc-clusters/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 2ba887c49..63ee41050 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -48,6 +48,7 @@ pub mod pallet { #[pallet::error] pub enum Error { ClusterAlreadyExists, + ClusterDoesNotExist, ClusterParamsExceedsLimit, AttemptToAddNonExistentNode, } @@ -82,6 +83,7 @@ pub mod pallet { node_pub_key: NodePubKey, ) -> DispatchResult { ensure_signed(origin)?; + ensure!(Clusters::::contains_key(&cluster_id), Error::::ClusterDoesNotExist); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToAddNonExistentNode)?; node.set_cluster_id(cluster_id); From a8d76a3bc52947fbcca3f8e097a21b9072994e8c Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 14:47:23 +0200 Subject: [PATCH 353/544] feat: endpoint for removing a node --- pallets/ddc-nodes/src/cdn_node.rs | 11 ++++++++- pallets/ddc-nodes/src/lib.rs | 35 ++++++++++++++++++++++++++- pallets/ddc-nodes/src/node.rs | 19 ++++++++++++++- pallets/ddc-nodes/src/storage_node.rs | 11 ++++++++- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 395f4e770..6407f34e0 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,5 +1,7 @@ use crate::{ - node::{Node, NodeError, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, + node::{ + Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, + }, ClusterId, }; use codec::{Decode, Encode}; @@ -44,6 +46,13 @@ impl NodeTrait for CDNNode { fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::CDNPropsRef(&self.props) } + fn set_props<'a>(&mut self, props: NodeProps) -> Result<(), NodeError> { + self.props = match props { + NodeProps::CDNProps(props) => props, + _ => return Err(NodeError::InvalidCDNNodeProps), + }; + Ok(()) + } fn get_cluster_id(&self) -> &Option { &self.cluster_id } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 781a5403f..f4565caff 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -48,6 +48,7 @@ pub mod pallet { #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { NodeCreated { node_type: u8, node_pub_key: NodePubKey }, + NodeRemoved { node_type: u8, node_pub_key: NodePubKey }, } #[pallet::error] @@ -56,6 +57,8 @@ pub mod pallet { NodeDoesNotExist, InvalidNodeParams, NodeParamsExceedsLimit, + OnlyNodeProvider, + NodeIsAssignedToCluster, } #[pallet::storage] @@ -82,8 +85,24 @@ pub mod pallet { let node_pub_key = node.get_pub_key().to_owned(); Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; Self::deposit_event(Event::::NodeCreated { + node_pub_key, node_type: node_type.into(), + }); + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn remove_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { + let provider_id = ensure_signed(origin)?; + let node = Self::get(node_pub_key.clone()) + .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + ensure!(node.get_provider_id() == &provider_id, Error::::OnlyNodeProvider); + ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); + Self::remove(node_pub_key.clone()) + .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + Self::deposit_event(Event::::NodeCreated { node_pub_key, + node_type: node.get_type().into(), }); Ok(()) } @@ -91,8 +110,9 @@ pub mod pallet { pub trait NodeRepository { fn create(node: Node) -> Result<(), NodeRepositoryError>; - fn get(pub_key: NodePubKey) -> Result, NodeRepositoryError>; + fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError>; fn update(node: Node) -> Result<(), NodeRepositoryError>; + fn remove(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError>; } pub enum NodeRepositoryError { @@ -163,5 +183,18 @@ pub mod pallet { } Ok(()) } + + fn remove(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError> { + match node_pub_key { + NodePubKey::StoragePubKey(pub_key) => { + StorageNodes::::remove(pub_key); + Ok(()) + }, + NodePubKey::CDNPubKey(pub_key) => { + CDNNodes::::remove(pub_key); + Ok(()) + }, + } + } } } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 6b32cb2c4..fc1b530f4 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -20,6 +20,12 @@ pub enum NodeParams { CDNParams(CDNNodeParams), } +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodeProps { + StorageProps(StorageNodeProps), + CDNProps(CDNNodeProps), +} + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { StoragePubKey(StorageNodePubKey), @@ -53,6 +59,7 @@ pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; fn get_provider_id(&self) -> &ProviderId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; + fn set_props<'a>(&mut self, props: NodeProps) -> Result<(), NodeError>; fn get_cluster_id(&self) -> &Option; fn set_cluster_id(&mut self, cluster_id: ClusterId); fn get_type(&self) -> NodeType; @@ -78,6 +85,12 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_props(), } } + fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { + match self { + Node::Storage(node) => node.set_props(props), + Node::CDN(node) => node.set_props(props), + } + } fn get_cluster_id(&self) -> &Option { match &self { Node::Storage(node) => node.get_cluster_id(), @@ -135,6 +148,8 @@ pub enum NodeError { InvalidCDNNodeParams, StorageNodeParamsExceedsLimit, CDNNodeParamsExceedsLimit, + InvalidCDNNodeProps, + InvalidStorageNodeProps, } impl From for Error { @@ -143,7 +158,9 @@ impl From for Error { NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, NodeError::StorageNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, - NodeError::CDNNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, + NodeError::CDNNodeParamsExceedsLimit => Error::::InvalidNodeParams, + NodeError::InvalidStorageNodeProps => Error::::InvalidNodeParams, + NodeError::InvalidCDNNodeProps => Error::::InvalidNodeParams, } } } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index e641d138e..e22d95ccf 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,5 +1,7 @@ use crate::{ - node::{Node, NodeError, NodeParams, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType}, + node::{ + Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, + }, ClusterId, }; use codec::{Decode, Encode}; @@ -44,6 +46,13 @@ impl NodeTrait for StorageNode { fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::StoragePropsRef(&self.props) } + fn set_props<'a>(&mut self, props: NodeProps) -> Result<(), NodeError> { + self.props = match props { + NodeProps::StorageProps(props) => props, + _ => return Err(NodeError::InvalidStorageNodeProps), + }; + Ok(()) + } fn get_cluster_id(&self) -> &Option { &self.cluster_id } From 42b7f7a40f0af6b0765d4a34e049361f371e993e Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 15:57:08 +0200 Subject: [PATCH 354/544] feat: endpoint for setting node parameter --- pallets/ddc-nodes/src/cdn_node.rs | 12 +++++++++- pallets/ddc-nodes/src/lib.rs | 32 ++++++++++++++++++++++----- pallets/ddc-nodes/src/node.rs | 11 ++++++++- pallets/ddc-nodes/src/storage_node.rs | 12 +++++++++- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 6407f34e0..9d7594bda 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -46,13 +46,23 @@ impl NodeTrait for CDNNode { fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::CDNPropsRef(&self.props) } - fn set_props<'a>(&mut self, props: NodeProps) -> Result<(), NodeError> { + fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { NodeProps::CDNProps(props) => props, _ => return Err(NodeError::InvalidCDNNodeProps), }; Ok(()) } + fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { + self.props.params = match node_params { + NodeParams::CDNParams(cdn_params) => match cdn_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNNodeParamsExceedsLimit), + }, + _ => return Err(NodeError::InvalidCDNNodeParams), + }; + Ok(()) + } fn get_cluster_id(&self) -> &Option { &self.cluster_id } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f4565caff..207805258 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -49,6 +49,7 @@ pub mod pallet { pub enum Event { NodeCreated { node_type: u8, node_pub_key: NodePubKey }, NodeRemoved { node_type: u8, node_pub_key: NodePubKey }, + NodeParamsChanged { node_type: u8, node_pub_key: NodePubKey }, } #[pallet::error] @@ -78,8 +79,8 @@ pub mod pallet { impl Pallet { #[pallet::weight(10_000)] pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { - let provider_id = ensure_signed(origin)?; - let node = Node::::new(provider_id, node_params) + let caller_id = ensure_signed(origin)?; + let node = Node::::new(caller_id, node_params) .map_err(|e| Into::>::into(NodeError::from(e)))?; let node_type = node.get_type(); let node_pub_key = node.get_pub_key().to_owned(); @@ -93,19 +94,40 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn remove_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { - let provider_id = ensure_signed(origin)?; + let caller_id = ensure_signed(origin)?; let node = Self::get(node_pub_key.clone()) .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; - ensure!(node.get_provider_id() == &provider_id, Error::::OnlyNodeProvider); + ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); Self::remove(node_pub_key.clone()) .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; - Self::deposit_event(Event::::NodeCreated { + Self::deposit_event(Event::::NodeRemoved { node_pub_key, node_type: node.get_type().into(), }); Ok(()) } + + #[pallet::weight(10_000)] + pub fn set_node_params( + origin: OriginFor, + node_pub_key: NodePubKey, + node_params: NodeParams, + ) -> DispatchResult { + let caller_id = ensure_signed(origin)?; + let mut node = Self::get(node_pub_key.clone()) + .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); + node.set_params(node_params) + .map_err(|e| Into::>::into(NodeError::from(e)))?; + let node_type = node.get_type(); + Self::update(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + Self::deposit_event(Event::::NodeParamsChanged { + node_pub_key, + node_type: node_type.into(), + }); + Ok(()) + } } pub trait NodeRepository { diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index fc1b530f4..85e93e419 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -14,12 +14,14 @@ pub enum Node { CDN(CDNNode), } +// Params fields are always coming from extrinsic input #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeParams { StorageParams(StorageNodeParams), CDNParams(CDNNodeParams), } +// Props fields may include internal protocol properties #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeProps { StorageProps(StorageNodeProps), @@ -59,7 +61,8 @@ pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; fn get_provider_id(&self) -> &ProviderId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; - fn set_props<'a>(&mut self, props: NodeProps) -> Result<(), NodeError>; + fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; + fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; fn get_cluster_id(&self) -> &Option; fn set_cluster_id(&mut self, cluster_id: ClusterId); fn get_type(&self) -> NodeType; @@ -91,6 +94,12 @@ impl NodeTrait for Node { Node::CDN(node) => node.set_props(props), } } + fn set_params(&mut self, params: NodeParams) -> Result<(), NodeError> { + match self { + Node::Storage(node) => node.set_params(params), + Node::CDN(node) => node.set_params(params), + } + } fn get_cluster_id(&self) -> &Option { match &self { Node::Storage(node) => node.get_cluster_id(), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index e22d95ccf..f89f3c113 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -46,13 +46,23 @@ impl NodeTrait for StorageNode { fn get_props<'a>(&'a self) -> NodePropsRef<'a> { NodePropsRef::StoragePropsRef(&self.props) } - fn set_props<'a>(&mut self, props: NodeProps) -> Result<(), NodeError> { + fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { NodeProps::StorageProps(props) => props, _ => return Err(NodeError::InvalidStorageNodeProps), }; Ok(()) } + fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { + self.props.params = match node_params { + NodeParams::StorageParams(cdn_params) => match cdn_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), + }, + _ => return Err(NodeError::InvalidStorageNodeParams), + }; + Ok(()) + } fn get_cluster_id(&self) -> &Option { &self.cluster_id } From e1eb800b043f7fa540025c53c97e96ec22f12b00 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 17:46:19 +0200 Subject: [PATCH 355/544] chore: separate node public key from its parameters --- pallets/ddc-nodes/src/cdn_node.rs | 32 ++++++++++++++----------- pallets/ddc-nodes/src/lib.rs | 33 ++++++++++---------------- pallets/ddc-nodes/src/node.rs | 23 ++++++++++++++---- pallets/ddc-nodes/src/storage_node.rs | 34 +++++++++++++++------------ 4 files changed, 68 insertions(+), 54 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 9d7594bda..ac4c55f4f 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,6 +1,7 @@ use crate::{ node::{ - Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, + Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKey, NodePubKeyRef, NodeTrait, + NodeType, }, ClusterId, }; @@ -32,7 +33,6 @@ pub struct CDNNodeProps { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeParams { - pub pub_key: CDNNodePubKey, pub params: Vec, // should be replaced with specific parameters for this type of node } @@ -73,22 +73,26 @@ impl NodeTrait for CDNNode { NodeType::CDN } fn new( + node_pub_key: NodePubKey, provider_id: ProviderId, node_params: NodeParams, ) -> Result, NodeError> { - match node_params { - NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { - provider_id, - pub_key: node_params.pub_key, - cluster_id: None, - props: CDNNodeProps { - params: match node_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNNodeParamsExceedsLimit), + match node_pub_key { + NodePubKey::CDNPubKey(pub_key) => match node_params { + NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { + provider_id, + pub_key, + cluster_id: None, + props: CDNNodeProps { + params: match node_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNNodeParamsExceedsLimit), + }, }, - }, - })), - _ => Err(NodeError::InvalidCDNNodeParams), + })), + _ => Err(NodeError::InvalidCDNNodeParams), + }, + _ => Err(NodeError::InvalidCDNNodePubKey), } } } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 207805258..7c9fbe2ef 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -47,15 +47,16 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - NodeCreated { node_type: u8, node_pub_key: NodePubKey }, - NodeRemoved { node_type: u8, node_pub_key: NodePubKey }, - NodeParamsChanged { node_type: u8, node_pub_key: NodePubKey }, + NodeCreated { node_pub_key: NodePubKey }, + NodeRemoved { node_pub_key: NodePubKey }, + NodeParamsChanged { node_pub_key: NodePubKey }, } #[pallet::error] pub enum Error { NodeAlreadyExists, NodeDoesNotExist, + InvalidNodePubKey, InvalidNodeParams, NodeParamsExceedsLimit, OnlyNodeProvider, @@ -78,17 +79,16 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::weight(10_000)] - pub fn create_node(origin: OriginFor, node_params: NodeParams) -> DispatchResult { + pub fn create_node( + origin: OriginFor, + node_pub_key: NodePubKey, + node_params: NodeParams, + ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let node = Node::::new(caller_id, node_params) + let node = Node::::new(node_pub_key.clone(), caller_id, node_params) .map_err(|e| Into::>::into(NodeError::from(e)))?; - let node_type = node.get_type(); - let node_pub_key = node.get_pub_key().to_owned(); Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; - Self::deposit_event(Event::::NodeCreated { - node_pub_key, - node_type: node_type.into(), - }); + Self::deposit_event(Event::::NodeCreated { node_pub_key }); Ok(()) } @@ -101,10 +101,7 @@ pub mod pallet { ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); Self::remove(node_pub_key.clone()) .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; - Self::deposit_event(Event::::NodeRemoved { - node_pub_key, - node_type: node.get_type().into(), - }); + Self::deposit_event(Event::::NodeRemoved { node_pub_key }); Ok(()) } @@ -120,12 +117,8 @@ pub mod pallet { ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); node.set_params(node_params) .map_err(|e| Into::>::into(NodeError::from(e)))?; - let node_type = node.get_type(); Self::update(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; - Self::deposit_event(Event::::NodeParamsChanged { - node_pub_key, - node_type: node_type.into(), - }); + Self::deposit_event(Event::::NodeParamsChanged { node_pub_key }); Ok(()) } } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 85e93e419..89b51d16d 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -66,7 +66,11 @@ pub trait NodeTrait { fn get_cluster_id(&self) -> &Option; fn set_cluster_id(&mut self, cluster_id: ClusterId); fn get_type(&self) -> NodeType; - fn new(provider_id: ProviderId, params: NodeParams) -> Result, NodeError>; + fn new( + node_pub_key: NodePubKey, + provider_id: ProviderId, + params: NodeParams, + ) -> Result, NodeError>; } impl NodeTrait for Node { @@ -118,10 +122,15 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_type(), } } - fn new(provider_id: ProviderId, params: NodeParams) -> Result, NodeError> { - match params { - NodeParams::StorageParams(_) => StorageNode::new(provider_id, params), - NodeParams::CDNParams(_) => CDNNode::new(provider_id, params), + fn new( + node_pub_key: NodePubKey, + provider_id: ProviderId, + node_params: NodeParams, + ) -> Result, NodeError> { + match node_pub_key { + NodePubKey::StoragePubKey(_) => + StorageNode::new(node_pub_key, provider_id, node_params), + NodePubKey::CDNPubKey(_) => CDNNode::new(node_pub_key, provider_id, node_params), } } } @@ -153,6 +162,8 @@ impl TryFrom for NodeType { } pub enum NodeError { + InvalidStorageNodePubKey, + InvalidCDNNodePubKey, InvalidStorageNodeParams, InvalidCDNNodeParams, StorageNodeParamsExceedsLimit, @@ -164,6 +175,8 @@ pub enum NodeError { impl From for Error { fn from(error: NodeError) -> Self { match error { + NodeError::InvalidStorageNodePubKey => Error::::InvalidNodePubKey, + NodeError::InvalidCDNNodePubKey => Error::::InvalidNodePubKey, NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, NodeError::StorageNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index f89f3c113..25de65043 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,6 +1,7 @@ use crate::{ node::{ - Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, + Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKey, NodePubKeyRef, NodeTrait, + NodeType, }, ClusterId, }; @@ -32,7 +33,6 @@ pub struct StorageNodeProps { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeParams { - pub pub_key: StorageNodePubKey, pub params: Vec, // should be replaced with specific parameters for this type of node } @@ -73,23 +73,27 @@ impl NodeTrait for StorageNode { NodeType::Storage } fn new( + node_pub_key: NodePubKey, provider_id: ProviderId, node_params: NodeParams, ) -> Result, NodeError> { - match node_params { - NodeParams::StorageParams(node_params) => - Ok(Node::Storage(StorageNode:: { - provider_id, - pub_key: node_params.pub_key, - cluster_id: None, - props: StorageNodeProps { - params: match node_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), + match node_pub_key { + NodePubKey::StoragePubKey(pub_key) => match node_params { + NodeParams::StorageParams(node_params) => + Ok(Node::Storage(StorageNode:: { + provider_id, + pub_key, + cluster_id: None, + props: StorageNodeProps { + params: match node_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), + }, }, - }, - })), - _ => Err(NodeError::InvalidStorageNodeParams), + })), + _ => Err(NodeError::InvalidStorageNodeParams), + }, + _ => Err(NodeError::InvalidStorageNodePubKey), } } } From 35bf0432fdfa4e781b7e55053731dd8b24ce3bb0 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 22:11:12 +0200 Subject: [PATCH 356/544] feat: storing node keys in cluster double-map --- pallets/ddc-clusters/src/lib.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 63ee41050..ec7344223 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -16,10 +16,8 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; -use sp_std::prelude::*; - pub use pallet::*; +use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; mod cluster; pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; @@ -43,6 +41,7 @@ pub mod pallet { #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { ClusterCreated { cluster_id: ClusterId }, + ClusterNodeAdded { cluster_id: ClusterId, node_pub_key: NodePubKey }, } #[pallet::error] @@ -51,13 +50,26 @@ pub mod pallet { ClusterDoesNotExist, ClusterParamsExceedsLimit, AttemptToAddNonExistentNode, + NodeIsAlreadyAssigned, } #[pallet::storage] - #[pallet::getter(fn storage_nodes)] + #[pallet::getter(fn clusters)] pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; + #[pallet::storage] + #[pallet::getter(fn clusters_nodes)] + pub type ClustersNodes = StorageDoubleMap< + _, + Blake2_128Concat, + ClusterId, + Blake2_128Concat, + NodePubKey, + bool, + ValueQuery, + >; + #[pallet::call] impl Pallet { #[pallet::weight(10_000)] @@ -67,9 +79,8 @@ pub mod pallet { cluster_params: ClusterParams, ) -> DispatchResult { let manager_id = ensure_signed(origin)?; - let cluster = Cluster::new(cluster_id, manager_id, cluster_params) + let cluster = Cluster::new(cluster_id.clone(), manager_id, cluster_params) .map_err(|e| Into::>::into(ClusterError::from(e)))?; - let cluster_id = cluster.cluster_id.clone(); ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); @@ -86,8 +97,16 @@ pub mod pallet { ensure!(Clusters::::contains_key(&cluster_id), Error::::ClusterDoesNotExist); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToAddNonExistentNode)?; - node.set_cluster_id(cluster_id); + ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); + + // todo: check that node is authorized by the 'NodeProviderAuthSC' contract + // todo: check that node provider has a bond for this 'cluster_id' and 'node_pub_key' + + node.set_cluster_id(cluster_id.clone()); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; + ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); + Self::deposit_event(Event::::ClusterNodeAdded { cluster_id, node_pub_key }); + Ok(()) } } From 1fbede8f90c2fb2f8a67b976f9812e4dfc81c085 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 13 Oct 2023 23:36:49 +0200 Subject: [PATCH 357/544] feat: removing node from a cluster --- pallets/ddc-clusters/src/lib.rs | 25 ++++++++++++++++++++++++- pallets/ddc-nodes/src/cdn_node.rs | 4 ++-- pallets/ddc-nodes/src/node.rs | 4 ++-- pallets/ddc-nodes/src/storage_node.rs | 4 ++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index ec7344223..033a57cf0 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -42,6 +42,7 @@ pub mod pallet { pub enum Event { ClusterCreated { cluster_id: ClusterId }, ClusterNodeAdded { cluster_id: ClusterId, node_pub_key: NodePubKey }, + ClusterNodeRemoved { cluster_id: ClusterId, node_pub_key: NodePubKey }, } #[pallet::error] @@ -50,7 +51,9 @@ pub mod pallet { ClusterDoesNotExist, ClusterParamsExceedsLimit, AttemptToAddNonExistentNode, + AttemptToRemoveNonExistentNode, NodeIsAlreadyAssigned, + NodeIsNotAssigned, } #[pallet::storage] @@ -102,12 +105,32 @@ pub mod pallet { // todo: check that node is authorized by the 'NodeProviderAuthSC' contract // todo: check that node provider has a bond for this 'cluster_id' and 'node_pub_key' - node.set_cluster_id(cluster_id.clone()); + node.set_cluster_id(Some(cluster_id.clone())); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); Self::deposit_event(Event::::ClusterNodeAdded { cluster_id, node_pub_key }); Ok(()) } + + #[pallet::weight(10_000)] + pub fn remove_node( + origin: OriginFor, + cluster_id: ClusterId, + node_pub_key: NodePubKey, + ) -> DispatchResult { + ensure_signed(origin)?; + ensure!(Clusters::::contains_key(&cluster_id), Error::::ClusterDoesNotExist); + let mut node = T::NodeRepository::get(node_pub_key.clone()) + .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; + ensure!(node.get_cluster_id() == &Some(cluster_id), Error::::NodeIsNotAssigned); + node.set_cluster_id(None); + T::NodeRepository::update(node) + .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; + ClustersNodes::::remove(cluster_id.clone(), node_pub_key.clone()); + Self::deposit_event(Event::::ClusterNodeRemoved { cluster_id, node_pub_key }); + + Ok(()) + } } } diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index ac4c55f4f..d237d3c5c 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -66,8 +66,8 @@ impl NodeTrait for CDNNode { fn get_cluster_id(&self) -> &Option { &self.cluster_id } - fn set_cluster_id(&mut self, cluster_id: ClusterId) { - self.cluster_id = Some(cluster_id); + fn set_cluster_id(&mut self, cluster_id: Option) { + self.cluster_id = cluster_id; } fn get_type(&self) -> NodeType { NodeType::CDN diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 89b51d16d..bb564fc65 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -64,7 +64,7 @@ pub trait NodeTrait { fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; fn get_cluster_id(&self) -> &Option; - fn set_cluster_id(&mut self, cluster_id: ClusterId); + fn set_cluster_id(&mut self, cluster_id: Option); fn get_type(&self) -> NodeType; fn new( node_pub_key: NodePubKey, @@ -110,7 +110,7 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_cluster_id(), } } - fn set_cluster_id(&mut self, cluster_id: ClusterId) { + fn set_cluster_id(&mut self, cluster_id: Option) { match self { Node::Storage(node) => node.set_cluster_id(cluster_id), Node::CDN(node) => node.set_cluster_id(cluster_id), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 25de65043..8276c446a 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -66,8 +66,8 @@ impl NodeTrait for StorageNode { fn get_cluster_id(&self) -> &Option { &self.cluster_id } - fn set_cluster_id(&mut self, cluster_id: ClusterId) { - self.cluster_id = Some(cluster_id); + fn set_cluster_id(&mut self, cluster_id: Option) { + self.cluster_id = cluster_id; } fn get_type(&self) -> NodeType { NodeType::Storage From 9a66fb81b5cb04e40eefd5de671b468d67023a19 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 14 Oct 2023 00:01:37 +0200 Subject: [PATCH 358/544] feat: setting cluster non-sensetive params --- pallets/ddc-clusters/src/cluster.rs | 36 +++++++++++++++++++++-------- pallets/ddc-clusters/src/lib.rs | 30 ++++++++++++++++++++---- pallets/ddc-nodes/src/lib.rs | 12 +++++----- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 58144292b..ec8ac01e3 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -11,30 +11,33 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct Cluster { +pub struct Cluster { pub cluster_id: ClusterId, - pub manager_id: ManagerId, - pub props: ClusterProps, + pub manager_id: AccountId, + pub props: ClusterProps, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct ClusterProps { +pub struct ClusterProps { // this is a temporal way of storing cluster parameters as a stringified json, // should be replaced with specific properties for cluster pub params: BoundedVec, + pub node_provider_auth_contract: AccountId, } +// ClusterParams includes Governance non-sensetive parameters only #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct ClusterParams { +pub struct ClusterParams { pub params: Vec, + pub node_provider_auth_contract: AccountId, } -impl Cluster { +impl Cluster { pub fn new( cluster_id: ClusterId, - manager_id: ManagerId, - cluster_params: ClusterParams, - ) -> Result, ClusterError> { + manager_id: AccountId, + cluster_params: ClusterParams, + ) -> Result, ClusterError> { Ok(Cluster { cluster_id, manager_id, @@ -43,9 +46,24 @@ impl Cluster { Ok(vec) => vec, Err(_) => return Err(ClusterError::ClusterParamsExceedsLimit), }, + node_provider_auth_contract: cluster_params.node_provider_auth_contract, }, }) } + + pub fn set_params( + &mut self, + cluster_params: ClusterParams, + ) -> Result<(), ClusterError> { + self.props = ClusterProps { + params: match cluster_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(ClusterError::ClusterParamsExceedsLimit), + }, + node_provider_auth_contract: cluster_params.node_provider_auth_contract, + }; + Ok(()) + } } pub enum ClusterError { diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 033a57cf0..6ed90d9e3 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -43,6 +43,7 @@ pub mod pallet { ClusterCreated { cluster_id: ClusterId }, ClusterNodeAdded { cluster_id: ClusterId, node_pub_key: NodePubKey }, ClusterNodeRemoved { cluster_id: ClusterId, node_pub_key: NodePubKey }, + ClusterParamsSet { cluster_id: ClusterId }, } #[pallet::error] @@ -54,6 +55,7 @@ pub mod pallet { AttemptToRemoveNonExistentNode, NodeIsAlreadyAssigned, NodeIsNotAssigned, + OnlyClusterManager, } #[pallet::storage] @@ -79,11 +81,11 @@ pub mod pallet { pub fn create_cluster( origin: OriginFor, cluster_id: ClusterId, - cluster_params: ClusterParams, + cluster_params: ClusterParams, ) -> DispatchResult { - let manager_id = ensure_signed(origin)?; - let cluster = Cluster::new(cluster_id.clone(), manager_id, cluster_params) - .map_err(|e| Into::>::into(ClusterError::from(e)))?; + let caller_id = ensure_signed(origin)?; + let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); @@ -132,5 +134,25 @@ pub mod pallet { Ok(()) } + + // Sets Governance non-sensetive parameters only + #[pallet::weight(10_000)] + pub fn set_cluster_params( + origin: OriginFor, + cluster_id: ClusterId, + cluster_params: ClusterParams, + ) -> DispatchResult { + let caller_id = ensure_signed(origin)?; + let mut cluster = + Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); + cluster + .set_params(cluster_params) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + Clusters::::insert(cluster_id.clone(), cluster); + Self::deposit_event(Event::::ClusterParamsSet { cluster_id }); + + Ok(()) + } } } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 7c9fbe2ef..c91881bd8 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -48,7 +48,7 @@ pub mod pallet { #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { NodeCreated { node_pub_key: NodePubKey }, - NodeRemoved { node_pub_key: NodePubKey }, + NodeDeleted { node_pub_key: NodePubKey }, NodeParamsChanged { node_pub_key: NodePubKey }, } @@ -93,15 +93,15 @@ pub mod pallet { } #[pallet::weight(10_000)] - pub fn remove_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { + pub fn delete_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { let caller_id = ensure_signed(origin)?; let node = Self::get(node_pub_key.clone()) .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); - Self::remove(node_pub_key.clone()) + Self::delete(node_pub_key.clone()) .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; - Self::deposit_event(Event::::NodeRemoved { node_pub_key }); + Self::deposit_event(Event::::NodeDeleted { node_pub_key }); Ok(()) } @@ -127,7 +127,7 @@ pub mod pallet { fn create(node: Node) -> Result<(), NodeRepositoryError>; fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError>; fn update(node: Node) -> Result<(), NodeRepositoryError>; - fn remove(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError>; + fn delete(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError>; } pub enum NodeRepositoryError { @@ -199,7 +199,7 @@ pub mod pallet { Ok(()) } - fn remove(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError> { + fn delete(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => { StorageNodes::::remove(pub_key); From 064bfba654679cf1fc97599a98d04a0d942c332b Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 17 Oct 2023 00:39:49 +0400 Subject: [PATCH 359/544] fix: checking for cluster manager permissions while adding and removing a node from a cluster --- pallets/ddc-clusters/src/lib.rs | 12 ++++++++---- pallets/ddc-nodes/src/cdn_node.rs | 14 +++++++------- pallets/ddc-nodes/src/node.rs | 22 +++++++++++----------- pallets/ddc-nodes/src/storage_node.rs | 14 +++++++------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6ed90d9e3..894e7e33e 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -98,8 +98,10 @@ pub mod pallet { cluster_id: ClusterId, node_pub_key: NodePubKey, ) -> DispatchResult { - ensure_signed(origin)?; - ensure!(Clusters::::contains_key(&cluster_id), Error::::ClusterDoesNotExist); + let caller_id = ensure_signed(origin)?; + let cluster = + Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToAddNonExistentNode)?; ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); @@ -121,8 +123,10 @@ pub mod pallet { cluster_id: ClusterId, node_pub_key: NodePubKey, ) -> DispatchResult { - ensure_signed(origin)?; - ensure!(Clusters::::contains_key(&cluster_id), Error::::ClusterDoesNotExist); + let caller_id = ensure_signed(origin)?; + let cluster = + Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; ensure!(node.get_cluster_id() == &Some(cluster_id), Error::::NodeIsNotAssigned); diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index d237d3c5c..96de56918 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -17,9 +17,9 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNode { +pub struct CDNNode { pub pub_key: CDNNodePubKey, - pub provider_id: ProviderId, + pub provider_id: AccountId, pub cluster_id: Option, pub props: CDNNodeProps, } @@ -36,11 +36,11 @@ pub struct CDNNodeParams { pub params: Vec, // should be replaced with specific parameters for this type of node } -impl NodeTrait for CDNNode { +impl NodeTrait for CDNNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::CDNPubKeyRef(&self.pub_key) } - fn get_provider_id(&self) -> &ProviderId { + fn get_provider_id(&self) -> &AccountId { &self.provider_id } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { @@ -74,12 +74,12 @@ impl NodeTrait for CDNNode { } fn new( node_pub_key: NodePubKey, - provider_id: ProviderId, + provider_id: AccountId, node_params: NodeParams, - ) -> Result, NodeError> { + ) -> Result, NodeError> { match node_pub_key { NodePubKey::CDNPubKey(pub_key) => match node_params { - NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { + NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { provider_id, pub_key, cluster_id: None, diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index bb564fc65..db3cb78b6 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -9,9 +9,9 @@ use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum Node { - Storage(StorageNode), - CDN(CDNNode), +pub enum Node { + Storage(StorageNode), + CDN(CDNNode), } // Params fields are always coming from extrinsic input @@ -57,9 +57,9 @@ pub enum NodePropsRef<'a> { CDNPropsRef(&'a CDNNodeProps), } -pub trait NodeTrait { +pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; - fn get_provider_id(&self) -> &ProviderId; + fn get_provider_id(&self) -> &AccountId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; @@ -68,19 +68,19 @@ pub trait NodeTrait { fn get_type(&self) -> NodeType; fn new( node_pub_key: NodePubKey, - provider_id: ProviderId, + provider_id: AccountId, params: NodeParams, - ) -> Result, NodeError>; + ) -> Result, NodeError>; } -impl NodeTrait for Node { +impl NodeTrait for Node { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { match &self { Node::Storage(node) => node.get_pub_key(), Node::CDN(node) => node.get_pub_key(), } } - fn get_provider_id(&self) -> &ProviderId { + fn get_provider_id(&self) -> &AccountId { match &self { Node::Storage(node) => node.get_provider_id(), Node::CDN(node) => node.get_provider_id(), @@ -124,9 +124,9 @@ impl NodeTrait for Node { } fn new( node_pub_key: NodePubKey, - provider_id: ProviderId, + provider_id: AccountId, node_params: NodeParams, - ) -> Result, NodeError> { + ) -> Result, NodeError> { match node_pub_key { NodePubKey::StoragePubKey(_) => StorageNode::new(node_pub_key, provider_id, node_params), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 8276c446a..74167bdc8 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -17,9 +17,9 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct StorageNode { +pub struct StorageNode { pub pub_key: StorageNodePubKey, - pub provider_id: ProviderId, + pub provider_id: AccountId, pub cluster_id: Option, pub props: StorageNodeProps, } @@ -36,11 +36,11 @@ pub struct StorageNodeParams { pub params: Vec, // should be replaced with specific parameters for this type of node } -impl NodeTrait for StorageNode { +impl NodeTrait for StorageNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::StoragePubKeyRef(&self.pub_key) } - fn get_provider_id(&self) -> &ProviderId { + fn get_provider_id(&self) -> &AccountId { &self.provider_id } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { @@ -74,13 +74,13 @@ impl NodeTrait for StorageNode { } fn new( node_pub_key: NodePubKey, - provider_id: ProviderId, + provider_id: AccountId, node_params: NodeParams, - ) -> Result, NodeError> { + ) -> Result, NodeError> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => match node_params { NodeParams::StorageParams(node_params) => - Ok(Node::Storage(StorageNode:: { + Ok(Node::Storage(StorageNode:: { provider_id, pub_key, cluster_id: None, From 49b0c057a1117652f1948a26724f6aa98df86459 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 16 Oct 2023 18:55:58 +0600 Subject: [PATCH 360/544] Add extension contract address field to `Cluster` --- pallets/ddc-clusters/src/cluster.rs | 3 +++ pallets/ddc-clusters/src/lib.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index ec8ac01e3..876a9f9c7 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -15,6 +15,7 @@ pub struct Cluster { pub cluster_id: ClusterId, pub manager_id: AccountId, pub props: ClusterProps, + pub extension_smart_contract: AccountId, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -37,6 +38,7 @@ impl Cluster { cluster_id: ClusterId, manager_id: AccountId, cluster_params: ClusterParams, + extension_smart_contract: AccountId, ) -> Result, ClusterError> { Ok(Cluster { cluster_id, @@ -48,6 +50,7 @@ impl Cluster { }, node_provider_auth_contract: cluster_params.node_provider_auth_contract, }, + extension_smart_contract, }) } diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 894e7e33e..16c27921b 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -82,10 +82,16 @@ pub mod pallet { origin: OriginFor, cluster_id: ClusterId, cluster_params: ClusterParams, + extension_smart_contract: T::AccountId, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + let cluster = Cluster::new( + cluster_id.clone(), + caller_id, + cluster_params, + extension_smart_contract, + ) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); From e4f4a49aaa4f73f2087a4eae194ad7b39a268f9d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 16 Oct 2023 18:59:00 +0600 Subject: [PATCH 361/544] Add ddc-nodes tight coupling with contracts pallet --- Cargo.lock | 1 + pallets/ddc-clusters/Cargo.toml | 2 ++ pallets/ddc-clusters/src/lib.rs | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7978f71d..9a0c99ad5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4854,6 +4854,7 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-contracts", "pallet-ddc-nodes", "parity-scale-codec", "scale-info", diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 22786b2dd..4a7c75661 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -15,6 +15,7 @@ sp-runtime = { version = "6.0.0", default-features = false, git = "https://githu sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } [dev-dependencies] @@ -29,6 +30,7 @@ std = [ "frame-support/std", "frame-system/std", "frame-benchmarking/std", + "pallet-contracts/std", "scale-info/std", "sp-io/std", "sp-runtime/std", diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 16c27921b..4cf8fd9d7 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -25,6 +25,7 @@ pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; #[frame_support::pallet] pub mod pallet { use super::*; + use pallet_contracts::chain_extension::UncheckedFrom; #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] @@ -32,7 +33,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + pallet_contracts::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type NodeRepository: NodeRepository; } @@ -76,7 +77,10 @@ pub mod pallet { >; #[pallet::call] - impl Pallet { + impl Pallet + where + T::AccountId: UncheckedFrom + AsRef<[u8]>, + { #[pallet::weight(10_000)] pub fn create_cluster( origin: OriginFor, From 5005e1095cd794bcdc22309fe10ff757283a5d04 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 9 Oct 2023 12:15:51 +0600 Subject: [PATCH 362/544] Typo fix --- pallets/ddc-staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index fa05a1ade..5dc48372c 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -271,7 +271,7 @@ pub mod pallet { pub type Edges = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// The map of (wannabe) storage network participants stash keys to the DDC cluster ID they wish - /// to participate into.. + /// to participate into. #[pallet::storage] #[pallet::getter(fn storages)] pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; From 1cd9859a502e3420d409a65f16577807c6d8f70a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:28:53 +0600 Subject: [PATCH 363/544] Add storage item for DDC node ID to stash linking --- pallets/ddc-staking/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 5dc48372c..145241510 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -334,6 +334,11 @@ pub mod pallet { #[pallet::getter(fn cluster_managers)] pub type ClusterManagers = StorageValue<_, Vec, ValueQuery>; + /// Map from DDC node ID to the node operator stash account. + #[pallet::storage] + #[pallet::getter(fn nodes)] + pub type Nodes = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + #[pallet::genesis_config] pub struct GenesisConfig { pub edges: Vec<(T::AccountId, T::AccountId, BalanceOf, ClusterId)>, From 4184684d3ee428059f6b8dfff6729d61c363da1c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:33:35 +0600 Subject: [PATCH 364/544] Add `node` parameter to `bond` extrinsic --- pallets/ddc-staking/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 145241510..8d3fd843e 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -505,6 +505,7 @@ pub mod pallet { pub fn bond( origin: OriginFor, controller: ::Source, + node: ::Source, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let stash = ensure_signed(origin)?; @@ -524,8 +525,17 @@ pub mod pallet { Err(Error::::InsufficientBond)? } + let node = T::Lookup::lookup(node)?; + + // Reject a bond with a known DDC node. + if Nodes::::contains_key(&node) { + Err(Error::::AlreadyPaired)? + } + frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; + Nodes::::insert(&node, &stash); + // You're auto-bonded forever, here. We might improve this by only bonding when // you actually store/serve and remove once you unbond __everything__. >::insert(&stash, &controller); From 2b4660731170e511af26f1323f5b86603544917e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:34:45 +0600 Subject: [PATCH 365/544] Update `AlreadyPaired` error docstring --- pallets/ddc-staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 8d3fd843e..a9f7cf28c 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -447,7 +447,7 @@ pub mod pallet { NotStash, /// Stash is already bonded. AlreadyBonded, - /// Controller is already paired. + /// Controller or node is already paired. AlreadyPaired, /// Cannot have a storage network or CDN participant, with the size less than defined by /// governance (see `BondSize`). If unbonding is the intention, `chill` first to remove From 8a811038f6855fd81bdb8e37d4e12871ecae38c3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:35:23 +0600 Subject: [PATCH 366/544] Add DDC node removal together with its stash --- pallets/ddc-staking/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index a9f7cf28c..4e10301b8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -1036,6 +1036,10 @@ pub mod pallet { >::remove(stash); >::remove(&controller); + if let Some((node, _)) = >::iter().find(|(_, v)| v == stash) { + >::remove(node); + } + Self::do_remove_storage(stash); Self::do_remove_edge(stash); From 463b6b51b44e80853515ce0ac0092c93d60ad64b Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:36:37 +0600 Subject: [PATCH 367/544] Add DDC node ID setter extrinsic --- pallets/ddc-staking/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 4e10301b8..890d9c641 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -921,6 +921,29 @@ pub mod pallet { Ok(()) } + + /// (Re-)set the node operator stash account of a DDC node. + /// + /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. + #[pallet::weight(10_000)] + pub fn set_node( + origin: OriginFor, + node: ::Source, + ) -> DispatchResult { + let stash = ensure_signed(origin)?; + + let node = T::Lookup::lookup(node)?; + + if let Some(existing_node_stash) = Nodes::::get(&node) { + if existing_node_stash != stash { + Err(Error::::AlreadyPaired)? + } + } + + >::insert(node, stash); + + Ok(()) + } } impl Pallet { From 438a346e9bf39759515d0ddd0b8eb99c97be1127 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:37:10 +0600 Subject: [PATCH 368/544] Accept DDC node ID in genesis config --- pallets/ddc-staking/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 890d9c641..dd053381d 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -341,8 +341,8 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { - pub edges: Vec<(T::AccountId, T::AccountId, BalanceOf, ClusterId)>, - pub storages: Vec<(T::AccountId, T::AccountId, BalanceOf, ClusterId)>, + pub edges: Vec<(T::AccountId, T::AccountId, T::AccountId, BalanceOf, ClusterId)>, + pub storages: Vec<(T::AccountId, T::AccountId, T::AccountId, BalanceOf, ClusterId)>, pub settings: Vec<(ClusterId, BalanceOf, EraIndex, BalanceOf, EraIndex)>, } @@ -381,7 +381,7 @@ pub mod pallet { } // Add initial CDN participants - for &(ref stash, ref controller, balance, cluster) in &self.edges { + for &(ref stash, ref controller, ref node, balance, cluster) in &self.edges { assert!( T::Currency::free_balance(&stash) >= balance, "Stash do not have enough balance to participate in CDN." @@ -389,6 +389,7 @@ pub mod pallet { assert_ok!(Pallet::::bond( T::RuntimeOrigin::from(Some(stash.clone()).into()), T::Lookup::unlookup(controller.clone()), + T::Lookup::unlookup(node.clone()), balance, )); assert_ok!(Pallet::::serve( @@ -398,7 +399,7 @@ pub mod pallet { } // Add initial storage network participants - for &(ref stash, ref controller, balance, cluster) in &self.storages { + for &(ref stash, ref controller, ref node, balance, cluster) in &self.storages { assert!( T::Currency::free_balance(&stash) >= balance, "Stash do not have enough balance to participate in storage network." @@ -406,6 +407,7 @@ pub mod pallet { assert_ok!(Pallet::::bond( T::RuntimeOrigin::from(Some(stash.clone()).into()), T::Lookup::unlookup(controller.clone()), + T::Lookup::unlookup(node.clone()), balance, )); assert_ok!(Pallet::::store( From ceac9da46d0a0a48db932cf9199b1ebdb5ebe4f2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:38:15 +0600 Subject: [PATCH 369/544] Add DDC node ID in existing benchmarks and tests --- pallets/ddc-staking/src/benchmarking.rs | 17 ++++++++------ pallets/ddc-staking/src/mock.rs | 12 +++++----- pallets/ddc-staking/src/testing_utils.rs | 30 +++++++++++++++++------- pallets/ddc-staking/src/tests.rs | 9 +++---- pallets/ddc-validator/src/mock.rs | 8 ++++++- 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index e7a35e87f..25d7ae33a 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -21,19 +21,22 @@ benchmarks! { let controller = create_funded_user::("controller", USER_SEED, 100); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); + let node = create_funded_user::("node", USER_SEED, 100); + let node_lookup: ::Source = T::Lookup::unlookup(node.clone()); let amount = T::Currency::minimum_balance() * 10u32.into(); whitelist_account!(stash); - }: _(RawOrigin::Signed(stash.clone()), controller_lookup, amount) + }: _(RawOrigin::Signed(stash.clone()), controller_lookup, node_lookup, amount) verify { assert!(Bonded::::contains_key(stash)); assert!(Ledger::::contains_key(controller)); + assert!(Nodes::::contains_key(node)); } unbond { // clean up any existing state. clear_storages_and_edges::(); - let (stash, controller) = create_stash_controller::(0, 100)?; + let (stash, controller, _) = create_stash_controller_node::(0, 100)?; let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_bonded: BalanceOf = ledger.active; let amount = T::Currency::minimum_balance() * 5u32.into(); // Half of total @@ -47,7 +50,7 @@ benchmarks! { } withdraw_unbonded { - let (stash, controller) = create_stash_controller::(0, 100)?; + let (stash, controller, _) = create_stash_controller_node::(0, 100)?; let amount = T::Currency::minimum_balance() * 5u32.into(); // Half of total DdcStaking::::unbond(RawOrigin::Signed(controller.clone()).into(), amount)?; CurrentEra::::put(EraIndex::max_value()); @@ -62,7 +65,7 @@ benchmarks! { } store { - let (stash, controller) = create_stash_controller_with_balance::(0, T::DefaultStorageBondSize::get())?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultStorageBondSize::get())?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), 1) @@ -71,7 +74,7 @@ benchmarks! { } serve { - let (stash, controller) = create_stash_controller_with_balance::(0, T::DefaultEdgeBondSize::get())?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultEdgeBondSize::get())?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), 1) @@ -83,7 +86,7 @@ benchmarks! { // clean up any existing state. clear_storages_and_edges::(); - let (edge_stash, edge_controller) = create_stash_controller_with_balance::(0, T::DefaultEdgeBondSize::get())?; + let (edge_stash, edge_controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultEdgeBondSize::get())?; DdcStaking::::serve(RawOrigin::Signed(edge_controller.clone()).into(), 1)?; assert!(Edges::::contains_key(&edge_stash)); CurrentEra::::put(1); @@ -97,7 +100,7 @@ benchmarks! { } set_controller { - let (stash, _) = create_stash_controller::(USER_SEED, 100)?; + let (stash, _, _) = create_stash_controller_node::(USER_SEED, 100)?; let new_controller = create_funded_user::("new_controller", USER_SEED, 100); let new_controller_lookup = T::Lookup::unlookup(new_controller.clone()); whitelist_account!(stash); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index c82675b73..3d0dae597 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -195,17 +195,17 @@ impl ExtBuilder { let mut edges = vec![]; if self.has_edges { edges = vec![ - // (stash, controller, stake, cluster) - (11, 10, 100, 1), - (21, 20, 100, 1), + // (stash, controller, node, stake, cluster) + (11, 10, 12, 100, 1), + (21, 20, 22, 100, 1), ]; } let mut storages = vec![]; if self.has_storages { storages = vec![ - // (stash, controller, stake, cluster) - (31, 30, 100, 1), - (41, 40, 100, 1), + // (stash, controller, node, stake, cluster) + (31, 30, 32, 100, 1), + (41, 40, 42, 100, 1), ]; } diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 6d31a4749..4898d7313 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -43,29 +43,43 @@ pub fn create_funded_user_with_balance( } /// Create a stash and controller pair. -pub fn create_stash_controller( +pub fn create_stash_controller_node( n: u32, balance_factor: u32, -) -> Result<(T::AccountId, T::AccountId), &'static str> { +) -> Result<(T::AccountId, T::AccountId, T::AccountId), &'static str> { let stash = create_funded_user::("stash", n, balance_factor); let controller = create_funded_user::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); + let node = create_funded_user::("node", n, balance_factor); + let node_lookup: ::Source = T::Lookup::unlookup(node.clone()); let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); - DdcStaking::::bond(RawOrigin::Signed(stash.clone()).into(), controller_lookup, amount)?; - return Ok((stash, controller)) + DdcStaking::::bond( + RawOrigin::Signed(stash.clone()).into(), + controller_lookup, + node_lookup, + amount, + )?; + return Ok((stash, controller, node)) } /// Create a stash and controller pair with fixed balance. -pub fn create_stash_controller_with_balance( +pub fn create_stash_controller_node_with_balance( n: u32, balance: crate::BalanceOf, -) -> Result<(T::AccountId, T::AccountId), &'static str> { +) -> Result<(T::AccountId, T::AccountId, T::AccountId), &'static str> { let stash = create_funded_user_with_balance::("stash", n, balance); let controller = create_funded_user_with_balance::("controller", n, balance); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); + let node = create_funded_user_with_balance::("node", n, balance); + let node_lookup: ::Source = T::Lookup::unlookup(node.clone()); - DdcStaking::::bond(RawOrigin::Signed(stash.clone()).into(), controller_lookup, balance)?; - Ok((stash, controller)) + DdcStaking::::bond( + RawOrigin::Signed(stash.clone()).into(), + controller_lookup, + node_lookup, + balance, + )?; + Ok((stash, controller, node)) } diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 6d024cf64..17fe47caa 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -109,12 +109,12 @@ fn staking_should_work() { let _ = Balances::make_free_balance_be(&i, 2000); } - // Add new CDN participant, account 3 controlled by 4. - assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, 1500)); + // Add new CDN participant, account 3 controlled by 4 with node 5. + assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, 5, 1500)); assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), 1)); - // Account 4 controls the stash from account 3, which is 1500 units and 3 is a CDN - // participant. + // Account 4 controls the stash from account 3, which is 1500 units, 3 is a CDN + // participant, 5 is a DDC node. assert_eq!(DdcStaking::bonded(&3), Some(4)); assert_eq!( DdcStaking::ledger(&4), @@ -127,6 +127,7 @@ fn staking_should_work() { }) ); assert_eq!(DdcStaking::edges(3), Some(1)); + assert_eq!(DdcStaking::nodes(5), Some(3)); // Set `CurrentEra`. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 00497301c..c358aaab1 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -366,7 +366,13 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let _ = pallet_staking::GenesisConfig:: { stakers, ..Default::default() } .assimilate_storage(&mut storage); - let edges = vec![(AccountId::from([0x1; 32]), AccountId::from([0x11; 32]), 100, 1)]; + let edges = vec![( + AccountId::from([0x1; 32]), + AccountId::from([0x11; 32]), + AccountId::from([0x21; 32]), + 100, + 1, + )]; let storages = vec![]; let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } .assimilate_storage(&mut storage); From ff5ddf0dd63be5467dd4f8f99d2403bd1d62f910 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:38:59 +0600 Subject: [PATCH 370/544] Add DDC node ID setter benchmark --- pallets/ddc-staking/src/benchmarking.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 25d7ae33a..70dde5733 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -109,6 +109,16 @@ benchmarks! { assert!(Ledger::::contains_key(&new_controller)); } + set_node { + let (stash, _, _) = create_stash_controller_node::(USER_SEED, 100)?; + let new_node = create_funded_user::("new_node", USER_SEED, 100); + let new_node_lookup = T::Lookup::unlookup(new_node.clone()); + whitelist_account!(stash); + }: _(RawOrigin::Signed(stash), new_node_lookup) + verify { + assert!(Nodes::::contains_key(&new_node)); + } + allow_cluster_manager { let new_cluster_manager = create_funded_user::("cluster_manager", USER_SEED, 100); let new_cluster_manager_lookup = T::Lookup::unlookup(new_cluster_manager.clone()); From 36d9b112ed115fc464a35f6bf71cfc204b462040 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 12:58:36 +0600 Subject: [PATCH 371/544] Generate weights for `bond` and `set_node` --- pallets/ddc-staking/src/weights.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index acb858060..3b69615ab 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -1,7 +1,7 @@ //! Autogenerated weights for pallet_ddc_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-10-10, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `e14`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 @@ -35,6 +35,7 @@ pub trait WeightInfo { fn serve() -> Weight; fn chill() -> Weight; fn set_controller() -> Weight; + fn set_node() -> Weight; fn allow_cluster_manager() -> Weight; fn disallow_cluster_manager() -> Weight; } @@ -44,11 +45,12 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(49_113_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(55_007_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Edges (r:1 w:0) @@ -105,6 +107,12 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } + // Storage: DdcStaking Nodes (r:1 w:1) + fn set_node() -> Weight { + Weight::from_ref_time(21_779_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } // Storage: DdcStaking ClusterManagers (r:1 w:1) fn allow_cluster_manager() -> Weight { Weight::from_ref_time(11_727_000 as u64) @@ -123,11 +131,12 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(49_113_000 as u64) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(55_007_000 as u64) + .saturating_add(RocksDbWeight::get().reads(4 as u64)) + .saturating_add(RocksDbWeight::get().writes(4 as u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Edges (r:1 w:0) @@ -184,6 +193,12 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } + // Storage: DdcStaking Nodes (r:1 w:1) + fn set_node() -> Weight { + Weight::from_ref_time(21_779_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } // Storage: DdcStaking ClusterManagers (r:1 w:1) fn allow_cluster_manager() -> Weight { Weight::from_ref_time(11_727_000 as u64) From 3c0d4cf5cd21f6ae71349717ffd37678ccb07cd2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 10 Oct 2023 14:01:36 +0600 Subject: [PATCH 372/544] Use generated weight for the `set_node` extrinsic --- pallets/ddc-staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index dd053381d..669571b97 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -927,7 +927,7 @@ pub mod pallet { /// (Re-)set the node operator stash account of a DDC node. /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::set_node())] pub fn set_node( origin: OriginFor, node: ::Source, From d13b5117a0655a70045cc06d92bc1ace6d907e62 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 11 Oct 2023 12:54:05 +0600 Subject: [PATCH 373/544] Set rewards for stash account instead of DDC node --- pallets/ddc-validator/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 117eefe73..8c86cace9 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -991,7 +991,14 @@ pub mod pallet { let tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { era: current_ddc_era - 1, - stakers_points: cdn_nodes_reward_points.clone(), + // Vec<(ddc_node_account), reward) -> Vec<(stash_account, reward)> + stakers_points: cdn_nodes_reward_points + .iter() + .filter_map(|(node_acc, reward)| { + ddc_staking::pallet::Pallet::::nodes(node_acc) + .and_then(|stash_acc| Some((stash_acc, *reward))) + }) + .collect::>(), }); match tx_res { From d79787a50169a5116d3bd1a6f65c589ac2217012 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 12 Oct 2023 14:39:34 +0600 Subject: [PATCH 374/544] Request DAC data by the edge node account --- pallets/ddc-validator/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 8c86cace9..593c344d3 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -812,13 +812,20 @@ pub mod pallet { for assigned_edge in assigned_edges.iter() { log::debug!("assigned edge: {:?}", assigned_edge); + let Some((node, _)) = >::iter().find(|(n, s)| assigned_edge == s) else { + log::debug!("no known node for: {:?}", assigned_edge); + continue; + }; + + log::debug!("assigned edge node: {:?}", assigned_edge); + // form url for each node let edge_url = format!( "{}{}{}/$.{}", data_url, "ddc:dac:aggregation:nodes:", current_ddc_era - 1, - utils::account_to_string::(assigned_edge.clone()) + utils::account_to_string::(node) ); log::debug!("edge url: {:?}", edge_url); From 560ee73da539ff52926ed77dca2f8f90d0fd9d93 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 12 Oct 2023 14:40:06 +0600 Subject: [PATCH 375/544] Set reward points by the edge stash account --- pallets/ddc-validator/src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 593c344d3..5d3b91005 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -998,14 +998,7 @@ pub mod pallet { let tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { era: current_ddc_era - 1, - // Vec<(ddc_node_account), reward) -> Vec<(stash_account, reward)> - stakers_points: cdn_nodes_reward_points - .iter() - .filter_map(|(node_acc, reward)| { - ddc_staking::pallet::Pallet::::nodes(node_acc) - .and_then(|stash_acc| Some((stash_acc, *reward))) - }) - .collect::>(), + stakers_points: cdn_nodes_reward_points.clone(), }); match tx_res { From 49276c452a6fe31dfd641270d322e5b93829544c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 12 Oct 2023 14:41:03 +0600 Subject: [PATCH 376/544] Fix ddc-validation test regression --- pallets/ddc-validator/src/mock.rs | 2 ++ pallets/ddc-validator/src/tests.rs | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index c358aaab1..92b3f3b26 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -317,6 +317,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (AccountId::from([0x1; 32]), 1000), // edge controller (AccountId::from([0x11; 32]), 1000), + // edge node + (AccountId::from([0x21; 32]), 1000), // validator1 stash; has to be equal to the OCW key in the current implementation ( AccountId::from([ diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index fedd3f713..5c8056efd 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -38,8 +38,11 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { t.register_extension(TransactionPoolExt::new(pool)); let era_to_validate: EraIndex = 3; - let cdn_node_to_validate = AccountId::from([0x1; 32]); - let cdn_node_to_validate_str = utils::account_to_string::(cdn_node_to_validate.clone()); + let edge_stash_to_validate = AccountId::from([0x1; 32]); + let edge_stash_to_validate_str = + utils::account_to_string::(edge_stash_to_validate.clone()); + let edge_node_to_validate = AccountId::from([0x21; 32]); + let edge_node_to_validate_str = utils::account_to_string::(edge_node_to_validate.clone()); let validator_1_stash = AccountId::from([ 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, @@ -67,7 +70,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { expect_request( &format!( "{}/JSON.GET/ddc:dac:aggregation:nodes:{}/$.{}", - DEFAULT_DATA_PROVIDER_URL, era_to_validate, cdn_node_to_validate_str + DEFAULT_DATA_PROVIDER_URL, era_to_validate, edge_node_to_validate_str ), include_bytes!("./mock-data/set-1/aggregated-node-data-for-era.json"), ); @@ -116,7 +119,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", DEFAULT_DATA_PROVIDER_URL, OCW_PUB_KEY_STR, - cdn_node_to_validate_str, + edge_stash_to_validate_str, era_to_validate, url_encoded_result_json, ), @@ -195,9 +198,9 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { tx.call, crate::mock::RuntimeCall::DdcValidator(crate::Call::set_validation_decision { era: era_to_validate, - cdn_node: cdn_node_to_validate.clone(), + cdn_node: edge_stash_to_validate.clone(), validation_decision: ValidationDecision { - edge: cdn_node_to_validate_str, + edge: edge_stash_to_validate_str, result: true, payload: utils::hash(&serialized_decisions), totals: DacTotalAggregates { @@ -213,7 +216,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let tx = transactions.pop().unwrap(); let tx = Extrinsic::decode(&mut &*tx).unwrap(); - let stakers_points = vec![(cdn_node_to_validate, common_decision.totals.sent)]; + let stakers_points = vec![(edge_stash_to_validate, common_decision.totals.sent)]; assert!(tx.signature.is_some()); assert_eq!( From 231895784c309fcbd29c316aae8e297f83620512 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 12:55:00 +0600 Subject: [PATCH 377/544] Require idle state to change staking node account --- pallets/ddc-staking/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 669571b97..2a5d4f1ad 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -924,7 +924,7 @@ pub mod pallet { Ok(()) } - /// (Re-)set the node operator stash account of a DDC node. + /// (Re-)set the DDC node of a node operator stash account. Requires to chill first. /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. #[pallet::weight(T::WeightInfo::set_node())] @@ -942,6 +942,10 @@ pub mod pallet { } } + // Ensure only one node per stash during the DDC era. + ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); + >::insert(node, stash); Ok(()) From 792df9e6abe97885b8afaffccc8df3506418e9a8 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 12:56:56 +0600 Subject: [PATCH 378/544] Rename `set_node` extrinsic parameter --- pallets/ddc-staking/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 2a5d4f1ad..b54dbc1a6 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -930,13 +930,13 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_node())] pub fn set_node( origin: OriginFor, - node: ::Source, + new_node: ::Source, ) -> DispatchResult { let stash = ensure_signed(origin)?; - let node = T::Lookup::lookup(node)?; + let new_node = T::Lookup::lookup(new_node)?; - if let Some(existing_node_stash) = Nodes::::get(&node) { + if let Some(existing_node_stash) = Nodes::::get(&new_node) { if existing_node_stash != stash { Err(Error::::AlreadyPaired)? } @@ -946,7 +946,7 @@ pub mod pallet { ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); - >::insert(node, stash); + >::insert(new_node, stash); Ok(()) } From 9950727ecce3c903d71e0f5ab0009f1c0b0eb37d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 15:16:05 +0600 Subject: [PATCH 379/544] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f6b0c20..b5d85401c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument and `--dac-url` argument to specify DAC endpoint. It will only work on the nodes with validation and offchain workers enabled as well. - [D] Several calls for `pallet-ddc-staking` to distribute rewards. +- [D] Third kind of account in DDC Staking for DDC nodes (along with stash and controller). - [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance. - [Zombienet](https://github.com/paritytech/zombienet) configurations to test block building and spawn a network for DDC validation debugging. From 2d6db4741213424a5f68d4515f0613718a2aa081 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 15:17:39 +0600 Subject: [PATCH 380/544] Bump devnet `spec_version` --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index ff5778e9e..3a9719d7c 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48005, + spec_version: 48006, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From 7509f5a218357ea0ba7a532ddda1b2130f70b94f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 12:16:39 +0600 Subject: [PATCH 381/544] Add node auth check to `add_node` extrinsic --- pallets/ddc-clusters/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 4cf8fd9d7..2f52e3c3c 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -57,6 +57,7 @@ pub mod pallet { NodeIsAlreadyAssigned, NodeIsNotAssigned, OnlyClusterManager, + NotAuthorized, } #[pallet::storage] @@ -116,7 +117,21 @@ pub mod pallet { .map_err(|_| Error::::AttemptToAddNonExistentNode)?; ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); - // todo: check that node is authorized by the 'NodeProviderAuthSC' contract + let is_authorized: bool = pallet_contracts::Pallet::::bare_call( + caller_id, + cluster.extension_smart_contract, + Default::default(), + Default::default(), + None, + Vec::from([0x96, 0xb0, 0x45, 0x3e]), // blake2("is_authorized"), https://use.ink/basics/selectors#selector-calculation + false, + ) + .result? + .data + .first() + .is_some_and(|x| *x == 1); + ensure!(is_authorized, Error::::NotAuthorized); + // todo: check that node provider has a bond for this 'cluster_id' and 'node_pub_key' node.set_cluster_id(Some(cluster_id.clone())); From 4cdbd1e46a5bbdf2144c246bcf1455a556d5c096 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 12:18:18 +0600 Subject: [PATCH 382/544] Allow `is_some_and` feature --- pallets/ddc-clusters/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 2f52e3c3c..df1d2d565 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -13,6 +13,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +#![feature(is_some_and)] // ToDo: delete at rustc > 1.70 use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; From 182b4b6b02686017dd18048dabf294f6196ffe10 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 17 Oct 2023 15:53:15 +0600 Subject: [PATCH 383/544] Use `Vec` from `sp_std` prelude --- pallets/ddc-clusters/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index df1d2d565..4f6cf2b05 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -19,6 +19,7 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; +use sp_std::prelude::*; mod cluster; pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; From 2d199ea82a52392d7bdc51692aa8daab1aa7ddd5 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 18 Oct 2023 11:08:32 +0600 Subject: [PATCH 384/544] Remove extension contract addr field duplicate --- pallets/ddc-clusters/src/cluster.rs | 3 --- pallets/ddc-clusters/src/lib.rs | 12 +++--------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 876a9f9c7..ec8ac01e3 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -15,7 +15,6 @@ pub struct Cluster { pub cluster_id: ClusterId, pub manager_id: AccountId, pub props: ClusterProps, - pub extension_smart_contract: AccountId, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -38,7 +37,6 @@ impl Cluster { cluster_id: ClusterId, manager_id: AccountId, cluster_params: ClusterParams, - extension_smart_contract: AccountId, ) -> Result, ClusterError> { Ok(Cluster { cluster_id, @@ -50,7 +48,6 @@ impl Cluster { }, node_provider_auth_contract: cluster_params.node_provider_auth_contract, }, - extension_smart_contract, }) } diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 4f6cf2b05..90827e33f 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -89,16 +89,10 @@ pub mod pallet { origin: OriginFor, cluster_id: ClusterId, cluster_params: ClusterParams, - extension_smart_contract: T::AccountId, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let cluster = Cluster::new( - cluster_id.clone(), - caller_id, - cluster_params, - extension_smart_contract, - ) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); @@ -121,7 +115,7 @@ pub mod pallet { let is_authorized: bool = pallet_contracts::Pallet::::bare_call( caller_id, - cluster.extension_smart_contract, + cluster.props.node_provider_auth_contract, Default::default(), Default::default(), None, From 8915680916a9902dae710215d3e0e5c261345a90 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 18 Oct 2023 17:46:38 +0600 Subject: [PATCH 385/544] A const for the contract auth message selector --- pallets/ddc-clusters/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 90827e33f..edc98608c 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -24,6 +24,11 @@ mod cluster; pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; +/// ink! 4.x selector for the "is_authorized" message, equals to the first four bytes of the +/// blake2("is_authorized"). See also: https://use.ink/basics/selectors#selector-calculation/, +/// https://use.ink/macros-attributes/selector/. +const INK_SELECTOR_IS_AUTHORIZED: [u8; 4] = [0x96, 0xb0, 0x45, 0x3e]; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -119,7 +124,7 @@ pub mod pallet { Default::default(), Default::default(), None, - Vec::from([0x96, 0xb0, 0x45, 0x3e]), // blake2("is_authorized"), https://use.ink/basics/selectors#selector-calculation + Vec::from(INK_SELECTOR_IS_AUTHORIZED), false, ) .result? From f21d7fae46b0b5570c9de3efd45649dc8c49c990 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 19 Oct 2023 17:32:28 +0600 Subject: [PATCH 386/544] Set cluster extension contract call gas limit --- pallets/ddc-clusters/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index edc98608c..6e8a26a04 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -29,6 +29,10 @@ pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; /// https://use.ink/macros-attributes/selector/. const INK_SELECTOR_IS_AUTHORIZED: [u8; 4] = [0x96, 0xb0, 0x45, 0x3e]; +/// The maximum amount of weight that the cluster extension contract call is allowed to consume. +/// See also https://github.com/paritytech/substrate/blob/a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d/frame/contracts/rpc/src/lib.rs#L63. +const EXTENSION_CALL_GAS_LIMIT: Weight = Weight::from_ref_time(5_000_000_000_000); + #[frame_support::pallet] pub mod pallet { use super::*; @@ -122,7 +126,7 @@ pub mod pallet { caller_id, cluster.props.node_provider_auth_contract, Default::default(), - Default::default(), + EXTENSION_CALL_GAS_LIMIT, None, Vec::from(INK_SELECTOR_IS_AUTHORIZED), false, From ef345f196987d01aa41b2cc4babfb79a4fb2af54 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 18 Oct 2023 14:02:47 +0600 Subject: [PATCH 387/544] Add ddc-nodes tight coupling with ddc-staking --- Cargo.lock | 1 + pallets/ddc-clusters/Cargo.toml | 2 ++ pallets/ddc-clusters/src/lib.rs | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9a0c99ad5..9c993136e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4856,6 +4856,7 @@ dependencies = [ "log", "pallet-contracts", "pallet-ddc-nodes", + "pallet-ddc-staking", "parity-scale-codec", "scale-info", "sp-core", diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 4a7c75661..c28f38795 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -17,6 +17,7 @@ sp-std = { version = "4.0.0-dev", default-features = false, git = "https://githu sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } +pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../ddc-staking" } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -31,6 +32,7 @@ std = [ "frame-system/std", "frame-benchmarking/std", "pallet-contracts/std", + "pallet-ddc-staking/std", "scale-info/std", "sp-io/std", "sp-runtime/std", diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6e8a26a04..84daec2fe 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -44,7 +44,9 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_contracts::Config { + pub trait Config: + frame_system::Config + pallet_contracts::Config + pallet_ddc_staking::Config + { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type NodeRepository: NodeRepository; } From 01d1e7fea187cdf1baffb38e78d60d2dd6e3ab29 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 18 Oct 2023 14:04:26 +0600 Subject: [PATCH 388/544] Add DDC stake check to `add_node` extrinsic --- pallets/ddc-clusters/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 84daec2fe..071daeda8 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -71,6 +71,7 @@ pub mod pallet { NodeIsNotAssigned, OnlyClusterManager, NotAuthorized, + NoStake, } #[pallet::storage] @@ -139,7 +140,16 @@ pub mod pallet { .is_some_and(|x| *x == 1); ensure!(is_authorized, Error::::NotAuthorized); - // todo: check that node provider has a bond for this 'cluster_id' and 'node_pub_key' + let node_provider_stash = + >::nodes(&node_pub_key).ok_or(Error::::NoStake)?; + let maybe_edge_in_cluster = + >::edges(&node_provider_stash); + let maybe_storage_in_cluster = + >::storages(&node_provider_stash); + let has_stake = maybe_edge_in_cluster + .or(maybe_storage_in_cluster) + .is_some_and(|staking_cluster| staking_cluster == cluster_id); + ensure!(has_stake, Error::::NoStake); node.set_cluster_id(Some(cluster_id.clone())); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; From 45bfdf192b780e8a8e90ca2b98f5a64f6a1390e2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 19 Oct 2023 11:46:40 +0600 Subject: [PATCH 389/544] New `ddc-primitives` crate with basic DDC entities --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + primitives/Cargo.toml | 23 +++++++++++++++++++++++ primitives/src/lib.rs | 21 +++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 primitives/Cargo.toml create mode 100644 primitives/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 9c993136e..e38563b7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1607,6 +1607,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ddc-primitives" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", +] + [[package]] name = "der" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 9bfa3cfa5..835a9919a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ "pallets/ddc-accounts", "pallets/ddc-nodes", "pallets/ddc-clusters", + "primitives", ] [profile.release] diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml new file mode 100644 index 000000000..178800a4b --- /dev/null +++ b/primitives/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "ddc-primitives" +version = "0.1.0" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +serde = { version = "1.0.136", default-features = false, features = [ "derive" ], optional = true } + +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", + "serde", + "sp-core/std", + "sp-runtime/std", +] +runtime-benchmarks = [] diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs new file mode 100644 index 000000000..de23aa1fd --- /dev/null +++ b/primitives/src/lib.rs @@ -0,0 +1,21 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + +use sp_core::hash::H160; +use sp_runtime::{AccountId32, RuntimeDebug}; + +pub type ClusterId = H160; + +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodePubKey { + StoragePubKey(StorageNodePubKey), + CDNPubKey(CDNNodePubKey), +} + +pub type StorageNodePubKey = AccountId32; +pub type CDNNodePubKey = AccountId32; From 1ef123eee515ca0e2ad56abb96c74191ac1646ff Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 14:21:16 +0600 Subject: [PATCH 390/544] Add `pallet-ddc-clusters` to cere-dev std feature --- runtime/cere-dev/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index a770756e9..71b9c5112 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -188,6 +188,7 @@ std = [ "pallet-ddc-validator/std", "pallet-ddc-accounts/std", "pallet-ddc-nodes/std", + "pallet-ddc-clusters/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", From c07f2c78ad3d0a1eaad509dc953857775ae2b1ff Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:06:03 +0600 Subject: [PATCH 391/544] Use `ddc-primitives` in `ddc-staking` --- pallets/ddc-staking/Cargo.toml | 2 ++ pallets/ddc-staking/src/lib.rs | 24 ++++++++---------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index f6c3b69eb..572a2fd25 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -26,6 +27,7 @@ substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/parity default = ["std"] std = [ "codec/std", + "ddc-primitives/std", "frame-support/std", "frame-system/std", "frame-benchmarking/std", diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index b54dbc1a6..8c394a500 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -28,6 +28,7 @@ pub mod weights; use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; +use ddc_primitives::{ClusterId, NodePubKey}; use frame_support::{ assert_ok, pallet_prelude::*, @@ -66,8 +67,6 @@ pub type RewardPoint = u64; pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -pub type ClusterId = u32; - parameter_types! { /// A limit to the number of pending unlocks an account may have in parallel. pub MaxUnlockingChunks: u32 = 32; @@ -337,12 +336,12 @@ pub mod pallet { /// Map from DDC node ID to the node operator stash account. #[pallet::storage] #[pallet::getter(fn nodes)] - pub type Nodes = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; + pub type Nodes = StorageMap<_, Twox64Concat, NodePubKey, T::AccountId>; #[pallet::genesis_config] pub struct GenesisConfig { - pub edges: Vec<(T::AccountId, T::AccountId, T::AccountId, BalanceOf, ClusterId)>, - pub storages: Vec<(T::AccountId, T::AccountId, T::AccountId, BalanceOf, ClusterId)>, + pub edges: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, + pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, pub settings: Vec<(ClusterId, BalanceOf, EraIndex, BalanceOf, EraIndex)>, } @@ -389,7 +388,7 @@ pub mod pallet { assert_ok!(Pallet::::bond( T::RuntimeOrigin::from(Some(stash.clone()).into()), T::Lookup::unlookup(controller.clone()), - T::Lookup::unlookup(node.clone()), + node.clone(), balance, )); assert_ok!(Pallet::::serve( @@ -407,7 +406,7 @@ pub mod pallet { assert_ok!(Pallet::::bond( T::RuntimeOrigin::from(Some(stash.clone()).into()), T::Lookup::unlookup(controller.clone()), - T::Lookup::unlookup(node.clone()), + node.clone(), balance, )); assert_ok!(Pallet::::store( @@ -507,7 +506,7 @@ pub mod pallet { pub fn bond( origin: OriginFor, controller: ::Source, - node: ::Source, + node: NodePubKey, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let stash = ensure_signed(origin)?; @@ -527,8 +526,6 @@ pub mod pallet { Err(Error::::InsufficientBond)? } - let node = T::Lookup::lookup(node)?; - // Reject a bond with a known DDC node. if Nodes::::contains_key(&node) { Err(Error::::AlreadyPaired)? @@ -928,14 +925,9 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. #[pallet::weight(T::WeightInfo::set_node())] - pub fn set_node( - origin: OriginFor, - new_node: ::Source, - ) -> DispatchResult { + pub fn set_node(origin: OriginFor, new_node: NodePubKey) -> DispatchResult { let stash = ensure_signed(origin)?; - let new_node = T::Lookup::lookup(new_node)?; - if let Some(existing_node_stash) = Nodes::::get(&new_node) { if existing_node_stash != stash { Err(Error::::AlreadyPaired)? From 4a7665418f87d3b282a3b52ae93060ad680f36e2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:06:50 +0600 Subject: [PATCH 392/544] Fix node key conversion to string --- pallets/ddc-validator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 5d3b91005..e7dd27dc2 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -825,7 +825,7 @@ pub mod pallet { data_url, "ddc:dac:aggregation:nodes:", current_ddc_era - 1, - utils::account_to_string::(node) + array_bytes::bytes2hex("", node.encode()), ); log::debug!("edge url: {:?}", edge_url); From 56860750d4d0c450296bed96221cb24d9a2b4999 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:12:50 +0600 Subject: [PATCH 393/544] Minor fixes suggested by warnings --- pallets/ddc-validator/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index e7dd27dc2..ac0bfe531 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -485,7 +485,6 @@ pub mod pallet { stakers_points: Vec<(T::AccountId, u64)>, ) -> DispatchResult { let ddc_valitor_key = ensure_signed(origin)?; - let mut rewards_counter = 0; ensure!( DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), @@ -812,7 +811,7 @@ pub mod pallet { for assigned_edge in assigned_edges.iter() { log::debug!("assigned edge: {:?}", assigned_edge); - let Some((node, _)) = >::iter().find(|(n, s)| assigned_edge == s) else { + let Some((node, _)) = >::iter().find(|(_, s)| assigned_edge == s) else { log::debug!("no known node for: {:?}", assigned_edge); continue; }; From 43b93d31d9d6a94dd2e8b895936ae87a3a6129c5 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:21:07 +0600 Subject: [PATCH 394/544] Use `ddc-primitives` in `ddc-nodes` --- pallets/ddc-nodes/Cargo.toml | 3 +++ pallets/ddc-nodes/src/cdn_node.rs | 12 ++++-------- pallets/ddc-nodes/src/lib.rs | 11 ++++------- pallets/ddc-nodes/src/node.rs | 11 +++-------- pallets/ddc-nodes/src/storage_node.rs | 12 ++++-------- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index d05d85bf2..607ab47fa 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -25,6 +26,7 @@ substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/parity default = ["std"] std = [ "codec/std", + "ddc-primitives/std", "frame-support/std", "frame-system/std", "frame-benchmarking/std", @@ -33,5 +35,6 @@ std = [ "sp-runtime/std", "sp-staking/std", "sp-std/std", + "sp-core/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 96de56918..2bf763e44 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,17 +1,13 @@ -use crate::{ - node::{ - Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKey, NodePubKeyRef, NodeTrait, - NodeType, - }, - ClusterId, +use crate::node::{ + Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, }; use codec::{Decode, Encode}; +use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; -use sp_runtime::{AccountId32, RuntimeDebug}; +use sp_runtime::RuntimeDebug; use sp_std::prelude::*; -pub type CDNNodePubKey = AccountId32; parameter_types! { pub MaxCDNNodeParamsLen: u16 = 2048; } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index c91881bd8..a6ff1b3d4 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -14,9 +14,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, StorageNodePubKey}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -use sp_core::hash::H160; use sp_std::prelude::*; pub use pallet::*; @@ -25,9 +25,9 @@ mod node; mod storage_node; pub use crate::{ - cdn_node::{CDNNode, CDNNodePubKey}, - node::{Node, NodeError, NodeParams, NodePubKey, NodeTrait}, - storage_node::{StorageNode, StorageNodePubKey}, + cdn_node::CDNNode, + node::{Node, NodeError, NodeParams, NodeTrait}, + storage_node::StorageNode, }; #[frame_support::pallet] @@ -73,9 +73,6 @@ pub mod pallet { pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; - // todo: add the type to the Config - pub type ClusterId = H160; - #[pallet::call] impl Pallet { #[pallet::weight(10_000)] diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index db3cb78b6..e571cfe85 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,10 +1,11 @@ use crate::{ - cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps, CDNNodePubKey}, + cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps}, pallet::Error, - storage_node::{StorageNode, StorageNodeParams, StorageNodeProps, StorageNodePubKey}, + storage_node::{StorageNode, StorageNodeParams, StorageNodeProps}, ClusterId, }; use codec::{Decode, Encode}; +use ddc_primitives::{CDNNodePubKey, NodePubKey, StorageNodePubKey}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -28,12 +29,6 @@ pub enum NodeProps { CDNProps(CDNNodeProps), } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum NodePubKey { - StoragePubKey(StorageNodePubKey), - CDNPubKey(CDNNodePubKey), -} - #[derive(Clone, RuntimeDebug, PartialEq)] pub enum NodePubKeyRef<'a> { StoragePubKeyRef(&'a StorageNodePubKey), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 74167bdc8..92b867391 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,17 +1,13 @@ -use crate::{ - node::{ - Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKey, NodePubKeyRef, NodeTrait, - NodeType, - }, - ClusterId, +use crate::node::{ + Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, }; use codec::{Decode, Encode}; +use ddc_primitives::{ClusterId, NodePubKey, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; -use sp_runtime::{AccountId32, RuntimeDebug}; +use sp_runtime::RuntimeDebug; use sp_std::prelude::Vec; -pub type StorageNodePubKey = AccountId32; parameter_types! { pub MaxStorageNodeParamsLen: u16 = 2048; } From eb0acaefb7767858108ca4f4252ea1f8f21d649c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:22:46 +0600 Subject: [PATCH 395/544] Use `ddc-primitives` in `ddc-clusters` --- pallets/ddc-clusters/Cargo.toml | 2 ++ pallets/ddc-clusters/src/cluster.rs | 3 +-- pallets/ddc-clusters/src/lib.rs | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index c28f38795..4810f9b16 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -28,6 +29,7 @@ substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/parity default = ["std"] std = [ "codec/std", + "ddc-primitives/std", "frame-support/std", "frame-system/std", "frame-benchmarking/std", diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index ec8ac01e3..862c42ddf 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -1,11 +1,10 @@ use crate::pallet::Error; use codec::{Decode, Encode}; +use ddc_primitives::ClusterId; use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; use scale_info::TypeInfo; -use sp_core::hash::H160; use sp_std::vec::Vec; -pub type ClusterId = H160; parameter_types! { pub MaxClusterParamsLen: u16 = 2048; } diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 071daeda8..e4131c0fe 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -15,14 +15,15 @@ #![recursion_limit = "256"] #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 +use ddc_primitives::{ClusterId, NodePubKey}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; pub use pallet::*; -use pallet_ddc_nodes::{NodePubKey, NodeRepository, NodeTrait}; +use pallet_ddc_nodes::{NodeRepository, NodeTrait}; use sp_std::prelude::*; mod cluster; -pub use crate::cluster::{Cluster, ClusterError, ClusterId, ClusterParams}; +pub use crate::cluster::{Cluster, ClusterError, ClusterParams}; /// ink! 4.x selector for the "is_authorized" message, equals to the first four bytes of the /// blake2("is_authorized"). See also: https://use.ink/basics/selectors#selector-calculation/, From a426fd13a608436ed6a81f5ac355a1f4c8b66dde Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:23:05 +0600 Subject: [PATCH 396/544] Add missing std feature dependencies --- pallets/ddc-clusters/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 4810f9b16..a7ed43bdf 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -34,8 +34,10 @@ std = [ "frame-system/std", "frame-benchmarking/std", "pallet-contracts/std", + "pallet-ddc-nodes/std", "pallet-ddc-staking/std", "scale-info/std", + "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-staking/std", From 6fce399cda41c7c9fd6fc3143f50859d6f2a4e94 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:24:34 +0600 Subject: [PATCH 397/544] Update `Cargo.lock` --- Cargo.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e38563b7c..9fcf86474 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1613,6 +1613,7 @@ version = "0.1.0" dependencies = [ "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-runtime", ] @@ -4860,6 +4861,7 @@ dependencies = [ name = "pallet-ddc-clusters" version = "4.8.1" dependencies = [ + "ddc-primitives", "frame-benchmarking", "frame-support", "frame-system", @@ -4908,6 +4910,7 @@ dependencies = [ name = "pallet-ddc-nodes" version = "4.8.1" dependencies = [ + "ddc-primitives", "frame-benchmarking", "frame-support", "frame-system", @@ -4927,6 +4930,7 @@ dependencies = [ name = "pallet-ddc-staking" version = "4.8.1" dependencies = [ + "ddc-primitives", "frame-benchmarking", "frame-support", "frame-system", From 6df62e71497bd2ccbd1dcf153ce63d14f4922021 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:37:52 +0600 Subject: [PATCH 398/544] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5d85401c..975dd715d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [D] Third kind of account in DDC Staking for DDC nodes (along with stash and controller). - [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance. - [Zombienet](https://github.com/paritytech/zombienet) configurations to test block building and spawn a network for DDC validation debugging. +- New `ddc-primitives` crate with DDC common types definition ### Changed From d192dada2af0b8b72cefedb730dc0327e849aa19 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 16:39:32 +0600 Subject: [PATCH 399/544] Bump `cere-dev` runtime `spec_version` --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3a9719d7c..d71e17e5c 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48006, + spec_version: 48007, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From 5b38f6992c3e0575658b43994e67fc30558e3836 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 20 Oct 2023 18:45:49 +0600 Subject: [PATCH 400/544] Fix `runtime-benchmarks` build and tests --- Cargo.lock | 1 + pallets/ddc-staking/src/benchmarking.rs | 19 ++++++------- pallets/ddc-staking/src/lib.rs | 2 +- pallets/ddc-staking/src/mock.rs | 33 +++++++++++++++++++--- pallets/ddc-staking/src/testing_utils.rs | 15 +++++----- pallets/ddc-staking/src/tests.rs | 35 +++++++++++++++--------- pallets/ddc-validator/Cargo.toml | 1 + pallets/ddc-validator/src/mock.rs | 7 ++--- pallets/ddc-validator/src/tests.rs | 5 ++-- 9 files changed, 76 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fcf86474..669a99063 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4955,6 +4955,7 @@ dependencies = [ "alt_serde", "array-bytes 6.1.0", "base64 0.21.2", + "ddc-primitives", "frame-election-provider-support", "frame-support", "frame-system", diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 70dde5733..f5454fc99 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -2,6 +2,7 @@ use super::*; use crate::Pallet as DdcStaking; +use ddc_primitives::CDNNodePubKey; use testing_utils::*; use frame_support::traits::{Currency, Get}; @@ -21,11 +22,10 @@ benchmarks! { let controller = create_funded_user::("controller", USER_SEED, 100); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = create_funded_user::("node", USER_SEED, 100); - let node_lookup: ::Source = T::Lookup::unlookup(node.clone()); + let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); let amount = T::Currency::minimum_balance() * 10u32.into(); whitelist_account!(stash); - }: _(RawOrigin::Signed(stash.clone()), controller_lookup, node_lookup, amount) + }: _(RawOrigin::Signed(stash.clone()), controller_lookup, node.clone(), amount) verify { assert!(Bonded::::contains_key(stash)); assert!(Ledger::::contains_key(controller)); @@ -68,7 +68,7 @@ benchmarks! { let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultStorageBondSize::get())?; whitelist_account!(controller); - }: _(RawOrigin::Signed(controller), 1) + }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) verify { assert!(Storages::::contains_key(&stash)); } @@ -77,7 +77,7 @@ benchmarks! { let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultEdgeBondSize::get())?; whitelist_account!(controller); - }: _(RawOrigin::Signed(controller), 1) + }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) verify { assert!(Edges::::contains_key(&stash)); } @@ -87,11 +87,11 @@ benchmarks! { clear_storages_and_edges::(); let (edge_stash, edge_controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultEdgeBondSize::get())?; - DdcStaking::::serve(RawOrigin::Signed(edge_controller.clone()).into(), 1)?; + DdcStaking::::serve(RawOrigin::Signed(edge_controller.clone()).into(), ClusterId::from([1; 20]))?; assert!(Edges::::contains_key(&edge_stash)); CurrentEra::::put(1); DdcStaking::::chill(RawOrigin::Signed(edge_controller.clone()).into())?; - CurrentEra::::put(1 + Settings::::get(1).edge_chill_delay); + CurrentEra::::put(1 + Settings::::get(ClusterId::from([1; 20])).edge_chill_delay); whitelist_account!(edge_controller); }: _(RawOrigin::Signed(edge_controller)) @@ -111,10 +111,9 @@ benchmarks! { set_node { let (stash, _, _) = create_stash_controller_node::(USER_SEED, 100)?; - let new_node = create_funded_user::("new_node", USER_SEED, 100); - let new_node_lookup = T::Lookup::unlookup(new_node.clone()); + let new_node = NodePubKey::CDNPubKey(CDNNodePubKey::new([1; 32])); whitelist_account!(stash); - }: _(RawOrigin::Signed(stash), new_node_lookup) + }: _(RawOrigin::Signed(stash), new_node.clone()) verify { assert!(Nodes::::contains_key(&new_node)); } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 8c394a500..c349b3271 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -28,7 +28,7 @@ pub mod weights; use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; -use ddc_primitives::{ClusterId, NodePubKey}; +pub use ddc_primitives::{ClusterId, NodePubKey}; use frame_support::{ assert_ok, pallet_prelude::*, diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 3d0dae597..48d046fb6 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -3,6 +3,7 @@ #![allow(dead_code)] use crate::{self as pallet_ddc_staking, *}; +use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; use frame_support::{ construct_runtime, traits::{ConstU32, ConstU64, Everything, GenesisBuild}, @@ -196,16 +197,40 @@ impl ExtBuilder { if self.has_edges { edges = vec![ // (stash, controller, node, stake, cluster) - (11, 10, 12, 100, 1), - (21, 20, 22, 100, 1), + ( + 11, + 10, + NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])), + 100, + ClusterId::from([1; 20]), + ), + ( + 21, + 20, + NodePubKey::CDNPubKey(CDNNodePubKey::new([22; 32])), + 100, + ClusterId::from([1; 20]), + ), ]; } let mut storages = vec![]; if self.has_storages { storages = vec![ // (stash, controller, node, stake, cluster) - (31, 30, 32, 100, 1), - (41, 40, 42, 100, 1), + ( + 31, + 30, + NodePubKey::StoragePubKey(StorageNodePubKey::new([32; 32])), + 100, + ClusterId::from([1; 20]), + ), + ( + 41, + 40, + NodePubKey::StoragePubKey(StorageNodePubKey::new([42; 32])), + 100, + ClusterId::from([1; 20]), + ), ]; } diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 4898d7313..74e61221c 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -1,6 +1,7 @@ //! Testing utils for ddc-staking. use crate::{Pallet as DdcStaking, *}; +use ddc_primitives::CDNNodePubKey; use frame_benchmarking::account; use frame_system::RawOrigin; @@ -46,18 +47,17 @@ pub fn create_funded_user_with_balance( pub fn create_stash_controller_node( n: u32, balance_factor: u32, -) -> Result<(T::AccountId, T::AccountId, T::AccountId), &'static str> { +) -> Result<(T::AccountId, T::AccountId, NodePubKey), &'static str> { let stash = create_funded_user::("stash", n, balance_factor); let controller = create_funded_user::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = create_funded_user::("node", n, balance_factor); - let node_lookup: ::Source = T::Lookup::unlookup(node.clone()); + let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); DdcStaking::::bond( RawOrigin::Signed(stash.clone()).into(), controller_lookup, - node_lookup, + node.clone(), amount, )?; return Ok((stash, controller, node)) @@ -67,18 +67,17 @@ pub fn create_stash_controller_node( pub fn create_stash_controller_node_with_balance( n: u32, balance: crate::BalanceOf, -) -> Result<(T::AccountId, T::AccountId, T::AccountId), &'static str> { +) -> Result<(T::AccountId, T::AccountId, NodePubKey), &'static str> { let stash = create_funded_user_with_balance::("stash", n, balance); let controller = create_funded_user_with_balance::("controller", n, balance); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = create_funded_user_with_balance::("node", n, balance); - let node_lookup: ::Source = T::Lookup::unlookup(node.clone()); + let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); DdcStaking::::bond( RawOrigin::Signed(stash.clone()).into(), controller_lookup, - node_lookup, + node.clone(), balance, )?; Ok((stash, controller, node)) diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 17fe47caa..2af19cce0 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,6 +1,7 @@ //! Tests for the module. use super::{mock::*, *}; +use ddc_primitives::CDNNodePubKey; use frame_support::{ assert_noop, assert_ok, assert_storage_noop, error::BadOrigin, traits::ReservableCurrency, }; @@ -15,7 +16,7 @@ fn set_settings_works() { // setting works assert_ok!(DdcStaking::set_settings( RuntimeOrigin::root(), - 1, + ClusterId::from([1; 20]), Some(ClusterSettings { edge_bond_size: 10, edge_chill_delay: 2, @@ -23,15 +24,15 @@ fn set_settings_works() { storage_chill_delay: 2, }), )); - let settings = DdcStaking::settings(1); + let settings = DdcStaking::settings(ClusterId::from([1; 20])); assert_eq!(settings.edge_bond_size, 10); assert_eq!(settings.edge_chill_delay, 2); assert_eq!(settings.storage_bond_size, 10); assert_eq!(settings.storage_chill_delay, 2); // removing works - assert_ok!(DdcStaking::set_settings(RuntimeOrigin::root(), 1, None)); - let settings = DdcStaking::settings(1); + assert_ok!(DdcStaking::set_settings(RuntimeOrigin::root(), ClusterId::from([1; 20]), None)); + let settings = DdcStaking::settings(ClusterId::from([1; 20])); let default_settings: ClusterSettings = Default::default(); assert_eq!(settings.edge_bond_size, default_settings.edge_bond_size); assert_eq!(settings.edge_chill_delay, default_settings.edge_chill_delay); @@ -77,7 +78,7 @@ fn basic_setup_works() { assert_eq!(DdcStaking::ledger(&1), None); // Cluster 1 settings are default - assert_eq!(DdcStaking::settings(1), Default::default()); + assert_eq!(DdcStaking::settings(ClusterId::from([1; 20])), Default::default()); }); } @@ -95,9 +96,12 @@ fn change_controller_works() { assert_eq!(DdcStaking::bonded(&11), Some(3)); // 10 is no longer in control. - assert_noop!(DdcStaking::serve(RuntimeOrigin::signed(10), 1), Error::::NotController); + assert_noop!( + DdcStaking::serve(RuntimeOrigin::signed(10), ClusterId::from([1; 20])), + Error::::NotController + ); // 3 is a new controller. - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), 1)); + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), ClusterId::from([1; 20]))); }) } @@ -110,8 +114,13 @@ fn staking_should_work() { } // Add new CDN participant, account 3 controlled by 4 with node 5. - assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, 5, 1500)); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), 1)); + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 1500 + )); + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([0; 20]))); // Account 4 controls the stash from account 3, which is 1500 units, 3 is a CDN // participant, 5 is a DDC node. @@ -126,8 +135,8 @@ fn staking_should_work() { unlocking: Default::default(), }) ); - assert_eq!(DdcStaking::edges(3), Some(1)); - assert_eq!(DdcStaking::nodes(5), Some(3)); + assert_eq!(DdcStaking::edges(3), Some(ClusterId::from([0; 20]))); + assert_eq!(DdcStaking::nodes(NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32]))), Some(3)); // Set `CurrentEra`. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); @@ -137,8 +146,8 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. - let chilling = - DdcStaking::current_era().unwrap() + DdcStaking::settings(1).edge_chill_delay; + let chilling = DdcStaking::current_era().unwrap() + + DdcStaking::settings(ClusterId::from([0; 20])).edge_chill_delay; assert_eq!( DdcStaking::ledger(&4), Some(StakingLedger { diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 886e6cfa6..d1ceeec47 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -33,6 +33,7 @@ pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/ pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +ddc-primitives = { version = "0.1.0", path = "../../primitives" } [features] default = ["std"] diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 92b3f3b26..085469277 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -1,4 +1,5 @@ use crate::{self as pallet_ddc_validator, *}; +use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey}; use frame_election_provider_support::{onchain, SequentialPhragmen}; use frame_support::{ parameter_types, @@ -317,8 +318,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (AccountId::from([0x1; 32]), 1000), // edge controller (AccountId::from([0x11; 32]), 1000), - // edge node - (AccountId::from([0x21; 32]), 1000), // validator1 stash; has to be equal to the OCW key in the current implementation ( AccountId::from([ @@ -371,9 +370,9 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let edges = vec![( AccountId::from([0x1; 32]), AccountId::from([0x11; 32]), - AccountId::from([0x21; 32]), + NodePubKey::CDNPubKey(CDNNodePubKey::new([0x21; 32])), 100, - 1, + ClusterId::from([1; 20]), )]; let storages = vec![]; let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 5c8056efd..fc537b88a 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -6,6 +6,7 @@ use crate::{ Error as ValidatorError, }; use codec::Decode; +use ddc_primitives::{CDNNodePubKey, NodePubKey}; use frame_support::{assert_noop, assert_ok}; use pallet_ddc_accounts::{BucketsDetails, Error as AccountsError}; use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; @@ -41,8 +42,8 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { let edge_stash_to_validate = AccountId::from([0x1; 32]); let edge_stash_to_validate_str = utils::account_to_string::(edge_stash_to_validate.clone()); - let edge_node_to_validate = AccountId::from([0x21; 32]); - let edge_node_to_validate_str = utils::account_to_string::(edge_node_to_validate.clone()); + let edge_node_to_validate = NodePubKey::CDNPubKey(CDNNodePubKey::new([0x21; 32])); + let edge_node_to_validate_str = array_bytes::bytes2hex("", edge_node_to_validate.encode()); let validator_1_stash = AccountId::from([ 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, From a4efa99b2e5ed00f1ca88cb34583009f7cb97869 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 18:26:15 +0600 Subject: [PATCH 401/544] Add `clippy` component to the toolchain file --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 9bcb924a2..bcf909e27 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2022-10-09" -components = [ "rustfmt" ] +components = [ "clippy", "rustfmt" ] targets = [ "wasm32-unknown-unknown" ] From 625913c4b2578bad2969908b43c9430bb374d70a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 23 Oct 2023 16:57:58 +0600 Subject: [PATCH 402/544] Add clippy config --- .cargo/config.toml | 31 +++++++++++++++++++++++++++++++ .gitignore | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..fc82ca587 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,31 @@ +# An auto defined `clippy` feature was introduced, +# but it was found to clash with user defined features, +# so was renamed to `cargo-clippy`. +# +# If you want standard clippy run: +# RUSTFLAGS= cargo clippy +[target.'cfg(feature = "cargo-clippy")'] +rustflags = [ + "-Aclippy::all", + "-Dclippy::correctness", + "-Aclippy::if-same-then-else", + "-Aclippy::clone-double-ref", + "-Dclippy::complexity", + "-Aclippy::zero-prefixed-literal", # 00_1000_000 + "-Aclippy::type_complexity", # raison d'etre + "-Aclippy::nonminimal-bool", # maybe + "-Aclippy::borrowed-box", # Reasonable to fix this one + "-Aclippy::too-many-arguments", # (Turning this on would lead to) + "-Aclippy::unnecessary_cast", # Types may change + "-Aclippy::identity-op", # One case where we do 0 + + "-Aclippy::useless_conversion", # Types may change + "-Aclippy::unit_arg", # styalistic. + "-Aclippy::option-map-unit-fn", # styalistic + "-Aclippy::bind_instead_of_map", # styalistic + "-Aclippy::erasing_op", # E.g. 0 * DOLLARS + "-Aclippy::eq_op", # In tests we test equality. + "-Aclippy::while_immutable_condition", # false positives + "-Aclippy::needless_option_as_deref", # false positives + "-Aclippy::derivable_impls", # false positives + "-Aclippy::stable_sort_primitive", # prefer stable sort +] diff --git a/.gitignore b/.gitignore index 90db35e94..6dd97a7f6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ .DS_Store # The cache for docker container dependency -.cargo +.cargo/** +!/.cargo/config.toml # The cache for chain data in container .local From 8c3d4dbc4116ac4a10d7f8acaf0b14d0eb0b9d09 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 23 Oct 2023 12:30:18 +0600 Subject: [PATCH 403/544] Disable clippy linter in legacy pallets --- pallets/chainbridge/src/lib.rs | 1 + pallets/ddc-metrics-offchain-worker/src/lib.rs | 2 +- pallets/ddc/src/lib.rs | 1 + pallets/erc20/src/lib.rs | 1 + pallets/erc721/src/lib.rs | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index 1e48b4a7d..562b54566 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/pallets/ddc-metrics-offchain-worker/src/lib.rs b/pallets/ddc-metrics-offchain-worker/src/lib.rs index 991fdabb2..7f68798ab 100644 --- a/pallets/ddc-metrics-offchain-worker/src/lib.rs +++ b/pallets/ddc-metrics-offchain-worker/src/lib.rs @@ -1,7 +1,7 @@ // Offchain worker for DDC metrics. // // Inspired from https://github.com/paritytech/substrate/tree/master/frame/example-offchain-worker - +#![allow(clippy::all)] #![cfg_attr(not(feature = "std"), no_std)] #[cfg(test)] diff --git a/pallets/ddc/src/lib.rs b/pallets/ddc/src/lib.rs index e1d572af6..8308b880c 100644 --- a/pallets/ddc/src/lib.rs +++ b/pallets/ddc/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] #![cfg_attr(not(feature = "std"), no_std)] use frame_support::{ diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index a9474ae2f..e025c5177 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index c5b7244d7..7d93c96f9 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] From 66520f979eaa3904aaf21ae2460874c3eb803d6d Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 23 Oct 2023 15:52:40 +0600 Subject: [PATCH 404/544] Suppress `clippy::needless_lifetimes` in ddc-nodes --- pallets/ddc-nodes/src/cdn_node.rs | 2 ++ pallets/ddc-nodes/src/node.rs | 2 ++ pallets/ddc-nodes/src/storage_node.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 2bf763e44..fe499717b 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_lifetimes)] // ToDo + use crate::node::{ Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, }; diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index e571cfe85..4b48d4054 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_lifetimes)] // ToDo + use crate::{ cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps}, pallet::Error, diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 92b867391..d9cd253d1 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_lifetimes)] // ToDo + use crate::node::{ Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, }; From d5d671d1f3edc5bae3d513bf42d1ffda92f2af70 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 18:35:21 +0600 Subject: [PATCH 405/544] Apply `cargo clippy --fix --all` --- cli/src/command.rs | 10 +- node/service/src/lib.rs | 10 +- pallets/chainbridge/src/lib.rs | 20 +-- pallets/chainbridge/src/mock.rs | 2 +- pallets/chainbridge/src/tests.rs | 76 +++++------ pallets/ddc-accounts/src/lib.rs | 4 +- pallets/ddc-clusters/src/lib.rs | 24 ++-- .../ddc-metrics-offchain-worker/src/lib.rs | 20 +-- .../src/tests/mod.rs | 8 +- pallets/ddc-nodes/src/lib.rs | 14 +- pallets/ddc-staking/src/lib.rs | 20 +-- pallets/ddc-staking/src/mock.rs | 2 +- pallets/ddc-staking/src/testing_utils.rs | 2 +- pallets/ddc-staking/src/weights.rs | 120 +++++++++--------- pallets/ddc-validator/src/dac.rs | 26 ++-- pallets/ddc-validator/src/lib.rs | 45 +++---- pallets/ddc-validator/src/shm.rs | 8 +- pallets/ddc-validator/src/tests.rs | 6 +- pallets/ddc-validator/src/utils.rs | 4 +- pallets/ddc/src/lib.rs | 6 +- pallets/erc20/src/lib.rs | 6 +- pallets/erc721/src/lib.rs | 10 +- pallets/erc721/src/tests.rs | 16 +-- runtime/cere-dev/src/impls.rs | 16 +-- runtime/cere-dev/src/lib.rs | 28 ++-- runtime/cere/src/impls.rs | 16 +-- runtime/cere/src/lib.rs | 28 ++-- 27 files changed, 269 insertions(+), 278 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 9865ccf85..665ba9d31 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -67,7 +67,7 @@ impl SubstrateCli for Cli { #[cfg(feature = "cere-native")] { - return &cere_service::cere_runtime::VERSION + &cere_service::cere_runtime::VERSION } #[cfg(not(feature = "cere-native"))] @@ -161,17 +161,17 @@ pub fn run() -> sc_cli::Result<()> { #[cfg(feature = "cere-dev-native")] if chain_spec.is_cere_dev() { - return Ok(runner.sync_run(|config| { + return runner.sync_run(|config| { cmd.run::(config) - })?) + }) } // else we assume it is Cere #[cfg(feature = "cere-native")] { - return Ok(runner.sync_run(|config| { + runner.sync_run(|config| { cmd.run::(config) - })?) + }) } #[cfg(not(feature = "cere-native"))] diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 6988b5641..68e5386a6 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -88,7 +88,7 @@ where let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( - &config, + config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, )?; @@ -287,7 +287,7 @@ pub fn build_full( #[cfg(feature = "cere-native")] { - return new_full::( + new_full::( config, disable_hardware_benchmarks, enable_ddc_validation, @@ -347,7 +347,7 @@ where { let hwbench = if !disable_hardware_benchmarks { config.database.path().map(|database_path| { - let _ = std::fs::create_dir_all(&database_path); + let _ = std::fs::create_dir_all(database_path); sc_sysinfo::gather_hwbench(Some(database_path)) }) } else { @@ -461,7 +461,7 @@ where let proposer = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), - transaction_pool.clone(), + transaction_pool, prometheus_registry.as_ref(), telemetry.as_ref().map(|x| x.handle()), ); @@ -646,7 +646,7 @@ pub fn new_chain_ops( #[cfg(feature = "cere-native")] { - return chain_ops!(config; cere_runtime, CereExecutorDispatch, Cere) + chain_ops!(config; cere_runtime, CereExecutorDispatch, Cere) } #[cfg(not(feature = "cere-native"))] diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index 562b54566..9972be688 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -37,7 +37,7 @@ pub fn derive_resource_id(chain: u8, id: &[u8]) -> ResourceId { for i in 0..range { r_id[30 - i] = id[range - 1 - i]; // Ensure left padding for eth compatibility } - return r_id + r_id } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] @@ -77,7 +77,7 @@ impl ProposalVotes { /// Returns true if `who` has voted for or against the proposal fn has_voted(&self, who: &A) -> bool { - self.votes_for.contains(&who) || self.votes_against.contains(&who) + self.votes_for.contains(who) || self.votes_against.contains(who) } /// Return true if the expiry time has been reached @@ -295,7 +295,7 @@ decl_module! { /// # /// - weight of proposed call, regardless of whether execution is performed /// # - #[weight = (call.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), call.get_dispatch_info().class, Pays::Yes)] + #[weight = (call.get_dispatch_info().weight + Weight::from_ref_time(195_000_000_u64), call.get_dispatch_info().class, Pays::Yes)] pub fn acknowledge_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<::Proposal>) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(Self::is_relayer(&who), Error::::MustBeRelayer); @@ -328,7 +328,7 @@ decl_module! { /// # /// - weight of proposed call, regardless of whether execution is performed /// # - #[weight = (prop.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), prop.get_dispatch_info().class, Pays::Yes)] + #[weight = (prop.get_dispatch_info().weight + Weight::from_ref_time(195_000_000_u64), prop.get_dispatch_info().class, Pays::Yes)] pub fn eval_vote_state(origin, nonce: DepositNonce, src_id: ChainId, prop: Box<::Proposal>) -> DispatchResult { ensure_signed(origin)?; @@ -358,12 +358,12 @@ impl Module { /// Asserts if a resource is registered pub fn resource_exists(id: ResourceId) -> bool { - return Self::resources(id) != None + Self::resources(id).is_some() } /// Checks if a chain exists as a whitelisted destination pub fn chain_whitelisted(id: ChainId) -> bool { - return Self::chains(id) != None + Self::chains(id).is_some() } /// Increments the deposit nonce for the specified chain ID @@ -401,7 +401,7 @@ impl Module { ensure!(id != T::ChainId::get(), Error::::InvalidChainId); // Cannot whitelist with an existing entry ensure!(!Self::chain_whitelisted(id), Error::::ChainAlreadyWhitelisted); - ::insert(&id, 0); + ::insert(id, 0); Self::deposit_event(RawEvent::ChainWhitelisted(id)); Ok(()) } @@ -452,13 +452,13 @@ impl Module { if in_favour { votes.votes_for.push(who.clone()); - Self::deposit_event(RawEvent::VoteFor(src_id, nonce, who.clone())); + Self::deposit_event(RawEvent::VoteFor(src_id, nonce, who)); } else { votes.votes_against.push(who.clone()); - Self::deposit_event(RawEvent::VoteAgainst(src_id, nonce, who.clone())); + Self::deposit_event(RawEvent::VoteAgainst(src_id, nonce, who)); } - >::insert(src_id, (nonce, prop.clone()), votes.clone()); + >::insert(src_id, (nonce, prop), votes.clone()); Ok(()) } diff --git a/pallets/chainbridge/src/mock.rs b/pallets/chainbridge/src/mock.rs index 5e22f6e92..2a3fd20b5 100644 --- a/pallets/chainbridge/src/mock.rs +++ b/pallets/chainbridge/src/mock.rs @@ -152,6 +152,6 @@ pub fn assert_events(mut expected: Vec) { for evt in expected { let next = actual.pop().expect("event expected"); - assert_eq!(next, evt.into(), "Events don't match (actual,expected)"); + assert_eq!(next, evt, "Events don't match (actual,expected)"); } } diff --git a/pallets/chainbridge/src/tests.rs b/pallets/chainbridge/src/tests.rs index bd0ae5a03..ce0e308c0 100644 --- a/pallets/chainbridge/src/tests.rs +++ b/pallets/chainbridge/src/tests.rs @@ -137,50 +137,50 @@ fn asset_transfer_success() { let token_id = vec![1, 2, 3, 4]; let method = "Erc20.transfer".as_bytes().to_vec(); - assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), resource_id, method.clone())); + assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), resource_id, method)); assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); - assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id.clone())); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id)); assert_ok!(Bridge::transfer_fungible( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, to.clone(), amount.into() )); assert_events(vec![ - RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(dest_id.clone())), + RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(dest_id)), RuntimeEvent::Bridge(RawEvent::FungibleTransfer( - dest_id.clone(), + dest_id, 1, - resource_id.clone(), + resource_id, amount.into(), to.clone(), )), ]); assert_ok!(Bridge::transfer_nonfungible( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, token_id.clone(), to.clone(), metadata.clone() )); assert_events(vec![RuntimeEvent::Bridge(RawEvent::NonFungibleTransfer( - dest_id.clone(), + dest_id, 2, - resource_id.clone(), + resource_id, token_id, - to.clone(), + to, metadata.clone(), ))]); assert_ok!(Bridge::transfer_generic( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, metadata.clone() )); assert_events(vec![RuntimeEvent::Bridge(RawEvent::GenericTransfer( - dest_id.clone(), + dest_id, 3, resource_id, metadata, @@ -197,13 +197,13 @@ fn asset_transfer_invalid_resource_id() { let amount = 100; assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); - assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id.clone())); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id)); assert_noop!( Bridge::transfer_fungible( - dest_id.clone(), - resource_id.clone(), - to.clone(), + dest_id, + resource_id, + to, amount.into() ), Error::::ResourceDoesNotExist @@ -211,8 +211,8 @@ fn asset_transfer_invalid_resource_id() { assert_noop!( Bridge::transfer_nonfungible( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, vec![], vec![], vec![] @@ -221,7 +221,7 @@ fn asset_transfer_invalid_resource_id() { ); assert_noop!( - Bridge::transfer_generic(dest_id.clone(), resource_id.clone(), vec![]), + Bridge::transfer_generic(dest_id, resource_id, vec![]), Error::::ResourceDoesNotExist ); }) @@ -234,21 +234,21 @@ fn asset_transfer_invalid_chain() { let bad_dest_id = 3; let resource_id = [4; 32]; - assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), chain_id.clone())); - assert_events(vec![RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(chain_id.clone()))]); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), chain_id)); + assert_events(vec![RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(chain_id))]); assert_noop!( - Bridge::transfer_fungible(bad_dest_id, resource_id.clone(), vec![], U256::zero()), + Bridge::transfer_fungible(bad_dest_id, resource_id, vec![], U256::zero()), Error::::ChainNotWhitelisted ); assert_noop!( - Bridge::transfer_nonfungible(bad_dest_id, resource_id.clone(), vec![], vec![], vec![]), + Bridge::transfer_nonfungible(bad_dest_id, resource_id, vec![], vec![], vec![]), Error::::ChainNotWhitelisted ); assert_noop!( - Bridge::transfer_generic(bad_dest_id, resource_id.clone(), vec![]), + Bridge::transfer_generic(bad_dest_id, resource_id, vec![]), Error::::ChainNotWhitelisted ); }) @@ -310,7 +310,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -327,7 +327,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -344,7 +344,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A, RELAYER_C], votes_against: vec![RELAYER_B], @@ -380,7 +380,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -397,7 +397,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -414,7 +414,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B, RELAYER_C], @@ -452,7 +452,7 @@ fn execute_after_threshold_change() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -472,7 +472,7 @@ fn execute_after_threshold_change() { Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -510,7 +510,7 @@ fn proposal_expires() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -535,7 +535,7 @@ fn proposal_expires() { ); // Proposal state should remain unchanged - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -554,7 +554,7 @@ fn proposal_expires() { ), Error::::ProposalExpired ); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-accounts/src/lib.rs index e988cdd0f..4968204f3 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-accounts/src/lib.rs @@ -314,7 +314,7 @@ pub mod pallet { unlocking: Default::default(), }; Self::update_ledger_and_deposit(&stash, &controller, &item)?; - Self::deposit_event(Event::::Deposited(stash.clone(), value)); + Self::deposit_event(Event::::Deposited(stash, value)); Ok(()) } @@ -346,7 +346,7 @@ pub mod pallet { Self::update_ledger_and_deposit(&stash, &controller, &ledger)?; - Self::deposit_event(Event::::Deposited(stash.clone(), extra)); + Self::deposit_event(Event::::Deposited(stash, extra)); Ok(()) } diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index e4131c0fe..7d3499d4a 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -104,10 +104,10 @@ pub mod pallet { cluster_params: ClusterParams, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); - Clusters::::insert(cluster_id.clone(), cluster); + let cluster = Cluster::new(cluster_id, caller_id, cluster_params) + .map_err(Into::>::into)?; + ensure!(!Clusters::::contains_key(cluster_id), Error::::ClusterAlreadyExists); + Clusters::::insert(cluster_id, cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); Ok(()) } @@ -120,7 +120,7 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToAddNonExistentNode)?; @@ -152,9 +152,9 @@ pub mod pallet { .is_some_and(|staking_cluster| staking_cluster == cluster_id); ensure!(has_stake, Error::::NoStake); - node.set_cluster_id(Some(cluster_id.clone())); + node.set_cluster_id(Some(cluster_id)); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; - ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); + ClustersNodes::::insert(cluster_id, node_pub_key.clone(), true); Self::deposit_event(Event::::ClusterNodeAdded { cluster_id, node_pub_key }); Ok(()) @@ -168,7 +168,7 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; @@ -176,7 +176,7 @@ pub mod pallet { node.set_cluster_id(None); T::NodeRepository::update(node) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; - ClustersNodes::::remove(cluster_id.clone(), node_pub_key.clone()); + ClustersNodes::::remove(cluster_id, node_pub_key.clone()); Self::deposit_event(Event::::ClusterNodeRemoved { cluster_id, node_pub_key }); Ok(()) @@ -191,12 +191,12 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let mut cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); cluster .set_params(cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - Clusters::::insert(cluster_id.clone(), cluster); + .map_err(Into::>::into)?; + Clusters::::insert(cluster_id, cluster); Self::deposit_event(Event::::ClusterParamsSet { cluster_id }); Ok(()) diff --git a/pallets/ddc-metrics-offchain-worker/src/lib.rs b/pallets/ddc-metrics-offchain-worker/src/lib.rs index 7f68798ab..228def0f0 100644 --- a/pallets/ddc-metrics-offchain-worker/src/lib.rs +++ b/pallets/ddc-metrics-offchain-worker/src/lib.rs @@ -19,7 +19,7 @@ use frame_system::offchain::{ }; use hex_literal::hex; -use pallet_contracts; + use sp_core::crypto::{KeyTypeId, UncheckedFrom}; use sp_runtime::{ offchain::{http, storage::StorageValueRef, Duration}, @@ -194,7 +194,7 @@ where }; let should_proceed = Self::check_if_should_proceed(block_number); - if should_proceed == false { + if !should_proceed { return Ok(()) } @@ -246,7 +246,7 @@ where let block_timestamp = sp_io::offchain::timestamp().unix_millis(); if day_end_ms < block_timestamp { - Self::finalize_metric_period(contract_address.clone(), &signer, day_start_ms).map_err( + Self::finalize_metric_period(contract_address, &signer, day_start_ms).map_err( |err| { error!("[OCW] Contract error occurred: {:?}", err); "could not call finalize_metric_period TX" @@ -327,8 +327,8 @@ where fn get_start_of_day_ms() -> u64 { let now = sp_io::offchain::timestamp(); - let day_start_ms = (now.unix_millis() / MS_PER_DAY) * MS_PER_DAY; - day_start_ms + + (now.unix_millis() / MS_PER_DAY) * MS_PER_DAY } fn get_signer() -> ResultStr> { @@ -520,7 +520,7 @@ where account.id, p2p_id, is_online, ); - let call_data = Self::encode_report_ddn_status(&p2p_id, is_online); + let call_data = Self::encode_report_ddn_status(p2p_id, is_online); let contract_id_unl = <::Lookup as StaticLookup>::unlookup( contract_id.clone(), @@ -641,12 +641,12 @@ where "HTTP GET error" })?; - let parsed = serde_json::from_slice(&body).map_err(|err| { + + + serde_json::from_slice(&body).map_err(|err| { warn!("[OCW] Error while parsing JSON from {}: {:?}", url, err); "HTTP JSON parse error" - }); - - parsed + }) } fn http_get_request(http_url: &str) -> Result, http::Error> { diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs index a261b10c8..7480f8ea3 100644 --- a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs +++ b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs @@ -295,7 +295,7 @@ fn should_run_contract() { .unwrap(); let contract_exec_result = pallet_contracts::Pallet::::bare_call( - alice.clone(), + alice, contract_id, 0, Weight::from_ref_time(100_000_000_000), @@ -317,7 +317,7 @@ pub const CTOR_SELECTOR: [u8; 4] = hex!("9bae9d5e"); fn encode_constructor() -> Vec { let mut call_data = CTOR_SELECTOR.to_vec(); - let x = 0 as u128; + let x = 0_u128; for _ in 0..9 { x.encode_to(&mut call_data); } @@ -344,13 +344,13 @@ fn deploy_contract() -> AccountId { GAS_LIMIT, None, wasm.to_vec(), - contract_args.clone(), + contract_args, vec![], ) .unwrap(); // Configure worker with the contract address. - let contract_id = Contracts::contract_address(&alice, &wasm_hash, &vec![]); + let contract_id = Contracts::contract_address(&alice, &wasm_hash, &[]); pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("11a9e1b9"); diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index a6ff1b3d4..2871f1e29 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -83,8 +83,8 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let node = Node::::new(node_pub_key.clone(), caller_id, node_params) - .map_err(|e| Into::>::into(NodeError::from(e)))?; - Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; + Self::create(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeCreated { node_pub_key }); Ok(()) } @@ -93,11 +93,11 @@ pub mod pallet { pub fn delete_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { let caller_id = ensure_signed(origin)?; let node = Self::get(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); Self::delete(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; Self::deposit_event(Event::::NodeDeleted { node_pub_key }); Ok(()) } @@ -110,11 +110,11 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let mut node = Self::get(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); node.set_params(node_params) - .map_err(|e| Into::>::into(NodeError::from(e)))?; - Self::update(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; + Self::update(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeParamsChanged { node_pub_key }); Ok(()) } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index c349b3271..ec96bfe27 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -382,7 +382,7 @@ pub mod pallet { // Add initial CDN participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.edges { assert!( - T::Currency::free_balance(&stash) >= balance, + T::Currency::free_balance(stash) >= balance, "Stash do not have enough balance to participate in CDN." ); assert_ok!(Pallet::::bond( @@ -400,7 +400,7 @@ pub mod pallet { // Add initial storage network participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.storages { assert!( - T::Currency::free_balance(&stash) >= balance, + T::Currency::free_balance(stash) >= balance, "Stash do not have enough balance to participate in storage network." ); assert_ok!(Pallet::::bond( @@ -691,10 +691,10 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in CDN if already participating in storage network. - ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::edges(&stash) { + if let Some(current_cluster) = Self::edges(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -725,10 +725,10 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in storage network if already participating in CDN. - ensure!(!Edges::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!Edges::::contains_key(stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::storages(&stash) { + if let Some(current_cluster) = Self::storages(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -949,7 +949,7 @@ pub mod pallet { // ToDo: check that validation is finalised for era let era_reward_points: EraRewardPoints = - >::get(&era); + >::get(era); let price_per_byte: u128 = match Self::pricing() { Some(pricing) => pricing, @@ -991,7 +991,7 @@ pub mod pallet { } Self::deposit_event(Event::::PayoutNodes( era, - era_reward_points.clone(), + era_reward_points, price_per_byte, )); log::debug!("Payout event executed"); @@ -1036,7 +1036,7 @@ pub mod pallet { cluster: ClusterId, can_chill_from: EraIndex, ) { - Ledger::::mutate(&controller, |maybe_ledger| { + Ledger::::mutate(controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { ledger.chilling = Some(can_chill_from) } @@ -1099,7 +1099,7 @@ pub mod pallet { /// Reset the chilling era for a controller. pub fn reset_chilling(controller: &T::AccountId) { - Ledger::::mutate(&controller, |maybe_ledger| { + Ledger::::mutate(controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { ledger.chilling = None } diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 48d046fb6..2278b0148 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -239,7 +239,7 @@ impl ExtBuilder { TestExternalities::new(storage) } - pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + pub fn build_and_execute(self, test: impl FnOnce()) { sp_tracing::try_init_simple(); let mut ext = self.build(); ext.execute_with(test); diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 74e61221c..d2111f297 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -60,7 +60,7 @@ pub fn create_stash_controller_node( node.clone(), amount, )?; - return Ok((stash, controller, node)) + Ok((stash, controller, node)) } /// Create a stash and controller pair with fixed balance. diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 3b69615ab..67f428730 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -48,9 +48,9 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) + Weight::from_ref_time(55_007_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Edges (r:1 w:0) @@ -59,36 +59,36 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000 as u64) - .saturating_add(T::DbWeight::get().reads(6 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(47_727_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(69_750_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Edges (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(26_112_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(26_112_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Edges (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(19_892_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(19_892_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) @@ -96,34 +96,34 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000 as u64) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + Weight::from_ref_time(77_450_000_u64) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(38_521_000_u64) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:1) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(21_779_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking ClusterManagers (r:1 w:1) fn allow_cluster_manager() -> Weight { - Weight::from_ref_time(11_727_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(11_727_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking ClusterManagers (r:1 w:1) fn disallow_cluster_manager() -> Weight { - Weight::from_ref_time(18_006_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(18_006_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -134,9 +134,9 @@ impl WeightInfo for () { // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(4 as u64)) + Weight::from_ref_time(55_007_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Edges (r:1 w:0) @@ -145,36 +145,36 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000 as u64) - .saturating_add(RocksDbWeight::get().reads(6 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(47_727_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(69_750_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Edges (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(26_112_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(26_112_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Edges (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(19_892_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(19_892_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) @@ -182,33 +182,33 @@ impl WeightInfo for () { // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000 as u64) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + Weight::from_ref_time(77_450_000_u64) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000 as u64) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(38_521_000_u64) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:1) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(21_779_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking ClusterManagers (r:1 w:1) fn allow_cluster_manager() -> Weight { - Weight::from_ref_time(11_727_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(11_727_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking ClusterManagers (r:1 w:1) fn disallow_cluster_manager() -> Weight { - Weight::from_ref_time(18_006_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(18_006_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index c23b98588..a2b593182 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -260,12 +260,12 @@ pub fn get_served_bytes_sum(file_requests: &Requests) -> (u64, u64) { fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> u64 { let log_timestamp = chunk.log.timestamp; - let neighbors = get_closer_neighbors(log_timestamp, &ack_timestamps); + let neighbors = get_closer_neighbors(log_timestamp, ack_timestamps); let is_proved = is_lies_within_threshold(log_timestamp, neighbors, FAILED_CONTENT_CONSUMER_THRESHOLD); if is_proved { - return chunk.log.bytes_sent + chunk.log.bytes_sent } else { 0 } @@ -305,7 +305,7 @@ fn is_lies_within_threshold( pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec { log::debug!("fetch_file_request | url: {:?}", url); - let response: FileRequestWrapper = http_get_json(&url).unwrap(); + let response: FileRequestWrapper = http_get_json(url).unwrap(); log::debug!("response.json: {:?}", response.json); let map: Vec = serde_json::from_str(response.json.as_str()).unwrap(); // log::debug!("response.json: {:?}", response.json); @@ -315,7 +315,7 @@ pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec FileRequest { log::debug!("fetch_file_request | url: {:?}", url); - let response: FileRequestWrapper = http_get_json(&url).unwrap(); + let response: FileRequestWrapper = http_get_json(url).unwrap(); log::debug!("response.json: {:?}", response.json); let map: FileRequest = serde_json::from_str(response.json.as_str()).unwrap(); @@ -329,12 +329,12 @@ pub(crate) fn http_get_json(url: &str) -> crate::ResultSt "HTTP GET error" })?; - let parsed = serde_json::from_slice(&body).map_err(|err| { + + + serde_json::from_slice(&body).map_err(|err| { log::warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); "HTTP JSON parse error" - }); - - parsed + }) } fn http_get_request(http_url: &str) -> Result, http::Error> { @@ -365,7 +365,9 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validati let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); - let final_decision = ValidationDecision { + + + ValidationDecision { edge: decision_example.edge.clone(), result: decision_example.result, payload: utils::hash(&serialized_decisions), @@ -375,9 +377,7 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validati failed_by_client: 0, failure_rate: 0, }, - }; - - final_decision + } } fn find_largest_group(decisions: Vec) -> Option> { @@ -404,7 +404,7 @@ fn find_largest_group(decisions: Vec) -> Option half { Some(largest_group) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index ac0bfe531..175ab0b88 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -360,7 +360,7 @@ pub mod pallet { // Skip if DDC validation is not enabled. match StorageValueRef::persistent(ENABLE_DDC_VALIDATION_KEY).get::() { - Ok(Some(enabled)) if enabled == true => (), + Ok(Some(enabled)) if enabled => (), _ => return, } @@ -634,13 +634,7 @@ pub mod pallet { let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); - return if percentage_difference >= 0.0 && - (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 - { - true - } else { - false - } + percentage_difference >= 0.0 && (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 } /// Shuffle the `list` swapping it's random elements `list.len()` times. @@ -678,7 +672,7 @@ pub mod pallet { let validators: Vec = DDCValidatorToStashKeys::::iter_keys().collect(); log::debug!("Current validators: {:?}.", validators); - if validators.len() == 0 { + if validators.is_empty() { return Err(AssignmentError::NoValidators) } @@ -692,7 +686,7 @@ pub mod pallet { let edges: Vec = >::iter_keys().collect(); log::debug!("Current edges: {:?}.", edges); - if edges.len() == 0 { + if edges.is_empty() { return Ok(()) } @@ -725,7 +719,7 @@ pub mod pallet { }); } - return Ok(()) + Ok(()) } /// Randomly choose a number in range `[0, total)`. @@ -764,7 +758,7 @@ pub mod pallet { } fn find_validators_from_quorum(validator_id: &T::AccountId, era: &EraIndex) -> Vec { - let validator_edges = Self::assignments(era, &validator_id).unwrap(); + let validator_edges = Self::assignments(era, validator_id).unwrap(); let mut quorum_members: Vec = Vec::new(); >::iter_prefix(era).for_each(|(candidate_id, edges)| { @@ -778,10 +772,7 @@ pub mod pallet { } fn get_public_key() -> Option { - match sr25519_public_keys(KEY_TYPE).first() { - Some(pubkey) => Some(T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()), - None => None, - } + sr25519_public_keys(KEY_TYPE).first().map(|pubkey| T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()) } fn validate_edges() -> Result<(), &'static str> { @@ -832,7 +823,7 @@ pub mod pallet { log::debug!("node aggregates: {:?}", node_aggregates); // No data for node - if node_aggregates.len() == 0 { + if node_aggregates.is_empty() { continue } @@ -848,8 +839,8 @@ pub mod pallet { let file_request = dac::fetch_file_request(&request_id_url); requests.insert(file_request.file_request_id.clone(), file_request.clone()); } - dac::get_acknowledged_bytes_bucket(&requests, payments_per_bucket); - let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&requests); + dac::get_acknowledged_bytes_bucket(requests, payments_per_bucket); + let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(requests); let is_valid = Self::is_valid(bytes_sent, bytes_received); log::debug!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); @@ -916,18 +907,18 @@ pub mod pallet { u128, BucketsDetails>, > = BTreeMap::new(); - for bucket in payments_per_bucket.into_iter() { + for bucket in payments_per_bucket.iter_mut() { let cere_payment = bucket.1 as u32; - if payments.contains_key(&bucket.0) { - payments.entry(bucket.0).and_modify(|bucket_info| { - bucket_info.amount += cere_payment.into() - }); - } else { + if let std::collections::btree_map::Entry::Vacant(e) = payments.entry(bucket.0) { let bucket_info = BucketsDetails { bucket_id: bucket.0, amount: cere_payment.into(), }; - payments.insert(bucket.0, bucket_info); + e.insert(bucket_info); + } else { + payments.entry(bucket.0).and_modify(|bucket_info| { + bucket_info.amount += cere_payment.into() + }); } } let mut final_payments = vec![]; @@ -993,7 +984,7 @@ pub mod pallet { let signer = Self::get_signer().unwrap(); // ToDo: replace local call by a call from `ddc-staking` pallet - if cdn_nodes_reward_points.len() > 0 { + if !cdn_nodes_reward_points.is_empty() { let tx_res = signer.send_signed_transaction(|_account| Call::set_era_reward_points { era: current_ddc_era - 1, diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 6989e148f..066be9bd5 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -43,7 +43,7 @@ pub fn base64_decode(input: &String) -> Result, ()> { let mut buf = Vec::with_capacity(1000); // ToDo: calculate capacity buf.resize(1000, 0); BASE64_STANDARD.decode_slice(input, &mut buf).map_err(|_| ())?; - Ok(buf.iter().map(|&char| char as u8).collect()) + Ok(buf.to_vec()) } /// Encodes a vector of bytes into a vector of characters using base64 encoding. @@ -121,9 +121,9 @@ pub(crate) fn get_intermediate_decisions( }; let quorum_decisions = find_quorum_decisions(decisions_for_edge, quorum); - let decoded_decisions = decode_intermediate_decisions(quorum_decisions); + - decoded_decisions + decode_intermediate_decisions(quorum_decisions) } pub(crate) fn decode_intermediate_decisions( @@ -139,7 +139,7 @@ pub(crate) fn decode_intermediate_decisions( log::debug!("data_str: {:?}", data_trimmed); - let decoded_decision: ValidationDecision = serde_json::from_str(&data_trimmed).unwrap(); + let decoded_decision: ValidationDecision = serde_json::from_str(data_trimmed).unwrap(); decoded_decisions.push(decoded_decision); } diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index fc537b88a..4bd841fe8 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -20,7 +20,7 @@ const OCW_SEED: &str = "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; fn last_event() -> RuntimeEvent { - System::events().pop().expect("Event expected").event.into() + System::events().pop().expect("Event expected").event } #[test] @@ -137,7 +137,7 @@ fn it_sets_validation_decision_with_one_validator_in_quorum() { } t.execute_with(|| { - let era_block_number = 20 as u32 * era_to_validate; + let era_block_number = 20_u32 * era_to_validate; System::set_block_number(era_block_number); // required for randomness assert_ok!(DdcValidator::set_validator_key( // register validator 1 @@ -470,7 +470,7 @@ fn charge_payments_content_owners_works_as_expected() { ValidatorError::::DDCEraNotSet ); - let era_block_number = 20 as u32 * era_to_validate; + let era_block_number = 20_u32 * era_to_validate; System::set_block_number(era_block_number); Timestamp::set_timestamp( (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs index 5c5459b24..a43ee2aa1 100644 --- a/pallets/ddc-validator/src/utils.rs +++ b/pallets/ddc-validator/src/utils.rs @@ -6,9 +6,9 @@ pub use sp_std::prelude::*; pub fn account_to_string(account: T::AccountId) -> String { let to32 = T::AccountId::encode(&account); - let pub_key_str = array_bytes::bytes2hex("", to32); + - pub_key_str + array_bytes::bytes2hex("", to32) } pub fn string_to_account(pub_key_str: String) -> T::AccountId { diff --git a/pallets/ddc/src/lib.rs b/pallets/ddc/src/lib.rs index 8308b880c..c7bdc1d73 100644 --- a/pallets/ddc/src/lib.rs +++ b/pallets/ddc/src/lib.rs @@ -97,10 +97,10 @@ decl_module! { ensure!(data.len() >= T::MinLength::get(), Error::::TooShort); ensure!(data.len() <= T::MaxLength::get(), Error::::TooLong); - if let Some(_) = >::get(&sender) { - Self::deposit_event(RawEvent::DataStringChanged(sender.clone())); + if >::get(&sender).is_some() { + Self::deposit_event(RawEvent::DataStringChanged(sender)); } else { - Self::deposit_event(RawEvent::DataStringSet(sender.clone())); + Self::deposit_event(RawEvent::DataStringSet(sender)); }; >::insert(send_to, data); diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index e025c5177..8e7967ed6 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -82,7 +82,7 @@ decl_module! { let source = ensure_signed(origin)?; ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); let bridge_id = >::account_id(); - T::Currency::transfer(&source, &bridge_id, amount.into(), AllowDeath)?; + T::Currency::transfer(&source, &bridge_id, amount, AllowDeath)?; let resource_id = T::NativeTokenId::get(); let number_amount: u128 = amount.saturated_into(); @@ -96,7 +96,7 @@ decl_module! { pub fn transfer_erc721(origin, recipient: Vec, token_id: U256, dest_id: bridge::ChainId) -> DispatchResult { let source = ensure_signed(origin)?; ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); - match >::tokens(&token_id) { + match >::tokens(token_id) { Some(token) => { >::burn_token(source, token_id)?; let resource_id = T::Erc721Id::get(); @@ -116,7 +116,7 @@ decl_module! { #[weight = 195_000_000] pub fn transfer(origin, to: T::AccountId, amount: BalanceOf) -> DispatchResult { let source = T::BridgeOrigin::ensure_origin(origin)?; - ::Currency::transfer(&source, &to, amount.into(), AllowDeath)?; + ::Currency::transfer(&source, &to, amount, AllowDeath)?; Ok(()) } diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index 7d93c96f9..638dc864a 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -114,8 +114,8 @@ impl Module { let new_token = Erc721Token { id, metadata }; - ::insert(&id, new_token); - >::insert(&id, owner.clone()); + ::insert(id, new_token); + >::insert(id, owner.clone()); let new_total = ::get().saturating_add(U256::one()); ::put(new_total); @@ -130,7 +130,7 @@ impl Module { let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); // Update owner - >::insert(&id, to.clone()); + >::insert(id, to.clone()); Self::deposit_event(RawEvent::Transferred(from, to, id)); @@ -142,8 +142,8 @@ impl Module { let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); - ::remove(&id); - >::remove(&id); + ::remove(id); + >::remove(id); let new_total = ::get().saturating_sub(U256::one()); ::put(new_total); diff --git a/pallets/erc721/src/tests.rs b/pallets/erc721/src/tests.rs index f273f83a3..9fa6cde1b 100644 --- a/pallets/erc721/src/tests.rs +++ b/pallets/erc721/src/tests.rs @@ -22,7 +22,7 @@ fn mint_burn_tokens() { ); assert_eq!(Erc721::token_count(), 1.into()); assert_noop!( - Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone()), + Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a), Error::::TokenAlreadyExists ); @@ -33,19 +33,19 @@ fn mint_burn_tokens() { ); assert_eq!(Erc721::token_count(), 2.into()); assert_noop!( - Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone()), + Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b), Error::::TokenAlreadyExists ); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_a)); assert_eq!(Erc721::token_count(), 1.into()); - assert!(!::contains_key(&id_a)); - assert!(!>::contains_key(&id_a)); + assert!(!::contains_key(id_a)); + assert!(!>::contains_key(id_a)); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_b)); assert_eq!(Erc721::token_count(), 0.into()); - assert!(!::contains_key(&id_b)); - assert!(!>::contains_key(&id_b)); + assert!(!::contains_key(id_b)); + assert!(!>::contains_key(id_b)); }) } @@ -57,8 +57,8 @@ fn transfer_tokens() { let metadata_a: Vec = vec![1, 2, 3]; let metadata_b: Vec = vec![4, 5, 6]; - assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone())); - assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone())); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a)); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b)); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_B, id_a)); assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B); diff --git a/runtime/cere-dev/src/impls.rs b/runtime/cere-dev/src/impls.rs index c576e8d31..3e725dca7 100644 --- a/runtime/cere-dev/src/impls.rs +++ b/runtime/cere-dev/src/impls.rs @@ -98,7 +98,7 @@ mod multiplier_tests { fn run_with_system_weight(w: Weight, assertions: F) where - F: Fn() -> (), + F: Fn(), { let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() .build_storage::() @@ -114,12 +114,12 @@ mod multiplier_tests { fn truth_value_update_poc_works() { let fm = Multiplier::saturating_from_rational(1, 2); let test_set = vec![ - (0, fm.clone()), - (100, fm.clone()), - (1000, fm.clone()), - (target().ref_time(), fm.clone()), - (max_normal().ref_time() / 2, fm.clone()), - (max_normal().ref_time(), fm.clone()), + (0, fm), + (100, fm), + (1000, fm), + (target().ref_time(), fm), + (max_normal().ref_time() / 2, fm), + (max_normal().ref_time(), fm), ]; test_set.into_iter().for_each(|(w, fm)| { run_with_system_weight(Weight::from_ref_time(w), || { @@ -325,7 +325,7 @@ mod multiplier_tests { #[test] fn weight_to_fee_should_not_overflow_on_large_weights() { - let kb = 1024 as u64; + let kb = 1024_u64; let mb = kb * kb; let max_fm = Multiplier::saturating_from_integer(i128::MAX); diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index d71e17e5c..0bcc2c34a 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -406,7 +406,7 @@ impl pallet_indices::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * DOLLARS; + pub const ExistentialDeposit: Balance = DOLLARS; // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; @@ -566,9 +566,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = 1 * DOLLARS; - pub const SignedDepositBase: Balance = 1 * DOLLARS; - pub const SignedDepositByte: Balance = 1 * CENTS; + pub const SignedRewardBase: Balance = DOLLARS; + pub const SignedDepositBase: Balance = DOLLARS; + pub const SignedDepositByte: Balance = CENTS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -723,11 +723,11 @@ impl pallet_bags_list::Config for Runtime { } parameter_types! { - pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; - pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const LaunchPeriod: BlockNumber = 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; pub const MinimumDeposit: Balance = 5_000_000 * DOLLARS; - pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const EnactmentPeriod: BlockNumber = 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; } @@ -805,7 +805,7 @@ parameter_types! { pub const CandidacyBond: Balance = 500_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); - pub const VotingBondFactor: Balance = 1 * DOLLARS; + pub const VotingBondFactor: Balance = DOLLARS; pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -877,12 +877,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 5_000_000 * DOLLARS; - pub const SpendPeriod: BlockNumber = 1 * DAYS; + pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(0); - pub const TipCountdown: BlockNumber = 1 * DAYS; + pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 5_000_000 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * DOLLARS; + pub const DataDepositPerByte: Balance = DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; @@ -918,7 +918,7 @@ parameter_types! { pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const BountyDepositBase: Balance = 5_000_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = 1 * DOLLARS; + pub const CuratorDepositMin: Balance = DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; pub const BountyDepositPayoutDelay: BlockNumber = 8 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; @@ -940,7 +940,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = 1 * DOLLARS; + pub const ChildBountyValueMinimum: Balance = DOLLARS; } impl pallet_child_bounties::Config for Runtime { @@ -1193,7 +1193,7 @@ impl pallet_society::Config for Runtime { } parameter_types! { - pub const MinVestedTransfer: Balance = 1 * DOLLARS; + pub const MinVestedTransfer: Balance = DOLLARS; } impl pallet_vesting::Config for Runtime { diff --git a/runtime/cere/src/impls.rs b/runtime/cere/src/impls.rs index 6895f794e..f1763dea1 100644 --- a/runtime/cere/src/impls.rs +++ b/runtime/cere/src/impls.rs @@ -98,7 +98,7 @@ mod multiplier_tests { fn run_with_system_weight(w: Weight, assertions: F) where - F: Fn() -> (), + F: Fn(), { let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() .build_storage::() @@ -114,12 +114,12 @@ mod multiplier_tests { fn truth_value_update_poc_works() { let fm = Multiplier::saturating_from_rational(1, 2); let test_set = vec![ - (0, fm.clone()), - (100, fm.clone()), - (1000, fm.clone()), - (target().ref_time(), fm.clone()), - (max_normal().ref_time() / 2, fm.clone()), - (max_normal().ref_time(), fm.clone()), + (0, fm), + (100, fm), + (1000, fm), + (target().ref_time(), fm), + (max_normal().ref_time() / 2, fm), + (max_normal().ref_time(), fm), ]; test_set.into_iter().for_each(|(w, fm)| { run_with_system_weight(Weight::from_ref_time(w), || { @@ -325,7 +325,7 @@ mod multiplier_tests { #[test] fn weight_to_fee_should_not_overflow_on_large_weights() { - let kb = 1024 as u64; + let kb = 1024_u64; let mb = kb * kb; let max_fm = Multiplier::saturating_from_integer(i128::MAX); diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index c27c8e8e6..c7745b7eb 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -401,7 +401,7 @@ impl pallet_indices::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * DOLLARS; + pub const ExistentialDeposit: Balance = DOLLARS; // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; @@ -562,9 +562,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = 1 * DOLLARS; - pub const SignedDepositBase: Balance = 1 * DOLLARS; - pub const SignedDepositByte: Balance = 1 * CENTS; + pub const SignedRewardBase: Balance = DOLLARS; + pub const SignedDepositBase: Balance = DOLLARS; + pub const SignedDepositByte: Balance = CENTS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -719,11 +719,11 @@ impl pallet_bags_list::Config for Runtime { } parameter_types! { - pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; - pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const LaunchPeriod: BlockNumber = 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; pub const MinimumDeposit: Balance = 5_000_000 * DOLLARS; - pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const EnactmentPeriod: BlockNumber = 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; } @@ -801,7 +801,7 @@ parameter_types! { pub const CandidacyBond: Balance = 500_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); - pub const VotingBondFactor: Balance = 1 * DOLLARS; + pub const VotingBondFactor: Balance = DOLLARS; pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -873,12 +873,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 5_000_000 * DOLLARS; - pub const SpendPeriod: BlockNumber = 1 * DAYS; + pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(0); - pub const TipCountdown: BlockNumber = 1 * DAYS; + pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 5_000_000 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * DOLLARS; + pub const DataDepositPerByte: Balance = DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; @@ -914,7 +914,7 @@ parameter_types! { pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const BountyDepositBase: Balance = 5_000_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = 1 * DOLLARS; + pub const CuratorDepositMin: Balance = DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; pub const BountyDepositPayoutDelay: BlockNumber = 8 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; @@ -936,7 +936,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = 1 * DOLLARS; + pub const ChildBountyValueMinimum: Balance = DOLLARS; } impl pallet_child_bounties::Config for Runtime { @@ -1189,7 +1189,7 @@ impl pallet_society::Config for Runtime { } parameter_types! { - pub const MinVestedTransfer: Balance = 1 * DOLLARS; + pub const MinVestedTransfer: Balance = DOLLARS; } impl pallet_vesting::Config for Runtime { From ebe97f8cc517a539982dc2d6b4b1a92dcbc18ad3 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 18:41:46 +0600 Subject: [PATCH 406/544] Use `sp_std` as a BTreeMap type source --- pallets/ddc-validator/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 175ab0b88..0dade22e5 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -59,7 +59,10 @@ pub use sp_runtime::offchain::{ http, storage::StorageValueRef, storage_lock, storage_lock::StorageLock, Duration, Timestamp, }; pub use sp_staking::EraIndex; -pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +pub use sp_std::{ + collections::{btree_map, btree_map::BTreeMap}, + prelude::*, +}; extern crate alloc; @@ -909,7 +912,7 @@ pub mod pallet { > = BTreeMap::new(); for bucket in payments_per_bucket.iter_mut() { let cere_payment = bucket.1 as u32; - if let std::collections::btree_map::Entry::Vacant(e) = payments.entry(bucket.0) { + if let btree_map::Entry::Vacant(e) = payments.entry(bucket.0) { let bucket_info = BucketsDetails { bucket_id: bucket.0, amount: cere_payment.into(), From 17efbf4d97d6279496c16dd53b54146beca4dea2 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 23 Oct 2023 18:22:49 +0600 Subject: [PATCH 407/544] Disable rustfmt for legacy pallets --- rustfmt.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rustfmt.toml b/rustfmt.toml index 441913f61..f58198d98 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -21,3 +21,11 @@ match_block_trailing_comma = true trailing_comma = "Vertical" trailing_semicolon = false use_field_init_shorthand = true + +ignore = [ + "pallets/chainbridge", + "pallets/ddc-metrics-offchain-worker", + "pallets/ddc", + "pallets/erc20", + "pallets/erc721", +] From 3b367ba9aa22bf3cc9a4c01757b90cd70328cc7f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 21 Sep 2023 18:51:50 +0600 Subject: [PATCH 408/544] Apply rustfmt --- pallets/ddc-clusters/src/lib.rs | 4 +--- pallets/ddc-nodes/src/lib.rs | 12 ++++-------- pallets/ddc-staking/src/lib.rs | 6 +----- pallets/ddc-validator/src/dac.rs | 4 ---- pallets/ddc-validator/src/lib.rs | 7 +++++-- pallets/ddc-validator/src/shm.rs | 1 - pallets/ddc-validator/src/utils.rs | 1 - 7 files changed, 11 insertions(+), 24 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 7d3499d4a..7569b2760 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -193,9 +193,7 @@ pub mod pallet { let mut cluster = Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - cluster - .set_params(cluster_params) - .map_err(Into::>::into)?; + cluster.set_params(cluster_params).map_err(Into::>::into)?; Clusters::::insert(cluster_id, cluster); Self::deposit_event(Event::::ClusterParamsSet { cluster_id }); diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 2871f1e29..75d89e260 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -92,12 +92,10 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn delete_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let node = Self::get(node_pub_key.clone()) - .map_err(Into::>::into)?; + let node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); - Self::delete(node_pub_key.clone()) - .map_err(Into::>::into)?; + Self::delete(node_pub_key.clone()).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeDeleted { node_pub_key }); Ok(()) } @@ -109,11 +107,9 @@ pub mod pallet { node_params: NodeParams, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let mut node = Self::get(node_pub_key.clone()) - .map_err(Into::>::into)?; + let mut node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); - node.set_params(node_params) - .map_err(Into::>::into)?; + node.set_params(node_params).map_err(Into::>::into)?; Self::update(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeParamsChanged { node_pub_key }); Ok(()) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ec96bfe27..3c8464dc8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -989,11 +989,7 @@ pub mod pallet { current_rewards.push(rewards); }); } - Self::deposit_event(Event::::PayoutNodes( - era, - era_reward_points, - price_per_byte, - )); + Self::deposit_event(Event::::PayoutNodes(era, era_reward_points, price_per_byte)); log::debug!("Payout event executed"); log::debug!( diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs index a2b593182..205abba4e 100644 --- a/pallets/ddc-validator/src/dac.rs +++ b/pallets/ddc-validator/src/dac.rs @@ -329,8 +329,6 @@ pub(crate) fn http_get_json(url: &str) -> crate::ResultSt "HTTP GET error" })?; - - serde_json::from_slice(&body).map_err(|err| { log::warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); "HTTP JSON parse error" @@ -365,8 +363,6 @@ pub(crate) fn get_final_decision(decisions: Vec) -> Validati let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); - - ValidationDecision { edge: decision_example.edge.clone(), result: decision_example.result, diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 0dade22e5..f08727d4b 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -637,7 +637,8 @@ pub mod pallet { let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); - percentage_difference >= 0.0 && (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 + percentage_difference >= 0.0 && + (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 } /// Shuffle the `list` swapping it's random elements `list.len()` times. @@ -775,7 +776,9 @@ pub mod pallet { } fn get_public_key() -> Option { - sr25519_public_keys(KEY_TYPE).first().map(|pubkey| T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()) + sr25519_public_keys(KEY_TYPE) + .first() + .map(|pubkey| T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()) } fn validate_edges() -> Result<(), &'static str> { diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs index 066be9bd5..47619425c 100644 --- a/pallets/ddc-validator/src/shm.rs +++ b/pallets/ddc-validator/src/shm.rs @@ -121,7 +121,6 @@ pub(crate) fn get_intermediate_decisions( }; let quorum_decisions = find_quorum_decisions(decisions_for_edge, quorum); - decode_intermediate_decisions(quorum_decisions) } diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs index a43ee2aa1..2ba8379e9 100644 --- a/pallets/ddc-validator/src/utils.rs +++ b/pallets/ddc-validator/src/utils.rs @@ -6,7 +6,6 @@ pub use sp_std::prelude::*; pub fn account_to_string(account: T::AccountId) -> String { let to32 = T::AccountId::encode(&account); - array_bytes::bytes2hex("", to32) } From 1fce540127954ef632a65bb9a2568ac0d31334df Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 12:57:41 +0600 Subject: [PATCH 409/544] Apply clippy suggestions which it can't fix itself --- .gitignore | 2 -- pallets/ddc-metrics-offchain-worker/src/lib.rs | 17 ++++++++--------- .../src/tests/test_data/ddc.wasm | 0 .../src/tests/test_data/metadata.json | 0 4 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm create mode 100644 pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json diff --git a/.gitignore b/.gitignore index 6dd97a7f6..ac9d585fc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,3 @@ # ddc-metrics-offchain-worker mock files pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.contract -pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm -pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json diff --git a/pallets/ddc-metrics-offchain-worker/src/lib.rs b/pallets/ddc-metrics-offchain-worker/src/lib.rs index 228def0f0..ffa2dfbb1 100644 --- a/pallets/ddc-metrics-offchain-worker/src/lib.rs +++ b/pallets/ddc-metrics-offchain-worker/src/lib.rs @@ -304,11 +304,10 @@ where ); Err("Skipping") } else { - let block_interval_configured = Self::get_block_interval(); let mut block_interval = T::BlockInterval::get(); - if block_interval_configured.is_some() { + if let Some(block_interval_configured) = Self::get_block_interval() { block_interval = ::BlockNumber::from( - block_interval_configured.unwrap(), + block_interval_configured, ); } @@ -753,7 +752,12 @@ impl MetricsAggregator { let existing_pubkey_index = self.0.iter().position(|one_result_obj| metric.app_id == one_result_obj.app_id); - if existing_pubkey_index.is_none() { + if let Some(existing_pubkey_index) = existing_pubkey_index { + // Add to metrics of an existing app. + self.0[existing_pubkey_index].storage_bytes += metric.storage_bytes; + self.0[existing_pubkey_index].wcu_used += metric.wcu_used; + self.0[existing_pubkey_index].rcu_used += metric.rcu_used; + } else { // New app. let new_metric_obj = Metric { app_id: metric.app_id.clone(), @@ -762,11 +766,6 @@ impl MetricsAggregator { rcu_used: metric.rcu_used, }; self.0.push(new_metric_obj); - } else { - // Add to metrics of an existing app. - self.0[existing_pubkey_index.unwrap()].storage_bytes += metric.storage_bytes; - self.0[existing_pubkey_index.unwrap()].wcu_used += metric.wcu_used; - self.0[existing_pubkey_index.unwrap()].rcu_used += metric.rcu_used; } } diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm b/pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json b/pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json new file mode 100644 index 000000000..e69de29bb From e6a45d6f4d5a9d79132be253518d1247c6570904 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 13:20:50 +0600 Subject: [PATCH 410/544] Pre-push script invoking Clippy linter --- scripts/pre-push.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 scripts/pre-push.sh diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh new file mode 100755 index 000000000..9c6679c02 --- /dev/null +++ b/scripts/pre-push.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Check code with clippy before publishing +cargo clippy --all --all-targets -- -D warnings +if [ $? -ne 0 ]; then + echo "Run \`cargo clippy --fix --all --allow-staged --allow-dirty\` to apply clippy's suggestions." + exit 1 +fi From 2ec2d82ccc8f9564dc52c4c4c8c766162499bb28 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 13:21:41 +0600 Subject: [PATCH 411/544] Add pre-push script setup to init script --- scripts/init.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/init.sh b/scripts/init.sh index beca622b2..1472424dc 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -9,3 +9,4 @@ rustup install nightly-2022-10-09 rustup target add wasm32-unknown-unknown --toolchain nightly-2022-10-09 ln -sf $PWD/scripts/pre-commit.sh $PWD/.git/hooks/pre-commit || true +ln -sf $PWD/scripts/pre-push.sh $PWD/.git/hooks/pre-push || true From 585f1d86ccece2510882a2741fc543723eae969f Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 22 Sep 2023 13:23:33 +0600 Subject: [PATCH 412/544] Add Clippy to the `check` CI workflow --- .github/workflows/check.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index db63d8d96..27070bd99 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -35,6 +35,10 @@ jobs: - name: Rust Cache uses: Swatinem/rust-cache@v2 + - name: Check with Clippy + run: | + cargo clippy --all --all-targets -- -D warnings + - name: Check Build run: | SKIP_WASM_BUILD=1 cargo check --release From 666f2202384627db47241d4247ee6c3068dd3de6 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 24 Oct 2023 12:38:46 +0200 Subject: [PATCH 413/544] Reduce by 2 orders of magnitude the constants changed in v4.7.1 --- CHANGELOG.md | 11 ++ Cargo.lock | 330 ++++++++++++++++++------------------ runtime/cere-dev/src/lib.rs | 10 +- runtime/cere/src/lib.rs | 10 +- 4 files changed, 186 insertions(+), 175 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 975dd715d..780fcf968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [C,D] Updated Substrate to polkadot-v0.9.30 +## [4.7.2] + +### Changed + +- Reduce by 2 orders of magnitude the constants changed in v4.7.1 + +## [4.7.1] + +### Changed +- Updated governance related constants + ## [4.7.0] ### Changed diff --git a/Cargo.lock b/Cargo.lock index 669a99063..c24b3b135 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2069,7 +2069,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2086,7 +2086,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2109,7 +2109,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "array-bytes 4.2.0", @@ -2160,7 +2160,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2171,7 +2171,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2187,7 +2187,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2216,7 +2216,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-metadata", @@ -2248,7 +2248,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2262,7 +2262,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2274,7 +2274,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2284,7 +2284,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2302,7 +2302,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2317,7 +2317,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2326,7 +2326,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -4374,7 +4374,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4583,7 +4583,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4599,7 +4599,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4614,7 +4614,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4638,7 +4638,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4658,7 +4658,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4673,7 +4673,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4724,7 +4724,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4743,7 +4743,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4760,7 +4760,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -4788,7 +4788,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -4803,7 +4803,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4813,7 +4813,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4830,7 +4830,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -4985,7 +4985,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5001,7 +5001,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5025,7 +5025,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5038,7 +5038,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5094,7 +5094,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5115,7 +5115,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5138,7 +5138,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5154,7 +5154,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5174,7 +5174,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5191,7 +5191,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5208,7 +5208,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5223,7 +5223,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5240,7 +5240,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5260,7 +5260,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5270,7 +5270,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5287,7 +5287,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5310,7 +5310,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5325,7 +5325,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5339,7 +5339,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5354,7 +5354,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5370,7 +5370,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5391,7 +5391,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5407,7 +5407,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5421,7 +5421,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5444,7 +5444,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5455,7 +5455,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5469,7 +5469,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5487,7 +5487,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5506,7 +5506,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5522,7 +5522,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5537,7 +5537,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5548,7 +5548,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5566,7 +5566,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5583,7 +5583,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5599,7 +5599,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -6485,7 +6485,7 @@ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", @@ -6744,7 +6744,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6755,7 +6755,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6782,7 +6782,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6805,7 +6805,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6821,7 +6821,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6838,7 +6838,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6849,7 +6849,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "chrono", @@ -6889,7 +6889,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -6917,7 +6917,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -6942,7 +6942,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6966,7 +6966,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", @@ -7008,7 +7008,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7030,7 +7030,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -7043,7 +7043,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7067,7 +7067,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -7078,7 +7078,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -7105,7 +7105,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -7121,7 +7121,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7136,7 +7136,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", @@ -7156,7 +7156,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "array-bytes 4.2.0", @@ -7197,7 +7197,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -7218,7 +7218,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7235,7 +7235,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7250,7 +7250,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7297,7 +7297,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cid", "futures", @@ -7317,7 +7317,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -7343,7 +7343,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7361,7 +7361,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7382,7 +7382,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "fork-tree", @@ -7410,7 +7410,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7429,7 +7429,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "bytes", @@ -7459,7 +7459,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", @@ -7472,7 +7472,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7481,7 +7481,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7511,7 +7511,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7534,7 +7534,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7547,7 +7547,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7617,7 +7617,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7631,7 +7631,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7650,7 +7650,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7669,7 +7669,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7687,7 +7687,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7718,7 +7718,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7729,7 +7729,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7755,7 +7755,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7768,7 +7768,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -8191,7 +8191,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8209,7 +8209,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -8221,7 +8221,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8234,7 +8234,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -8249,7 +8249,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8262,7 +8262,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8274,7 +8274,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8286,7 +8286,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8304,7 +8304,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8323,7 +8323,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8346,7 +8346,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8360,7 +8360,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8373,7 +8373,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "base58", @@ -8419,7 +8419,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", @@ -8433,7 +8433,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8444,7 +8444,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8453,7 +8453,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8463,7 +8463,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8474,7 +8474,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8492,7 +8492,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8506,7 +8506,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8532,7 +8532,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8543,7 +8543,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8560,7 +8560,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8569,7 +8569,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8583,7 +8583,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8593,7 +8593,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8603,7 +8603,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8613,7 +8613,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8636,7 +8636,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8654,7 +8654,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8666,7 +8666,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8680,7 +8680,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8694,7 +8694,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8705,7 +8705,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8727,12 +8727,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8745,7 +8745,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8758,7 +8758,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8774,7 +8774,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8786,7 +8786,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8795,7 +8795,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8811,7 +8811,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", @@ -8834,7 +8834,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8851,7 +8851,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8862,7 +8862,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8875,7 +8875,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -9016,7 +9016,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -9024,7 +9024,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -9045,7 +9045,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -9058,7 +9058,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -9079,7 +9079,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -9089,7 +9089,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9100,7 +9100,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -9561,7 +9561,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index d71e17e5c..a8e695f8d 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -726,7 +726,7 @@ parameter_types! { pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; - pub const MinimumDeposit: Balance = 5_000_000 * DOLLARS; + pub const MinimumDeposit: Balance = 50_000 * DOLLARS; pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; @@ -802,7 +802,7 @@ impl pallet_collective::Config for Runtime { } parameter_types! { - pub const CandidacyBond: Balance = 500_000_000 * DOLLARS; + pub const CandidacyBond: Balance = 5_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); pub const VotingBondFactor: Balance = 1 * DOLLARS; @@ -876,12 +876,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 5_000_000 * DOLLARS; + pub const ProposalBondMinimum: Balance = 50_000 * DOLLARS; pub const SpendPeriod: BlockNumber = 1 * DAYS; pub const Burn: Permill = Permill::from_percent(0); pub const TipCountdown: BlockNumber = 1 * DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); - pub const TipReportDepositBase: Balance = 5_000_000 * DOLLARS; + pub const TipReportDepositBase: Balance = 50_000 * DOLLARS; pub const DataDepositPerByte: Balance = 1 * DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; @@ -916,7 +916,7 @@ impl pallet_treasury::Config for Runtime { parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 10 * DOLLARS; - pub const BountyDepositBase: Balance = 5_000_000 * DOLLARS; + pub const BountyDepositBase: Balance = 50_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); pub const CuratorDepositMin: Balance = 1 * DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index c27c8e8e6..448a721b2 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -722,7 +722,7 @@ parameter_types! { pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; - pub const MinimumDeposit: Balance = 5_000_000 * DOLLARS; + pub const MinimumDeposit: Balance = 50_000 * DOLLARS; pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; @@ -798,7 +798,7 @@ impl pallet_collective::Config for Runtime { } parameter_types! { - pub const CandidacyBond: Balance = 500_000_000 * DOLLARS; + pub const CandidacyBond: Balance = 5_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); pub const VotingBondFactor: Balance = 1 * DOLLARS; @@ -872,12 +872,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 5_000_000 * DOLLARS; + pub const ProposalBondMinimum: Balance = 50_000 * DOLLARS; pub const SpendPeriod: BlockNumber = 1 * DAYS; pub const Burn: Permill = Permill::from_percent(0); pub const TipCountdown: BlockNumber = 1 * DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); - pub const TipReportDepositBase: Balance = 5_000_000 * DOLLARS; + pub const TipReportDepositBase: Balance = 50_000 * DOLLARS; pub const DataDepositPerByte: Balance = 1 * DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; @@ -912,7 +912,7 @@ impl pallet_treasury::Config for Runtime { parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); pub const BountyValueMinimum: Balance = 10 * DOLLARS; - pub const BountyDepositBase: Balance = 5_000_000 * DOLLARS; + pub const BountyDepositBase: Balance = 50_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); pub const CuratorDepositMin: Balance = 1 * DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; From 460b1bbed30c748c2034429ea59225d1b3a128ea Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Tue, 24 Oct 2023 15:22:09 +0200 Subject: [PATCH 414/544] Update spec_version --- runtime/cere-dev/src/lib.rs | 2 +- runtime/cere/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index a8e695f8d..3279c7529 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48007, + spec_version: 48009, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 448a721b2..be5ab085d 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -125,7 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48005, + spec_version: 48009, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From 61c58d2a0cdeb05041e6f3a3fb990dcdcd821280 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 25 Oct 2023 18:24:20 +0200 Subject: [PATCH 415/544] remove controller from account deposit --- Cargo.toml | 2 +- .../Cargo.toml | 2 +- .../src/lib.rs | 157 ++++++++---------- pallets/ddc-validator/Cargo.toml | 4 +- pallets/ddc-validator/src/lib.rs | 2 +- runtime/cere-dev/Cargo.toml | 4 +- 6 files changed, 72 insertions(+), 99 deletions(-) rename pallets/{ddc-accounts => ddc-customer-accounts}/Cargo.toml (97%) rename pallets/{ddc-accounts => ddc-customer-accounts}/src/lib.rs (77%) diff --git a/Cargo.toml b/Cargo.toml index 835a9919a..e5687657f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ members = [ "pallets/erc20", "pallets/ddc-metrics-offchain-worker", "pallets/ddc-validator", - "pallets/ddc-accounts", + "pallets/ddc-customer-accounts", "pallets/ddc-nodes", "pallets/ddc-clusters", "primitives", diff --git a/pallets/ddc-accounts/Cargo.toml b/pallets/ddc-customer-accounts/Cargo.toml similarity index 97% rename from pallets/ddc-accounts/Cargo.toml rename to pallets/ddc-customer-accounts/Cargo.toml index 89f3de545..3f3ed6fcb 100644 --- a/pallets/ddc-accounts/Cargo.toml +++ b/pallets/ddc-customer-accounts/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pallet-ddc-accounts" +name = "pallet-ddc-customer-accounts" version = "0.1.0" edition = "2021" diff --git a/pallets/ddc-accounts/src/lib.rs b/pallets/ddc-customer-accounts/src/lib.rs similarity index 77% rename from pallets/ddc-accounts/src/lib.rs rename to pallets/ddc-customer-accounts/src/lib.rs index e988cdd0f..30bfa9bce 100644 --- a/pallets/ddc-accounts/src/lib.rs +++ b/pallets/ddc-customer-accounts/src/lib.rs @@ -55,17 +55,17 @@ pub struct BucketsDetails { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct AccountsLedger { - /// The stash account whose balance is actually locked and can be used for CDN usage. - pub stash: AccountId, - /// The total amount of the stash's balance that we are currently accounting for. + /// The owner account whose balance is actually locked and can be used for CDN usage. + pub owner: AccountId, + /// The total amount of the owner's balance that we are currently accounting for. /// It's just `active` plus all the `unlocking` balances. #[codec(compact)] pub total: Balance, - /// The total amount of the stash's balance that will be accessible for CDN payments in any + /// The total amount of the owner's balance that will be accessible for CDN payments in any /// forthcoming rounds. #[codec(compact)] pub active: Balance, - /// Any balance that is becoming free, which may eventually be transferred out of the stash + /// Any balance that is becoming free, which may eventually be transferred out of the owner /// (assuming that the content owner has to pay for network usage). It is assumed that this /// will be treated as a first in, first out queue where the new (higher value) eras get pushed /// on the back. @@ -75,9 +75,9 @@ pub struct AccountsLedger { impl AccountsLedger { - /// Initializes the default object using the given stash. - pub fn default_from(stash: AccountId) -> Self { - Self { stash, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } + /// Initializes the default object using the given owner. + pub fn default_from(owner: AccountId) -> Self { + Self { owner, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } } /// Remove entries from `unlocking` that are sufficiently old and reduce the @@ -102,7 +102,7 @@ impl; } - /// Map from all locked "stash" accounts to the controller account. - #[pallet::storage] - #[pallet::getter(fn bonded)] - pub type Bonded = StorageMap<_, Identity, T::AccountId, T::AccountId>; - - /// Map from all (unlocked) "controller" accounts to the info regarding the staking. + /// Map from all (unlocked) "owner" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = @@ -187,15 +180,15 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// An account has bonded this amount. \[stash, amount\] + /// An account has bonded this amount. \[owner, amount\] /// /// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably, /// it will not be emitted for staking rewards when they are added to stake. Deposited(T::AccountId, BalanceOf), - /// An account has unbonded this amount. \[stash, amount\] + /// An account has unbonded this amount. \[owner, amount\] Unbonded(T::AccountId, BalanceOf), /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` - /// from the unlocking queue. \[stash, amount\] + /// from the unlocking queue. \[owner, amount\] Withdrawn(T::AccountId, BalanceOf), /// Total amount charged from all accounts to pay CDN nodes Charged(BalanceOf), @@ -203,13 +196,9 @@ pub mod pallet { #[pallet::error] pub enum Error { - /// Not a controller account. - NotController, - /// Not a stash account. - NotStash, - /// Stash is already bonded. - AlreadyBonded, - /// Controller is already paired. + /// Not a owner account. + NotOwner, + /// Owner is already bonded. AlreadyPaired, /// Cannot deposit dust InsufficientDeposit, @@ -270,29 +259,22 @@ pub mod pallet { Ok(()) } - /// Take the origin account as a stash and lock up `value` of its balance. `controller` will + /// Take the origin account as a owner and lock up `value` of its balance. `Owner` will /// be the account that controls it. /// /// `value` must be more than the `minimum_balance` specified by `T::Currency`. /// - /// The dispatch origin for this call must be _Signed_ by the stash account. + /// The dispatch origin for this call must be _Signed_ by the owner account. /// /// Emits `Deposited`. #[pallet::weight(10_000)] pub fn deposit( origin: OriginFor, - controller: ::Source, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { - let stash = ensure_signed(origin)?; - - if >::contains_key(&stash) { - Err(Error::::AlreadyBonded)? - } + let owner = ensure_signed(origin)?; - let controller = T::Lookup::lookup(controller)?; - - if >::contains_key(&controller) { + if >::contains_key(&owner) { Err(Error::::AlreadyPaired)? } @@ -301,27 +283,25 @@ pub mod pallet { Err(Error::::InsufficientDeposit)? } - frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; - - >::insert(&stash, &controller); + frame_system::Pallet::::inc_consumers(&owner).map_err(|_| Error::::BadState)?; - let stash_balance = ::Currency::free_balance(&stash); - let value = value.min(stash_balance); + let owner_balance = ::Currency::free_balance(&owner); + let value = value.min(owner_balance); let item = AccountsLedger { - stash: stash.clone(), + owner: owner.clone(), total: value, active: value, unlocking: Default::default(), }; - Self::update_ledger_and_deposit(&stash, &controller, &item)?; - Self::deposit_event(Event::::Deposited(stash.clone(), value)); + Self::update_ledger_and_deposit(&owner, &item)?; + Self::deposit_event(Event::::Deposited(owner, value)); Ok(()) } - /// Add some extra amount that have appeared in the stash `free_balance` into the balance up + /// Add some extra amount that have appeared in the owner `free_balance` into the balance up /// for CDN payments. /// - /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. + /// The dispatch origin for this call must be _Signed_ by the owner. /// /// Emits `Deposited`. #[pallet::weight(10_000)] @@ -329,13 +309,12 @@ pub mod pallet { origin: OriginFor, #[pallet::compact] max_additional: BalanceOf, ) -> DispatchResult { - let stash = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; - let controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; - let stash_balance = ::Currency::free_balance(&stash); - let extra = stash_balance.min(max_additional); + let owner_balance = ::Currency::free_balance(&owner); + let extra = owner_balance.min(max_additional); ledger.total += extra; ledger.active += extra; // Last check: the new active amount of ledger must be more than ED. @@ -344,18 +323,18 @@ pub mod pallet { Error::::InsufficientDeposit ); - Self::update_ledger_and_deposit(&stash, &controller, &ledger)?; + Self::update_ledger_and_deposit(&owner, &ledger)?; - Self::deposit_event(Event::::Deposited(stash.clone(), extra)); + Self::deposit_event(Event::::Deposited(owner.clone(), extra)); Ok(()) } - /// Schedule a portion of the stash to be unlocked ready for transfer out after the bond + /// Schedule a portion of the owner to be unlocked ready for transfer out after the bond /// period ends. If this leaves an amount actively bonded less than /// T::Currency::minimum_balance(), then it is increased to the full amount. /// - /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. + /// The dispatch origin for this call must be _Signed_ by the owner. /// /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move /// the funds out of management ready for transfer. @@ -372,8 +351,8 @@ pub mod pallet { origin: OriginFor, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { - let controller = ensure_signed(origin)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let owner = ensure_signed(origin)?; + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, @@ -396,9 +375,7 @@ pub mod pallet { let era = current_era + ::BondingDuration::get(); log::debug!("Era for the unbond: {:?}", era); - if let Some(mut chunk) = - ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) - { + if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { // To keep the chunk count down, we only keep one chunk per era. Since // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will // be the last one. @@ -410,28 +387,28 @@ pub mod pallet { .map_err(|_| Error::::NoMoreChunks)?; }; - Self::update_ledger(&controller, &ledger); + Self::update_ledger(&owner, &ledger); - Self::deposit_event(Event::::Unbonded(ledger.stash, value)); + Self::deposit_event(Event::::Unbonded(ledger.owner, value)); } Ok(()) } /// Remove any unlocked chunks from the `unlocking` queue from our management. /// - /// This essentially frees up that balance to be used by the stash account to do + /// This essentially frees up that balance to be used by the owner account to do /// whatever it wants. /// - /// The dispatch origin for this call must be _Signed_ by the controller. + /// The dispatch origin for this call must be _Signed_ by the owner. /// /// Emits `Withdrawn`. /// /// See also [`Call::unbond`]. #[pallet::weight(10_000)] pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { - let controller = ensure_signed(origin)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - let (stash, old_total) = (ledger.stash.clone(), ledger.total); + let owner = ensure_signed(origin)?; + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let (owner, old_total) = (ledger.owner.clone(), ledger.total); let current_era = ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; ledger = ledger.consolidate_unlocked(current_era); @@ -440,15 +417,15 @@ pub mod pallet { if ledger.unlocking.is_empty() && ledger.active < ::Currency::minimum_balance() { - log::debug!("Killing stash"); + log::debug!("Killing owner"); // This account must have called `unbond()` with some value that caused the active // portion to fall below existential deposit + will have no more unlocking chunks // left. We can now safely remove all accounts-related information. - Self::kill_stash(&stash)?; + Self::kill_owner(&owner)?; } else { log::debug!("Updating ledger"); // This was the consequence of a partial unbond. just update the ledger and move on. - Self::update_ledger(&controller, &ledger); + Self::update_ledger(&owner, &ledger); }; log::debug!("Current total: {:?}", ledger.total); @@ -465,11 +442,11 @@ pub mod pallet { ::Currency::transfer( &account_id, - &stash, + &owner, value, ExistenceRequirement::KeepAlive, )?; - Self::deposit_event(Event::::Withdrawn(stash, value)); + Self::deposit_event(Event::::Withdrawn(owner, value)); } Ok(()) @@ -480,48 +457,44 @@ pub mod pallet { pub fn account_id() -> T::AccountId { T::PalletId::get().into_account_truncating() } - /// Update the ledger for a controller. + /// Update the ledger for a owner. /// /// This will also deposit the funds to pallet. fn update_ledger_and_deposit( - stash: &T::AccountId, - controller: &T::AccountId, + owner: &T::AccountId, ledger: &AccountsLedger>, ) -> DispatchResult { let account_id = Self::account_id(); ::Currency::transfer( - stash, + owner, &account_id, ledger.total, ExistenceRequirement::KeepAlive, )?; - >::insert(controller, ledger); + >::insert(owner, ledger); Ok(()) } - /// Update the ledger for a controller. + /// Update the ledger for a owner. fn update_ledger( - controller: &T::AccountId, + owner: &T::AccountId, ledger: &AccountsLedger>, ) { - >::insert(controller, ledger); + >::insert(owner, ledger); } - /// Remove all associated data of a stash account from the accounts system. + /// Remove all associated data of a owner account from the accounts system. /// /// Assumes storage is upgraded before calling. /// /// This is called: - /// - after a `withdraw_unbonded()` call that frees all of a stash's bonded balance. - fn kill_stash(stash: &T::AccountId) -> DispatchResult { - let controller = >::get(stash).ok_or(Error::::NotStash)?; - - >::remove(stash); - >::remove(&controller); + /// - after a `withdraw_unbonded()` call that frees all of a owner's bonded balance. + fn kill_owner(owner: &T::AccountId) -> DispatchResult { + >::remove(&owner); - frame_system::Pallet::::dec_consumers(stash); + frame_system::Pallet::::dec_consumers(owner); Ok(()) } @@ -539,7 +512,7 @@ pub mod pallet { let content_owner = bucket.owner_id; let amount = bucket_details.amount * pricing.saturated_into::>(); - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotController)?; + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; if ledger.active >= amount { ledger.total -= amount; ledger.active -= amount; diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index d1ceeec47..1c5200e79 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -14,7 +14,7 @@ frame-system = { version = "4.0.0-dev", default-features = false, git = "https:/ lite-json = { version = "0.2.0", default-features = false } log = { version = "0.4.17", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-accounts = { version = "0.1.0", default-features = false, path = "../ddc-accounts" } +pallet-ddc-customer-accounts = { version = "0.1.0", default-features = false, path = "../ddc-customer-accounts" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -44,7 +44,7 @@ std = [ "frame-system/std", "lite-json/std", "pallet-contracts/std", - "pallet-ddc-accounts/std", + "pallet-ddc-customer-accounts/std", "pallet-ddc-staking/std", "pallet-session/std", "pallet-staking/std", diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index ac0bfe531..647332f9f 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -47,7 +47,7 @@ pub use frame_system::{ }; pub use lite_json::json::JsonValue; pub use pallet::*; -pub use pallet_ddc_accounts::{self as ddc_accounts, BucketsDetails}; +pub use pallet_ddc_customer_accounts::{self as ddc_accounts, BucketsDetails}; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_session as session; pub use pallet_staking::{self as staking}; diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 71b9c5112..7302356bc 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -99,7 +99,7 @@ cere-dev-runtime-constants = { path = "./constants", default-features = false } pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } -pallet-ddc-accounts = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-accounts" } +pallet-ddc-customer-accounts = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customer-accounts" } pallet-ddc-validator = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-validator" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } @@ -186,7 +186,7 @@ std = [ "cere-runtime-common/std", "cere-dev-runtime-constants/std", "pallet-ddc-validator/std", - "pallet-ddc-accounts/std", + "pallet-ddc-customer-accounts/std", "pallet-ddc-nodes/std", "pallet-ddc-clusters/std", ] From a34d3b10cacba05ae6f3de543ae1ee9cede80b5b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 25 Oct 2023 18:54:10 +0200 Subject: [PATCH 416/544] add method allocate bucket to cluster --- pallets/ddc-customer-accounts/src/lib.rs | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pallets/ddc-customer-accounts/src/lib.rs b/pallets/ddc-customer-accounts/src/lib.rs index 30bfa9bce..f9d062b69 100644 --- a/pallets/ddc-customer-accounts/src/lib.rs +++ b/pallets/ddc-customer-accounts/src/lib.rs @@ -43,6 +43,7 @@ pub struct UnlockChunk { pub struct Bucket { bucket_id: u128, owner_id: AccountId, + cluster_id: Option, public_availability: bool, resources_reserved: u128, } @@ -198,12 +199,16 @@ pub mod pallet { pub enum Error { /// Not a owner account. NotOwner, + /// Not an owner of bucket + NotBucketOwner, /// Owner is already bonded. AlreadyPaired, /// Cannot deposit dust InsufficientDeposit, /// Can not schedule more unlock chunks. NoMoreChunks, + /// Bucket with speicifed id doesn't exist. + NoBucketWithId, /// Internal state has become somehow corrupted and the operation cannot continue. BadState, /// Current era not set during runtime @@ -250,6 +255,7 @@ pub mod pallet { let bucket = Bucket { bucket_id: cur_bucket_id + 1, owner_id: bucket_owner, + cluster_id: None, public_availability, resources_reserved, }; @@ -259,6 +265,26 @@ pub mod pallet { Ok(()) } + /// Allocates specified bucket into specified cluster + /// + /// Only bucket owner can call this method + #[pallet::weight(10_000)] + pub fn allocate_bucket_to_cluster( + origin: OriginFor, + bucket_id: u128, + cluster_id: u128, + ) -> DispatchResult { + let bucket_owner = ensure_signed(origin)?; + + let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; + + ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); + + bucket.cluster_id = Some(cluster_id); + + Ok(()) + } + /// Take the origin account as a owner and lock up `value` of its balance. `Owner` will /// be the account that controls it. /// From 064476e8d3951c7624a81b251248d6073bb4d5c8 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 25 Oct 2023 19:03:34 +0200 Subject: [PATCH 417/544] update pallet name --- pallets/ddc-validator/src/mock.rs | 4 ++-- pallets/ddc-validator/src/tests.rs | 2 +- runtime/cere-dev/src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 085469277..026a844db 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -41,7 +41,7 @@ frame_support::construct_runtime!( Timestamp: pallet_timestamp, Session: pallet_session, Staking: pallet_staking, - DdcAccounts: pallet_ddc_accounts, + DdcAccounts: pallet_ddc_customer_accounts, DdcStaking: pallet_ddc_staking, RandomnessCollectiveFlip: pallet_randomness_collective_flip, DdcValidator: pallet_ddc_validator, @@ -242,7 +242,7 @@ parameter_types! { pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); } -impl pallet_ddc_accounts::Config for Test { +impl pallet_ddc_customer_accounts::Config for Test { type BondingDuration = BondingDuration; type Currency = Balances; type RuntimeEvent = RuntimeEvent; diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index fc537b88a..5fa240a5f 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -8,7 +8,7 @@ use crate::{ use codec::Decode; use ddc_primitives::{CDNNodePubKey, NodePubKey}; use frame_support::{assert_noop, assert_ok}; -use pallet_ddc_accounts::{BucketsDetails, Error as AccountsError}; +use pallet_ddc_customer_accounts::{BucketsDetails, Error as AccountsError}; use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3279c7529..65baf978d 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -48,8 +48,8 @@ pub use node_primitives::{AccountId, Signature}; use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; pub use pallet_cere_ddc; pub use pallet_chainbridge; -pub use pallet_ddc_accounts; pub use pallet_ddc_clusters; +pub use pallet_ddc_customer_accounts; pub use pallet_ddc_metrics_offchain_worker; pub use pallet_ddc_nodes; pub use pallet_ddc_staking; @@ -1340,7 +1340,7 @@ parameter_types! { pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake } -impl pallet_ddc_accounts::Config for Runtime { +impl pallet_ddc_customer_accounts::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; type PalletId = DdcAccountsPalletId; @@ -1425,7 +1425,7 @@ construct_runtime!( DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Storage, Event}, DdcStaking: pallet_ddc_staking, DdcValidator: pallet_ddc_validator, - DdcAccounts: pallet_ddc_accounts, + DdcAccounts: pallet_ddc_customer_accounts, DdcNodes: pallet_ddc_nodes, DdcClusters: pallet_ddc_clusters } From eedff72b1cf89b0f9993dff5bd663e1cd5863eac Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 26 Oct 2023 11:25:00 +0600 Subject: [PATCH 418/544] New `fast_chill` call in `ddc-clusters` --- pallets/ddc-clusters/src/lib.rs | 36 +++++++++++++++++++++++++++++++++ pallets/ddc-staking/src/lib.rs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index e4131c0fe..482c0ce49 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -73,6 +73,11 @@ pub mod pallet { OnlyClusterManager, NotAuthorized, NoStake, + /// Conditions for fast chill are not met, try the regular `chill` from + /// `pallet-ddc-staking`. + FastChillProhibited, + /// Cluster candidate should not plan to chill. + ChillingProhibited, } #[pallet::storage] @@ -201,5 +206,36 @@ pub mod pallet { Ok(()) } + + /// Allow cluster node candidate to chill in the next DDC era. + /// + /// The dispatch origin for this call must be _Signed_ by the controller. + #[pallet::weight(10_000)] + pub fn fast_chill(origin: OriginFor) -> DispatchResult { + let controller = ensure_signed(origin)?; + + let stash = >::ledger(&controller) + .ok_or(>::NotController)? + .stash; + let node = >::iter() + .find(|(_, v)| *v == stash) + .ok_or(>::BadState)? + .0; + let cluster = >::edges(&stash) + .or(>::storages(&stash)) + .ok_or(Error::::NoStake)?; + let is_cluster_node = ClustersNodes::::get(cluster, node); + ensure!(!is_cluster_node, Error::::FastChillProhibited); + + let can_chill_from = >::current_era().unwrap_or(0) + 1; + >::chill_stash_soon( + &stash, + &controller, + cluster, + can_chill_from, + ); + + Ok(()) + } } } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index c349b3271..be39bc668 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -1030,7 +1030,7 @@ pub mod pallet { } /// Note a desire of a stash account to chill soon. - fn chill_stash_soon( + pub fn chill_stash_soon( stash: &T::AccountId, controller: &T::AccountId, cluster: ClusterId, From dabbf840bd7a1ecd7cd05f58547dd08127447b57 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 26 Oct 2023 11:27:01 +0600 Subject: [PATCH 419/544] Reject cluster node candidates planning to chill --- pallets/ddc-clusters/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 482c0ce49..16e4f7d88 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -131,6 +131,7 @@ pub mod pallet { .map_err(|_| Error::::AttemptToAddNonExistentNode)?; ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); + // Cluster extension smart contract allows joining. let is_authorized: bool = pallet_contracts::Pallet::::bare_call( caller_id, cluster.props.node_provider_auth_contract, @@ -146,6 +147,7 @@ pub mod pallet { .is_some_and(|x| *x == 1); ensure!(is_authorized, Error::::NotAuthorized); + // Sufficient funds are locked at the DDC Staking module. let node_provider_stash = >::nodes(&node_pub_key).ok_or(Error::::NoStake)?; let maybe_edge_in_cluster = @@ -157,6 +159,16 @@ pub mod pallet { .is_some_and(|staking_cluster| staking_cluster == cluster_id); ensure!(has_stake, Error::::NoStake); + // Candidate is not planning to pause operations any time soon. + let node_provider_controller = + >::bonded(&node_provider_stash) + .ok_or(>::BadState)?; + let chilling = >::ledger(&node_provider_controller) + .ok_or(>::BadState)? + .chilling + .is_some(); + ensure!(!chilling, Error::::ChillingProhibited); + node.set_cluster_id(Some(cluster_id.clone())); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); From 5020deea9e54440e0afbe36c6d3770316621bb87 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Thu, 26 Oct 2023 11:30:07 +0600 Subject: [PATCH 420/544] Bump `cere-dev` runtime `spec_version` --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3279c7529..a44edc47f 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48009, + spec_version: 48010, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From d2cb6000a5a3e4ca388cad6bfaa84fc40a9bb881 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 26 Oct 2023 16:00:07 +0200 Subject: [PATCH 421/544] update type for ClusterId and check cluster exists when allocating bucket --- Cargo.lock | 1417 +++++++++++----------- pallets/ddc-customer-accounts/Cargo.toml | 4 + pallets/ddc-customer-accounts/src/lib.rs | 14 +- pallets/ddc-staking/src/lib.rs | 4 +- 4 files changed, 756 insertions(+), 683 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c24b3b135..e04480f9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,11 +23,11 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ - "gimli 0.27.3", + "gimli 0.28.0", ] [[package]] @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" dependencies = [ "getrandom 0.2.10", "once_cell", @@ -84,9 +84,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -146,9 +146,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "approx" @@ -211,20 +211,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", - "event-listener", + "event-listener 2.5.3", "futures-core", ] [[package]] name = "async-executor" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0" dependencies = [ "async-lock", "async-task", "concurrent-queue", - "fastrand", + "fastrand 2.0.1", "futures-lite", "slab", ] @@ -258,36 +258,53 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.23", + "rustix 0.37.26", "slab", - "socket2 0.4.9", + "socket2 0.4.10", "waker-fn", ] [[package]] name = "async-lock" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ - "event-listener", + "event-listener 2.5.3", ] [[package]] name = "async-process" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" +checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" dependencies = [ "async-io", "async-lock", - "autocfg", + "async-signal", "blocking", "cfg-if", - "event-listener", + "event-listener 3.0.0", "futures-lite", - "rustix 0.37.23", - "signal-hook", + "rustix 0.38.20", + "windows-sys 0.48.0", +] + +[[package]] +name = "async-signal" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2a5415b7abcdc9cd7d63d6badba5288b2ca017e3fbd4173b8f405449f1a2399" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix 0.38.20", + "signal-hook-registry", + "slab", "windows-sys 0.48.0", ] @@ -312,7 +329,7 @@ dependencies = [ "log", "memchr", "once_cell", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "pin-utils", "slab", "wasm-bindgen-futures", @@ -329,45 +346,45 @@ dependencies = [ "futures-io", "futures-util", "pin-utils", - "socket2 0.4.9", + "socket2 0.4.10", "trust-dns-resolver", ] [[package]] name = "async-task" -version = "4.4.0" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" +checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" [[package]] name = "async-trait" -version = "0.1.71" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] name = "asynchronous-codec" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06a0daa378f5fd10634e44b0a29b2a87b890657658e072a30d6f26e57ddee182" +checksum = "4057f2c32adbb2fc158e22fb38433c8e9bbf76b75a4732c7c0cbaf695fb65568" dependencies = [ "bytes", "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", ] [[package]] name = "atomic-waker" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "atty" @@ -388,16 +405,16 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ - "addr2line 0.20.0", + "addr2line 0.21.0", "cc", "cfg-if", "libc", "miniz_oxide", - "object 0.31.1", + "object 0.32.1", "rustc-demangle", ] @@ -427,9 +444,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "base64ct" @@ -473,13 +490,13 @@ dependencies = [ "lazy_static", "lazycell", "peeking_take_while", - "prettyplease 0.2.10", + "prettyplease 0.2.15", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -490,9 +507,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "bitvec" @@ -527,31 +544,31 @@ dependencies = [ [[package]] name = "blake2b_simd" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" dependencies = [ "arrayref", "arrayvec 0.7.4", - "constant_time_eq 0.2.6", + "constant_time_eq 0.3.0", ] [[package]] name = "blake2s_simd" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" +checksum = "94230421e395b9920d23df13ea5d77a20e1725331f90fbbf6df6040b33f756ae" dependencies = [ "arrayref", "arrayvec 0.7.4", - "constant_time_eq 0.2.6", + "constant_time_eq 0.3.0", ] [[package]] name = "blake3" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" dependencies = [ "arrayref", "arrayvec 0.7.4", @@ -601,17 +618,18 @@ dependencies = [ [[package]] name = "blocking" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" dependencies = [ "async-channel", "async-lock", "async-task", - "atomic-waker", - "fastrand", + "fastrand 2.0.1", + "futures-io", "futures-lite", - "log", + "piper", + "tracing", ] [[package]] @@ -622,9 +640,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +checksum = "c79ad7fb2dd38f3dabd76b09c6a5a20c038fc0213ef1e9afd30eb777f120f019" dependencies = [ "memchr", "serde", @@ -641,9 +659,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byte-slice-cast" @@ -659,15 +677,15 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "bzip2-sys" @@ -691,9 +709,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" +checksum = "12024c4645c97566567129c204f65d5815a8c9aecf30fcbe682b2fe034996d36" dependencies = [ "serde", ] @@ -706,18 +724,19 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.18", + "semver 1.0.20", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", ] [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "jobserver", + "libc", ] [[package]] @@ -810,8 +829,8 @@ dependencies = [ "pallet-contracts", "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", - "pallet-ddc-accounts", "pallet-ddc-clusters", + "pallet-ddc-customer-accounts", "pallet-ddc-metrics-offchain-worker", "pallet-ddc-nodes", "pallet-ddc-staking", @@ -1122,17 +1141,16 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", - "time", "wasm-bindgen", - "winapi", + "windows-targets", ] [[package]] @@ -1188,7 +1206,7 @@ dependencies = [ "bitflags 1.3.2", "clap_derive", "clap_lex", - "indexmap", + "indexmap 1.9.3", "once_cell", "strsim", "termcolor", @@ -1239,9 +1257,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" dependencies = [ "crossbeam-utils", ] @@ -1258,12 +1276,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "constant_time_eq" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" - [[package]] name = "constant_time_eq" version = "0.3.0" @@ -1306,9 +1318,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" dependencies = [ "libc", ] @@ -1420,16 +1432,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -1569,18 +1571,31 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-rc.1" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" dependencies = [ "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", "fiat-crypto", - "packed_simd_2", - "platforms 3.0.2", + "platforms 3.1.2", + "rustc_version 0.4.0", "subtle", "zeroize", ] +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "data-encoding" version = "2.4.0" @@ -1759,9 +1774,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" +checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" [[package]] name = "ecdsa" @@ -1805,7 +1820,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ "curve25519-dalek 3.2.0", - "hashbrown", + "hashbrown 0.12.3", "hex", "rand_core 0.6.4", "sha2 0.9.9", @@ -1814,9 +1829,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" @@ -1850,22 +1865,22 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c041f5090df68b32bcd905365fd51769c8b9d553fe87fde0b683534f10c01bd2" +checksum = "5998b4f30320c9d93aed72f63af821bfdac50465b75428fce77b48ec482c3939" dependencies = [ "enumflags2_derive", ] [[package]] name = "enumflags2_derive" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" +checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -1900,6 +1915,12 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48c92028aaa870e83d51c64e5d4e0b6981b360c522198c23959f219a4e1b15b" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.2.8" @@ -1913,11 +1934,10 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys 0.48.0", ] @@ -1938,6 +1958,17 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "event-listener" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite 0.2.13", +] + [[package]] name = "exit-future" version = "0.2.0" @@ -1968,6 +1999,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fdlimit" version = "0.2.1" @@ -1989,9 +2026,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.20" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" +checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" [[package]] name = "file-per-thread-logger" @@ -2005,13 +2042,13 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.21" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.2.16", + "redox_syscall 0.3.5", "windows-sys 0.48.0", ] @@ -2051,9 +2088,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "libz-sys", @@ -2069,7 +2106,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2086,7 +2123,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2109,7 +2146,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "array-bytes 4.2.0", @@ -2139,7 +2176,7 @@ dependencies = [ "sc-service", "sc-sysinfo", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "serde_nanos", "sp-api", "sp-blockchain", @@ -2160,7 +2197,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2171,7 +2208,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2187,7 +2224,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2216,7 +2253,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-metadata", @@ -2248,7 +2285,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2262,7 +2299,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2274,7 +2311,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2284,7 +2321,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2302,7 +2339,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2317,7 +2354,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2326,7 +2363,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -2424,12 +2461,12 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ - "fastrand", + "fastrand 1.9.0", "futures-core", "futures-io", "memchr", "parking", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "waker-fn", ] @@ -2441,7 +2478,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -2486,7 +2523,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "pin-utils", "slab", ] @@ -2570,15 +2607,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", - "indexmap", + "indexmap 1.9.3", "stable_deref_trait", ] [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glob" @@ -2588,9 +2625,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1391ab1f92ffcc08911957149833e682aa3fe252b9f45f966d2ef972274c97df" +checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" dependencies = [ "aho-corasick", "bstr", @@ -2624,9 +2661,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -2634,7 +2671,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -2643,15 +2680,15 @@ dependencies = [ [[package]] name = "handlebars" -version = "4.3.7" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c3372087601b532857d332f5957cbae686da52bb7810bf038c3e3c3cc2fa0d" +checksum = "c39b3bc2a8f715298032cf5087e58573809374b08160aa7d750582bdb82d2683" dependencies = [ "log", "pest", "pest_derive", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "thiserror", ] @@ -2679,6 +2716,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" + [[package]] name = "heck" version = "0.4.1" @@ -2696,9 +2739,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -2749,6 +2792,15 @@ dependencies = [ "hmac 0.8.1", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "hostname" version = "0.3.1" @@ -2779,7 +2831,7 @@ checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", ] [[package]] @@ -2790,9 +2842,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "humantime" @@ -2816,8 +2868,8 @@ dependencies = [ "httparse", "httpdate", "itoa 1.0.9", - "pin-project-lite 0.2.10", - "socket2 0.4.9", + "pin-project-lite 0.2.13", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -2841,16 +2893,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows 0.48.0", + "windows-core", ] [[package]] @@ -2908,7 +2960,7 @@ dependencies = [ "log", "rtnetlink", "system-configuration", - "windows 0.34.0", + "windows", ] [[package]] @@ -2947,10 +2999,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", "serde", ] +[[package]] +name = "indexmap" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown 0.14.2", +] + [[package]] name = "inout" version = "0.1.3" @@ -2990,7 +3052,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", "windows-sys 0.48.0", ] @@ -3007,7 +3069,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2 0.5.3", + "socket2 0.5.5", "widestring", "windows-sys 0.48.0", "winreg", @@ -3015,9 +3077,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" @@ -3025,8 +3087,8 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.2", - "rustix 0.38.4", + "hermit-abi 0.3.3", + "rustix 0.38.20", "windows-sys 0.48.0", ] @@ -3053,9 +3115,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -3128,7 +3190,7 @@ dependencies = [ "rand 0.8.5", "rustc-hash", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "soketto", "thiserror", "tokio", @@ -3149,7 +3211,7 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-types", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "tokio", "tracing", "tracing-futures", @@ -3176,7 +3238,7 @@ dependencies = [ "anyhow", "beef", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "thiserror", "tracing", ] @@ -3204,7 +3266,7 @@ dependencies = [ "http", "jsonrpsee-core", "jsonrpsee-types", - "serde_json 1.0.103", + "serde_json 1.0.107", "soketto", "tokio", "tokio-stream", @@ -3296,9 +3358,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" @@ -3322,15 +3384,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" - -[[package]] -name = "libm" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libp2p" @@ -3420,9 +3476,9 @@ dependencies = [ "prost 0.10.4", "prost-build 0.10.4", "rand 0.8.5", - "ring", + "ring 0.16.20", "rw-stream-sink", - "sha2 0.10.7", + "sha2 0.10.8", "smallvec", "thiserror", "unsigned-varint", @@ -3496,7 +3552,7 @@ dependencies = [ "prost-build 0.10.4", "rand 0.7.3", "regex", - "sha2 0.10.7", + "sha2 0.10.8", "smallvec", "unsigned-varint", "wasm-timer", @@ -3543,7 +3599,7 @@ dependencies = [ "prost 0.10.4", "prost-build 0.10.4", "rand 0.7.3", - "sha2 0.10.7", + "sha2 0.10.8", "smallvec", "thiserror", "uint", @@ -3568,7 +3624,7 @@ dependencies = [ "log", "rand 0.8.5", "smallvec", - "socket2 0.4.9", + "socket2 0.4.10", "void", ] @@ -3621,7 +3677,7 @@ dependencies = [ "prost 0.10.4", "prost-build 0.10.4", "rand 0.8.5", - "sha2 0.10.7", + "sha2 0.10.8", "snow", "static_assertions", "x25519-dalek", @@ -3718,7 +3774,7 @@ dependencies = [ "prost 0.10.4", "prost-build 0.10.4", "rand 0.8.5", - "sha2 0.10.7", + "sha2 0.10.8", "thiserror", "unsigned-varint", "void", @@ -3786,7 +3842,7 @@ dependencies = [ "libc", "libp2p-core", "log", - "socket2 0.4.9", + "socket2 0.4.10", ] [[package]] @@ -3912,9 +3968,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.9" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" +checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" dependencies = [ "cc", "pkg-config", @@ -3960,9 +4016,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lite-json" @@ -3984,9 +4040,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -3994,9 +4050,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" dependencies = [ "value-bag", ] @@ -4007,7 +4063,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" dependencies = [ - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -4071,9 +4127,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "matrixmultiply" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090126dc04f95dc0d1c1c91f61bdd474b3930ca064c1edc8a849da2c6cbe1e77" +checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2" dependencies = [ "autocfg", "rawpointer", @@ -4081,17 +4137,17 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memfd" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.37.23", + "rustix 0.38.20", ] [[package]] @@ -4128,7 +4184,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.12.3", "parity-util-mem", ] @@ -4167,9 +4223,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -4217,7 +4273,7 @@ dependencies = [ "core2", "digest 0.10.7", "multihash-derive", - "sha2 0.10.7", + "sha2 0.10.8", "sha3", "unsigned-varint", ] @@ -4374,7 +4430,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4419,9 +4475,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ "autocfg", "num-integer", @@ -4430,9 +4486,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" dependencies = [ "num-traits", ] @@ -4476,19 +4532,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg", - "num-bigint 0.4.3", + "num-bigint 0.4.4", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", - "libm 0.2.7", + "libm", ] [[package]] @@ -4497,7 +4553,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", ] @@ -4508,16 +4564,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "crc32fast", - "hashbrown", - "indexmap", + "hashbrown 0.12.3", + "indexmap 1.9.3", "memchr", ] [[package]] name = "object" -version = "0.31.1" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] @@ -4548,9 +4604,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "os_str_bytes" -version = "6.5.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "output_vt100" @@ -4570,20 +4626,10 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "packed_simd_2" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282" -dependencies = [ - "cfg-if", - "libm 0.1.4", -] - [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4599,7 +4645,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4614,7 +4660,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4638,7 +4684,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4658,7 +4704,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4673,7 +4719,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4724,7 +4770,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4743,7 +4789,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4760,7 +4806,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -4788,7 +4834,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -4803,7 +4849,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4813,7 +4859,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4830,7 +4876,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -4841,42 +4887,44 @@ dependencies = [ ] [[package]] -name = "pallet-ddc-accounts" -version = "0.1.0" +name = "pallet-ddc-clusters" +version = "4.8.1" dependencies = [ + "ddc-primitives", + "frame-benchmarking", "frame-support", "frame-system", "log", + "pallet-contracts", + "pallet-ddc-nodes", "pallet-ddc-staking", "parity-scale-codec", "scale-info", + "sp-core", "sp-io", "sp-runtime", "sp-staking", "sp-std", + "sp-tracing", "substrate-test-utils", ] [[package]] -name = "pallet-ddc-clusters" -version = "4.8.1" +name = "pallet-ddc-customer-accounts" +version = "0.1.0" dependencies = [ "ddc-primitives", - "frame-benchmarking", "frame-support", "frame-system", "log", - "pallet-contracts", - "pallet-ddc-nodes", + "pallet-ddc-clusters", "pallet-ddc-staking", "parity-scale-codec", "scale-info", - "sp-core", "sp-io", "sp-runtime", "sp-staking", "sp-std", - "sp-tracing", "substrate-test-utils", ] @@ -4954,7 +5002,7 @@ version = "0.1.0" dependencies = [ "alt_serde", "array-bytes 6.1.0", - "base64 0.21.2", + "base64 0.21.5", "ddc-primitives", "frame-election-provider-support", "frame-support", @@ -4963,7 +5011,7 @@ dependencies = [ "log", "pallet-balances", "pallet-contracts", - "pallet-ddc-accounts", + "pallet-ddc-customer-accounts", "pallet-ddc-staking", "pallet-randomness-collective-flip", "pallet-session", @@ -4985,7 +5033,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5001,7 +5049,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5025,7 +5073,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5038,7 +5086,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5094,7 +5142,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5115,7 +5163,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5138,7 +5186,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5154,7 +5202,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5174,7 +5222,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5191,7 +5239,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5208,7 +5256,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5223,7 +5271,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5240,7 +5288,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5260,7 +5308,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5270,7 +5318,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5287,7 +5335,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5310,7 +5358,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5325,7 +5373,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5339,7 +5387,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5354,7 +5402,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5370,7 +5418,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5391,7 +5439,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5407,7 +5455,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5421,7 +5469,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5444,7 +5492,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5455,7 +5503,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5469,7 +5517,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5487,7 +5535,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5506,7 +5554,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5522,7 +5570,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5537,7 +5585,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5548,7 +5596,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5566,7 +5614,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5583,7 +5631,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5599,7 +5647,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5632,9 +5680,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.3" +version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "756d439303e94fae44f288ba881ad29670c65b0c4b0e05674ca81061bb65f2c5" +checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" dependencies = [ "arrayvec 0.7.4", "bitvec", @@ -5647,9 +5695,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.3" +version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d884d78fcf214d70b1e239fcd1c6e5e95aa3be1881918da2e488cc946c7a476" +checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5670,7 +5718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if", - "hashbrown", + "hashbrown 0.12.3", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.1", @@ -5707,9 +5755,9 @@ checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" [[package]] name = "parking" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "parking_lot" @@ -5729,7 +5777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.8", + "parking_lot_core 0.9.9", ] [[package]] @@ -5748,13 +5796,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall 0.4.1", "smallvec", "windows-targets", ] @@ -5797,19 +5845,20 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pest" -version = "2.7.0" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" +checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" dependencies = [ + "memchr", "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.7.0" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" +checksum = "81d78524685f5ef2a3b3bd1cafbc9fcabb036253d9b1463e726a91cd16e2dfc2" dependencies = [ "pest", "pest_generator", @@ -5817,56 +5866,56 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.0" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" +checksum = "68bd1206e71118b5356dae5ddc61c8b11e28b09ef6a31acbd15ea48a28e0c227" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] name = "pest_meta" -version = "2.7.0" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" +checksum = "7c747191d4ad9e4a4ab9c8798f1e82a39affe7ef9648390b7e5548d18e099de6" dependencies = [ "once_cell", "pest", - "sha2 0.10.7", + "sha2 0.10.8", ] [[package]] name = "petgraph" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap", + "indexmap 2.0.2", ] [[package]] name = "pin-project" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -5877,9 +5926,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -5887,6 +5936,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.1", + "futures-io", +] + [[package]] name = "pkcs8" version = "0.8.0" @@ -5912,9 +5972,9 @@ checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" [[package]] name = "platforms" -version = "3.0.2" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" [[package]] name = "polling" @@ -5928,7 +5988,7 @@ dependencies = [ "concurrent-queue", "libc", "log", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "windows-sys 0.48.0", ] @@ -5985,12 +6045,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -6042,9 +6102,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -6236,9 +6296,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.31" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -6357,9 +6417,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -6367,14 +6427,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -6395,6 +6453,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -6408,22 +6475,22 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1641819477c319ef452a075ac34a4be92eb9ba09f6841f62d594d50fdcf0bf6b" +checksum = "acde58d073e9c79da00f2b5b84eed919c8326832648a5b109b3fce1bb1175280" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68bf53dad9b6086826722cdc99140793afd9f62faa14a1ad07eb4f955e7a7216" +checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -6440,14 +6507,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.3", - "regex-syntax 0.7.4", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -6461,13 +6528,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.3" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.8.2", ] [[package]] @@ -6478,21 +6545,21 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", "log", "parity-scale-codec", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-core", "sp-io", "sp-runtime", @@ -6529,12 +6596,26 @@ dependencies = [ "cc", "libc", "once_cell", - "spin", - "untrusted", + "spin 0.5.2", + "untrusted 0.7.1", "web-sys", "winapi", ] +[[package]] +name = "ring" +version = "0.17.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" +dependencies = [ + "cc", + "getrandom 0.2.10", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.48.0", +] + [[package]] name = "rocksdb" version = "0.18.0" @@ -6614,14 +6695,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.18", + "semver 1.0.20", ] [[package]] name = "rustix" -version = "0.35.14" +version = "0.35.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6380889b07a03b5ecf1d44dc9ede6fd2145d84b502a2a9ca0b03c48e0cc3220f" +checksum = "413c4d41e2f1b0814c63567d11618483de0bd64f451b452f2ca43896579486ba" dependencies = [ "bitflags 1.3.2", "errno 0.2.8", @@ -6633,12 +6714,12 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.37.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "84f3f8f960ed3b5a59055428714943298bf3fa2d4a1d53135084e0544829d995" dependencies = [ "bitflags 1.3.2", - "errno 0.3.1", + "errno 0.3.5", "io-lifetimes 1.0.11", "libc", "linux-raw-sys 0.3.8", @@ -6647,25 +6728,25 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ - "bitflags 2.3.3", - "errno 0.3.1", + "bitflags 2.4.1", + "errno 0.3.5", "libc", - "linux-raw-sys 0.4.3", + "linux-raw-sys 0.4.10", "windows-sys 0.48.0", ] [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", - "ring", + "ring 0.16.20", "sct", "webpki", ] @@ -6688,7 +6769,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.2", + "base64 0.21.5", ] [[package]] @@ -6744,7 +6825,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6755,7 +6836,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6782,7 +6863,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6805,7 +6886,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6821,7 +6902,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6830,7 +6911,7 @@ dependencies = [ "sc-network-common", "sc-telemetry", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-core", "sp-runtime", ] @@ -6838,7 +6919,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6849,7 +6930,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "chrono", @@ -6873,7 +6954,7 @@ dependencies = [ "sc-tracing", "sc-utils", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-blockchain", "sp-core", "sp-keyring", @@ -6889,7 +6970,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -6917,7 +6998,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -6942,7 +7023,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6966,7 +7047,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", @@ -7008,7 +7089,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7030,7 +7111,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -7043,7 +7124,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7067,7 +7148,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -7078,7 +7159,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -7105,7 +7186,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -7121,7 +7202,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7136,7 +7217,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", @@ -7144,7 +7225,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-wasm 0.45.0", - "rustix 0.35.14", + "rustix 0.35.15", "sc-allocator", "sc-executor-common", "sp-runtime-interface", @@ -7156,7 +7237,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "array-bytes 4.2.0", @@ -7180,7 +7261,7 @@ dependencies = [ "sc-network-gossip", "sc-telemetry", "sc-utils", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-api", "sp-application-crypto", "sp-arithmetic", @@ -7197,7 +7278,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -7208,7 +7289,7 @@ dependencies = [ "sc-finality-grandpa", "sc-rpc", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-blockchain", "sp-core", "sp-runtime", @@ -7218,7 +7299,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7235,12 +7316,12 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", "parking_lot 0.12.1", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-application-crypto", "sp-core", "sp-keystore", @@ -7250,7 +7331,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7281,7 +7362,7 @@ dependencies = [ "sc-peerset", "sc-utils", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "smallvec", "sp-arithmetic", "sp-blockchain", @@ -7297,7 +7378,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cid", "futures", @@ -7317,7 +7398,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -7343,7 +7424,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7361,7 +7442,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7382,7 +7463,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "fork-tree", @@ -7410,7 +7491,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7429,7 +7510,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "bytes", @@ -7459,20 +7540,20 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", "log", "sc-utils", - "serde_json 1.0.103", + "serde_json 1.0.107", "wasm-timer", ] [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7481,7 +7562,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7496,7 +7577,7 @@ dependencies = [ "sc-tracing", "sc-transaction-pool-api", "sc-utils", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-api", "sp-blockchain", "sp-core", @@ -7511,7 +7592,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7522,7 +7603,7 @@ dependencies = [ "sc-transaction-pool-api", "scale-info", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-core", "sp-rpc", "sp-runtime", @@ -7534,12 +7615,12 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", "log", - "serde_json 1.0.103", + "serde_json 1.0.107", "substrate-prometheus-endpoint", "tokio", ] @@ -7547,7 +7628,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7586,7 +7667,7 @@ dependencies = [ "sc-transaction-pool-api", "sc-utils", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-api", "sp-application-crypto", "sp-block-builder", @@ -7617,7 +7698,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7631,7 +7712,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7641,7 +7722,7 @@ dependencies = [ "sc-consensus-epochs", "sc-finality-grandpa", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-blockchain", "sp-runtime", "thiserror", @@ -7650,7 +7731,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7660,7 +7741,7 @@ dependencies = [ "regex", "sc-telemetry", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-core", "sp-io", "sp-std", @@ -7669,7 +7750,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7679,7 +7760,7 @@ dependencies = [ "pin-project", "rand 0.7.3", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "thiserror", "wasm-timer", ] @@ -7687,7 +7768,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7718,7 +7799,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7729,7 +7810,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7755,7 +7836,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7768,7 +7849,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7780,9 +7861,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" dependencies = [ "bitvec", "cfg-if", @@ -7794,9 +7875,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7833,18 +7914,18 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sct" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring", - "untrusted", + "ring 0.17.5", + "untrusted 0.9.0", ] [[package]] @@ -7889,9 +7970,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -7902,9 +7983,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -7930,9 +8011,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" dependencies = [ "serde", ] @@ -7945,22 +8026,22 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.171" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.171" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -7975,9 +8056,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.103" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa 1.0.9", "ryu", @@ -8033,9 +8114,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -8054,28 +8135,18 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ "lazy_static", ] [[package]] name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - -[[package]] -name = "signal-hook" -version = "0.3.16" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b824b6e687aff278cdbf3b36f07aa52d4bd4099699324d5da86a2ebce3aa00b3" -dependencies = [ - "libc", - "signal-hook-registry", -] +checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" [[package]] name = "signal-hook-registry" @@ -8110,9 +8181,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] @@ -8125,9 +8196,9 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "snap" @@ -8137,26 +8208,26 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "snow" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ccba027ba85743e09d15c03296797cad56395089b832b48b5a5217880f57733" +checksum = "0c9d1425eb528a21de2755c75af4c9b5d57f50a0d4c3b7f1828a4cd03f8ba155" dependencies = [ "aes-gcm", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-rc.1", + "curve25519-dalek 4.1.1", "rand_core 0.6.4", - "ring", + "ring 0.16.20", "rustc_version 0.4.0", - "sha2 0.10.7", + "sha2 0.10.8", "subtle", ] [[package]] name = "socket2" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", @@ -8164,9 +8235,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.3" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys 0.48.0", @@ -8191,7 +8262,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8209,7 +8280,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -8221,7 +8292,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8234,7 +8305,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -8249,7 +8320,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8262,7 +8333,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8274,7 +8345,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8286,7 +8357,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8304,7 +8375,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8323,7 +8394,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8346,7 +8417,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8360,7 +8431,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8373,7 +8444,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "base58", @@ -8419,12 +8490,12 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", "digest 0.10.7", - "sha2 0.10.7", + "sha2 0.10.8", "sha3", "sp-std", "twox-hash", @@ -8433,7 +8504,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8444,7 +8515,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8453,7 +8524,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8463,7 +8534,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8474,7 +8545,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8492,7 +8563,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8506,7 +8577,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8532,7 +8603,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8543,7 +8614,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8560,7 +8631,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8569,7 +8640,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8583,7 +8654,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8593,7 +8664,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8603,7 +8674,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8613,7 +8684,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8636,7 +8707,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8654,7 +8725,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8666,7 +8737,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8680,7 +8751,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8694,7 +8765,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8705,7 +8776,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8727,12 +8798,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8745,7 +8816,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8758,7 +8829,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8774,7 +8845,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8786,7 +8857,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8795,7 +8866,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8811,11 +8882,11 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", - "hashbrown", + "hashbrown 0.12.3", "lazy_static", "lru", "memory-db", @@ -8834,7 +8905,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8851,7 +8922,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8862,7 +8933,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8875,7 +8946,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -8894,6 +8965,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "spki" version = "0.5.4" @@ -8906,16 +8983,16 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.41.0" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc443bad666016e012538782d9e3006213a7db43e9fb1dda91657dc06a6fa08" +checksum = "5e6915280e2d0db8911e5032a5c275571af6bdded2916abd691a659be25d3439" dependencies = [ "Inflector", "num-format", "proc-macro2", "quote", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "unicode-xid", ] @@ -9016,7 +9093,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -9024,7 +9101,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -9034,7 +9111,7 @@ dependencies = [ "sc-client-api", "sc-rpc-api", "sc-transaction-pool-api", - "serde_json 1.0.103", + "serde_json 1.0.107", "sp-api", "sp-block-builder", "sp-blockchain", @@ -9045,7 +9122,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -9058,7 +9135,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -9079,7 +9156,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -9089,7 +9166,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9100,7 +9177,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -9133,9 +9210,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.26" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -9183,29 +9260,28 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.9" +version = "0.12.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8e77cb757a61f51b947ec4a7e3646efd825b73561db1c232a8ccb639e611a0" +checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" [[package]] name = "tempfile" -version = "3.6.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "autocfg", "cfg-if", - "fastrand", + "fastrand 2.0.1", "redox_syscall 0.3.5", - "rustix 0.37.23", + "rustix 0.38.20", "windows-sys 0.48.0", ] [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] @@ -9218,22 +9294,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.43" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.43" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -9272,17 +9348,6 @@ dependencies = [ "libc", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "tiny-bip39" version = "0.8.2" @@ -9319,20 +9384,19 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", "mio", "num_cpus", "parking_lot 0.12.1", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "signal-hook-registry", - "socket2 0.4.9", + "socket2 0.5.5", "tokio-macros", "windows-sys 0.48.0", ] @@ -9345,7 +9409,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -9366,21 +9430,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "tokio", ] [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "tokio", "tracing", ] @@ -9402,32 +9466,31 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", - "pin-project-lite 0.2.10", + "pin-project-lite 0.2.13", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -9445,12 +9508,12 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" dependencies = [ - "lazy_static", "log", + "once_cell", "tracing-core", ] @@ -9477,7 +9540,7 @@ dependencies = [ "parking_lot 0.11.2", "regex", "serde", - "serde_json 1.0.103", + "serde_json 1.0.107", "sharded-slab", "smallvec", "thread_local", @@ -9494,7 +9557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "004e1e8f92535694b4cb1444dc5a8073ecf0815e3357f729638b9f8fc4062908" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.12.3", "log", "rustc-hex", "smallvec", @@ -9561,7 +9624,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", @@ -9604,9 +9667,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" @@ -9628,9 +9691,9 @@ dependencies = [ [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] @@ -9643,9 +9706,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -9658,9 +9721,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" @@ -9680,9 +9743,9 @@ dependencies = [ [[package]] name = "unsigned-varint" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" +checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" dependencies = [ "asynchronous-codec", "bytes", @@ -9696,6 +9759,12 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.4.1" @@ -9715,9 +9784,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92ccd67fb88503048c01b59152a04effd0782d035a83a6d256ce6085f08f4a3" +checksum = "4a72e1902dde2bd6441347de2b70b7f5d59bf157c6c62f0c44572607a1d55bbe" [[package]] name = "vcpkg" @@ -9739,15 +9808,15 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "waker-fn" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", "winapi-util", @@ -9768,12 +9837,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -9801,7 +9864,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -9835,7 +9898,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -9908,7 +9971,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57d20cb3c59b788653d99541c646c561c9dd26506f25c0cebfe810659c54c6d7" dependencies = [ "downcast-rs", - "libm 0.2.7", + "libm", "memory_units", "num-rational 0.4.1", "num-traits", @@ -9920,7 +9983,7 @@ version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5d3e08b13876f96dd55608d03cd4883a0545884932d5adf11925876c96daef" dependencies = [ - "indexmap", + "indexmap 1.9.3", ] [[package]] @@ -9932,7 +9995,7 @@ dependencies = [ "anyhow", "bincode", "cfg-if", - "indexmap", + "indexmap 1.9.3", "libc", "log", "object 0.29.0", @@ -9972,7 +10035,7 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix 0.35.14", + "rustix 0.35.15", "serde", "sha2 0.9.9", "toml", @@ -10010,7 +10073,7 @@ dependencies = [ "anyhow", "cranelift-entity", "gimli 0.26.2", - "indexmap", + "indexmap 1.9.3", "log", "object 0.29.0", "serde", @@ -10035,7 +10098,7 @@ dependencies = [ "log", "object 0.29.0", "rustc-demangle", - "rustix 0.35.14", + "rustix 0.35.15", "serde", "target-lexicon", "thiserror", @@ -10053,7 +10116,7 @@ checksum = "f671b588486f5ccec8c5a3dba6b4c07eac2e66ab8c60e6f4e53717c77f709731" dependencies = [ "object 0.29.0", "once_cell", - "rustix 0.35.14", + "rustix 0.35.15", ] [[package]] @@ -10065,7 +10128,7 @@ dependencies = [ "anyhow", "cc", "cfg-if", - "indexmap", + "indexmap 1.9.3", "libc", "log", "mach", @@ -10073,7 +10136,7 @@ dependencies = [ "memoffset 0.6.5", "paste", "rand 0.8.5", - "rustix 0.35.14", + "rustix 0.35.15", "thiserror", "wasmtime-asm-macros", "wasmtime-environ", @@ -10105,12 +10168,12 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.0" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring", - "untrusted", + "ring 0.17.5", + "untrusted 0.9.0", ] [[package]] @@ -10124,13 +10187,14 @@ dependencies = [ [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix 0.38.20", ] [[package]] @@ -10157,9 +10221,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -10184,10 +10248,10 @@ dependencies = [ ] [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ "windows-targets", ] @@ -10231,17 +10295,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -10252,9 +10316,9 @@ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" @@ -10276,9 +10340,9 @@ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" @@ -10300,9 +10364,9 @@ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" @@ -10324,9 +10388,9 @@ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" @@ -10348,9 +10412,9 @@ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" @@ -10360,9 +10424,9 @@ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" @@ -10384,9 +10448,9 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" @@ -10449,7 +10513,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.38", ] [[package]] @@ -10473,11 +10537,10 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" +version = "2.0.9+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/pallets/ddc-customer-accounts/Cargo.toml b/pallets/ddc-customer-accounts/Cargo.toml index 3f3ed6fcb..a0b59e62e 100644 --- a/pallets/ddc-customer-accounts/Cargo.toml +++ b/pallets/ddc-customer-accounts/Cargo.toml @@ -5,8 +5,10 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -22,6 +24,8 @@ substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/parity default = ["std"] std = [ "codec/std", + "ddc-primitives/std", + "pallet-ddc-clusters/std", "frame-support/std", "frame-system/std", "scale-info/std", diff --git a/pallets/ddc-customer-accounts/src/lib.rs b/pallets/ddc-customer-accounts/src/lib.rs index f9d062b69..fa970cc61 100644 --- a/pallets/ddc-customer-accounts/src/lib.rs +++ b/pallets/ddc-customer-accounts/src/lib.rs @@ -3,11 +3,13 @@ use codec::{Decode, Encode, HasCompact}; +use ddc_primitives::ClusterId; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, BoundedVec, PalletId, }; +pub use pallet_ddc_clusters::{self as ddc_clusters}; pub use pallet_ddc_staking::{self as ddc_staking}; use scale_info::TypeInfo; use sp_runtime::{ @@ -43,7 +45,7 @@ pub struct UnlockChunk { pub struct Bucket { bucket_id: u128, owner_id: AccountId, - cluster_id: Option, + cluster_id: Option, public_availability: bool, resources_reserved: u128, } @@ -146,7 +148,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + ddc_staking::Config { + pub trait Config: frame_system::Config + ddc_staking::Config + ddc_clusters::Config { /// The accounts's pallet id, used for deriving its sovereign account ID. #[pallet::constant] type PalletId: Get; @@ -215,6 +217,8 @@ pub mod pallet { DDCEraNotSet, /// Bucket with specified id doesn't exist BucketDoesNotExist, + /// DDC Cluster with provided id doesn't exist + ClusterDoesNotExist, } #[pallet::genesis_config] @@ -272,7 +276,7 @@ pub mod pallet { pub fn allocate_bucket_to_cluster( origin: OriginFor, bucket_id: u128, - cluster_id: u128, + cluster_id: ClusterId, ) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; @@ -280,6 +284,10 @@ pub mod pallet { ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); + ensure!( + ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), + Error::::ClusterDoesNotExist + ); bucket.cluster_id = Some(cluster_id); Ok(()) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index c349b3271..dc6164a38 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -609,9 +609,7 @@ pub mod pallet { // Note: in case there is no current era it is fine to bond one era more. let era = Self::current_era().unwrap_or(0) + T::BondingDuration::get(); - if let Some(mut chunk) = - ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) - { + if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { // To keep the chunk count down, we only keep one chunk per era. Since // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will // be the last one. From caede3080efd9a7f02fef5fd9bffb16a34ed1a16 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 26 Oct 2023 16:19:24 +0200 Subject: [PATCH 422/544] rename ddc-customer-accounts to ddc-customers --- Cargo.lock | 6 +- Cargo.toml | 2 +- node/service/src/chain_spec.rs | 2 +- pallets/ddc-customer-accounts/Cargo.toml | 36 -- pallets/ddc-customer-accounts/src/lib.rs | 575 ----------------------- pallets/ddc-validator/Cargo.toml | 4 +- pallets/ddc-validator/src/lib.rs | 14 +- pallets/ddc-validator/src/tests.rs | 6 +- runtime/cere-dev/Cargo.toml | 4 +- runtime/cere-dev/src/lib.rs | 12 +- 10 files changed, 25 insertions(+), 636 deletions(-) delete mode 100644 pallets/ddc-customer-accounts/Cargo.toml delete mode 100644 pallets/ddc-customer-accounts/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e04480f9b..4447d7ae3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -830,7 +830,7 @@ dependencies = [ "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", "pallet-ddc-clusters", - "pallet-ddc-customer-accounts", + "pallet-ddc-customers", "pallet-ddc-metrics-offchain-worker", "pallet-ddc-nodes", "pallet-ddc-staking", @@ -4910,7 +4910,7 @@ dependencies = [ ] [[package]] -name = "pallet-ddc-customer-accounts" +name = "pallet-ddc-customers" version = "0.1.0" dependencies = [ "ddc-primitives", @@ -5011,7 +5011,7 @@ dependencies = [ "log", "pallet-balances", "pallet-contracts", - "pallet-ddc-customer-accounts", + "pallet-ddc-customers", "pallet-ddc-staking", "pallet-randomness-collective-flip", "pallet-session", diff --git a/Cargo.toml b/Cargo.toml index e5687657f..0cf3246b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ members = [ "pallets/erc20", "pallets/ddc-metrics-offchain-worker", "pallets/ddc-validator", - "pallets/ddc-customer-accounts", + "pallets/ddc-customers", "pallets/ddc-nodes", "pallets/ddc-clusters", "primitives", diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 412649e65..1559b913a 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -233,7 +233,7 @@ pub fn cere_dev_genesis( }, vesting: Default::default(), transaction_payment: Default::default(), - ddc_accounts: Default::default(), + ddc_customers: Default::default(), nomination_pools: Default::default(), } } diff --git a/pallets/ddc-customer-accounts/Cargo.toml b/pallets/ddc-customer-accounts/Cargo.toml deleted file mode 100644 index a0b59e62e..000000000 --- a/pallets/ddc-customer-accounts/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "pallet-ddc-customer-accounts" -version = "0.1.0" -edition = "2021" - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } -pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } - -[dev-dependencies] -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } - -[features] -default = ["std"] -std = [ - "codec/std", - "ddc-primitives/std", - "pallet-ddc-clusters/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "sp-staking/std", - "sp-std/std", -] diff --git a/pallets/ddc-customer-accounts/src/lib.rs b/pallets/ddc-customer-accounts/src/lib.rs deleted file mode 100644 index fa970cc61..000000000 --- a/pallets/ddc-customer-accounts/src/lib.rs +++ /dev/null @@ -1,575 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![recursion_limit = "256"] - -use codec::{Decode, Encode, HasCompact}; - -use ddc_primitives::ClusterId; -use frame_support::{ - parameter_types, - traits::{Currency, DefensiveSaturating, ExistenceRequirement}, - BoundedVec, PalletId, -}; -pub use pallet_ddc_clusters::{self as ddc_clusters}; -pub use pallet_ddc_staking::{self as ddc_staking}; -use scale_info::TypeInfo; -use sp_runtime::{ - traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, - RuntimeDebug, SaturatedConversion, -}; -use sp_staking::EraIndex; -use sp_std::prelude::*; - -pub use pallet::*; - -/// The balance type of this pallet. -pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - -parameter_types! { - /// A limit to the number of pending unlocks an account may have in parallel. - pub MaxUnlockingChunks: u32 = 32; -} - -/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct UnlockChunk { - /// Amount of funds to be unlocked. - #[codec(compact)] - value: Balance, - /// Era number at which point it'll be unlocked. - #[codec(compact)] - era: EraIndex, -} - -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct Bucket { - bucket_id: u128, - owner_id: AccountId, - cluster_id: Option, - public_availability: bool, - resources_reserved: u128, -} - -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct BucketsDetails { - pub bucket_id: u128, - pub amount: Balance, -} - -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct AccountsLedger { - /// The owner account whose balance is actually locked and can be used for CDN usage. - pub owner: AccountId, - /// The total amount of the owner's balance that we are currently accounting for. - /// It's just `active` plus all the `unlocking` balances. - #[codec(compact)] - pub total: Balance, - /// The total amount of the owner's balance that will be accessible for CDN payments in any - /// forthcoming rounds. - #[codec(compact)] - pub active: Balance, - /// Any balance that is becoming free, which may eventually be transferred out of the owner - /// (assuming that the content owner has to pay for network usage). It is assumed that this - /// will be treated as a first in, first out queue where the new (higher value) eras get pushed - /// on the back. - pub unlocking: BoundedVec, MaxUnlockingChunks>, -} - -impl - AccountsLedger -{ - /// Initializes the default object using the given owner. - pub fn default_from(owner: AccountId) -> Self { - Self { owner, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } - } - - /// Remove entries from `unlocking` that are sufficiently old and reduce the - /// total by the sum of their balances. - fn consolidate_unlocked(self, current_era: EraIndex) -> Self { - let mut total = self.total; - let unlocking: BoundedVec<_, _> = self - .unlocking - .into_iter() - .filter(|chunk| { - log::debug!("Chunk era: {:?}", chunk.era); - if chunk.era > current_era { - true - } else { - total = total.saturating_sub(chunk.value); - false - } - }) - .collect::>() - .try_into() - .expect( - "filtering items from a bounded vec always leaves length less than bounds. qed", - ); - - Self { owner: self.owner, total, active: self.active, unlocking } - } - - /// Charge funds that were scheduled for unlocking. - /// - /// Returns the updated ledger, and the amount actually charged. - fn charge_unlocking(mut self, value: Balance) -> (Self, Balance) { - let mut unlocking_balance = Balance::zero(); - - while let Some(last) = self.unlocking.last_mut() { - if unlocking_balance + last.value <= value { - unlocking_balance += last.value; - self.active -= last.value; - self.unlocking.pop(); - } else { - let diff = value - unlocking_balance; - - unlocking_balance += diff; - self.active -= diff; - last.value -= diff; - } - - if unlocking_balance >= value { - break - } - } - - (self, unlocking_balance) - } -} - -#[frame_support::pallet] -pub mod pallet { - use super::*; - use frame_support::{pallet_prelude::*, traits::LockableCurrency}; - use frame_system::pallet_prelude::*; - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config + ddc_staking::Config + ddc_clusters::Config { - /// The accounts's pallet id, used for deriving its sovereign account ID. - #[pallet::constant] - type PalletId: Get; - type Currency: LockableCurrency; - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// Number of eras that staked funds must remain bonded for. - #[pallet::constant] - type BondingDuration: Get; - } - - /// Map from all (unlocked) "owner" accounts to the info regarding the staking. - #[pallet::storage] - #[pallet::getter(fn ledger)] - pub type Ledger = - StorageMap<_, Identity, T::AccountId, AccountsLedger>>; - - #[pallet::type_value] - pub fn DefaultBucketCount() -> u128 { - 0_u128 - } - #[pallet::storage] - #[pallet::getter(fn buckets_count)] - pub type BucketsCount = - StorageValue>; - - /// Map from bucket ID to to the bucket structure - #[pallet::storage] - #[pallet::getter(fn buckets)] - pub type Buckets = - StorageMap<_, Twox64Concat, u128, Bucket, OptionQuery>; - - #[pallet::event] - #[pallet::generate_deposit(pub(crate) fn deposit_event)] - pub enum Event { - /// An account has bonded this amount. \[owner, amount\] - /// - /// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably, - /// it will not be emitted for staking rewards when they are added to stake. - Deposited(T::AccountId, BalanceOf), - /// An account has unbonded this amount. \[owner, amount\] - Unbonded(T::AccountId, BalanceOf), - /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` - /// from the unlocking queue. \[owner, amount\] - Withdrawn(T::AccountId, BalanceOf), - /// Total amount charged from all accounts to pay CDN nodes - Charged(BalanceOf), - } - - #[pallet::error] - pub enum Error { - /// Not a owner account. - NotOwner, - /// Not an owner of bucket - NotBucketOwner, - /// Owner is already bonded. - AlreadyPaired, - /// Cannot deposit dust - InsufficientDeposit, - /// Can not schedule more unlock chunks. - NoMoreChunks, - /// Bucket with speicifed id doesn't exist. - NoBucketWithId, - /// Internal state has become somehow corrupted and the operation cannot continue. - BadState, - /// Current era not set during runtime - DDCEraNotSet, - /// Bucket with specified id doesn't exist - BucketDoesNotExist, - /// DDC Cluster with provided id doesn't exist - ClusterDoesNotExist, - } - - #[pallet::genesis_config] - pub struct GenesisConfig; - - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self - } - } - - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) { - let account_id = >::account_id(); - let min = ::Currency::minimum_balance(); - if ::Currency::free_balance(&account_id) < min { - let _ = ::Currency::make_free_balance_be(&account_id, min); - } - } - } - - #[pallet::call] - impl Pallet { - /// Create new bucket with provided public availability & reserved resources - /// - /// Anyone can create a bucket - #[pallet::weight(10_000)] - pub fn create_bucket( - origin: OriginFor, - public_availability: bool, - resources_reserved: u128, - ) -> DispatchResult { - let bucket_owner = ensure_signed(origin)?; - let cur_bucket_id = Self::buckets_count(); - - let bucket = Bucket { - bucket_id: cur_bucket_id + 1, - owner_id: bucket_owner, - cluster_id: None, - public_availability, - resources_reserved, - }; - - >::set(cur_bucket_id + 1); - >::insert(cur_bucket_id + 1, bucket); - Ok(()) - } - - /// Allocates specified bucket into specified cluster - /// - /// Only bucket owner can call this method - #[pallet::weight(10_000)] - pub fn allocate_bucket_to_cluster( - origin: OriginFor, - bucket_id: u128, - cluster_id: ClusterId, - ) -> DispatchResult { - let bucket_owner = ensure_signed(origin)?; - - let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; - - ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); - - ensure!( - ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), - Error::::ClusterDoesNotExist - ); - bucket.cluster_id = Some(cluster_id); - - Ok(()) - } - - /// Take the origin account as a owner and lock up `value` of its balance. `Owner` will - /// be the account that controls it. - /// - /// `value` must be more than the `minimum_balance` specified by `T::Currency`. - /// - /// The dispatch origin for this call must be _Signed_ by the owner account. - /// - /// Emits `Deposited`. - #[pallet::weight(10_000)] - pub fn deposit( - origin: OriginFor, - #[pallet::compact] value: BalanceOf, - ) -> DispatchResult { - let owner = ensure_signed(origin)?; - - if >::contains_key(&owner) { - Err(Error::::AlreadyPaired)? - } - - // Reject a deposit which is considered to be _dust_. - if value < ::Currency::minimum_balance() { - Err(Error::::InsufficientDeposit)? - } - - frame_system::Pallet::::inc_consumers(&owner).map_err(|_| Error::::BadState)?; - - let owner_balance = ::Currency::free_balance(&owner); - let value = value.min(owner_balance); - let item = AccountsLedger { - owner: owner.clone(), - total: value, - active: value, - unlocking: Default::default(), - }; - Self::update_ledger_and_deposit(&owner, &item)?; - Self::deposit_event(Event::::Deposited(owner, value)); - Ok(()) - } - - /// Add some extra amount that have appeared in the owner `free_balance` into the balance up - /// for CDN payments. - /// - /// The dispatch origin for this call must be _Signed_ by the owner. - /// - /// Emits `Deposited`. - #[pallet::weight(10_000)] - pub fn deposit_extra( - origin: OriginFor, - #[pallet::compact] max_additional: BalanceOf, - ) -> DispatchResult { - let owner = ensure_signed(origin)?; - - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; - - let owner_balance = ::Currency::free_balance(&owner); - let extra = owner_balance.min(max_additional); - ledger.total += extra; - ledger.active += extra; - // Last check: the new active amount of ledger must be more than ED. - ensure!( - ledger.active >= ::Currency::minimum_balance(), - Error::::InsufficientDeposit - ); - - Self::update_ledger_and_deposit(&owner, &ledger)?; - - Self::deposit_event(Event::::Deposited(owner.clone(), extra)); - - Ok(()) - } - - /// Schedule a portion of the owner to be unlocked ready for transfer out after the bond - /// period ends. If this leaves an amount actively bonded less than - /// T::Currency::minimum_balance(), then it is increased to the full amount. - /// - /// The dispatch origin for this call must be _Signed_ by the owner. - /// - /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move - /// the funds out of management ready for transfer. - /// - /// No more than a limited number of unlocking chunks (see `MaxUnlockingChunks`) - /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need - /// to be called first to remove some of the chunks (if possible). - /// - /// Emits `Unbonded`. - /// - /// See also [`Call::withdraw_unbonded`]. - #[pallet::weight(10_000)] - pub fn unbond( - origin: OriginFor, - #[pallet::compact] value: BalanceOf, - ) -> DispatchResult { - let owner = ensure_signed(origin)?; - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; - ensure!( - ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, - Error::::NoMoreChunks, - ); - - let mut value = value.min(ledger.active); - - if !value.is_zero() { - ledger.active -= value; - - // Avoid there being a dust balance left in the accounts system. - if ledger.active < ::Currency::minimum_balance() { - value += ledger.active; - ledger.active = Zero::zero(); - } - - let current_era = ddc_staking::pallet::Pallet::::current_era() - .ok_or(Error::::DDCEraNotSet)?; - // Note: bonding for extra era to allow for accounting - let era = current_era + ::BondingDuration::get(); - log::debug!("Era for the unbond: {:?}", era); - - if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { - // To keep the chunk count down, we only keep one chunk per era. Since - // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will - // be the last one. - chunk.value = chunk.value.defensive_saturating_add(value) - } else { - ledger - .unlocking - .try_push(UnlockChunk { value, era }) - .map_err(|_| Error::::NoMoreChunks)?; - }; - - Self::update_ledger(&owner, &ledger); - - Self::deposit_event(Event::::Unbonded(ledger.owner, value)); - } - Ok(()) - } - - /// Remove any unlocked chunks from the `unlocking` queue from our management. - /// - /// This essentially frees up that balance to be used by the owner account to do - /// whatever it wants. - /// - /// The dispatch origin for this call must be _Signed_ by the owner. - /// - /// Emits `Withdrawn`. - /// - /// See also [`Call::unbond`]. - #[pallet::weight(10_000)] - pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { - let owner = ensure_signed(origin)?; - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; - let (owner, old_total) = (ledger.owner.clone(), ledger.total); - let current_era = - ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; - ledger = ledger.consolidate_unlocked(current_era); - log::debug!("Current era: {:?}", current_era); - - if ledger.unlocking.is_empty() && - ledger.active < ::Currency::minimum_balance() - { - log::debug!("Killing owner"); - // This account must have called `unbond()` with some value that caused the active - // portion to fall below existential deposit + will have no more unlocking chunks - // left. We can now safely remove all accounts-related information. - Self::kill_owner(&owner)?; - } else { - log::debug!("Updating ledger"); - // This was the consequence of a partial unbond. just update the ledger and move on. - Self::update_ledger(&owner, &ledger); - }; - - log::debug!("Current total: {:?}", ledger.total); - log::debug!("Old total: {:?}", old_total); - - // `old_total` should never be less than the new total because - // `consolidate_unlocked` strictly subtracts balance. - if ledger.total < old_total { - log::debug!("Preparing for transfer"); - // Already checked that this won't overflow by entry condition. - let value = old_total - ledger.total; - - let account_id = Self::account_id(); - - ::Currency::transfer( - &account_id, - &owner, - value, - ExistenceRequirement::KeepAlive, - )?; - Self::deposit_event(Event::::Withdrawn(owner, value)); - } - - Ok(()) - } - } - - impl Pallet { - pub fn account_id() -> T::AccountId { - T::PalletId::get().into_account_truncating() - } - /// Update the ledger for a owner. - /// - /// This will also deposit the funds to pallet. - fn update_ledger_and_deposit( - owner: &T::AccountId, - ledger: &AccountsLedger>, - ) -> DispatchResult { - let account_id = Self::account_id(); - - ::Currency::transfer( - owner, - &account_id, - ledger.total, - ExistenceRequirement::KeepAlive, - )?; - >::insert(owner, ledger); - - Ok(()) - } - - /// Update the ledger for a owner. - fn update_ledger( - owner: &T::AccountId, - ledger: &AccountsLedger>, - ) { - >::insert(owner, ledger); - } - - /// Remove all associated data of a owner account from the accounts system. - /// - /// Assumes storage is upgraded before calling. - /// - /// This is called: - /// - after a `withdraw_unbonded()` call that frees all of a owner's bonded balance. - fn kill_owner(owner: &T::AccountId) -> DispatchResult { - >::remove(&owner); - - frame_system::Pallet::::dec_consumers(owner); - - Ok(()) - } - - // Charge payments from content owners - pub fn charge_content_owners( - paying_accounts: Vec>>, - pricing: u128, - ) -> DispatchResult { - let mut total_charged = BalanceOf::::zero(); - - for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id) - .ok_or(Error::::BucketDoesNotExist)?; - let content_owner = bucket.owner_id; - let amount = bucket_details.amount * pricing.saturated_into::>(); - - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; - if ledger.active >= amount { - ledger.total -= amount; - ledger.active -= amount; - total_charged += amount; - log::debug!("Ledger updated state: {:?}", &ledger); - Self::update_ledger(&content_owner, &ledger); - } else { - let diff = amount - ledger.active; - total_charged += ledger.active; - ledger.total -= ledger.active; - ledger.active = BalanceOf::::zero(); - let (ledger, charged) = ledger.charge_unlocking(diff); - log::debug!("Ledger updated state: {:?}", &ledger); - Self::update_ledger(&content_owner, &ledger); - total_charged += charged; - } - } - log::debug!("Total charged: {:?}", &total_charged); - - Self::deposit_event(Event::::Charged(total_charged)); - log::debug!("Deposit event executed"); - - Ok(()) - } - } -} diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 1c5200e79..b608de995 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -14,7 +14,7 @@ frame-system = { version = "4.0.0-dev", default-features = false, git = "https:/ lite-json = { version = "0.2.0", default-features = false } log = { version = "0.4.17", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-customer-accounts = { version = "0.1.0", default-features = false, path = "../ddc-customer-accounts" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../ddc-customers" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -44,7 +44,7 @@ std = [ "frame-system/std", "lite-json/std", "pallet-contracts/std", - "pallet-ddc-customer-accounts/std", + "pallet-ddc-customers/std", "pallet-ddc-staking/std", "pallet-session/std", "pallet-staking/std", diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs index 647332f9f..fc6d1109c 100644 --- a/pallets/ddc-validator/src/lib.rs +++ b/pallets/ddc-validator/src/lib.rs @@ -47,7 +47,7 @@ pub use frame_system::{ }; pub use lite_json::json::JsonValue; pub use pallet::*; -pub use pallet_ddc_customer_accounts::{self as ddc_accounts, BucketsDetails}; +pub use pallet_ddc_customers::{self as ddc_customers, BucketsDetails}; pub use pallet_ddc_staking::{self as ddc_staking}; pub use pallet_session as session; pub use pallet_staking::{self as staking}; @@ -196,7 +196,7 @@ pub mod pallet { + pallet_contracts::Config + pallet_session::Config::AccountId> + pallet_staking::Config - + ddc_accounts::Config + + ddc_customers::Config + ddc_staking::Config + CreateSignedTransaction> where @@ -536,9 +536,9 @@ pub mod pallet { #[pallet::weight(100_000)] pub fn charge_payments_content_owners( origin: OriginFor, - paying_accounts: Vec>>, /* ToDo check if - * bounded vec - * should be used */ + paying_accounts: Vec>>, /* ToDo check if + * bounded vec + * should be used */ ) -> DispatchResult { let ddc_valitor_key = ensure_signed(origin)?; log::debug!("validator is {:?}", &ddc_valitor_key); @@ -567,7 +567,7 @@ pub mod pallet { >::pricing().ok_or(Error::::PricingNotSet)?; EraContentOwnersCharged::::insert(current_era, ddc_valitor_key, true); - >::charge_content_owners(paying_accounts, pricing) + >::charge_content_owners(paying_accounts, pricing) } /// Exstrinsic registers a ddc validator key for future use @@ -914,7 +914,7 @@ pub mod pallet { let mut payments: BTreeMap< u128, - BucketsDetails>, + BucketsDetails>, > = BTreeMap::new(); for bucket in payments_per_bucket.into_iter() { let cere_payment = bucket.1 as u32; diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 5fa240a5f..6626dbd39 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -526,7 +526,7 @@ fn charge_payments_content_owners_works_as_expected() { // Create buckets for range in 1..6 { - assert_ok!(ddc_accounts::Pallet::::create_bucket( + assert_ok!(ddc_customers::Pallet::::create_bucket( RuntimeOrigin::signed(validator_1_stash.clone()), true, range @@ -543,7 +543,7 @@ fn charge_payments_content_owners_works_as_expected() { ); // Deposit funds for account - assert_ok!(ddc_accounts::Pallet::::deposit( + assert_ok!(ddc_customers::Pallet::::deposit( RuntimeOrigin::signed(validator_1_stash.clone()), validator_1_stash.clone(), 1_000, @@ -564,7 +564,7 @@ fn charge_payments_content_owners_works_as_expected() { ); let last_evt = System::events().pop().expect("Event expected").event; - assert_eq!(last_evt, ddc_accounts::Event::Charged(bucket_info.amount).into()); + assert_eq!(last_evt, ddc_customers::Event::Charged(bucket_info.amount).into()); }) } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 7302356bc..c5188dbd5 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -99,7 +99,7 @@ cere-dev-runtime-constants = { path = "./constants", default-features = false } pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } -pallet-ddc-customer-accounts = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customer-accounts" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } pallet-ddc-validator = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-validator" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } @@ -186,7 +186,7 @@ std = [ "cere-runtime-common/std", "cere-dev-runtime-constants/std", "pallet-ddc-validator/std", - "pallet-ddc-customer-accounts/std", + "pallet-ddc-customers/std", "pallet-ddc-nodes/std", "pallet-ddc-clusters/std", ] diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 65baf978d..a023034a2 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -49,7 +49,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment}; pub use pallet_cere_ddc; pub use pallet_chainbridge; pub use pallet_ddc_clusters; -pub use pallet_ddc_customer_accounts; +pub use pallet_ddc_customers; pub use pallet_ddc_metrics_offchain_worker; pub use pallet_ddc_nodes; pub use pallet_ddc_staking; @@ -1331,19 +1331,19 @@ impl pallet_ddc_staking::Config for Runtime { type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; - type StakersPayoutSource = DdcAccountsPalletId; + type StakersPayoutSource = DdcCustomersPalletId; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } parameter_types! { - pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake + pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake } -impl pallet_ddc_customer_accounts::Config for Runtime { +impl pallet_ddc_customers::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; - type PalletId = DdcAccountsPalletId; + type PalletId = DdcCustomersPalletId; type RuntimeEvent = RuntimeEvent; } @@ -1425,7 +1425,7 @@ construct_runtime!( DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Storage, Event}, DdcStaking: pallet_ddc_staking, DdcValidator: pallet_ddc_validator, - DdcAccounts: pallet_ddc_customer_accounts, + DdcCustomers: pallet_ddc_customers, DdcNodes: pallet_ddc_nodes, DdcClusters: pallet_ddc_clusters } From 79e08fd32d7119658fd45ec8cecacab467fa1337 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 26 Oct 2023 16:32:58 +0200 Subject: [PATCH 423/544] forgot to add renamed pallet --- pallets/ddc-customers/Cargo.toml | 36 ++ pallets/ddc-customers/src/lib.rs | 575 +++++++++++++++++++++++++++++++ 2 files changed, 611 insertions(+) create mode 100644 pallets/ddc-customers/Cargo.toml create mode 100644 pallets/ddc-customers/src/lib.rs diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml new file mode 100644 index 000000000..8007013bb --- /dev/null +++ b/pallets/ddc-customers/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "pallet-ddc-customers" +version = "0.1.0" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } +pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +log = { version = "0.4.17", default-features = false } + +[dev-dependencies] +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] +std = [ + "codec/std", + "ddc-primitives/std", + "pallet-ddc-clusters/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", +] diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs new file mode 100644 index 000000000..fa970cc61 --- /dev/null +++ b/pallets/ddc-customers/src/lib.rs @@ -0,0 +1,575 @@ +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +use codec::{Decode, Encode, HasCompact}; + +use ddc_primitives::ClusterId; +use frame_support::{ + parameter_types, + traits::{Currency, DefensiveSaturating, ExistenceRequirement}, + BoundedVec, PalletId, +}; +pub use pallet_ddc_clusters::{self as ddc_clusters}; +pub use pallet_ddc_staking::{self as ddc_staking}; +use scale_info::TypeInfo; +use sp_runtime::{ + traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, + RuntimeDebug, SaturatedConversion, +}; +use sp_staking::EraIndex; +use sp_std::prelude::*; + +pub use pallet::*; + +/// The balance type of this pallet. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +parameter_types! { + /// A limit to the number of pending unlocks an account may have in parallel. + pub MaxUnlockingChunks: u32 = 32; +} + +/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct UnlockChunk { + /// Amount of funds to be unlocked. + #[codec(compact)] + value: Balance, + /// Era number at which point it'll be unlocked. + #[codec(compact)] + era: EraIndex, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct Bucket { + bucket_id: u128, + owner_id: AccountId, + cluster_id: Option, + public_availability: bool, + resources_reserved: u128, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct BucketsDetails { + pub bucket_id: u128, + pub amount: Balance, +} + +#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] +pub struct AccountsLedger { + /// The owner account whose balance is actually locked and can be used for CDN usage. + pub owner: AccountId, + /// The total amount of the owner's balance that we are currently accounting for. + /// It's just `active` plus all the `unlocking` balances. + #[codec(compact)] + pub total: Balance, + /// The total amount of the owner's balance that will be accessible for CDN payments in any + /// forthcoming rounds. + #[codec(compact)] + pub active: Balance, + /// Any balance that is becoming free, which may eventually be transferred out of the owner + /// (assuming that the content owner has to pay for network usage). It is assumed that this + /// will be treated as a first in, first out queue where the new (higher value) eras get pushed + /// on the back. + pub unlocking: BoundedVec, MaxUnlockingChunks>, +} + +impl + AccountsLedger +{ + /// Initializes the default object using the given owner. + pub fn default_from(owner: AccountId) -> Self { + Self { owner, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } + } + + /// Remove entries from `unlocking` that are sufficiently old and reduce the + /// total by the sum of their balances. + fn consolidate_unlocked(self, current_era: EraIndex) -> Self { + let mut total = self.total; + let unlocking: BoundedVec<_, _> = self + .unlocking + .into_iter() + .filter(|chunk| { + log::debug!("Chunk era: {:?}", chunk.era); + if chunk.era > current_era { + true + } else { + total = total.saturating_sub(chunk.value); + false + } + }) + .collect::>() + .try_into() + .expect( + "filtering items from a bounded vec always leaves length less than bounds. qed", + ); + + Self { owner: self.owner, total, active: self.active, unlocking } + } + + /// Charge funds that were scheduled for unlocking. + /// + /// Returns the updated ledger, and the amount actually charged. + fn charge_unlocking(mut self, value: Balance) -> (Self, Balance) { + let mut unlocking_balance = Balance::zero(); + + while let Some(last) = self.unlocking.last_mut() { + if unlocking_balance + last.value <= value { + unlocking_balance += last.value; + self.active -= last.value; + self.unlocking.pop(); + } else { + let diff = value - unlocking_balance; + + unlocking_balance += diff; + self.active -= diff; + last.value -= diff; + } + + if unlocking_balance >= value { + break + } + } + + (self, unlocking_balance) + } +} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::{pallet_prelude::*, traits::LockableCurrency}; + use frame_system::pallet_prelude::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config + ddc_staking::Config + ddc_clusters::Config { + /// The accounts's pallet id, used for deriving its sovereign account ID. + #[pallet::constant] + type PalletId: Get; + type Currency: LockableCurrency; + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// Number of eras that staked funds must remain bonded for. + #[pallet::constant] + type BondingDuration: Get; + } + + /// Map from all (unlocked) "owner" accounts to the info regarding the staking. + #[pallet::storage] + #[pallet::getter(fn ledger)] + pub type Ledger = + StorageMap<_, Identity, T::AccountId, AccountsLedger>>; + + #[pallet::type_value] + pub fn DefaultBucketCount() -> u128 { + 0_u128 + } + #[pallet::storage] + #[pallet::getter(fn buckets_count)] + pub type BucketsCount = + StorageValue>; + + /// Map from bucket ID to to the bucket structure + #[pallet::storage] + #[pallet::getter(fn buckets)] + pub type Buckets = + StorageMap<_, Twox64Concat, u128, Bucket, OptionQuery>; + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + /// An account has bonded this amount. \[owner, amount\] + /// + /// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably, + /// it will not be emitted for staking rewards when they are added to stake. + Deposited(T::AccountId, BalanceOf), + /// An account has unbonded this amount. \[owner, amount\] + Unbonded(T::AccountId, BalanceOf), + /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` + /// from the unlocking queue. \[owner, amount\] + Withdrawn(T::AccountId, BalanceOf), + /// Total amount charged from all accounts to pay CDN nodes + Charged(BalanceOf), + } + + #[pallet::error] + pub enum Error { + /// Not a owner account. + NotOwner, + /// Not an owner of bucket + NotBucketOwner, + /// Owner is already bonded. + AlreadyPaired, + /// Cannot deposit dust + InsufficientDeposit, + /// Can not schedule more unlock chunks. + NoMoreChunks, + /// Bucket with speicifed id doesn't exist. + NoBucketWithId, + /// Internal state has become somehow corrupted and the operation cannot continue. + BadState, + /// Current era not set during runtime + DDCEraNotSet, + /// Bucket with specified id doesn't exist + BucketDoesNotExist, + /// DDC Cluster with provided id doesn't exist + ClusterDoesNotExist, + } + + #[pallet::genesis_config] + pub struct GenesisConfig; + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + let account_id = >::account_id(); + let min = ::Currency::minimum_balance(); + if ::Currency::free_balance(&account_id) < min { + let _ = ::Currency::make_free_balance_be(&account_id, min); + } + } + } + + #[pallet::call] + impl Pallet { + /// Create new bucket with provided public availability & reserved resources + /// + /// Anyone can create a bucket + #[pallet::weight(10_000)] + pub fn create_bucket( + origin: OriginFor, + public_availability: bool, + resources_reserved: u128, + ) -> DispatchResult { + let bucket_owner = ensure_signed(origin)?; + let cur_bucket_id = Self::buckets_count(); + + let bucket = Bucket { + bucket_id: cur_bucket_id + 1, + owner_id: bucket_owner, + cluster_id: None, + public_availability, + resources_reserved, + }; + + >::set(cur_bucket_id + 1); + >::insert(cur_bucket_id + 1, bucket); + Ok(()) + } + + /// Allocates specified bucket into specified cluster + /// + /// Only bucket owner can call this method + #[pallet::weight(10_000)] + pub fn allocate_bucket_to_cluster( + origin: OriginFor, + bucket_id: u128, + cluster_id: ClusterId, + ) -> DispatchResult { + let bucket_owner = ensure_signed(origin)?; + + let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; + + ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); + + ensure!( + ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), + Error::::ClusterDoesNotExist + ); + bucket.cluster_id = Some(cluster_id); + + Ok(()) + } + + /// Take the origin account as a owner and lock up `value` of its balance. `Owner` will + /// be the account that controls it. + /// + /// `value` must be more than the `minimum_balance` specified by `T::Currency`. + /// + /// The dispatch origin for this call must be _Signed_ by the owner account. + /// + /// Emits `Deposited`. + #[pallet::weight(10_000)] + pub fn deposit( + origin: OriginFor, + #[pallet::compact] value: BalanceOf, + ) -> DispatchResult { + let owner = ensure_signed(origin)?; + + if >::contains_key(&owner) { + Err(Error::::AlreadyPaired)? + } + + // Reject a deposit which is considered to be _dust_. + if value < ::Currency::minimum_balance() { + Err(Error::::InsufficientDeposit)? + } + + frame_system::Pallet::::inc_consumers(&owner).map_err(|_| Error::::BadState)?; + + let owner_balance = ::Currency::free_balance(&owner); + let value = value.min(owner_balance); + let item = AccountsLedger { + owner: owner.clone(), + total: value, + active: value, + unlocking: Default::default(), + }; + Self::update_ledger_and_deposit(&owner, &item)?; + Self::deposit_event(Event::::Deposited(owner, value)); + Ok(()) + } + + /// Add some extra amount that have appeared in the owner `free_balance` into the balance up + /// for CDN payments. + /// + /// The dispatch origin for this call must be _Signed_ by the owner. + /// + /// Emits `Deposited`. + #[pallet::weight(10_000)] + pub fn deposit_extra( + origin: OriginFor, + #[pallet::compact] max_additional: BalanceOf, + ) -> DispatchResult { + let owner = ensure_signed(origin)?; + + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + + let owner_balance = ::Currency::free_balance(&owner); + let extra = owner_balance.min(max_additional); + ledger.total += extra; + ledger.active += extra; + // Last check: the new active amount of ledger must be more than ED. + ensure!( + ledger.active >= ::Currency::minimum_balance(), + Error::::InsufficientDeposit + ); + + Self::update_ledger_and_deposit(&owner, &ledger)?; + + Self::deposit_event(Event::::Deposited(owner.clone(), extra)); + + Ok(()) + } + + /// Schedule a portion of the owner to be unlocked ready for transfer out after the bond + /// period ends. If this leaves an amount actively bonded less than + /// T::Currency::minimum_balance(), then it is increased to the full amount. + /// + /// The dispatch origin for this call must be _Signed_ by the owner. + /// + /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move + /// the funds out of management ready for transfer. + /// + /// No more than a limited number of unlocking chunks (see `MaxUnlockingChunks`) + /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need + /// to be called first to remove some of the chunks (if possible). + /// + /// Emits `Unbonded`. + /// + /// See also [`Call::withdraw_unbonded`]. + #[pallet::weight(10_000)] + pub fn unbond( + origin: OriginFor, + #[pallet::compact] value: BalanceOf, + ) -> DispatchResult { + let owner = ensure_signed(origin)?; + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + ensure!( + ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, + Error::::NoMoreChunks, + ); + + let mut value = value.min(ledger.active); + + if !value.is_zero() { + ledger.active -= value; + + // Avoid there being a dust balance left in the accounts system. + if ledger.active < ::Currency::minimum_balance() { + value += ledger.active; + ledger.active = Zero::zero(); + } + + let current_era = ddc_staking::pallet::Pallet::::current_era() + .ok_or(Error::::DDCEraNotSet)?; + // Note: bonding for extra era to allow for accounting + let era = current_era + ::BondingDuration::get(); + log::debug!("Era for the unbond: {:?}", era); + + if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { + // To keep the chunk count down, we only keep one chunk per era. Since + // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will + // be the last one. + chunk.value = chunk.value.defensive_saturating_add(value) + } else { + ledger + .unlocking + .try_push(UnlockChunk { value, era }) + .map_err(|_| Error::::NoMoreChunks)?; + }; + + Self::update_ledger(&owner, &ledger); + + Self::deposit_event(Event::::Unbonded(ledger.owner, value)); + } + Ok(()) + } + + /// Remove any unlocked chunks from the `unlocking` queue from our management. + /// + /// This essentially frees up that balance to be used by the owner account to do + /// whatever it wants. + /// + /// The dispatch origin for this call must be _Signed_ by the owner. + /// + /// Emits `Withdrawn`. + /// + /// See also [`Call::unbond`]. + #[pallet::weight(10_000)] + pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { + let owner = ensure_signed(origin)?; + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let (owner, old_total) = (ledger.owner.clone(), ledger.total); + let current_era = + ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; + ledger = ledger.consolidate_unlocked(current_era); + log::debug!("Current era: {:?}", current_era); + + if ledger.unlocking.is_empty() && + ledger.active < ::Currency::minimum_balance() + { + log::debug!("Killing owner"); + // This account must have called `unbond()` with some value that caused the active + // portion to fall below existential deposit + will have no more unlocking chunks + // left. We can now safely remove all accounts-related information. + Self::kill_owner(&owner)?; + } else { + log::debug!("Updating ledger"); + // This was the consequence of a partial unbond. just update the ledger and move on. + Self::update_ledger(&owner, &ledger); + }; + + log::debug!("Current total: {:?}", ledger.total); + log::debug!("Old total: {:?}", old_total); + + // `old_total` should never be less than the new total because + // `consolidate_unlocked` strictly subtracts balance. + if ledger.total < old_total { + log::debug!("Preparing for transfer"); + // Already checked that this won't overflow by entry condition. + let value = old_total - ledger.total; + + let account_id = Self::account_id(); + + ::Currency::transfer( + &account_id, + &owner, + value, + ExistenceRequirement::KeepAlive, + )?; + Self::deposit_event(Event::::Withdrawn(owner, value)); + } + + Ok(()) + } + } + + impl Pallet { + pub fn account_id() -> T::AccountId { + T::PalletId::get().into_account_truncating() + } + /// Update the ledger for a owner. + /// + /// This will also deposit the funds to pallet. + fn update_ledger_and_deposit( + owner: &T::AccountId, + ledger: &AccountsLedger>, + ) -> DispatchResult { + let account_id = Self::account_id(); + + ::Currency::transfer( + owner, + &account_id, + ledger.total, + ExistenceRequirement::KeepAlive, + )?; + >::insert(owner, ledger); + + Ok(()) + } + + /// Update the ledger for a owner. + fn update_ledger( + owner: &T::AccountId, + ledger: &AccountsLedger>, + ) { + >::insert(owner, ledger); + } + + /// Remove all associated data of a owner account from the accounts system. + /// + /// Assumes storage is upgraded before calling. + /// + /// This is called: + /// - after a `withdraw_unbonded()` call that frees all of a owner's bonded balance. + fn kill_owner(owner: &T::AccountId) -> DispatchResult { + >::remove(&owner); + + frame_system::Pallet::::dec_consumers(owner); + + Ok(()) + } + + // Charge payments from content owners + pub fn charge_content_owners( + paying_accounts: Vec>>, + pricing: u128, + ) -> DispatchResult { + let mut total_charged = BalanceOf::::zero(); + + for bucket_details in paying_accounts.iter() { + let bucket: Bucket = Self::buckets(bucket_details.bucket_id) + .ok_or(Error::::BucketDoesNotExist)?; + let content_owner = bucket.owner_id; + let amount = bucket_details.amount * pricing.saturated_into::>(); + + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; + if ledger.active >= amount { + ledger.total -= amount; + ledger.active -= amount; + total_charged += amount; + log::debug!("Ledger updated state: {:?}", &ledger); + Self::update_ledger(&content_owner, &ledger); + } else { + let diff = amount - ledger.active; + total_charged += ledger.active; + ledger.total -= ledger.active; + ledger.active = BalanceOf::::zero(); + let (ledger, charged) = ledger.charge_unlocking(diff); + log::debug!("Ledger updated state: {:?}", &ledger); + Self::update_ledger(&content_owner, &ledger); + total_charged += charged; + } + } + log::debug!("Total charged: {:?}", &total_charged); + + Self::deposit_event(Event::::Charged(total_charged)); + log::debug!("Deposit event executed"); + + Ok(()) + } + } +} From a0ea96c66df0fa48d8ce25879a6d5af64efade35 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 26 Oct 2023 17:47:41 +0200 Subject: [PATCH 424/544] rename unbonding to unlock across pallet-customers --- pallets/ddc-customers/src/lib.rs | 57 ++++++++++++++++---------------- runtime/cere-dev/src/lib.rs | 3 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index fa970cc61..0092bf9e0 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -154,9 +154,9 @@ pub mod pallet { type PalletId: Get; type Currency: LockableCurrency; type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// Number of eras that staked funds must remain bonded for. + /// Number of eras that staked funds must remain locked for. #[pallet::constant] - type BondingDuration: Get; + type LockingDuration: Get; } /// Map from all (unlocked) "owner" accounts to the info regarding the staking. @@ -183,15 +183,15 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// An account has bonded this amount. \[owner, amount\] + /// An account has deposited this amount. \[owner, amount\] /// - /// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably, + /// NOTE: This event is only emitted when funds are deposited via a dispatchable. Notably, /// it will not be emitted for staking rewards when they are added to stake. Deposited(T::AccountId, BalanceOf), - /// An account has unbonded this amount. \[owner, amount\] - Unbonded(T::AccountId, BalanceOf), - /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` - /// from the unlocking queue. \[owner, amount\] + /// An account has initiated unlock for amount. \[owner, amount\] + InitiatDepositUnlock(T::AccountId, BalanceOf), + /// An account has called `withdraw_unlocked_deposit` and removed unlocking chunks worth + /// `Balance` from the unlocking queue. \[owner, amount\] Withdrawn(T::AccountId, BalanceOf), /// Total amount charged from all accounts to pay CDN nodes Charged(BalanceOf), @@ -203,7 +203,7 @@ pub mod pallet { NotOwner, /// Not an owner of bucket NotBucketOwner, - /// Owner is already bonded. + /// Owner is already paired with structure representing account. AlreadyPaired, /// Cannot deposit dust InsufficientDeposit, @@ -364,24 +364,24 @@ pub mod pallet { Ok(()) } - /// Schedule a portion of the owner to be unlocked ready for transfer out after the bond - /// period ends. If this leaves an amount actively bonded less than + /// Schedule a portion of the owner deposited funds to be unlocked ready for transfer out + /// after the lock period ends. If this leaves an amount actively locked less than /// T::Currency::minimum_balance(), then it is increased to the full amount. /// /// The dispatch origin for this call must be _Signed_ by the owner. /// - /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move - /// the funds out of management ready for transfer. + /// Once the unlock period is done, you can call `withdraw_unlocked_deposit` to actually + /// move the funds out of management ready for transfer. /// /// No more than a limited number of unlocking chunks (see `MaxUnlockingChunks`) - /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need + /// can co-exists at the same time. In that case, [`Call::withdraw_unlocked_deposit`] need /// to be called first to remove some of the chunks (if possible). /// - /// Emits `Unbonded`. + /// Emits `InitiatDepositUnlock`. /// - /// See also [`Call::withdraw_unbonded`]. + /// See also [`Call::withdraw_unlocked_deposit`]. #[pallet::weight(10_000)] - pub fn unbond( + pub fn unlock_deposit( origin: OriginFor, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { @@ -405,9 +405,9 @@ pub mod pallet { let current_era = ddc_staking::pallet::Pallet::::current_era() .ok_or(Error::::DDCEraNotSet)?; - // Note: bonding for extra era to allow for accounting - let era = current_era + ::BondingDuration::get(); - log::debug!("Era for the unbond: {:?}", era); + // Note: locking for extra era to allow for accounting + let era = current_era + ::LockingDuration::get(); + log::debug!("Era for the unlock: {:?}", era); if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { // To keep the chunk count down, we only keep one chunk per era. Since @@ -423,7 +423,7 @@ pub mod pallet { Self::update_ledger(&owner, &ledger); - Self::deposit_event(Event::::Unbonded(ledger.owner, value)); + Self::deposit_event(Event::::InitiatDepositUnlock(ledger.owner, value)); } Ok(()) } @@ -437,9 +437,9 @@ pub mod pallet { /// /// Emits `Withdrawn`. /// - /// See also [`Call::unbond`]. + /// See also [`Call::unlock_deposit`]. #[pallet::weight(10_000)] - pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { + pub fn withdraw_unlocked_deposit(origin: OriginFor) -> DispatchResult { let owner = ensure_signed(origin)?; let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; let (owner, old_total) = (ledger.owner.clone(), ledger.total); @@ -452,13 +452,14 @@ pub mod pallet { ledger.active < ::Currency::minimum_balance() { log::debug!("Killing owner"); - // This account must have called `unbond()` with some value that caused the active - // portion to fall below existential deposit + will have no more unlocking chunks - // left. We can now safely remove all accounts-related information. + // This account must have called `unlock_deposit()` with some value that caused the + // active portion to fall below existential deposit + will have no more unlocking + // chunks left. We can now safely remove all accounts-related information. Self::kill_owner(&owner)?; } else { log::debug!("Updating ledger"); - // This was the consequence of a partial unbond. just update the ledger and move on. + // This was the consequence of a partial deposit unlock. just update the ledger and + // move on. Self::update_ledger(&owner, &ledger); }; @@ -524,7 +525,7 @@ pub mod pallet { /// Assumes storage is upgraded before calling. /// /// This is called: - /// - after a `withdraw_unbonded()` call that frees all of a owner's bonded balance. + /// - after a `withdraw_unlocked_deposit()` call that frees all of a owner's locked balance. fn kill_owner(owner: &T::AccountId) -> DispatchResult { >::remove(&owner); diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index a023034a2..167acace3 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1338,10 +1338,11 @@ impl pallet_ddc_staking::Config for Runtime { parameter_types! { pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake + pub const LockingDuration: sp_staking::EraIndex = 30 * 24; // 1 hour * 24 = 1 day; (1 era is 2 mins) } impl pallet_ddc_customers::Config for Runtime { - type BondingDuration = BondingDuration; + type LockingDuration = LockingDuration; type Currency = Balances; type PalletId = DdcCustomersPalletId; type RuntimeEvent = RuntimeEvent; From 1cd02861f967805d03883142463c87a95ead29d2 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 26 Oct 2023 18:03:41 +0200 Subject: [PATCH 425/544] fix tests for green CI :) --- Cargo.lock | 332 +++++++++++++++-------------- pallets/ddc-validator/Cargo.toml | 4 + pallets/ddc-validator/src/mock.rs | 18 +- pallets/ddc-validator/src/tests.rs | 5 +- 4 files changed, 188 insertions(+), 171 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4447d7ae3..3d2141735 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2106,7 +2106,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2123,7 +2123,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2146,7 +2146,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "array-bytes 4.2.0", @@ -2197,7 +2197,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2208,7 +2208,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2224,7 +2224,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2253,7 +2253,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-metadata", @@ -2285,7 +2285,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2299,7 +2299,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2311,7 +2311,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2321,7 +2321,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2339,7 +2339,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2354,7 +2354,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -4430,7 +4430,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4629,7 +4629,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4645,7 +4645,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4660,7 +4660,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4684,7 +4684,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4704,7 +4704,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4719,7 +4719,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4770,7 +4770,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4789,7 +4789,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4806,7 +4806,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -4834,7 +4834,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -4849,7 +4849,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4859,7 +4859,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4876,7 +4876,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -5011,7 +5011,9 @@ dependencies = [ "log", "pallet-balances", "pallet-contracts", + "pallet-ddc-clusters", "pallet-ddc-customers", + "pallet-ddc-nodes", "pallet-ddc-staking", "pallet-randomness-collective-flip", "pallet-session", @@ -5033,7 +5035,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5049,7 +5051,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5073,7 +5075,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5086,7 +5088,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5142,7 +5144,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5163,7 +5165,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5186,7 +5188,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5202,7 +5204,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5222,7 +5224,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5239,7 +5241,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5256,7 +5258,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5271,7 +5273,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5288,7 +5290,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5308,7 +5310,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5318,7 +5320,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5335,7 +5337,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5358,7 +5360,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5373,7 +5375,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5387,7 +5389,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5402,7 +5404,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5418,7 +5420,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5439,7 +5441,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5455,7 +5457,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5469,7 +5471,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5492,7 +5494,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5503,7 +5505,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5517,7 +5519,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5535,7 +5537,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5554,7 +5556,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5570,7 +5572,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5585,7 +5587,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5596,7 +5598,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5614,7 +5616,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5631,7 +5633,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5647,7 +5649,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -6552,7 +6554,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", @@ -6825,7 +6827,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6836,7 +6838,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6863,7 +6865,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6886,7 +6888,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6902,7 +6904,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6919,7 +6921,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6930,7 +6932,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "chrono", @@ -6970,7 +6972,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -6998,7 +7000,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -7023,7 +7025,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7047,7 +7049,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", @@ -7089,7 +7091,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7111,7 +7113,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -7124,7 +7126,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7148,7 +7150,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -7159,7 +7161,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -7186,7 +7188,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -7202,7 +7204,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7217,7 +7219,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", @@ -7237,7 +7239,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "array-bytes 4.2.0", @@ -7278,7 +7280,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -7299,7 +7301,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7316,7 +7318,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7331,7 +7333,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7378,7 +7380,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cid", "futures", @@ -7398,7 +7400,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -7424,7 +7426,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7442,7 +7444,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7463,7 +7465,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "fork-tree", @@ -7491,7 +7493,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7510,7 +7512,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "bytes", @@ -7540,7 +7542,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", @@ -7553,7 +7555,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7562,7 +7564,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7592,7 +7594,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7615,7 +7617,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7628,7 +7630,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7698,7 +7700,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7712,7 +7714,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7731,7 +7733,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7750,7 +7752,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7768,7 +7770,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7799,7 +7801,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7810,7 +7812,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7836,7 +7838,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7849,7 +7851,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -8262,7 +8264,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8280,7 +8282,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -8292,7 +8294,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8305,7 +8307,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -8320,7 +8322,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8333,7 +8335,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8345,7 +8347,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8357,7 +8359,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8375,7 +8377,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8394,7 +8396,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8417,7 +8419,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8431,7 +8433,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8444,7 +8446,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "base58", @@ -8490,7 +8492,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", @@ -8504,7 +8506,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8515,7 +8517,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8524,7 +8526,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8534,7 +8536,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8545,7 +8547,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8563,7 +8565,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8577,7 +8579,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8603,7 +8605,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8614,7 +8616,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8631,7 +8633,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8640,7 +8642,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8654,7 +8656,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8664,7 +8666,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8674,7 +8676,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8684,7 +8686,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8707,7 +8709,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8725,7 +8727,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8737,7 +8739,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8751,7 +8753,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8765,7 +8767,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8776,7 +8778,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8798,12 +8800,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8816,7 +8818,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8829,7 +8831,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8845,7 +8847,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8857,7 +8859,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8866,7 +8868,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8882,7 +8884,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", @@ -8905,7 +8907,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8922,7 +8924,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8933,7 +8935,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8946,7 +8948,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -9093,7 +9095,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -9101,7 +9103,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -9122,7 +9124,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -9135,7 +9137,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -9156,7 +9158,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -9166,7 +9168,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9177,7 +9179,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -9624,7 +9626,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index b608de995..1ea14fd9a 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -16,6 +16,8 @@ log = { version = "0.4.17", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../ddc-customers" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } +pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } +pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } @@ -46,6 +48,8 @@ std = [ "pallet-contracts/std", "pallet-ddc-customers/std", "pallet-ddc-staking/std", + "pallet-ddc-clusters/std", + "pallet-ddc-nodes/std", "pallet-session/std", "pallet-staking/std", "scale-info/std", diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 026a844db..2d9568768 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -41,10 +41,12 @@ frame_support::construct_runtime!( Timestamp: pallet_timestamp, Session: pallet_session, Staking: pallet_staking, - DdcAccounts: pallet_ddc_customer_accounts, + DdcAccounts: pallet_ddc_customers, DdcStaking: pallet_ddc_staking, RandomnessCollectiveFlip: pallet_randomness_collective_flip, DdcValidator: pallet_ddc_validator, + DdcClusters: pallet_ddc_clusters, + DdcNodes: pallet_ddc_nodes, } ); @@ -240,10 +242,11 @@ impl pallet_staking::Config for Test { parameter_types! { pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); + pub const LockingDuration: sp_staking::EraIndex = 30 * 24; } -impl pallet_ddc_customer_accounts::Config for Test { - type BondingDuration = BondingDuration; +impl pallet_ddc_customers::Config for Test { + type LockingDuration = LockingDuration; type Currency = Balances; type RuntimeEvent = RuntimeEvent; type PalletId = DdcAccountsPalletId; @@ -269,6 +272,15 @@ impl pallet_ddc_staking::Config for Test { type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; } +impl pallet_ddc_clusters::Config for Test { + type RuntimeEvent = RuntimeEvent; + type NodeRepository = pallet_ddc_nodes::Pallet; +} + +impl pallet_ddc_nodes::Config for Test { + type RuntimeEvent = RuntimeEvent; +} + parameter_types! { pub const DdcValidatorsQuorumSize: u32 = 3; pub const ValidationThreshold: u32 = 5; diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs index 6626dbd39..9493f2771 100644 --- a/pallets/ddc-validator/src/tests.rs +++ b/pallets/ddc-validator/src/tests.rs @@ -8,7 +8,7 @@ use crate::{ use codec::Decode; use ddc_primitives::{CDNNodePubKey, NodePubKey}; use frame_support::{assert_noop, assert_ok}; -use pallet_ddc_customer_accounts::{BucketsDetails, Error as AccountsError}; +use pallet_ddc_customers::{BucketsDetails, Error as AccountsError}; use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; @@ -539,13 +539,12 @@ fn charge_payments_content_owners_works_as_expected() { RuntimeOrigin::signed(validator_1_stash.clone()), vec![bucket_info.clone()] ), - AccountsError::::NotController + AccountsError::::NotOwner ); // Deposit funds for account assert_ok!(ddc_customers::Pallet::::deposit( RuntimeOrigin::signed(validator_1_stash.clone()), - validator_1_stash.clone(), 1_000, )); From 4239f279f5e8194afdb3f9fbba5c4f27ac228b3d Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 26 Oct 2023 23:31:02 +0200 Subject: [PATCH 426/544] feat: payment pallet prototype --- Cargo.lock | 351 +++++++++++++++++---------------- Cargo.toml | 1 + pallets/ddc-payouts/Cargo.toml | 40 ++++ pallets/ddc-payouts/src/lib.rs | 345 ++++++++++++++++++++++++++++++++ primitives/src/lib.rs | 1 + runtime/cere-dev/Cargo.toml | 2 + runtime/cere-dev/src/lib.rs | 8 +- 7 files changed, 582 insertions(+), 166 deletions(-) create mode 100644 pallets/ddc-payouts/Cargo.toml create mode 100644 pallets/ddc-payouts/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c24b3b135..1f222c0a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,6 +814,7 @@ dependencies = [ "pallet-ddc-clusters", "pallet-ddc-metrics-offchain-worker", "pallet-ddc-nodes", + "pallet-ddc-payouts", "pallet-ddc-staking", "pallet-ddc-validator", "pallet-democracy", @@ -2069,7 +2070,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2086,7 +2087,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2109,7 +2110,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "array-bytes 4.2.0", @@ -2160,7 +2161,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2171,7 +2172,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2187,7 +2188,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2216,7 +2217,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-metadata", @@ -2248,7 +2249,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2262,7 +2263,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2274,7 +2275,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2284,7 +2285,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2302,7 +2303,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2317,7 +2318,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2326,7 +2327,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -4374,7 +4375,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4583,7 +4584,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4599,7 +4600,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4614,7 +4615,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4638,7 +4639,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4658,7 +4659,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4673,7 +4674,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4724,7 +4725,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4743,7 +4744,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4760,7 +4761,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -4788,7 +4789,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -4803,7 +4804,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4813,7 +4814,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4830,7 +4831,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -4926,6 +4927,26 @@ dependencies = [ "substrate-test-utils", ] +[[package]] +name = "pallet-ddc-payouts" +version = "4.8.1" +dependencies = [ + "ddc-primitives", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "sp-tracing", + "substrate-test-utils", +] + [[package]] name = "pallet-ddc-staking" version = "4.8.1" @@ -4985,7 +5006,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5001,7 +5022,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5025,7 +5046,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5038,7 +5059,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5094,7 +5115,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5115,7 +5136,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5138,7 +5159,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5154,7 +5175,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5174,7 +5195,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5191,7 +5212,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5208,7 +5229,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5223,7 +5244,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5240,7 +5261,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5260,7 +5281,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5270,7 +5291,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5287,7 +5308,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5310,7 +5331,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5325,7 +5346,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5339,7 +5360,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5354,7 +5375,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5370,7 +5391,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5391,7 +5412,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5407,7 +5428,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5421,7 +5442,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5444,7 +5465,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5455,7 +5476,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5469,7 +5490,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5487,7 +5508,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5506,7 +5527,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5522,7 +5543,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5537,7 +5558,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5548,7 +5569,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5566,7 +5587,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5583,7 +5604,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5599,7 +5620,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -6485,7 +6506,7 @@ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", @@ -6744,7 +6765,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6755,7 +6776,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6782,7 +6803,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6805,7 +6826,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6821,7 +6842,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6838,7 +6859,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6849,7 +6870,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "chrono", @@ -6889,7 +6910,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -6917,7 +6938,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -6942,7 +6963,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6966,7 +6987,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", @@ -7008,7 +7029,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7030,7 +7051,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -7043,7 +7064,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7067,7 +7088,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -7078,7 +7099,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -7105,7 +7126,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -7121,7 +7142,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7136,7 +7157,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", @@ -7156,7 +7177,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "array-bytes 4.2.0", @@ -7197,7 +7218,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -7218,7 +7239,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7235,7 +7256,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7250,7 +7271,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7297,7 +7318,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cid", "futures", @@ -7317,7 +7338,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -7343,7 +7364,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7361,7 +7382,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7382,7 +7403,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "fork-tree", @@ -7410,7 +7431,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7429,7 +7450,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "bytes", @@ -7459,7 +7480,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", @@ -7472,7 +7493,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7481,7 +7502,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7511,7 +7532,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7534,7 +7555,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7547,7 +7568,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7617,7 +7638,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7631,7 +7652,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7650,7 +7671,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7669,7 +7690,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7687,7 +7708,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7718,7 +7739,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7729,7 +7750,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7755,7 +7776,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7768,7 +7789,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -8191,7 +8212,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8209,7 +8230,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -8221,7 +8242,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8234,7 +8255,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -8249,7 +8270,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8262,7 +8283,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8274,7 +8295,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8286,7 +8307,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8304,7 +8325,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8323,7 +8344,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8346,7 +8367,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8360,7 +8381,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8373,7 +8394,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "base58", @@ -8419,7 +8440,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", @@ -8433,7 +8454,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8444,7 +8465,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8453,7 +8474,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8463,7 +8484,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8474,7 +8495,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8492,7 +8513,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8506,7 +8527,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8532,7 +8553,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8543,7 +8564,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8560,7 +8581,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8569,7 +8590,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8583,7 +8604,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8593,7 +8614,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8603,7 +8624,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8613,7 +8634,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8636,7 +8657,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8654,7 +8675,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8666,7 +8687,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8680,7 +8701,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8694,7 +8715,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8705,7 +8726,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8727,12 +8748,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8745,7 +8766,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8758,7 +8779,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8774,7 +8795,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8786,7 +8807,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8795,7 +8816,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8811,7 +8832,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", @@ -8834,7 +8855,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8851,7 +8872,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8862,7 +8883,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8875,7 +8896,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -9016,7 +9037,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -9024,7 +9045,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -9045,7 +9066,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -9058,7 +9079,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -9079,7 +9100,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -9089,7 +9110,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9100,7 +9121,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -9561,7 +9582,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", diff --git a/Cargo.toml b/Cargo.toml index 835a9919a..538f83fb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ "pallets/ddc-accounts", "pallets/ddc-nodes", "pallets/ddc-clusters", + "pallets/ddc-payouts", "primitives", ] diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml new file mode 100644 index 000000000..8f171e21b --- /dev/null +++ b/pallets/ddc-payouts/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "pallet-ddc-payouts" +version = "4.8.1" +edition = "2021" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } + +[dev-dependencies] +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] +std = [ + "codec/std", + "ddc-primitives/std", + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", + "sp-core/std", +] +runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs new file mode 100644 index 000000000..e676f2eb3 --- /dev/null +++ b/pallets/ddc-payouts/src/lib.rs @@ -0,0 +1,345 @@ +//! # DDC Payouts Pallet +//! +//! The DDC Payouts pallet is used to distribute payouts based on DAC validation +//! +//! - [`Config`] +//! - [`Call`] +//! - [`Pallet`] +//! +//! ## GenesisConfig +//! +//! The DDC Payouts pallet depends on the [`GenesisConfig`]. The +//! `GenesisConfig` is optional and allow to set some initial nodes in DDC. + +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +use ddc_primitives::{ClusterId, DdcEra}; +use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; +use frame_system::pallet_prelude::*; +pub use pallet::*; +use sp_runtime::Perbill; +use sp_std::{ops::Mul, prelude::*}; + +type BatchIndex = u16; + +parameter_types! { + pub MaxBatchesCount: u16 = 1000; +} + +#[frame_support::pallet] +pub mod pallet { + + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + BillingReportInitialized { cluster_id: ClusterId, era: DdcEra }, + ChargingStarted { cluster_id: ClusterId, era: DdcEra }, + ChargingFinished { cluster_id: ClusterId, era: DdcEra }, + RewardingStarted { cluster_id: ClusterId, era: DdcEra }, + RewardingFinished { cluster_id: ClusterId, era: DdcEra }, + BillingReportFinalized { cluster_id: ClusterId, era: DdcEra }, + } + + #[pallet::error] + pub enum Error { + BillingReportDoesNotExist, + NotExpectedState, + BatchIndexAlreadyProcessed, + BatchIndexIsOutOfRange, + BatchesMissed, + NotDistributedBalance, + BatchIndexOverflow, + BoundedVecOverflow, + } + + #[pallet::storage] + #[pallet::getter(fn active_billing_reports)] + pub type ActiveBillingReports = StorageDoubleMap< + _, + Blake2_128Concat, + ClusterId, + Blake2_128Concat, + DdcEra, + BillingReport, + ValueQuery, + >; + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Default)] + pub struct BillingReport { + state: State, + total_balance: u128, + distributed_balance: u128, + // stage 1 + charging_max_batch_index: BatchIndex, + charging_processed_batches: BoundedVec, + // stage 2 + rewarding_max_batch_index: BatchIndex, + rewarding_processed_batches: BoundedVec, + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Default)] + pub enum State { + #[default] + NotInitialized, + Initialized, + ChargingCustomers, + CustomersCharged, + RewardingProviders, + ProvidersRewarded, + Finalized, + } + + #[pallet::call] + impl Pallet { + #[pallet::weight(10_000)] + pub fn begin_billing_report( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + ) -> DispatchResult { + ensure_signed(origin)?; // todo: check that the caller is DAC account + + let mut billing_report = BillingReport::default(); + billing_report.state = State::Initialized; + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + + Self::deposit_event(Event::::BillingReportInitialized { cluster_id, era }); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn begin_charging_customers( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + max_batch_index: BatchIndex, + ) -> DispatchResult { + ensure_signed(origin)?; + + ensure!( + max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), + Error::::BatchIndexOverflow + ); + + let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!(billing_report.state == State::Initialized, Error::::NotExpectedState); + + billing_report.charging_max_batch_index = max_batch_index; + billing_report.state = State::ChargingCustomers; + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + + Self::deposit_event(Event::::ChargingStarted { cluster_id, era }); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn send_charging_customers_batch( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + batch_index: BatchIndex, + payers: Vec<(T::AccountId, u128)>, + ) -> DispatchResult { + ensure_signed(origin)?; + + let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!(billing_report.state == State::ChargingCustomers, Error::::NotExpectedState); + ensure!( + billing_report.charging_max_batch_index >= batch_index, + Error::::BatchIndexIsOutOfRange + ); + ensure!( + !billing_report.charging_processed_batches.contains(&batch_index), + Error::::BatchIndexAlreadyProcessed + ); + + let mut updated_billing_report = billing_report.clone(); + for payer in payers { + let _customer = payer.0; // todo: charge customer + let amount = payer.1; + updated_billing_report.total_balance += amount; + } + + updated_billing_report + .charging_processed_batches + .try_push(batch_index) + .map_err(|_| Error::::BoundedVecOverflow)?; + + ActiveBillingReports::::insert(cluster_id, era, updated_billing_report); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn end_charging_customers( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + ) -> DispatchResult { + ensure_signed(origin)?; + + let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!(billing_report.state == State::ChargingCustomers, Error::::NotExpectedState); + ensure!( + billing_report.charging_max_batch_index as usize == + billing_report.charging_processed_batches.len() - 1usize, + Error::::BatchesMissed + ); + + billing_report.state = State::CustomersCharged; + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + + Self::deposit_event(Event::::ChargingFinished { cluster_id, era }); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn begin_rewarding_providers( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + max_batch_index: BatchIndex, + ) -> DispatchResult { + ensure_signed(origin)?; + + ensure!( + max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), + Error::::BatchIndexOverflow + ); + + let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!(billing_report.state == State::CustomersCharged, Error::::NotExpectedState); + + billing_report.rewarding_max_batch_index = max_batch_index; + billing_report.state = State::RewardingProviders; + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + + Self::deposit_event(Event::::RewardingStarted { cluster_id, era }); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn send_rewarding_providers_batch( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + batch_index: BatchIndex, + payees: Vec<(T::AccountId, Perbill)>, + ) -> DispatchResult { + ensure_signed(origin)?; + + let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!( + billing_report.state == State::RewardingProviders, + Error::::NotExpectedState + ); + ensure!( + billing_report.rewarding_max_batch_index >= batch_index, + Error::::BatchIndexIsOutOfRange + ); + ensure!( + !billing_report.rewarding_processed_batches.contains(&batch_index), + Error::::BatchIndexAlreadyProcessed + ); + + let mut updated_billing_report = billing_report.clone(); + for payee in payees { + let _provider = payee.0; // todo: reward provider + let share = payee.1; + let amount = share.mul(billing_report.total_balance); + updated_billing_report.distributed_balance += amount; + } + + updated_billing_report + .rewarding_processed_batches + .try_push(batch_index) + .map_err(|_| Error::::BoundedVecOverflow)?; + + ActiveBillingReports::::insert(cluster_id, era, updated_billing_report); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn end_rewarding_providers( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + ) -> DispatchResult { + ensure_signed(origin)?; + + let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!( + billing_report.state == State::RewardingProviders, + Error::::NotExpectedState + ); + ensure!( + billing_report.rewarding_max_batch_index as usize == + billing_report.rewarding_processed_batches.len() - 1usize, + Error::::BatchesMissed + ); + + billing_report.state = State::ProvidersRewarded; + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + + Self::deposit_event(Event::::RewardingFinished { cluster_id, era }); + + Ok(()) + } + + #[pallet::weight(10_000)] + pub fn end_billing_report( + origin: OriginFor, + cluster_id: ClusterId, + era: DdcEra, + ) -> DispatchResult { + ensure_signed(origin)?; + + let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!(billing_report.state == State::ProvidersRewarded, Error::::NotExpectedState); + ensure!( + billing_report.total_balance == billing_report.distributed_balance, + Error::::NotDistributedBalance + ); + + billing_report.state = State::Finalized; + // todo: clear and archive billing_report + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + + Self::deposit_event(Event::::BillingReportFinalized { cluster_id, era }); + + Ok(()) + } + } +} diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index de23aa1fd..f8d9be6ee 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -9,6 +9,7 @@ use sp_core::hash::H160; use sp_runtime::{AccountId32, RuntimeDebug}; pub type ClusterId = H160; +pub type DdcEra = u64; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 71b9c5112..14b228d39 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -106,6 +106,7 @@ pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pall pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } +pallet-ddc-payouts = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-payouts" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -189,6 +190,7 @@ std = [ "pallet-ddc-accounts/std", "pallet-ddc-nodes/std", "pallet-ddc-clusters/std", + "pallet-ddc-payouts/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3279c7529..7f13e599f 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -52,6 +52,7 @@ pub use pallet_ddc_accounts; pub use pallet_ddc_clusters; pub use pallet_ddc_metrics_offchain_worker; pub use pallet_ddc_nodes; +pub use pallet_ddc_payouts; pub use pallet_ddc_staking; use pallet_election_provider_multi_phase::SolutionAccuracyOf; use pallet_grandpa::{ @@ -1372,6 +1373,10 @@ impl pallet_ddc_clusters::Config for Runtime { type NodeRepository = pallet_ddc_nodes::Pallet; } +impl pallet_ddc_payouts::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + construct_runtime!( pub enum Runtime where Block = Block, @@ -1427,7 +1432,8 @@ construct_runtime!( DdcValidator: pallet_ddc_validator, DdcAccounts: pallet_ddc_accounts, DdcNodes: pallet_ddc_nodes, - DdcClusters: pallet_ddc_clusters + DdcClusters: pallet_ddc_clusters, + DdcPayouts: pallet_ddc_payouts } ); From 2c02252cb7f93162f40f5bc311d2e3132dafcc3a Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 27 Oct 2023 17:45:30 +0600 Subject: [PATCH 427/544] Optimize `fast_chill` removing iteration over keys --- pallets/ddc-clusters/src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 16e4f7d88..4da5c814e 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -78,6 +78,8 @@ pub mod pallet { FastChillProhibited, /// Cluster candidate should not plan to chill. ChillingProhibited, + /// Origin of the call is not a controller of the stake associated with the provided node. + NotNodeController, } #[pallet::storage] @@ -223,16 +225,16 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller. #[pallet::weight(10_000)] - pub fn fast_chill(origin: OriginFor) -> DispatchResult { + pub fn fast_chill(origin: OriginFor, node: NodePubKey) -> DispatchResult { let controller = ensure_signed(origin)?; let stash = >::ledger(&controller) .ok_or(>::NotController)? .stash; - let node = >::iter() - .find(|(_, v)| *v == stash) - .ok_or(>::BadState)? - .0; + let node_stash = >::nodes(&node) + .ok_or(>::BadState)?; + ensure!(stash == node_stash, Error::::NotNodeController); + let cluster = >::edges(&stash) .or(>::storages(&stash)) .ok_or(Error::::NoStake)?; From f26f83d82b56aa03bdcc80405785501e3f8a71fe Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 27 Oct 2023 18:57:24 +0600 Subject: [PATCH 428/544] Impl conversion from `NodePubKey` variant to `u8` --- primitives/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index de23aa1fd..401f5974e 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -17,5 +17,14 @@ pub enum NodePubKey { CDNPubKey(CDNNodePubKey), } +impl NodePubKey { + pub fn variant_as_number(&self) -> u8 { + match self { + NodePubKey::CDNPubKey(_) => 0, + NodePubKey::StoragePubKey(_) => 1, + } + } +} + pub type StorageNodePubKey = AccountId32; pub type CDNNodePubKey = AccountId32; From 139295607fea26a37443b727554857d47330a341 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 27 Oct 2023 19:00:06 +0600 Subject: [PATCH 429/544] Reorder node auth and DDC stake check --- pallets/ddc-clusters/src/lib.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 4da5c814e..972ba9f62 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -133,22 +133,6 @@ pub mod pallet { .map_err(|_| Error::::AttemptToAddNonExistentNode)?; ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); - // Cluster extension smart contract allows joining. - let is_authorized: bool = pallet_contracts::Pallet::::bare_call( - caller_id, - cluster.props.node_provider_auth_contract, - Default::default(), - EXTENSION_CALL_GAS_LIMIT, - None, - Vec::from(INK_SELECTOR_IS_AUTHORIZED), - false, - ) - .result? - .data - .first() - .is_some_and(|x| *x == 1); - ensure!(is_authorized, Error::::NotAuthorized); - // Sufficient funds are locked at the DDC Staking module. let node_provider_stash = >::nodes(&node_pub_key).ok_or(Error::::NoStake)?; @@ -171,6 +155,22 @@ pub mod pallet { .is_some(); ensure!(!chilling, Error::::ChillingProhibited); + // Cluster extension smart contract allows joining. + let is_authorized: bool = pallet_contracts::Pallet::::bare_call( + caller_id, + cluster.props.node_provider_auth_contract, + Default::default(), + EXTENSION_CALL_GAS_LIMIT, + None, + Vec::from(INK_SELECTOR_IS_AUTHORIZED), + false, + ) + .result? + .data + .first() + .is_some_and(|x| *x == 1); + ensure!(is_authorized, Error::::NotAuthorized); + node.set_cluster_id(Some(cluster_id.clone())); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); From 819fbfe9502c9a6e1a4c250d5480a550ac860c5c Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Fri, 27 Oct 2023 19:01:24 +0600 Subject: [PATCH 430/544] Pass node and provider ids to the auth extension --- pallets/ddc-clusters/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 972ba9f62..f8a5b35cf 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -156,13 +156,19 @@ pub mod pallet { ensure!(!chilling, Error::::ChillingProhibited); // Cluster extension smart contract allows joining. + // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool + let mut call_data = Vec::new(); + call_data.extend_from_slice(&INK_SELECTOR_IS_AUTHORIZED); + call_data.append(&mut node_provider_stash.encode()); + call_data.append(&mut node_pub_key.encode()); + call_data.push(node_pub_key.variant_as_number()); let is_authorized: bool = pallet_contracts::Pallet::::bare_call( caller_id, cluster.props.node_provider_auth_contract, Default::default(), EXTENSION_CALL_GAS_LIMIT, None, - Vec::from(INK_SELECTOR_IS_AUTHORIZED), + call_data, false, ) .result? From 26f4a33bac7374d02825f1eb1a988381ccd9d9f9 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Mon, 30 Oct 2023 12:00:38 +0600 Subject: [PATCH 431/544] Bump `cere-dev` runtime `spec_version` --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3cf8bb6f9..46ee3b429 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48010, + spec_version: 48011, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From 003a344403b72f69578df642bc4ba091bbfbfc32 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 31 Oct 2023 12:47:04 +0600 Subject: [PATCH 432/544] Fix cluster extension contract call data encoding --- pallets/ddc-clusters/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index f8a5b35cf..fafa00f9b 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -156,13 +156,17 @@ pub mod pallet { ensure!(!chilling, Error::::ChillingProhibited); // Cluster extension smart contract allows joining. - // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool - let mut call_data = Vec::new(); - call_data.extend_from_slice(&INK_SELECTOR_IS_AUTHORIZED); - call_data.append(&mut node_provider_stash.encode()); - call_data.append(&mut node_pub_key.encode()); - call_data.push(node_pub_key.variant_as_number()); - let is_authorized: bool = pallet_contracts::Pallet::::bare_call( + let call_data = { + // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool + let args: ([u8; 4], T::AccountId, Vec, u8) = ( + INK_SELECTOR_IS_AUTHORIZED, + node_provider_stash, + node_pub_key.encode()[1..].to_vec(), // remove the first byte added by SCALE + node_pub_key.variant_as_number(), + ); + args.encode() + }; + let is_authorized = pallet_contracts::Pallet::::bare_call( caller_id, cluster.props.node_provider_auth_contract, Default::default(), From b489d542841b907e815da8b069778222d9810272 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 2 Nov 2023 00:19:03 +0100 Subject: [PATCH 433/544] feat: generating a vault address for each billing report --- pallets/ddc-payouts/src/lib.rs | 46 +++++++++++++++++++++++++++++++--- primitives/src/lib.rs | 2 +- runtime/cere-dev/src/lib.rs | 5 ++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index e676f2eb3..f647f7047 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -31,6 +31,9 @@ parameter_types! { pub mod pallet { use super::*; + use frame_support::PalletId; + use sp_io::hashing::blake2_128; + use sp_runtime::traits::{AccountIdConversion, Zero}; #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] @@ -40,6 +43,8 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + #[pallet::constant] + type PalletId: Get; } #[pallet::event] @@ -73,13 +78,15 @@ pub mod pallet { ClusterId, Blake2_128Concat, DdcEra, - BillingReport, + BillingReport, ValueQuery, >; - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Default)] - pub struct BillingReport { + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] + #[scale_info(skip_type_params(T))] + pub struct BillingReport { state: State, + vault: T::AccountId, total_balance: u128, distributed_balance: u128, // stage 1 @@ -90,6 +97,21 @@ pub mod pallet { rewarding_processed_batches: BoundedVec, } + impl Default for BillingReport { + fn default() -> Self { + Self { + state: State::default(), + vault: T::PalletId::get().into_account_truncating(), + total_balance: Zero::zero(), + distributed_balance: Zero::zero(), + charging_max_batch_index: Zero::zero(), + charging_processed_batches: BoundedVec::default(), + rewarding_max_batch_index: Zero::zero(), + rewarding_processed_batches: BoundedVec::default(), + } + } + } + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Default)] pub enum State { #[default] @@ -113,6 +135,7 @@ pub mod pallet { ensure_signed(origin)?; // todo: check that the caller is DAC account let mut billing_report = BillingReport::default(); + billing_report.vault = Self::sub_account_id(cluster_id.clone(), era); billing_report.state = State::Initialized; ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); @@ -342,4 +365,21 @@ pub mod pallet { Ok(()) } } + + impl Pallet { + fn account_id() -> T::AccountId { + T::PalletId::get().into_account_truncating() + } + + fn sub_account_id(cluster_id: ClusterId, era: DdcEra) -> T::AccountId { + let mut bytes = Vec::new(); + bytes.extend_from_slice(&cluster_id[..]); + bytes.extend_from_slice(&era.encode()); + let hash = blake2_128(&bytes); + // "modl" + "payouts_" + hash is 28 bytes, the T::AccountId is 32 bytes, so we should be + // safe from the truncation and possible collisions caused by it. The rest 4 bytes will + // be fulfilled with trailing zeros. + T::PalletId::get().into_sub_account_truncating(hash) + } + } } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index f8d9be6ee..38bf95d96 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -9,7 +9,7 @@ use sp_core::hash::H160; use sp_runtime::{AccountId32, RuntimeDebug}; pub type ClusterId = H160; -pub type DdcEra = u64; +pub type DdcEra = u32; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 99d5d06ac..886ea9f25 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1374,8 +1374,13 @@ impl pallet_ddc_clusters::Config for Runtime { type NodeRepository = pallet_ddc_nodes::Pallet; } +parameter_types! { + pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); +} + impl pallet_ddc_payouts::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type PalletId = PayoutsPalletId; } construct_runtime!( From bbf5ea858a6e3eb23f72560fb72c9d644ea291b5 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 2 Nov 2023 23:16:36 +0100 Subject: [PATCH 434/544] feat: ddc-traits module is added for loose coupling between pallets --- Cargo.lock | 344 +++++++++++++++++--------------- pallets/ddc-clusters/Cargo.toml | 3 +- pallets/ddc-clusters/src/lib.rs | 99 ++++----- pallets/ddc-staking/Cargo.toml | 1 + pallets/ddc-staking/src/lib.rs | 100 +++++++++- runtime/cere-dev/src/lib.rs | 2 + traits/Cargo.toml | 11 + traits/src/cluster.rs | 12 ++ traits/src/lib.rs | 4 + traits/src/staking.rs | 16 ++ 10 files changed, 356 insertions(+), 236 deletions(-) create mode 100644 traits/Cargo.toml create mode 100644 traits/src/cluster.rs create mode 100644 traits/src/lib.rs create mode 100644 traits/src/staking.rs diff --git a/Cargo.lock b/Cargo.lock index 3d2141735..143e726d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1633,6 +1633,17 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "ddc-traits" +version = "0.1.0" +dependencies = [ + "ddc-primitives", + "frame-support", + "frame-system", + "sp-core", + "sp-std", +] + [[package]] name = "der" version = "0.5.1" @@ -2106,7 +2117,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2123,7 +2134,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2146,7 +2157,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "array-bytes 4.2.0", @@ -2197,7 +2208,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2208,7 +2219,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2224,7 +2235,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2253,7 +2264,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-metadata", @@ -2285,7 +2296,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2299,7 +2310,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2311,7 +2322,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2321,7 +2332,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2339,7 +2350,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2354,7 +2365,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2363,7 +2374,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -4430,7 +4441,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4629,7 +4640,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4645,7 +4656,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4660,7 +4671,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4684,7 +4695,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4704,7 +4715,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4719,7 +4730,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4770,7 +4781,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4789,7 +4800,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4806,7 +4817,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -4834,7 +4845,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -4849,7 +4860,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4859,7 +4870,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4876,7 +4887,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -4891,13 +4902,13 @@ name = "pallet-ddc-clusters" version = "4.8.1" dependencies = [ "ddc-primitives", + "ddc-traits", "frame-benchmarking", "frame-support", "frame-system", "log", "pallet-contracts", "pallet-ddc-nodes", - "pallet-ddc-staking", "parity-scale-codec", "scale-info", "sp-core", @@ -4979,6 +4990,7 @@ name = "pallet-ddc-staking" version = "4.8.1" dependencies = [ "ddc-primitives", + "ddc-traits", "frame-benchmarking", "frame-support", "frame-system", @@ -5035,7 +5047,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5051,7 +5063,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5075,7 +5087,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5088,7 +5100,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5144,7 +5156,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5165,7 +5177,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5188,7 +5200,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5204,7 +5216,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5224,7 +5236,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5241,7 +5253,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5258,7 +5270,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5273,7 +5285,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5290,7 +5302,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5310,7 +5322,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5320,7 +5332,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5337,7 +5349,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5360,7 +5372,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5375,7 +5387,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5389,7 +5401,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5404,7 +5416,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5420,7 +5432,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5441,7 +5453,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5457,7 +5469,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5471,7 +5483,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5494,7 +5506,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5505,7 +5517,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5519,7 +5531,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5537,7 +5549,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5556,7 +5568,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5572,7 +5584,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5587,7 +5599,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5598,7 +5610,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5616,7 +5628,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5633,7 +5645,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5649,7 +5661,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -6554,7 +6566,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", @@ -6827,7 +6839,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6838,7 +6850,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6865,7 +6877,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6888,7 +6900,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6904,7 +6916,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6921,7 +6933,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6932,7 +6944,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "chrono", @@ -6972,7 +6984,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -7000,7 +7012,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -7025,7 +7037,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7049,7 +7061,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", @@ -7091,7 +7103,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7113,7 +7125,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -7126,7 +7138,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7150,7 +7162,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -7161,7 +7173,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -7188,7 +7200,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -7204,7 +7216,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7219,7 +7231,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", @@ -7239,7 +7251,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "array-bytes 4.2.0", @@ -7280,7 +7292,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -7301,7 +7313,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7318,7 +7330,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7333,7 +7345,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -7380,7 +7392,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cid", "futures", @@ -7400,7 +7412,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -7426,7 +7438,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7444,7 +7456,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7465,7 +7477,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "fork-tree", @@ -7493,7 +7505,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "futures", @@ -7512,7 +7524,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "bytes", @@ -7542,7 +7554,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", @@ -7555,7 +7567,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7564,7 +7576,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7594,7 +7606,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7617,7 +7629,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7630,7 +7642,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7700,7 +7712,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7714,7 +7726,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7733,7 +7745,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7752,7 +7764,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7770,7 +7782,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7801,7 +7813,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7812,7 +7824,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7838,7 +7850,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7851,7 +7863,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -8264,7 +8276,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8282,7 +8294,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -8294,7 +8306,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8307,7 +8319,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -8322,7 +8334,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8335,7 +8347,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8347,7 +8359,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8359,7 +8371,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8377,7 +8389,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8396,7 +8408,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8419,7 +8431,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8433,7 +8445,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8446,7 +8458,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes 4.2.0", "base58", @@ -8492,7 +8504,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", @@ -8506,7 +8518,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8517,7 +8529,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8526,7 +8538,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8536,7 +8548,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8547,7 +8559,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8565,7 +8577,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8579,7 +8591,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8605,7 +8617,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8616,7 +8628,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8633,7 +8645,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8642,7 +8654,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8656,7 +8668,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8666,7 +8678,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8676,7 +8688,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8686,7 +8698,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8709,7 +8721,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8727,7 +8739,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8739,7 +8751,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8753,7 +8765,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8767,7 +8779,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8778,7 +8790,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8800,12 +8812,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8818,7 +8830,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8831,7 +8843,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8847,7 +8859,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8859,7 +8871,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8868,7 +8880,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8884,7 +8896,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", @@ -8907,7 +8919,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8924,7 +8936,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8935,7 +8947,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8948,7 +8960,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -9095,7 +9107,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -9103,7 +9115,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -9124,7 +9136,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -9137,7 +9149,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -9158,7 +9170,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -9168,7 +9180,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9179,7 +9191,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -9626,7 +9638,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index a7ed43bdf..62f59dd67 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -18,7 +19,6 @@ sp-std = { version = "4.0.0-dev", default-features = false, git = "https://githu sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } -pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../ddc-staking" } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -35,7 +35,6 @@ std = [ "frame-benchmarking/std", "pallet-contracts/std", "pallet-ddc-nodes/std", - "pallet-ddc-staking/std", "scale-info/std", "sp-core/std", "sp-io/std", diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index fafa00f9b..32547c464 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -16,6 +16,10 @@ #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_traits::{ + cluster::{ClusterVisitor, ClusterVisitorError}, + staking::{StakingVisitor, StakingVisitorError}, +}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; pub use pallet::*; @@ -45,11 +49,10 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: - frame_system::Config + pallet_contracts::Config + pallet_ddc_staking::Config - { + pub trait Config: frame_system::Config + pallet_contracts::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type NodeRepository: NodeRepository; + type NodeRepository: NodeRepository; // todo: get rid of tight coupling with nodes-pallet + type StakingVisitor: StakingVisitor; } #[pallet::event] @@ -71,15 +74,11 @@ pub mod pallet { NodeIsAlreadyAssigned, NodeIsNotAssigned, OnlyClusterManager, - NotAuthorized, - NoStake, - /// Conditions for fast chill are not met, try the regular `chill` from - /// `pallet-ddc-staking`. - FastChillProhibited, + NodeIsNotAuthorized, + NodeHasNoStake, + NodeStakeIsInvalid, /// Cluster candidate should not plan to chill. - ChillingProhibited, - /// Origin of the call is not a controller of the stake associated with the provided node. - NotNodeController, + NodeChillingIsProhibited, } #[pallet::storage] @@ -129,38 +128,28 @@ pub mod pallet { let cluster = Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); + + // Node with this node with this public key exists let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToAddNonExistentNode)?; ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); // Sufficient funds are locked at the DDC Staking module. - let node_provider_stash = - >::nodes(&node_pub_key).ok_or(Error::::NoStake)?; - let maybe_edge_in_cluster = - >::edges(&node_provider_stash); - let maybe_storage_in_cluster = - >::storages(&node_provider_stash); - let has_stake = maybe_edge_in_cluster - .or(maybe_storage_in_cluster) - .is_some_and(|staking_cluster| staking_cluster == cluster_id); - ensure!(has_stake, Error::::NoStake); + let has_stake = T::StakingVisitor::node_has_stake(&node_pub_key, &cluster_id) + .map_err(|e| Into::>::into(StakingVisitorError::from(e)))?; + ensure!(has_stake, Error::::NodeHasNoStake); // Candidate is not planning to pause operations any time soon. - let node_provider_controller = - >::bonded(&node_provider_stash) - .ok_or(>::BadState)?; - let chilling = >::ledger(&node_provider_controller) - .ok_or(>::BadState)? - .chilling - .is_some(); - ensure!(!chilling, Error::::ChillingProhibited); + let is_chilling = T::StakingVisitor::node_is_chilling(&node_pub_key) + .map_err(|e| Into::>::into(StakingVisitorError::from(e)))?; + ensure!(!is_chilling, Error::::NodeChillingIsProhibited); // Cluster extension smart contract allows joining. let call_data = { // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool - let args: ([u8; 4], T::AccountId, Vec, u8) = ( + let args: ([u8; 4], /* T::AccountId, */ Vec, u8) = ( INK_SELECTOR_IS_AUTHORIZED, - node_provider_stash, + // *node.get_provider_id(), node_pub_key.encode()[1..].to_vec(), // remove the first byte added by SCALE node_pub_key.variant_as_number(), ); @@ -179,7 +168,7 @@ pub mod pallet { .data .first() .is_some_and(|x| *x == 1); - ensure!(is_authorized, Error::::NotAuthorized); + ensure!(is_authorized, Error::::NodeIsNotAuthorized); node.set_cluster_id(Some(cluster_id.clone())); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; @@ -230,36 +219,26 @@ pub mod pallet { Ok(()) } + } - /// Allow cluster node candidate to chill in the next DDC era. - /// - /// The dispatch origin for this call must be _Signed_ by the controller. - #[pallet::weight(10_000)] - pub fn fast_chill(origin: OriginFor, node: NodePubKey) -> DispatchResult { - let controller = ensure_signed(origin)?; - - let stash = >::ledger(&controller) - .ok_or(>::NotController)? - .stash; - let node_stash = >::nodes(&node) - .ok_or(>::BadState)?; - ensure!(stash == node_stash, Error::::NotNodeController); - - let cluster = >::edges(&stash) - .or(>::storages(&stash)) - .ok_or(Error::::NoStake)?; - let is_cluster_node = ClustersNodes::::get(cluster, node); - ensure!(!is_cluster_node, Error::::FastChillProhibited); + impl ClusterVisitor for Pallet { + fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool { + ClustersNodes::::get(cluster_id, node_pub_key) + } - let can_chill_from = >::current_era().unwrap_or(0) + 1; - >::chill_stash_soon( - &stash, - &controller, - cluster, - can_chill_from, - ); + fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { + Clusters::::get(&cluster_id) + .map(|_| ()) + .ok_or(ClusterVisitorError::ClusterDoesNotExist) + } + } - Ok(()) + impl From for Error { + fn from(error: StakingVisitorError) -> Self { + match error { + StakingVisitorError::NodeStakeDoesNotExist => Error::::NodeHasNoStake, + StakingVisitorError::NodeStakeIsInBadState => Error::::NodeStakeIsInvalid, + } } } } diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index 572a2fd25..9fbcc154e 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 6a64ac9b3..55614769b 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -13,6 +13,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +#![feature(is_some_and)] // ToDo: delete at rustc > 1.70 #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; @@ -29,6 +30,11 @@ use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; pub use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_traits::{ + cluster::{ClusterVisitor, ClusterVisitorError}, + staking::{StakingVisitor, StakingVisitorError}, +}; + use frame_support::{ assert_ok, pallet_prelude::*, @@ -244,6 +250,8 @@ pub mod pallet { /// Time used for computing era index. It is guaranteed to start being called from the first /// `on_finalize`. type UnixTime: UnixTime; + + type ClusterVisitor: ClusterVisitor; } /// Map from all locked "stash" accounts to the controller account. @@ -475,6 +483,12 @@ pub mod pallet { BudgetOverflow, /// Current era not set during runtime DDCEraNotSet, + /// Origin of the call is not a controller of the stake associated with the provided node. + NotNodeController, + /// No stake found associated with the provided node. + NodeHasNoStake, + /// Conditions for fast chill are not met, try the regular `chill` from + FastChillProhibited, } #[pallet::hooks] @@ -678,12 +692,15 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The /// bond size must be greater than or equal to the `EdgeBondSize`. #[pallet::weight(T::WeightInfo::serve())] - pub fn serve(origin: OriginFor, cluster: ClusterId) -> DispatchResult { + pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; + T::ClusterVisitor::ensure_cluster(&cluster_id) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; ensure!( - ledger.active >= Self::settings(cluster).edge_bond_size, + ledger.active >= Self::settings(cluster_id).edge_bond_size, Error::::InsufficientBond ); let stash = &ledger.stash; @@ -694,13 +711,13 @@ pub mod pallet { // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::edges(&stash) { // Switching the cluster is prohibited. The user should chill first. - ensure!(current_cluster == cluster, Error::::AlreadyInRole); + ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts Self::reset_chilling(&controller); return Ok(()) } - Self::do_add_edge(stash, cluster); + Self::do_add_edge(stash, cluster_id); Ok(()) } @@ -712,12 +729,15 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The /// bond size must be greater than or equal to the `StorageBondSize`. #[pallet::weight(T::WeightInfo::store())] - pub fn store(origin: OriginFor, cluster: ClusterId) -> DispatchResult { + pub fn store(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; + T::ClusterVisitor::ensure_cluster(&cluster_id) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; ensure!( - ledger.active >= Self::settings(cluster).storage_bond_size, + ledger.active >= Self::settings(cluster_id).storage_bond_size, Error::::InsufficientBond ); let stash = &ledger.stash; @@ -728,13 +748,13 @@ pub mod pallet { // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::storages(&stash) { // Switching the cluster is prohibited. The user should chill first. - ensure!(current_cluster == cluster, Error::::AlreadyInRole); + ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts Self::reset_chilling(&controller); return Ok(()) } - Self::do_add_storage(stash, cluster); + Self::do_add_storage(stash, cluster_id); Ok(()) } @@ -940,6 +960,30 @@ pub mod pallet { Ok(()) } + + /// Allow cluster node candidate to chill in the next DDC era. + /// + /// The dispatch origin for this call must be _Signed_ by the controller. + #[pallet::weight(10_000)] + pub fn fast_chill(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { + let controller = ensure_signed(origin)?; + + let stash = >::get(&controller).ok_or(Error::::NotController)?.stash; + let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; + ensure!(stash == node_stash, Error::::NotNodeController); + + let cluster_id = >::get(&stash) + .or(>::get(&stash)) + .ok_or(Error::::NodeHasNoStake)?; + + let is_cluster_node = T::ClusterVisitor::cluster_has_node(&cluster_id, &node_pub_key); + ensure!(!is_cluster_node, Error::::FastChillProhibited); + + let can_chill_from = Self::current_era().unwrap_or(0) + 1; + Self::chill_stash_soon(&stash, &controller, cluster_id, can_chill_from); + + Ok(()) + } } impl Pallet { @@ -1116,4 +1160,44 @@ pub mod pallet { }); } } + + impl StakingVisitor for Pallet { + fn node_has_stake( + node_pub_key: &NodePubKey, + cluster_id: &ClusterId, + ) -> Result { + let stash = + >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; + let maybe_edge_in_cluster = Edges::::get(&stash); + let maybe_storage_in_cluster = Storages::::get(&stash); + + let has_stake: bool = maybe_edge_in_cluster + .or(maybe_storage_in_cluster) + .is_some_and(|staking_cluster| staking_cluster == *cluster_id); + + Ok(has_stake) + } + + fn node_is_chilling(node_pub_key: &NodePubKey) -> Result { + let stash = + >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; + let controller = + >::get(&stash).ok_or(StakingVisitorError::NodeStakeIsInBadState)?; + + let is_chilling = >::get(&controller) + .ok_or(StakingVisitorError::NodeStakeIsInBadState)? + .chilling + .is_some(); + + Ok(is_chilling) + } + } + + impl From for Error { + fn from(error: ClusterVisitorError) -> Self { + match error { + ClusterVisitorError::ClusterDoesNotExist => Error::::NodeHasNoStake, + } + } + } } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 46ee3b429..0637375e6 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1334,6 +1334,7 @@ impl pallet_ddc_staking::Config for Runtime { type StakersPayoutSource = DdcCustomersPalletId; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; + type ClusterVisitor = pallet_ddc_clusters::Pallet; } parameter_types! { @@ -1371,6 +1372,7 @@ impl pallet_ddc_nodes::Config for Runtime { impl pallet_ddc_clusters::Config for Runtime { type RuntimeEvent = RuntimeEvent; type NodeRepository = pallet_ddc_nodes::Pallet; + type StakingVisitor = pallet_ddc_staking::Pallet; } construct_runtime!( diff --git a/traits/Cargo.toml b/traits/Cargo.toml new file mode 100644 index 000000000..ef2bb96e9 --- /dev/null +++ b/traits/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "ddc-traits" +version = "0.1.0" +edition = "2021" + +[dependencies] +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs new file mode 100644 index 000000000..a1cae3515 --- /dev/null +++ b/traits/src/cluster.rs @@ -0,0 +1,12 @@ +use ddc_primitives::{ClusterId, NodePubKey}; +use frame_system::Config; + +pub trait ClusterVisitor { + fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; + + fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError>; +} + +pub enum ClusterVisitorError { + ClusterDoesNotExist, +} diff --git a/traits/src/lib.rs b/traits/src/lib.rs new file mode 100644 index 000000000..f6eb2b0a4 --- /dev/null +++ b/traits/src/lib.rs @@ -0,0 +1,4 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod cluster; +pub mod staking; diff --git a/traits/src/staking.rs b/traits/src/staking.rs new file mode 100644 index 000000000..5ec1e8bcf --- /dev/null +++ b/traits/src/staking.rs @@ -0,0 +1,16 @@ +use ddc_primitives::{ClusterId, NodePubKey}; +use frame_system::Config; + +pub trait StakingVisitor { + fn node_has_stake( + node_pub_key: &NodePubKey, + cluster_id: &ClusterId, + ) -> Result; + + fn node_is_chilling(node_pub_key: &NodePubKey) -> Result; +} + +pub enum StakingVisitorError { + NodeStakeDoesNotExist, + NodeStakeIsInBadState, +} From 46cbf996073ecf53cbea62f41fb1199182411d99 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 2 Nov 2023 23:25:56 +0100 Subject: [PATCH 435/544] fix: mock object for ddc-staking tests is fixed --- pallets/ddc-staking/src/mock.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 48d046fb6..9a03bd114 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -4,6 +4,7 @@ use crate::{self as pallet_ddc_staking, *}; use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; +use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; use frame_support::{ construct_runtime, traits::{ConstU32, ConstU64, Everything, GenesisBuild}, @@ -110,11 +111,20 @@ impl crate::pallet::Config for Test { type UnixTime = Timestamp; type WeightInfo = (); type StakersPayoutSource = DdcAccountsPalletId; + type ClusterVisitor = TestClusterVisitor; } pub(crate) type DdcStakingCall = crate::Call; pub(crate) type TestRuntimeCall = ::RuntimeCall; - +pub struct TestClusterVisitor {} +impl ClusterVisitor for TestClusterVisitor { + fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { + true + } + fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { + Ok(()) + } +} pub struct ExtBuilder { has_edges: bool, has_storages: bool, From b490d954461a0464ea507b888b35400901ec86d0 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 3 Nov 2023 01:06:34 +0100 Subject: [PATCH 436/544] feat: trait bounds are added for the node provider type --- pallets/ddc-clusters/src/lib.rs | 13 +++++----- pallets/ddc-nodes/src/cdn_node.rs | 15 ++++++------ pallets/ddc-nodes/src/lib.rs | 19 +++++++-------- pallets/ddc-nodes/src/node.rs | 24 +++++++++---------- pallets/ddc-nodes/src/storage_node.rs | 34 +++++++++++++-------------- primitives/src/lib.rs | 9 ------- 6 files changed, 53 insertions(+), 61 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 32547c464..6ab995511 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -95,7 +95,7 @@ pub mod pallet { Blake2_128Concat, NodePubKey, bool, - ValueQuery, + OptionQuery, >; #[pallet::call] @@ -147,11 +147,12 @@ pub mod pallet { // Cluster extension smart contract allows joining. let call_data = { // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool - let args: ([u8; 4], /* T::AccountId, */ Vec, u8) = ( + let args: ([u8; 4], T::AccountId, Vec, u8) = ( INK_SELECTOR_IS_AUTHORIZED, - // *node.get_provider_id(), - node_pub_key.encode()[1..].to_vec(), // remove the first byte added by SCALE - node_pub_key.variant_as_number(), + node.get_provider_id().to_owned(), + /* remove the first byte* added by SCALE */ + node.get_pub_key().to_owned().encode()[1..].to_vec(), + node.get_type().into(), ); args.encode() }; @@ -223,7 +224,7 @@ pub mod pallet { impl ClusterVisitor for Pallet { fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool { - ClustersNodes::::get(cluster_id, node_pub_key) + ClustersNodes::::get(cluster_id, node_pub_key).is_some() } fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 2bf763e44..aa0392d3c 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -13,9 +13,10 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNode { +#[scale_info(skip_type_params(T))] +pub struct CDNNode { pub pub_key: CDNNodePubKey, - pub provider_id: AccountId, + pub provider_id: T::AccountId, pub cluster_id: Option, pub props: CDNNodeProps, } @@ -32,11 +33,11 @@ pub struct CDNNodeParams { pub params: Vec, // should be replaced with specific parameters for this type of node } -impl NodeTrait for CDNNode { +impl NodeTrait for CDNNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::CDNPubKeyRef(&self.pub_key) } - fn get_provider_id(&self) -> &AccountId { + fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { @@ -70,12 +71,12 @@ impl NodeTrait for CDNNode { } fn new( node_pub_key: NodePubKey, - provider_id: AccountId, + provider_id: T::AccountId, node_params: NodeParams, - ) -> Result, NodeError> { + ) -> Result, NodeError> { match node_pub_key { NodePubKey::CDNPubKey(pub_key) => match node_params { - NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { + NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { provider_id, pub_key, cluster_id: None, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index a6ff1b3d4..70efb076f 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -66,12 +66,11 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn storage_nodes)] pub type StorageNodes = - StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; + StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; #[pallet::storage] #[pallet::getter(fn cdn_nodes)] - pub type CDNNodes = - StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; + pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; #[pallet::call] impl Pallet { @@ -82,7 +81,7 @@ pub mod pallet { node_params: NodeParams, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let node = Node::::new(node_pub_key.clone(), caller_id, node_params) + let node = Node::::new(node_pub_key.clone(), caller_id, node_params) .map_err(|e| Into::>::into(NodeError::from(e)))?; Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; Self::deposit_event(Event::::NodeCreated { node_pub_key }); @@ -121,9 +120,9 @@ pub mod pallet { } pub trait NodeRepository { - fn create(node: Node) -> Result<(), NodeRepositoryError>; - fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError>; - fn update(node: Node) -> Result<(), NodeRepositoryError>; + fn create(node: Node) -> Result<(), NodeRepositoryError>; + fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError>; + fn update(node: Node) -> Result<(), NodeRepositoryError>; fn delete(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError>; } @@ -146,7 +145,7 @@ pub mod pallet { } impl NodeRepository for Pallet { - fn create(node: Node) -> Result<(), NodeRepositoryError> { + fn create(node: Node) -> Result<(), NodeRepositoryError> { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { @@ -165,7 +164,7 @@ pub mod pallet { } } - fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError> { + fn get(node_pub_key: NodePubKey) -> Result, NodeRepositoryError> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => match StorageNodes::::try_get(pub_key) { Ok(storage_node) => Ok(Node::Storage(storage_node)), @@ -178,7 +177,7 @@ pub mod pallet { } } - fn update(node: Node) -> Result<(), NodeRepositoryError> { + fn update(node: Node) -> Result<(), NodeRepositoryError> { match node { Node::Storage(storage_node) => { if !StorageNodes::::contains_key(&storage_node.pub_key) { diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index e571cfe85..abed0b026 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -10,9 +10,9 @@ use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum Node { - Storage(StorageNode), - CDN(CDNNode), +pub enum Node { + Storage(StorageNode), + CDN(CDNNode), } // Params fields are always coming from extrinsic input @@ -52,9 +52,9 @@ pub enum NodePropsRef<'a> { CDNPropsRef(&'a CDNNodeProps), } -pub trait NodeTrait { +pub trait NodeTrait { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; - fn get_provider_id(&self) -> &AccountId; + fn get_provider_id(&self) -> &T::AccountId; fn get_props<'a>(&'a self) -> NodePropsRef<'a>; fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; @@ -63,19 +63,19 @@ pub trait NodeTrait { fn get_type(&self) -> NodeType; fn new( node_pub_key: NodePubKey, - provider_id: AccountId, + provider_id: T::AccountId, params: NodeParams, - ) -> Result, NodeError>; + ) -> Result, NodeError>; } -impl NodeTrait for Node { +impl NodeTrait for Node { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { match &self { Node::Storage(node) => node.get_pub_key(), Node::CDN(node) => node.get_pub_key(), } } - fn get_provider_id(&self) -> &AccountId { + fn get_provider_id(&self) -> &T::AccountId { match &self { Node::Storage(node) => node.get_provider_id(), Node::CDN(node) => node.get_provider_id(), @@ -119,9 +119,9 @@ impl NodeTrait for Node { } fn new( node_pub_key: NodePubKey, - provider_id: AccountId, + provider_id: T::AccountId, node_params: NodeParams, - ) -> Result, NodeError> { + ) -> Result, NodeError> { match node_pub_key { NodePubKey::StoragePubKey(_) => StorageNode::new(node_pub_key, provider_id, node_params), @@ -175,7 +175,7 @@ impl From for Error { NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, NodeError::StorageNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, - NodeError::CDNNodeParamsExceedsLimit => Error::::InvalidNodeParams, + NodeError::CDNNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, NodeError::InvalidStorageNodeProps => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeProps => Error::::InvalidNodeParams, } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 92b867391..d55088195 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -13,9 +13,10 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct StorageNode { +#[scale_info(skip_type_params(T))] +pub struct StorageNode { pub pub_key: StorageNodePubKey, - pub provider_id: AccountId, + pub provider_id: T::AccountId, pub cluster_id: Option, pub props: StorageNodeProps, } @@ -32,11 +33,11 @@ pub struct StorageNodeParams { pub params: Vec, // should be replaced with specific parameters for this type of node } -impl NodeTrait for StorageNode { +impl NodeTrait for StorageNode { fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { NodePubKeyRef::StoragePubKeyRef(&self.pub_key) } - fn get_provider_id(&self) -> &AccountId { + fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } fn get_props<'a>(&'a self) -> NodePropsRef<'a> { @@ -70,23 +71,22 @@ impl NodeTrait for StorageNode { } fn new( node_pub_key: NodePubKey, - provider_id: AccountId, + provider_id: T::AccountId, node_params: NodeParams, - ) -> Result, NodeError> { + ) -> Result, NodeError> { match node_pub_key { NodePubKey::StoragePubKey(pub_key) => match node_params { - NodeParams::StorageParams(node_params) => - Ok(Node::Storage(StorageNode:: { - provider_id, - pub_key, - cluster_id: None, - props: StorageNodeProps { - params: match node_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), - }, + NodeParams::StorageParams(node_params) => Ok(Node::Storage(StorageNode:: { + provider_id, + pub_key, + cluster_id: None, + props: StorageNodeProps { + params: match node_params.params.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), }, - })), + }, + })), _ => Err(NodeError::InvalidStorageNodeParams), }, _ => Err(NodeError::InvalidStorageNodePubKey), diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 401f5974e..de23aa1fd 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -17,14 +17,5 @@ pub enum NodePubKey { CDNPubKey(CDNNodePubKey), } -impl NodePubKey { - pub fn variant_as_number(&self) -> u8 { - match self { - NodePubKey::CDNPubKey(_) => 0, - NodePubKey::StoragePubKey(_) => 1, - } - } -} - pub type StorageNodePubKey = AccountId32; pub type CDNNodePubKey = AccountId32; From c82f5e38b3c21897b94e33fe0fbdc8c4455579bb Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 3 Nov 2023 02:36:26 +0100 Subject: [PATCH 437/544] chore: auth contract call is moved to a module --- pallets/ddc-clusters/src/lib.rs | 63 ++++++++--------- .../ddc-clusters/src/node_provider_auth.rs | 69 +++++++++++++++++++ pallets/ddc-nodes/src/cdn_node.rs | 6 +- pallets/ddc-nodes/src/node.rs | 28 +------- pallets/ddc-nodes/src/storage_node.rs | 6 +- primitives/src/lib.rs | 26 +++++++ 6 files changed, 128 insertions(+), 70 deletions(-) create mode 100644 pallets/ddc-clusters/src/node_provider_auth.rs diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6ab995511..2d389b431 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -15,6 +15,10 @@ #![recursion_limit = "256"] #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 +use crate::{ + cluster::{Cluster, ClusterError, ClusterParams}, + node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, +}; use ddc_primitives::{ClusterId, NodePubKey}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, @@ -25,18 +29,9 @@ use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodeRepository, NodeTrait}; use sp_std::prelude::*; -mod cluster; - -pub use crate::cluster::{Cluster, ClusterError, ClusterParams}; - -/// ink! 4.x selector for the "is_authorized" message, equals to the first four bytes of the -/// blake2("is_authorized"). See also: https://use.ink/basics/selectors#selector-calculation/, -/// https://use.ink/macros-attributes/selector/. -const INK_SELECTOR_IS_AUTHORIZED: [u8; 4] = [0x96, 0xb0, 0x45, 0x3e]; -/// The maximum amount of weight that the cluster extension contract call is allowed to consume. -/// See also https://github.com/paritytech/substrate/blob/a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d/frame/contracts/rpc/src/lib.rs#L63. -const EXTENSION_CALL_GAS_LIMIT: Weight = Weight::from_ref_time(5_000_000_000_000); +mod cluster; +mod node_provider_auth; #[frame_support::pallet] pub mod pallet { @@ -79,6 +74,7 @@ pub mod pallet { NodeStakeIsInvalid, /// Cluster candidate should not plan to chill. NodeChillingIsProhibited, + NodeAuthContractCallFailed, } #[pallet::storage] @@ -129,7 +125,7 @@ pub mod pallet { Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - // Node with this node with this public key exists + // Node with this node with this public key exists. let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToAddNonExistentNode)?; ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); @@ -145,32 +141,20 @@ pub mod pallet { ensure!(!is_chilling, Error::::NodeChillingIsProhibited); // Cluster extension smart contract allows joining. - let call_data = { - // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool - let args: ([u8; 4], T::AccountId, Vec, u8) = ( - INK_SELECTOR_IS_AUTHORIZED, - node.get_provider_id().to_owned(), - /* remove the first byte* added by SCALE */ - node.get_pub_key().to_owned().encode()[1..].to_vec(), - node.get_type().into(), - ); - args.encode() - }; - let is_authorized = pallet_contracts::Pallet::::bare_call( - caller_id, + let auth_contract = NodeProviderAuthContract::::new( cluster.props.node_provider_auth_contract, - Default::default(), - EXTENSION_CALL_GAS_LIMIT, - None, - call_data, - false, - ) - .result? - .data - .first() - .is_some_and(|x| *x == 1); + caller_id, + ); + let is_authorized = auth_contract + .is_authorized( + node.get_provider_id().to_owned(), + node.get_pub_key().to_owned(), + node.get_type(), + ) + .map_err(|e| Into::>::into(NodeProviderAuthContractError::from(e)))?; ensure!(is_authorized, Error::::NodeIsNotAuthorized); + // Add node to the cluster. node.set_cluster_id(Some(cluster_id.clone())); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); @@ -242,4 +226,13 @@ pub mod pallet { } } } + + impl From for Error { + fn from(error: NodeProviderAuthContractError) -> Self { + match error { + NodeProviderAuthContractError::ContractCallFailed => + Error::::NodeAuthContractCallFailed, + } + } + } } diff --git a/pallets/ddc-clusters/src/node_provider_auth.rs b/pallets/ddc-clusters/src/node_provider_auth.rs new file mode 100644 index 000000000..e3f038818 --- /dev/null +++ b/pallets/ddc-clusters/src/node_provider_auth.rs @@ -0,0 +1,69 @@ +use crate::Config; +use codec::Encode; +use ddc_primitives::{NodePubKey, NodeType}; +use frame_support::weights::Weight; +use pallet_contracts::chain_extension::UncheckedFrom; +use sp_std::prelude::Vec; + +/// ink! 4.x selector for the "is_authorized" message, equals to the first four bytes of the +/// blake2("is_authorized"). See also: https://use.ink/basics/selectors#selector-calculation/, +/// https://use.ink/macros-attributes/selector/. +const INK_SELECTOR_IS_AUTHORIZED: [u8; 4] = [0x96, 0xb0, 0x45, 0x3e]; + +/// The maximum amount of weight that the cluster extension contract call is allowed to consume. +/// See also https://github.com/paritytech/substrate/blob/a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d/frame/contracts/rpc/src/lib.rs#L63. +const EXTENSION_CALL_GAS_LIMIT: Weight = Weight::from_ref_time(5_000_000_000_000); + +pub struct NodeProviderAuthContract { + contract_id: T::AccountId, + caller_id: T::AccountId, +} + +impl NodeProviderAuthContract +where + T::AccountId: UncheckedFrom + AsRef<[u8]>, +{ + pub fn is_authorized( + &self, + node_provider_id: T::AccountId, + node_pub_key: NodePubKey, + node_type: NodeType, + ) -> Result { + let call_data = { + // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool + let args: ([u8; 4], T::AccountId, Vec, u8) = ( + INK_SELECTOR_IS_AUTHORIZED, + node_provider_id, + /* remove the first byte* added by SCALE */ + node_pub_key.encode()[1..].to_vec(), + node_type.into(), + ); + args.encode() + }; + + let is_authorized = pallet_contracts::Pallet::::bare_call( + self.caller_id.clone(), + self.contract_id.clone(), + Default::default(), + EXTENSION_CALL_GAS_LIMIT, + None, + call_data, + false, + ) + .result + .map_err(|_| NodeProviderAuthContractError::ContractCallFailed)? + .data + .first() + .is_some_and(|x| *x == 1); + + Ok(is_authorized) + } + + pub fn new(contract_id: T::AccountId, caller_id: T::AccountId) -> Self { + Self { contract_id, caller_id } + } +} + +pub enum NodeProviderAuthContractError { + ContractCallFailed, +} diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index aa0392d3c..7bec6566b 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,8 +1,6 @@ -use crate::node::{ - Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, -}; +use crate::node::{Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey}; +use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index abed0b026..d9431c8b6 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -5,7 +5,7 @@ use crate::{ ClusterId, }; use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, NodePubKey, StorageNodePubKey}; +use ddc_primitives::{CDNNodePubKey, NodePubKey, NodeType, StorageNodePubKey}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -130,32 +130,6 @@ impl NodeTrait for Node { } } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum NodeType { - Storage = 1, - CDN = 2, -} - -impl From for u8 { - fn from(node_type: NodeType) -> Self { - match node_type { - NodeType::Storage => 1, - NodeType::CDN => 2, - } - } -} - -impl TryFrom for NodeType { - type Error = (); - fn try_from(value: u8) -> Result { - match value { - 1 => Ok(NodeType::Storage), - 2 => Ok(NodeType::CDN), - _ => Err(()), - } - } -} - pub enum NodeError { InvalidStorageNodePubKey, InvalidCDNNodePubKey, diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index d55088195..f847c119f 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,8 +1,6 @@ -use crate::node::{ - Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait, NodeType, -}; +use crate::node::{Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{ClusterId, NodePubKey, StorageNodePubKey}; +use ddc_primitives::{ClusterId, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index de23aa1fd..0f1efd446 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -19,3 +19,29 @@ pub enum NodePubKey { pub type StorageNodePubKey = AccountId32; pub type CDNNodePubKey = AccountId32; + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodeType { + Storage = 1, + CDN = 2, +} + +impl From for u8 { + fn from(node_type: NodeType) -> Self { + match node_type { + NodeType::Storage => 1, + NodeType::CDN => 2, + } + } +} + +impl TryFrom for NodeType { + type Error = (); + fn try_from(value: u8) -> Result { + match value { + 1 => Ok(NodeType::Storage), + 2 => Ok(NodeType::CDN), + _ => Err(()), + } + } +} From 232427aba560a0d5e953e33028f390480e72e1eb Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 3 Nov 2023 15:05:15 +0100 Subject: [PATCH 438/544] fix: tests compilation is fixed --- Cargo.lock | 1 + pallets/ddc-staking/src/mock.rs | 2 +- pallets/ddc-validator/Cargo.toml | 1 + pallets/ddc-validator/src/mock.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 143e726d2..01736ee8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5016,6 +5016,7 @@ dependencies = [ "array-bytes 6.1.0", "base64 0.21.5", "ddc-primitives", + "ddc-traits", "frame-election-provider-support", "frame-support", "frame-system", diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 9a03bd114..cf55112b7 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -116,7 +116,7 @@ impl crate::pallet::Config for Test { pub(crate) type DdcStakingCall = crate::Call; pub(crate) type TestRuntimeCall = ::RuntimeCall; -pub struct TestClusterVisitor {} +pub struct TestClusterVisitor; impl ClusterVisitor for TestClusterVisitor { fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { true diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 1ea14fd9a..513ab2c1e 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -29,6 +29,7 @@ sp-keystore = { version = "0.12.0", default-features = false, git = "https://git sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } [dev-dependencies] pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs index 2d9568768..6840c7d1d 100644 --- a/pallets/ddc-validator/src/mock.rs +++ b/pallets/ddc-validator/src/mock.rs @@ -1,5 +1,10 @@ use crate::{self as pallet_ddc_validator, *}; use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey}; +use ddc_traits::{ + cluster::{ClusterVisitor, ClusterVisitorError}, + staking::{StakingVisitor, StakingVisitorError}, +}; + use frame_election_provider_support::{onchain, SequentialPhragmen}; use frame_support::{ parameter_types, @@ -270,11 +275,37 @@ impl pallet_ddc_staking::Config for Test { type StakersPayoutSource = DdcAccountsPalletId; type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; + type ClusterVisitor = TestClusterVisitor; +} + +pub struct TestClusterVisitor; +impl ClusterVisitor for TestClusterVisitor { + fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { + true + } + fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { + Ok(()) + } } impl pallet_ddc_clusters::Config for Test { type RuntimeEvent = RuntimeEvent; type NodeRepository = pallet_ddc_nodes::Pallet; + type StakingVisitor = TestStakingVisitor; +} + +pub struct TestStakingVisitor; +impl StakingVisitor for TestStakingVisitor { + fn node_has_stake( + _node_pub_key: &NodePubKey, + _cluster_id: &ClusterId, + ) -> Result { + Ok(true) + } + + fn node_is_chilling(_node_pub_key: &NodePubKey) -> Result { + Ok(true) + } } impl pallet_ddc_nodes::Config for Test { From 13ba696005da9710dd9aeffc236b25e07427a90c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 16:41:32 +0100 Subject: [PATCH 439/544] rebase dev --- Cargo.lock | 64 +- Cargo.toml | 1 - pallets/ddc-validator/Cargo.toml | 1 + pallets/ddc-validator/README.md | 1 - pallets/ddc-validator/src/dac.rs | 414 ------- pallets/ddc-validator/src/lib.rs | 1015 ----------------- .../set-1/aggregated-node-data-for-era.json | 1 - .../src/mock-data/set-1/file-request1.json | 1 - .../src/mock-data/set-1/file-request2.json | 1 - .../src/mock-data/set-1/file-request3.json | 1 - .../set-1/final-validation-decision.json | 1 - .../save-validation-decision-result.json | 1 - .../shared-validation-decisions-for-era.json | 1 - .../mock-data/set-1/validation-decision.json | 1 - pallets/ddc-validator/src/payments.rs | 1 - pallets/ddc-validator/src/shm.rs | 162 --- pallets/ddc-validator/src/tests.rs | 606 ---------- pallets/ddc-validator/src/utils.rs | 73 -- pallets/ddc-validator/src/validation.rs | 1 - runtime/cere-dev/Cargo.toml | 2 - runtime/cere-dev/src/lib.rs | 33 +- 21 files changed, 27 insertions(+), 2355 deletions(-) delete mode 100644 pallets/ddc-validator/README.md delete mode 100644 pallets/ddc-validator/src/dac.rs delete mode 100644 pallets/ddc-validator/src/lib.rs delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/file-request1.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/file-request2.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/file-request3.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/save-validation-decision-result.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json delete mode 100644 pallets/ddc-validator/src/mock-data/set-1/validation-decision.json delete mode 100644 pallets/ddc-validator/src/payments.rs delete mode 100644 pallets/ddc-validator/src/shm.rs delete mode 100644 pallets/ddc-validator/src/tests.rs delete mode 100644 pallets/ddc-validator/src/utils.rs delete mode 100644 pallets/ddc-validator/src/validation.rs diff --git a/Cargo.lock b/Cargo.lock index 01736ee8a..3944e2252 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,12 +165,6 @@ version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52f63c5c1316a16a4b35eaac8b76a98248961a533f061684cb2a7cb0eafb6c6" -[[package]] -name = "array-bytes" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b1c5a481ec30a5abd8dfbd94ab5cf1bb4e9a66be7f1b3b322f2f1170c200fd" - [[package]] name = "arrayref" version = "0.3.7" @@ -834,7 +828,6 @@ dependencies = [ "pallet-ddc-metrics-offchain-worker", "pallet-ddc-nodes", "pallet-ddc-staking", - "pallet-ddc-validator", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", @@ -2160,7 +2153,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", - "array-bytes 4.2.0", + "array-bytes", "chrono", "clap", "comfy-table", @@ -5008,43 +5001,6 @@ dependencies = [ "substrate-test-utils", ] -[[package]] -name = "pallet-ddc-validator" -version = "0.1.0" -dependencies = [ - "alt_serde", - "array-bytes 6.1.0", - "base64 0.21.5", - "ddc-primitives", - "ddc-traits", - "frame-election-provider-support", - "frame-support", - "frame-system", - "lite-json", - "log", - "pallet-balances", - "pallet-contracts", - "pallet-ddc-clusters", - "pallet-ddc-customers", - "pallet-ddc-nodes", - "pallet-ddc-staking", - "pallet-randomness-collective-flip", - "pallet-session", - "pallet-staking", - "pallet-staking-reward-curve", - "pallet-timestamp", - "parity-scale-codec", - "scale-info", - "serde", - "serde_json 1.0.44", - "sp-core", - "sp-io", - "sp-keystore", - "sp-runtime", - "sp-staking", - "sp-std", -] - [[package]] name = "pallet-democracy" version = "4.0.0-dev" @@ -6947,7 +6903,7 @@ name = "sc-cli" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "chrono", "clap", "fdlimit", @@ -7255,7 +7211,7 @@ version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", - "array-bytes 4.2.0", + "array-bytes", "async-trait", "dyn-clone", "finality-grandpa", @@ -7333,7 +7289,7 @@ name = "sc-keystore" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "async-trait", "parking_lot 0.12.1", "serde_json 1.0.107", @@ -7348,7 +7304,7 @@ name = "sc-network" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "async-trait", "asynchronous-codec", "bitflags 1.3.2", @@ -7459,7 +7415,7 @@ name = "sc-network-light" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "futures", "libp2p", "log", @@ -7480,7 +7436,7 @@ name = "sc-network-sync" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "fork-tree", "futures", "libp2p", @@ -7508,7 +7464,7 @@ name = "sc-network-transactions" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "futures", "hex", "libp2p", @@ -7527,7 +7483,7 @@ name = "sc-offchain" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "bytes", "fnv", "futures", @@ -8461,7 +8417,7 @@ name = "sp-core" version = "6.0.0" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "array-bytes 4.2.0", + "array-bytes", "base58", "bitflags 1.3.2", "blake2", diff --git a/Cargo.toml b/Cargo.toml index 0cf3246b8..3d7599231 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ members = [ "pallets/erc721", "pallets/erc20", "pallets/ddc-metrics-offchain-worker", - "pallets/ddc-validator", "pallets/ddc-customers", "pallets/ddc-nodes", "pallets/ddc-clusters", diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml index 513ab2c1e..6ddfdda06 100644 --- a/pallets/ddc-validator/Cargo.toml +++ b/pallets/ddc-validator/Cargo.toml @@ -62,3 +62,4 @@ std = [ "sp-staking/std", "sp-std/std", ] + diff --git a/pallets/ddc-validator/README.md b/pallets/ddc-validator/README.md deleted file mode 100644 index ba9427397..000000000 --- a/pallets/ddc-validator/README.md +++ /dev/null @@ -1 +0,0 @@ -# DDC Validator \ No newline at end of file diff --git a/pallets/ddc-validator/src/dac.rs b/pallets/ddc-validator/src/dac.rs deleted file mode 100644 index c23b98588..000000000 --- a/pallets/ddc-validator/src/dac.rs +++ /dev/null @@ -1,414 +0,0 @@ -//! A module with Data Activity Capture (DAC) interaction. - -use crate::{utils, DacTotalAggregates, OpCode, ValidationDecision}; -use alloc::string::String; // ToDo: remove String usage -use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; -use codec::{Decode, Encode}; -use sp_runtime::offchain::{http, Duration}; -use sp_staking::EraIndex; -pub use sp_std::{ - collections::{btree_map::BTreeMap, btree_set::BTreeSet}, - prelude::*, -}; - -pub type TimestampInSec = u64; -pub const HTTP_TIMEOUT_MS: u64 = 30_000; -pub const FAILED_CONTENT_CONSUMER_THRESHOLD: TimestampInSec = 100; - -#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct RedisFtAggregate { - #[serde(rename = "FT.AGGREGATE")] - pub ft_aggregate: Vec, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(crate = "alt_serde")] -#[serde(untagged)] -pub enum FtAggregate { - Length(u32), - Node(Vec), -} - -#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] -pub struct BytesSent { - pub node_public_key: String, - pub era: EraIndex, - pub sum: u32, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileRequestWrapper { - #[serde(rename = "JSON.GET")] - json: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct CDNNodeAggregates { - aggregate: Vec, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct CDNNodeAggregate { - total_bytes_sent: u64, - total_queries: u64, - total_reads: u64, - total_reads_acked: u64, - total_queries_acked: u64, - average_response_time_ms: f64, - total_bytes_received: u64, - pub request_ids: Vec, - total_writes_acked: u64, - average_response_time_ms_samples: u64, - total_writes: u64, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileRequests { - requests: Requests, -} - -pub type Requests = BTreeMap; - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileRequest { - pub file_request_id: String, - file_info: FileInfo, - bucket_id: u128, - timestamp: u64, - chunks: BTreeMap, - user_public_key: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct Chunk { - log: Log, - cid: String, - ack: Option, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct Ack { - user_timestamp: u64, - nonce: String, - signature: Option, - aggregated: u64, - user_public_key: String, - bytes_received: u64, - requested_chunk_cids: Vec, - node_public_key: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct Log { - #[serde(rename = "type")] - log_type: u64, - signature: Option, - aggregated: u64, - user_public_key: String, - era: u64, - bucket_id: u128, - user_address: String, - bytes_sent: u64, - timestamp: u64, - node_public_key: String, - session_id: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct FileInfo { - #[serde(rename = "chunkCids", skip_deserializing)] - chunk_cids: Option>, - - #[serde(rename = "requestedChunkCids")] - requested_chunk_cids: Vec, -} - -type EdgeId = String; -type ValidatorId = String; - -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct EdgesToResults(BTreeMap>); - -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct Wrapper { - #[serde(rename = "HGET")] - decisions: String, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -#[serde(crate = "alt_serde")] -pub(crate) struct ValidationResult { - validator_id: ValidatorId, - edge_id: EdgeId, - result: bool, - received: u64, - sent: u64, - era: EraIndex, -} - -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct FinalDecision { - result: bool, - edge_id: EdgeId, - era: EraIndex, - received: u64, - sent: u64, - results_logs: Vec, -} - -#[derive(Debug, Deserialize, Serialize)] -#[serde(crate = "alt_serde")] -pub(crate) struct FinalDecisions(BTreeMap); - -#[derive(Clone, Debug, Encode, Decode, scale_info::TypeInfo, PartialEq)] -pub struct BytesReceived { - pub node_public_key: String, - pub era: EraIndex, - pub sum: u32, -} - -fn get_timestamps_with_ack(file_requests: &Requests) -> Vec { - let mut timestamps: Vec = Vec::new(); - - for (_, file_request) in file_requests { - for (_, chunk) in &file_request.chunks { - if let Some(_ack) = &chunk.ack { - timestamps.push(chunk.log.timestamp); - } - } - } - - timestamps.sort(); - - timestamps -} - -pub fn get_acknowledged_bytes_bucket<'a>( - file_requests: &'a Requests, - acknowledged_bytes_by_bucket: &'a mut Vec<(u128, u64)>, -) -> &'a Vec<(u128, u64)> { - let ack_timestamps = get_timestamps_with_ack(file_requests); - - for (_, file_request) in file_requests { - let mut total_bytes_received = 0u64; - let bucket_id = file_request.bucket_id; - for (_, chunk) in &file_request.chunks { - // Only check reads - match chunk.log.log_type.try_into() { - Ok(OpCode::Read) => - if let Some(ack) = &chunk.ack { - total_bytes_received += ack.bytes_received; - } else { - total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); - }, - _ => (), - } - } - acknowledged_bytes_by_bucket.push((bucket_id, total_bytes_received)); - } - - acknowledged_bytes_by_bucket -} - -pub fn get_served_bytes_sum(file_requests: &Requests) -> (u64, u64) { - let ack_timestamps = get_timestamps_with_ack(file_requests); - let mut total_bytes_received = 0u64; - let mut total_bytes_sent = 0u64; - - for (_, file_request) in file_requests { - for (_, chunk) in &file_request.chunks { - match chunk.log.log_type.try_into() { - Ok(OpCode::Read) => { - total_bytes_sent += chunk.log.bytes_sent; - - if let Some(ack) = &chunk.ack { - total_bytes_received += ack.bytes_received; - } else { - total_bytes_received += get_proved_delivered_bytes(chunk, &ack_timestamps); - } - }, - _ => (), - } - } - } - - (total_bytes_sent, total_bytes_received) -} - -fn get_proved_delivered_bytes(chunk: &Chunk, ack_timestamps: &Vec) -> u64 { - let log_timestamp = chunk.log.timestamp; - let neighbors = get_closer_neighbors(log_timestamp, &ack_timestamps); - let is_proved = - is_lies_within_threshold(log_timestamp, neighbors, FAILED_CONTENT_CONSUMER_THRESHOLD); - - if is_proved { - return chunk.log.bytes_sent - } else { - 0 - } -} - -fn get_closer_neighbors( - timestamp: TimestampInSec, - timestamps: &Vec, -) -> (TimestampInSec, TimestampInSec) { - let mut before = 0; - let mut after = TimestampInSec::MAX; - for ts in timestamps { - if ts < ×tamp { - before = before.max(*ts); - } else if ts > ×tamp { - after = after.min(*ts); - } - } - - (before, after) -} - -fn is_lies_within_threshold( - timestamp: TimestampInSec, - borders: (TimestampInSec, TimestampInSec), - threshold: TimestampInSec, -) -> bool { - let left_distance = timestamp - borders.0; - let right_distance = borders.1 - timestamp; - - if left_distance < threshold || right_distance < threshold { - return true - } - - false -} - -pub(crate) fn fetch_cdn_node_aggregates_request(url: &String) -> Vec { - log::debug!("fetch_file_request | url: {:?}", url); - let response: FileRequestWrapper = http_get_json(&url).unwrap(); - log::debug!("response.json: {:?}", response.json); - let map: Vec = serde_json::from_str(response.json.as_str()).unwrap(); - // log::debug!("response.json: {:?}", response.json); - - map -} - -pub(crate) fn fetch_file_request(url: &String) -> FileRequest { - log::debug!("fetch_file_request | url: {:?}", url); - let response: FileRequestWrapper = http_get_json(&url).unwrap(); - log::debug!("response.json: {:?}", response.json); - - let map: FileRequest = serde_json::from_str(response.json.as_str()).unwrap(); - - map -} - -pub(crate) fn http_get_json(url: &str) -> crate::ResultStr { - let body = http_get_request(url).map_err(|err| { - log::error!("[DAC Validator] Error while getting {}: {:?}", url, err); - "HTTP GET error" - })?; - - let parsed = serde_json::from_slice(&body).map_err(|err| { - log::warn!("[DAC Validator] Error while parsing JSON from {}: {:?}", url, err); - "HTTP JSON parse error" - }); - - parsed -} - -fn http_get_request(http_url: &str) -> Result, http::Error> { - // log::debug!("[DAC Validator] Sending request to: {:?}", http_url); - - // Initiate an external HTTP GET request. This is using high-level wrappers from - // `sp_runtime`. - let request = http::Request::get(http_url); - - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - - let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - - if response.code != 200 { - log::warn!("[DAC Validator] http_get_request unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - - // Next we fully read the response body and collect it to a vector of bytes. - Ok(response.body().collect::>()) -} - -pub(crate) fn get_final_decision(decisions: Vec) -> ValidationDecision { - let common_decisions = find_largest_group(decisions).unwrap(); - let decision_example = common_decisions.get(0).unwrap(); - - let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); - - let final_decision = ValidationDecision { - edge: decision_example.edge.clone(), - result: decision_example.result, - payload: utils::hash(&serialized_decisions), - totals: DacTotalAggregates { - received: decision_example.totals.received, - sent: decision_example.totals.sent, - failed_by_client: 0, - failure_rate: 0, - }, - }; - - final_decision -} - -fn find_largest_group(decisions: Vec) -> Option> { - let mut groups: Vec> = Vec::new(); - let half = decisions.len() / 2; - - for decision in decisions { - let mut found_group = false; - - for group in &mut groups { - if group.iter().all(|x| { - x.result == decision.result && - x.totals.received == decision.totals.received && - x.totals.sent == decision.totals.sent - }) { - group.push(decision.clone()); - found_group = true; - break - } - } - - if !found_group { - groups.push(vec![decision]); - } - } - - let largest_group = groups.into_iter().max_by_key(|group| group.len()).unwrap_or(Vec::new()); - - if largest_group.len() > half { - Some(largest_group) - } else { - None - } -} diff --git a/pallets/ddc-validator/src/lib.rs b/pallets/ddc-validator/src/lib.rs deleted file mode 100644 index fc6d1109c..000000000 --- a/pallets/ddc-validator/src/lib.rs +++ /dev/null @@ -1,1015 +0,0 @@ -//! # DDC Validator pallet -//! -//! The DDC Validator pallet defines storage item to store validation results and implements OCW -//! (off-chain worker) to produce these results using the data from Data Activity Capture (DAC). -//! -//! - [`Config`] -//! - [`Call`] -//! - [`Pallet`] -//! - [`Hooks`] -//! -//! ## Notes -//! -//! - Era definition in this pallet is different than in the `pallet-staking`. Check DAC -//! documentation for `era` definition used in this pallet. - -#![cfg_attr(not(feature = "std"), no_std)] - -mod dac; -mod payments; -mod shm; -mod utils; -mod validation; - -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -pub use alloc::{format, string::String}; -pub use alt_serde::{de::DeserializeOwned, Deserialize, Serialize}; -pub use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; -pub use core::fmt::Debug; -pub use frame_support::{ - decl_event, decl_module, decl_storage, defensive, - dispatch::DispatchResult, - pallet_prelude::*, - parameter_types, storage, - traits::{Currency, Randomness, UnixTime}, - weights::Weight, - BoundedVec, RuntimeDebug, -}; -pub use frame_system::{ - ensure_signed, - offchain::{AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes}, - pallet_prelude::*, -}; -pub use lite_json::json::JsonValue; -pub use pallet::*; -pub use pallet_ddc_customers::{self as ddc_customers, BucketsDetails}; -pub use pallet_ddc_staking::{self as ddc_staking}; -pub use pallet_session as session; -pub use pallet_staking::{self as staking}; -pub use scale_info::TypeInfo; -pub use serde_json::Value; -pub use sp_core::crypto::{AccountId32, KeyTypeId, UncheckedFrom}; -pub use sp_io::{crypto::sr25519_public_keys, offchain_index}; -pub use sp_runtime::offchain::{ - http, storage::StorageValueRef, storage_lock, storage_lock::StorageLock, Duration, Timestamp, -}; -pub use sp_staking::EraIndex; -pub use sp_std::{collections::btree_map::BTreeMap, prelude::*}; - -extern crate alloc; - -/// The balance type of this pallet. -type BalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -type ResultStr = Result; - -/// Offchain local storage key that holds the last era in which the validator completed its -/// assignment. -const LAST_VALIDATED_ERA_KEY: &[u8; 40] = b"pallet-ddc-validator::last_validated_era"; -/// Offchain local storage that holds the validation lock -const VALIDATION_LOCK: &[u8; 37] = b"pallet-ddc-validator::validation_lock"; - -/// Local storage key that holds the flag to enable DDC validation. Set it to true (0x01) to enable -/// DDC validation, set it to false (0x00) or delete the key to disable it. -const ENABLE_DDC_VALIDATION_KEY: &[u8; 21] = b"enable-ddc-validation"; - -pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv"); - -/// Webdis in experimental cluster connected to Redis in dev. -pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379"; -// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379"; -pub const DATA_PROVIDER_URL_KEY: &[u8; 7] = b"dac-url"; -pub const QUORUM_SIZE: usize = 1; - -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub enum OpCode { - Read = 1, - Write = 2, - Search = 3, -} - -impl TryFrom for OpCode { - type Error = &'static str; - - fn try_from(v: u64) -> Result { - match v { - x if x == OpCode::Write as u64 => Ok(OpCode::Write), - x if x == OpCode::Read as u64 => Ok(OpCode::Read), - x if x == OpCode::Search as u64 => Ok(OpCode::Search), - _ => Err("Invalid value to for log type"), - } - } -} - -#[derive(Debug)] -pub enum AssignmentError { - NoValidators, - NotEnoughValidators { requested_quorum: usize, available_validators: usize }, - DefensiveEmptyQuorumsCycle, -} - -/// Aggregated values from DAC that describe CDN node's activity during a certain era. -#[derive( - PartialEq, - Eq, - Clone, - Encode, - Decode, - RuntimeDebug, - TypeInfo, - MaxEncodedLen, - Serialize, - Deserialize, -)] -#[serde(crate = "alt_serde")] -pub struct DacTotalAggregates { - /// Total bytes received by the client. - pub received: u64, - /// Total bytes sent by the CDN node. - pub sent: u64, - /// Total bytes sent by the CDN node to the client which interrupts the connection. - pub failed_by_client: u64, - /// ToDo: explain. - pub failure_rate: u64, -} - -/// Final DAC Validation decision. -#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Serialize, Deserialize)] -#[serde(crate = "alt_serde")] -pub struct ValidationDecision { - /// CDN node public key. - pub edge: String, - /// Validation result. - pub result: bool, - /// A hash of the data used to produce validation result. - pub payload: [u8; 32], - /// Values aggregated from the payload. - pub totals: DacTotalAggregates, -} - -pub mod crypto { - use super::KEY_TYPE; - use frame_system::offchain::AppCrypto; - use sp_core::sr25519::Signature as Sr25519Signature; - use sp_runtime::{ - app_crypto::{app_crypto, sr25519}, - traits::Verify, - }; - app_crypto!(sr25519, KEY_TYPE); - - use sp_runtime::{MultiSignature, MultiSigner}; - - pub struct TestAuthId; - - impl AppCrypto<::Signer, Sr25519Signature> for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } - - impl AppCrypto for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } -} - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - #[pallet::pallet] - #[pallet::without_storage_info] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: - frame_system::Config - + pallet_contracts::Config - + pallet_session::Config::AccountId> - + pallet_staking::Config - + ddc_customers::Config - + ddc_staking::Config - + CreateSignedTransaction> - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Something that provides randomness in the runtime. Required by the tasks assignment - /// procedure. - type Randomness: Randomness; - - /// A dispatchable call. - type RuntimeCall: From>; - - type AuthorityId: AppCrypto; - - /// Number of validators expected to produce an individual validation decision to form a - /// consensus. Tasks assignment procedure use this value to determine the number of - /// validators are getting the same task. Must be an odd number. - #[pallet::constant] - type DdcValidatorsQuorumSize: Get; - - type ValidatorsMax: Get; - - /// Proof-of-Delivery parameter specifies an allowed deviation between bytes sent and bytes - /// received. The deviation is expressed as a percentage. For example, if the value is 10, - /// then the difference between bytes sent and bytes received is allowed to be up to 10%. - /// The value must be in range [0, 100]. - #[pallet::constant] - type ValidationThreshold: Get; - } - - /// The map from the era and validator stash key to the list of CDN nodes to validate. - #[pallet::storage] - #[pallet::getter(fn assignments)] - pub(super) type Assignments = - StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, Vec>; - - /// Map to from era and account ID to bool indicateing that a particular content owner was - /// charged for the era - #[pallet::storage] - #[pallet::getter(fn content_owners_charged)] - pub(super) type EraContentOwnersCharged = - StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, bool, ValueQuery>; - - /// A signal to start a process on all the validators. - #[pallet::storage] - #[pallet::getter(fn signal)] - pub(super) type Signal = StorageValue<_, bool>; - - /// The map from the era and CDN participant stash key to the validation decision related. - #[pallet::storage] - #[pallet::getter(fn validation_decisions)] - pub type ValidationDecisions = - StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, ValidationDecision>; - - // Map to check if validation decision was performed for the era - #[pallet::storage] - #[pallet::getter(fn validation_decision_set_for_node)] - pub(super) type ValidationDecisionSetForNode = - StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, bool, ValueQuery>; - - // Map to check if reward points were set for the era - #[pallet::storage] - #[pallet::getter(fn reward_points_set_for_node)] - pub(super) type RewardPointsSetForNode = - StorageDoubleMap<_, Twox64Concat, EraIndex, Identity, T::AccountId, bool, ValueQuery>; - - /// The last era for which the tasks assignment produced. - #[pallet::storage] - #[pallet::getter(fn last_managed_era)] - pub type LastManagedEra = StorageValue<_, EraIndex>; - - /// The mapping of ddc validator keys to validator stash keys - /// - /// Keys registered by validators are mapped to validator stash accounts. - /// The mapping is formed in the way that facilitates fast checking that storage contains key. - /// Similarly the validator stash is checked if he is still in the list of validators. - #[pallet::storage] - #[pallet::getter(fn get_stash_for_ddc_validator)] - pub type DDCValidatorToStashKeys = - StorageMap<_, Identity, T::AccountId, T::AccountId>; - - #[pallet::error] - pub enum Error { - /// Caller is not controller of validator node - NotController, - /// Checked stash is not an active validator - NotValidatorStash, - /// OCW key has not been registered by validator - DDCValidatorKeyNotRegistered, - /// Attempt to charge content owners twice - ContentOwnersDoubleSpend, - /// Validation decision has been already set for CDN node for some era - ValidationDecisionAlreadySet, - /// Node is not participating in the network - NodeNotActive, - /// Pricing has not been set by sudo - PricingNotSet, - /// Current era not set during runtime - DDCEraNotSet, - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - // Validator submits decision for an era - ValidationDecision(EraIndex, T::AccountId, ValidationDecision), - // Set era reward points - EraRewardPoints(EraIndex, Vec<(T::AccountId, u64)>), - } - - #[pallet::hooks] - impl Hooks> for Pallet - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - fn on_initialize(block_number: T::BlockNumber) -> Weight { - if block_number <= 1u32.into() { - return Weight::from_ref_time(0) - } - - Signal::::set(Some(false)); - - let current_ddc_era = match ddc_staking::pallet::Pallet::::current_era() { - Some(era) => era, - None => { - log::debug!("DDC era not set."); - return Weight::from_ref_time(0) - }, - }; - log::debug!("Current DDC era: {:?}.", current_ddc_era); - - // Skip assignment if already exists for current era - match Self::last_managed_era() { - Some(last_managed_era) if current_ddc_era < last_managed_era => - return Weight::from_ref_time(0), - _ => (), - } - - match Self::assign(3usize, current_ddc_era + 1) { - Ok(_) => >::put(current_ddc_era + 1), - Err(e) => log::debug!("DDC validation assignment error: {:?}.", e), - } - - Weight::from_ref_time(0) - } - - fn offchain_worker(_block_number: T::BlockNumber) { - // Skip if not a validator. - if !sp_io::offchain::is_validator() { - return - } - - // Skip if DDC validation is not enabled. - match StorageValueRef::persistent(ENABLE_DDC_VALIDATION_KEY).get::() { - Ok(Some(enabled)) if enabled == true => (), - _ => return, - } - - let mut should_validate_because_new_era = true; - - let mut validation_lock = StorageLock::::new(VALIDATION_LOCK); - - // Skip if the validation is already in progress. - if validation_lock.try_lock().is_err() { - should_validate_because_new_era = false; - } - - let last_validated_era_storage = StorageValueRef::persistent(LAST_VALIDATED_ERA_KEY); - let last_validated_era = match last_validated_era_storage.get::() { - Ok(Some(last_validated_era)) => last_validated_era, - _ => 0, // let's consider an absent or undecodable data as we never did a validation - }; - - let current_ddc_era = match ddc_staking::pallet::Pallet::::current_era() { - Some(era) => era, - None => { - defensive!("DDC era not set"); - return - }, - }; - - // Skip if the validation is already complete for the era. - if current_ddc_era <= last_validated_era { - should_validate_because_new_era = false; - } - - // Validation start forced externally? - let should_validate_because_signal = Signal::::get().unwrap_or(false); - - if !should_validate_because_new_era && !should_validate_because_signal { - return - } - - if let Err(e) = Self::validate_edges() { - log::warn!("🔎 DDC validation failed. {}", e); - return - } - last_validated_era_storage.set(¤t_ddc_era); - log::info!("🔎 DDC validation complete for {} era.", current_ddc_era); - } - } - - #[pallet::call] - impl Pallet - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - /// Run a process at the same time on all the validators. - #[pallet::weight(10_000)] - pub fn send_signal(origin: OriginFor) -> DispatchResult { - ensure_signed(origin)?; - - Signal::::set(Some(true)); - - Ok(()) - } - - /// Set validation decision for a given CDN node in an era. - /// - /// Only registered validator keys can call this exstrinsic. - /// Validation decision can be set only once per era per CDN node. - /// CDN node should be active. - #[pallet::weight(10_000)] - pub fn set_validation_decision( - origin: OriginFor, - era: EraIndex, - cdn_node: T::AccountId, - validation_decision: ValidationDecision, - ) -> DispatchResult { - let ddc_valitor_key = ensure_signed(origin)?; - - ensure!( - DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), - Error::::DDCValidatorKeyNotRegistered - ); - - ensure!( - staking::Validators::::contains_key( - Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap() - ), - Error::::NotValidatorStash - ); - - ensure!( - !Self::validation_decision_set_for_node(era, &cdn_node), - Error::::ValidationDecisionAlreadySet - ); - - ensure!( - >::contains_key(&cdn_node), - Error::::NodeNotActive - ); - - ValidationDecisions::::insert(era, cdn_node.clone(), validation_decision.clone()); - - ValidationDecisionSetForNode::::insert(era, cdn_node.clone(), true); - - Self::deposit_event(Event::::ValidationDecision(era, cdn_node, validation_decision)); - - Ok(()) - } - - /// Set reward points for CDN participants at the given era. - /// - /// Only registered validator keys can call this exstrinsic. - /// Reward points can be set only once per era per CDN node. - /// CDN node should be active. - /// - /// `stakers_points` is a vector of (stash account ID, reward points) pairs. The rewards - /// distribution will be based on total reward points, with each CDN participant receiving a - /// proportionate reward based on their individual reward points. - #[pallet::weight(100_000)] - pub fn set_era_reward_points( - origin: OriginFor, - era: EraIndex, - stakers_points: Vec<(T::AccountId, u64)>, - ) -> DispatchResult { - let ddc_valitor_key = ensure_signed(origin)?; - - ensure!( - DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), - Error::::DDCValidatorKeyNotRegistered - ); - - ensure!( - staking::Validators::::contains_key( - Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap() - ), - Error::::NotValidatorStash - ); - - let mut rewards_counter = 0; - - >::mutate(era, |era_rewards| { - for (staker, points) in stakers_points.clone().into_iter() { - if !Self::reward_points_set_for_node(era, &staker) { - // ToDo deal with edge case when node is chilling - if >::contains_key(&staker) { - *era_rewards.individual.entry(staker.clone()).or_default() += points; - era_rewards.total += points; - >::mutate( - &staker, - |current_reward_points| { - let rewards: ddc_staking::EraRewardPointsPerNode = - ddc_staking::EraRewardPointsPerNode { era, points }; - current_reward_points.push(rewards); - }, - ); - RewardPointsSetForNode::::insert(era, staker, true); - rewards_counter += 1; - } - } - } - }); - - if rewards_counter > 0 { - Self::deposit_event(Event::::EraRewardPoints(era, stakers_points)); - } - - Ok(()) - } - - /// Exstrinsic deducts balances of content owners - /// - /// Only registered validator keys can call this exstrinsic. - /// Reward points can be set only once per era per validator. - #[pallet::weight(100_000)] - pub fn charge_payments_content_owners( - origin: OriginFor, - paying_accounts: Vec>>, /* ToDo check if - * bounded vec - * should be used */ - ) -> DispatchResult { - let ddc_valitor_key = ensure_signed(origin)?; - log::debug!("validator is {:?}", &ddc_valitor_key); - - let current_era = - ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; - - ensure!( - DDCValidatorToStashKeys::::contains_key(&ddc_valitor_key), - Error::::DDCValidatorKeyNotRegistered - ); - - ensure!( - staking::Validators::::contains_key( - Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap() - ), - Error::::NotValidatorStash - ); - - ensure!( - !Self::content_owners_charged(current_era, &ddc_valitor_key), - Error::::ContentOwnersDoubleSpend - ); - - let pricing: u128 = - >::pricing().ok_or(Error::::PricingNotSet)?; - EraContentOwnersCharged::::insert(current_era, ddc_valitor_key, true); - - >::charge_content_owners(paying_accounts, pricing) - } - - /// Exstrinsic registers a ddc validator key for future use - /// - /// Only controller of validator can call this exstrinsic - /// Validator has to be in the active set - #[pallet::weight(100_000)] - pub fn set_validator_key( - origin: OriginFor, - ddc_validator_pub: T::AccountId, - ) -> DispatchResult { - let controller = ensure_signed(origin)?; - let ledger = staking::Ledger::::get(&controller).ok_or(Error::::NotController)?; - - ensure!( - staking::Validators::::contains_key(&ledger.stash), - Error::::NotValidatorStash - ); - - DDCValidatorToStashKeys::::insert(ddc_validator_pub, &ledger.stash); - Ok(()) - } - } - - impl Pallet - where - ::AccountId: AsRef<[u8]> + UncheckedFrom, - as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, - { - fn get_data_provider_url() -> String { - let url_ref = sp_io::offchain::local_storage_get( - sp_core::offchain::StorageKind::PERSISTENT, - DATA_PROVIDER_URL_KEY, - ); - - match url_ref { - Some(url) => - String::from_utf8(url).expect("Data provider URL should be valid UTF-8 string"), - None => String::from(DEFAULT_DATA_PROVIDER_URL), - } - } - - fn get_data_url() -> String { - let data_url = Self::get_data_provider_url(); - let json_getter = "/JSON.GET/"; - let url = format!("{}{}", data_url, json_getter); - - url - } - - fn get_signer() -> ResultStr> { - let signer = Signer::<_, _>::any_account(); - if !signer.can_sign() { - return Err("[DAC Validator] No local accounts available. Consider adding one via `author_insertKey` RPC."); - } - - Ok(signer) - } - - fn is_valid(bytes_sent: u64, bytes_received: u64) -> bool { - if bytes_sent == bytes_received { - return true - } - - let percentage_difference = 1f32 - (bytes_received as f32 / bytes_sent as f32); - - return if percentage_difference >= 0.0 && - (T::ValidationThreshold::get() as f32 - percentage_difference) > 0.0 - { - true - } else { - false - } - } - - /// Shuffle the `list` swapping it's random elements `list.len()` times. - fn shuffle(mut list: Vec) -> Vec { - let len = list.len(); - for i in 1..len { - let random_index = Self::choose(len as u32).unwrap() as usize; - list.swap(i, random_index) - } - - list - } - - /// Split the `list` to several chunks `segment_len` length each. - /// - /// The very last chunk will be shorter than `segment_len` if `list.len()` is not divisible - /// by `segment_len`. - fn split(list: Vec, segment_len: usize) -> Vec> { - let mut result: Vec> = Vec::new(); - - if segment_len == 0 { - return result - } - - for i in (0..list.len()).step_by(segment_len) { - let end = usize::min(i + segment_len, list.len()); - let chunk = list[i..end].to_vec(); - result.push(chunk); - } - - result - } - - fn assign(quorum_size: usize, era: EraIndex) -> Result<(), AssignmentError> { - let validators: Vec = DDCValidatorToStashKeys::::iter_keys().collect(); - log::debug!("Current validators: {:?}.", validators); - - if validators.len() == 0 { - return Err(AssignmentError::NoValidators) - } - - if validators.len() < quorum_size { - return Err(AssignmentError::NotEnoughValidators { - requested_quorum: quorum_size, - available_validators: validators.len(), - }) - } - - let edges: Vec = >::iter_keys().collect(); - log::debug!("Current edges: {:?}.", edges); - - if edges.len() == 0 { - return Ok(()) - } - - let shuffled_validators = Self::shuffle(validators); - let shuffled_edges = Self::shuffle(edges); - - let validators_keys: Vec = shuffled_validators - .iter() - .map(|v| utils::account_to_string::(v.clone())) - .collect(); - - // Create several groups of validators `quorum_size` length each. - let quorums = Self::split(validators_keys, quorum_size); - - // Write an assignment to each validator in each quorum. The difference between the - // number of edges assigned to each validator is not higher then 1. If the number of - // edges is less then the number of quorums, some quorums will not have any edges - // assigned. - let mut quorums_cycle = quorums.iter().cycle(); - for edge in shuffled_edges { - let Some(quorum_validators) = quorums_cycle.next() else { - return Err(AssignmentError::DefensiveEmptyQuorumsCycle); - }; - quorum_validators.iter().for_each(|validator| { - Assignments::::append( - era, - utils::string_to_account::(validator.clone()), - edge.clone(), - ); - }); - } - - return Ok(()) - } - - /// Randomly choose a number in range `[0, total)`. - /// Returns `None` for zero input. - /// Modification of `choose_ticket` from `pallet-lottery` version `4.0.0-dev`. - fn choose(total: u32) -> Option { - if total == 0 { - return None - } - let mut random_number = Self::generate_random_number(0); - - // Best effort attempt to remove bias from modulus operator. - for i in 1..128 { - if random_number < u32::MAX - u32::MAX % total { - break - } - - random_number = Self::generate_random_number(i); - } - - Some(random_number % total) - } - - /// Generate a random number from a given seed. - /// Note that there is potential bias introduced by using modulus operator. - /// You should call this function with different seed values until the random - /// number lies within `u32::MAX - u32::MAX % n`. - /// Modification of `generate_random_number` from `pallet-lottery` version `4.0.0-dev`. - fn generate_random_number(seed: u32) -> u32 { - let (random_seed, _) = - ::Randomness::random(&(b"ddc-validator", seed).encode()); - let random_number = ::decode(&mut random_seed.as_ref()) - .expect("secure hashes should always be bigger than u32; qed"); - - random_number - } - - fn find_validators_from_quorum(validator_id: &T::AccountId, era: &EraIndex) -> Vec { - let validator_edges = Self::assignments(era, &validator_id).unwrap(); - let mut quorum_members: Vec = Vec::new(); - - >::iter_prefix(era).for_each(|(candidate_id, edges)| { - if validator_edges == edges { - let candidate_id_str = utils::account_to_string::(candidate_id); - quorum_members.push(candidate_id_str); - } - }); - - quorum_members - } - - fn get_public_key() -> Option { - match sr25519_public_keys(KEY_TYPE).first() { - Some(pubkey) => Some(T::AccountId::decode(&mut &pubkey.encode()[..]).unwrap()), - None => None, - } - } - - fn validate_edges() -> Result<(), &'static str> { - let current_ddc_era = - ddc_staking::pallet::Pallet::::current_era().ok_or("DDC era not set")?; - let data_url = Self::get_data_url(); - let data_provider_url = Self::get_data_provider_url(); - log::debug!("[DAC Validator] Data provider URL: {:?}", &data_provider_url); - - let validator = match Self::get_public_key() { - Some(key) => key, - None => return Err("No validator public key found."), - }; - - log::debug!("validator: {:?}", validator); - - let assigned_edges = match Self::assignments(current_ddc_era - 1, validator.clone()) { - Some(edges) => edges, - None => return Err("No assignments for the previous era."), - }; - - log::debug!("assigned_edges: {:?}", assigned_edges); - - // Calculate CDN nodes reward points from validation decision aggregates - let mut cdn_nodes_reward_points: Vec<(T::AccountId, u64)> = vec![]; - - for assigned_edge in assigned_edges.iter() { - log::debug!("assigned edge: {:?}", assigned_edge); - - let Some((node, _)) = >::iter().find(|(_, s)| assigned_edge == s) else { - log::debug!("no known node for: {:?}", assigned_edge); - continue; - }; - - log::debug!("assigned edge node: {:?}", assigned_edge); - - // form url for each node - let edge_url = format!( - "{}{}{}/$.{}", - data_url, - "ddc:dac:aggregation:nodes:", - current_ddc_era - 1, - array_bytes::bytes2hex("", node.encode()), - ); - log::debug!("edge url: {:?}", edge_url); - - let node_aggregates = dac::fetch_cdn_node_aggregates_request(&edge_url); - log::debug!("node aggregates: {:?}", node_aggregates); - - // No data for node - if node_aggregates.len() == 0 { - continue - } - - let request_ids = &node_aggregates[0].request_ids; - log::debug!("request_ids: {:?}", request_ids); - - // Store bucket payments - let payments_per_bucket = &mut Vec::new(); - let requests = &mut dac::Requests::new(); - for request_id in request_ids.iter() { - let request_id_url = - format!("{}{}{}", data_url, "ddc:dac:data:file:", request_id.clone()); - let file_request = dac::fetch_file_request(&request_id_url); - requests.insert(file_request.file_request_id.clone(), file_request.clone()); - } - dac::get_acknowledged_bytes_bucket(&requests, payments_per_bucket); - let (bytes_sent, bytes_received) = dac::get_served_bytes_sum(&requests); - let is_valid = Self::is_valid(bytes_sent, bytes_received); - - log::debug!("bytes_sent, bytes_received: {:?}, {:?}", bytes_sent, bytes_received); - - let payload = serde_json::to_string(&requests).unwrap(); - let decision = ValidationDecision { - edge: utils::account_to_string::(assigned_edge.clone()), - result: is_valid, - payload: utils::hash(&payload), - totals: DacTotalAggregates { - received: bytes_received, - sent: bytes_sent, - failed_by_client: 0, - failure_rate: 0, - }, - }; - - log::debug!("decision to be encoded: {:?}", decision); - - let serialized_decision = serde_json::to_string(&decision).unwrap(); - let encoded_decision = - shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); - log::debug!("encoded decision: {:?}", encoded_decision); - - let validator_str = utils::account_to_string::(validator.clone()); - let edge_str = utils::account_to_string::(assigned_edge.clone()); - - let encoded_decision_str = encoded_decision.iter().cloned().collect::(); - - let response = shm::share_intermediate_validation_result( - &data_provider_url, - current_ddc_era - 1, - &validator_str, - &edge_str, - is_valid, - &encoded_decision_str, - ); - - if let Err(res) = response.clone() { - log::error!("share_intermediate_validation_result request failed: {:?}", res); - } - - if let Ok(res) = response.clone() { - log::debug!("shm res: {:?}", res.to_string()); - } - - if let Ok(_res) = response { - let edge = utils::account_to_string::(assigned_edge.clone()); - let prev_era = (current_ddc_era - 1) as EraIndex; - let quorum = Self::find_validators_from_quorum(&validator, &prev_era); - let validations_res = shm::get_intermediate_decisions( - &data_provider_url, - &edge_str, - &prev_era, - quorum, - ); - - log::debug!("get_intermediate_decisions result: {:?}", validations_res); - - if validations_res.len() == QUORUM_SIZE { - log::debug!("payments per bucket: {:?}", payments_per_bucket); - - let mut payments: BTreeMap< - u128, - BucketsDetails>, - > = BTreeMap::new(); - for bucket in payments_per_bucket.into_iter() { - let cere_payment = bucket.1 as u32; - if payments.contains_key(&bucket.0) { - payments.entry(bucket.0).and_modify(|bucket_info| { - bucket_info.amount += cere_payment.into() - }); - } else { - let bucket_info = BucketsDetails { - bucket_id: bucket.0, - amount: cere_payment.into(), - }; - payments.insert(bucket.0, bucket_info); - } - } - let mut final_payments = vec![]; - for (_, bucket_info) in payments { - final_payments.push(bucket_info); - } - log::debug!("final payments: {:?}", final_payments); - - // Store CDN node reward points on-chain - let signer: Signer = Signer::<_, _>::any_account(); - if !signer.can_sign() { - log::warn!("No local accounts available to charge payments for CDN. Consider adding one via `author_insertKey` RPC."); - return Err("signing key not set") - } - // ToDo: replace local call by a call from `ddc-staking` pallet - let tx_res: Option<(frame_system::offchain::Account, Result<(), ()>)> = - signer.send_signed_transaction(|_account| { - Call::charge_payments_content_owners { - paying_accounts: final_payments.clone(), - } - }); - - match tx_res { - Some((acc, Ok(()))) => - log::debug!("[{:?}]: submit transaction success.", acc.id), - Some((acc, Err(e))) => log::debug!( - "[{:?}]: submit transaction failure. Reason: {:?}", - acc.id, - e - ), - None => log::debug!("submit transaction failure."), - } - - let final_res = dac::get_final_decision(validations_res); - - let signer = Self::get_signer().unwrap(); - - let tx_res = - signer.send_signed_transaction(|_acct| Call::set_validation_decision { - era: current_ddc_era - 1, - cdn_node: utils::string_to_account::(edge.clone()), - validation_decision: final_res.clone(), - }); - - match tx_res { - Some((acc, Ok(()))) => - log::debug!("[{:?}]: submit transaction success.", acc.id), - Some((acc, Err(e))) => log::debug!( - "[{:?}]: submit transaction failure. Reason: {:?}", - acc.id, - e - ), - None => log::debug!("submit transaction failure."), - } - - cdn_nodes_reward_points.push(( - utils::string_to_account::(final_res.edge), - final_res.totals.sent, - )); - } - } - } - let signer = Self::get_signer().unwrap(); - - // ToDo: replace local call by a call from `ddc-staking` pallet - if cdn_nodes_reward_points.len() > 0 { - let tx_res = - signer.send_signed_transaction(|_account| Call::set_era_reward_points { - era: current_ddc_era - 1, - stakers_points: cdn_nodes_reward_points.clone(), - }); - - match tx_res { - Some((acc, Ok(()))) => - log::debug!("[{:?}]: submit transaction success.", acc.id), - Some((acc, Err(e))) => - log::debug!("[{:?}]: submit transaction failure. Reason: {:?}", acc.id, e), - None => log::debug!("submit transaction failure."), - } - } - - Ok(()) - } - } -} diff --git a/pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json b/pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json deleted file mode 100644 index 37b3242fe..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/aggregated-node-data-for-era.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"[{\"totalBytesSent\":600,\"totalQueries\":0,\"totalReads\":3,\"totalReadsAcked\":3,\"totalQueriesAcked\":0,\"averageResponseTimeMs\":1.8852459016393444,\"totalBytesReceived\":600,\"requestIds\":[\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"80a62530-fd76-40b5-bc53-dd82365e89ce\"],\"totalWritesAcked\":3,\"averageResponseTimeMsSamples\":61,\"totalWrites\":3}]"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/file-request1.json b/pallets/ddc-validator/src/mock-data/set-1/file-request1.json deleted file mode 100644 index 5a29a982b..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/file-request1.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"84640a53-fc1f-4ac5-921c-6695056840bc\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"]},\"bucketId\":5,\"timestamp\":1688473909701,\"chunks\":{\"84640a53-fc1f-4ac5-921c-6695056840bc:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":3,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49690\",\"bytesSent\":100,\"timestamp\":1688473909701,\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\",\"ack\":{\"userTimestamp\":1688473909709,\"nonce\":\"Gt7AFrznCPzgI/5q+tynLy2BKUooSGAkUCaGsF6AOMs=\",\"signature\":\"Gll6xIftbtP4JPB6miy3DLKMBDrKz05QSIBNJ3RqYi0Fg1wNJRFoSIqhOJDXDUB4NlrLQdl+HWrYRL20Hsx6iA==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":100,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcb2\"],\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/file-request2.json b/pallets/ddc-validator/src/mock-data/set-1/file-request2.json deleted file mode 100644 index b0e3fdc19..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/file-request2.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\"],\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\"]},\"bucketId\":5,\"timestamp\":1688473909723,\"chunks\":{\"d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7:bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\":{\"log\":{\"type\":2,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":3,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49714\",\"bytesSent\":200,\"timestamp\":1688473909723,\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\",\"ack\":{\"userTimestamp\":1688473909726,\"nonce\":\"2mdA3QVq02ME77vnqGjBNQqTRhM5gHjVAWcroNd5IZA=\",\"signature\":\"6PIWJXyEyHfWZrX6HKFNj3fRm5LbBsBX54zmVZpo+nMqqTV26xaQbEsRTfuhm4k+XGxci3VSuofPWFEpRuOmhg==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":200,\"requestedChunkCids\":[\"bafk2bzaceds3kr47j7imur2krbwhydosbocto73kx3erhmknjelpk6doltcd2\"],\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/file-request3.json b/pallets/ddc-validator/src/mock-data/set-1/file-request3.json deleted file mode 100644 index 047c057e6..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/file-request3.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"fileRequestId\":\"80a62530-fd76-40b5-bc53-dd82365e89ce\",\"fileInfo\":{\"chunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"]},\"bucketId\":5,\"timestamp\":1688473910041,\"chunks\":{\"80a62530-fd76-40b5-bc53-dd82365e89ce:bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\":{\"log\":{\"type\":1,\"signature\":null,\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"era\":3,\"bucketId\":5,\"userAddress\":\"172.18.0.1:49736\",\"bytesSent\":300,\"timestamp\":1688473910041,\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\",\"sessionId\":\"6afL1/kz+7NInOaHjwfUWZuoBwSZ2qX9JDOuSULCENk=\"},\"cid\":\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\",\"ack\":{\"userTimestamp\":1688473910043,\"nonce\":\"VU1XCPjQxA4y6TnrOAy44QabS7nmmxAU8vyduqoLt9U=\",\"signature\":\"Us7//t0+y00oHhthPSjqphHJYwE1qgPQtBSdy5hZxUInKdQXTBX58VLQekoKMHtptQQggR1gPf9Pyy1enmXziQ==\",\"aggregated\":1,\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\",\"bytesReceived\":300,\"requestedChunkCids\":[\"bafk2bzaced573lhaxdjlztd5xawkeakiz7j7dayrqbzrx5shjobordrrrlio4\"],\"nodePublicKey\":\"0101010101010101010101010101010101010101010101010101010101010101\"}}},\"userPublicKey\":\"knW4sRsf5iyoE+bP+duWD8KEYiRddtPDQ7Hpx1KLyEM=\"}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json b/pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json deleted file mode 100644 index b63b98c6c..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/final-validation-decision.json +++ /dev/null @@ -1 +0,0 @@ -{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[242,221,51,34,29,242,150,119,6,131,41,15,161,173,121,43,221,22,150,173,180,224,179,58,72,4,96,188,17,164,177,109],"totals":{"received":600,"sent":600,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/save-validation-decision-result.json b/pallets/ddc-validator/src/mock-data/set-1/save-validation-decision-result.json deleted file mode 100644 index 5fa9734a3..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/save-validation-decision-result.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":null} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json b/pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json deleted file mode 100644 index da4aa921a..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/shared-validation-decisions-for-era.json +++ /dev/null @@ -1 +0,0 @@ -{"JSON.GET":"{\"0101010101010101010101010101010101010101010101010101010101010101\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":true,\"data\":\"eyJlZGdlIjoiMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMSIsInJlc3VsdCI6dHJ1ZSwicGF5bG9hZCI6WzI0MiwgMjIxLCA1MSwgMzQsIDI5LCAyNDIsIDE1MCwgMTE5LCA2LCAxMzEsIDQxLCAxNSwgMTYxLCAxNzMsIDEyMSwgNDMsIDIyMSwgMjIsIDE1MCwgMTczLCAxODAsIDIyNCwgMTc5LCA1OCwgNzIsIDQsIDk2LCAxODgsIDE3LCAxNjQsIDE3NywgMTA5XSwidG90YWxzIjp7InJlY2VpdmVkIjo2MDAsInNlbnQiOjYwMCwiZmFpbGVkX2J5X2NsaWVudCI6MCwiZmFpbHVyZV9yYXRlIjowfX0=\"}},\"1c4a1b081af8dd09096ebb6e7ad61dd549ac2931cdb2b1216589094ad71ca90b\":{\"d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67\":{\"result\":false,\"data\":\"eyJlZGdlIjoiMWM0YTFiMDgxYWY4ZGQwOTA5NmViYjZlN2FkNjFkZDU0OWFjMjkzMWNkYjJiMTIxNjU4OTA5NGFkNzFjYTkwYiIsInJlc3VsdCI6ZmFsc2UsInBheWxvYWQiOlsxMDQsMjM4LDczLDczLDIwNCwxNzIsMjU0LDE4MSw3NywxMTYsMTM2LDE4OSwyNDYsOTAsMTY0LDE1NCwxNjcsMywxNTUsMjUzLDgwLDMzLDI1MSwxNCw3OCwyMzYsMTY3LDEzNCwxNjEsNjQsMjIyLDE4MV0sInRvdGFscyI6eyJyZWNlaXZlZCI6OTAwLCJzZW50Ijo1NDQsImZhaWxlZF9ieV9jbGllbnQiOjAsImZhaWx1cmVfcmF0ZSI6MH19\"}}}"} \ No newline at end of file diff --git a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json b/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json deleted file mode 100644 index de8eec3a7..000000000 --- a/pallets/ddc-validator/src/mock-data/set-1/validation-decision.json +++ /dev/null @@ -1 +0,0 @@ -{"edge":"0101010101010101010101010101010101010101010101010101010101010101","result":true,"payload":[56, 47, 100, 81, 135, 215, 168, 111, 55, 82, 203, 118, 238, 69, 174, 209, 232, 241, 187, 128, 231, 237, 139, 193, 162, 162, 91, 11, 169, 209, 27, 55],"totals":{"received":400,"sent":400,"failed_by_client":0,"failure_rate":0}} \ No newline at end of file diff --git a/pallets/ddc-validator/src/payments.rs b/pallets/ddc-validator/src/payments.rs deleted file mode 100644 index a1a26ade5..000000000 --- a/pallets/ddc-validator/src/payments.rs +++ /dev/null @@ -1 +0,0 @@ -//! Payments module to calculate and store a withdrawal per content owner and a payout per CDN node. diff --git a/pallets/ddc-validator/src/shm.rs b/pallets/ddc-validator/src/shm.rs deleted file mode 100644 index 6989e148f..000000000 --- a/pallets/ddc-validator/src/shm.rs +++ /dev/null @@ -1,162 +0,0 @@ -//! Validators' "shared memory" module. -//! -//! It implements a step of the DAC and Validation sequence when validators share their intermediate -//! validation results with each other. The design of the "shared memory" is expected to become like -//! transactions pool or peers list in the future, but for now it works on the centralized Redis -//! server which we maintain for DAC DataModel. - -use alloc::{format, string::String}; -pub use sp_std::collections::btree_map::BTreeMap; -// ToDo: remove String usage -use crate::{dac, utils, ValidationDecision}; -use alt_serde::{Deserialize, Serialize}; -use base64::prelude::*; -use lite_json::json::JsonValue; -use sp_runtime::offchain::{http, Duration}; -use sp_staking::EraIndex; -use sp_std::prelude::*; - -const HTTP_TIMEOUT_MS: u64 = 30_000; - -#[derive(Serialize, Deserialize, Debug)] -#[serde(crate = "alt_serde")] -#[serde(rename_all = "camelCase")] -pub struct IntermediateDecisionsWrapper { - #[serde(rename = "JSON.GET")] - json: String, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -#[serde(crate = "alt_serde")] -pub(crate) struct IntermediateDecisions { - validators_to_decisions: BTreeMap, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -#[serde(crate = "alt_serde")] -struct IntermediateDecision { - result: bool, - data: String, -} - -pub fn base64_decode(input: &String) -> Result, ()> { - let mut buf = Vec::with_capacity(1000); // ToDo: calculate capacity - buf.resize(1000, 0); - BASE64_STANDARD.decode_slice(input, &mut buf).map_err(|_| ())?; - Ok(buf.iter().map(|&char| char as u8).collect()) -} - -/// Encodes a vector of bytes into a vector of characters using base64 encoding. -pub fn base64_encode(input: &Vec) -> Result, ()> { - let mut buf = Vec::with_capacity(1000); // ToDo: calculate capacity - buf.resize(1000, 0); - BASE64_STANDARD.encode_slice(input, &mut buf).map_err(|_| ())?; - Ok(buf.iter().map(|&byte| byte as char).collect()) -} - -/// Publish intermediate validation result to redis. -pub fn share_intermediate_validation_result( - shared_memory_webdis_url: &String, - era: EraIndex, - validator: &String, - cdn_node: &String, - validation_result: bool, - validation_decision_encoded: &String, -) -> Result { - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(HTTP_TIMEOUT_MS)); - let validation_decision_string = String::from(validation_decision_encoded); - let json = serde_json::json!({ - "result": validation_result, - "data": validation_decision_string, - }); - let json_str = serde_json::to_string(&json).unwrap(); - let unescaped_json = utils::unescape(&json_str); - let url_encoded_json = utils::url_encode(&unescaped_json); - - log::debug!("json_str: {:?}", json_str); - - let url = format!( - "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", - shared_memory_webdis_url, validator, cdn_node, era, url_encoded_json, - ); - - log::debug!("share_intermediate_validation_result url: {:?}", url); - let request = http::Request::get(url.as_str()); - let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - if response.code != 200 { - log::warn!("Unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - let body = response.body().collect::>(); - let body_str = sp_std::str::from_utf8(&body).map_err(|_| { - log::warn!("No UTF-8 body"); - http::Error::Unknown - })?; - - log::debug!("body_str: {:?}", body_str); - - let json = lite_json::parse_json(body_str).map_err(|_| { - log::warn!("No JSON body"); - http::Error::Unknown - })?; - Ok(json) -} - -pub(crate) fn get_intermediate_decisions( - data_provider_url: &String, - edge: &str, - era: &EraIndex, - quorum: Vec, -) -> Vec { - let url = format!("{}/JSON.GET/ddc:dac:shared:nodes:{}", data_provider_url, era); - - let response: IntermediateDecisionsWrapper = dac::http_get_json(url.as_str()).unwrap(); - let mut edges_to_validators_decisions: BTreeMap< - String, - BTreeMap, - > = serde_json::from_str(&response.json).unwrap(); - let decisions_for_edge = IntermediateDecisions { - validators_to_decisions: edges_to_validators_decisions.remove(edge).unwrap(), - }; - - let quorum_decisions = find_quorum_decisions(decisions_for_edge, quorum); - let decoded_decisions = decode_intermediate_decisions(quorum_decisions); - - decoded_decisions -} - -pub(crate) fn decode_intermediate_decisions( - decisions: IntermediateDecisions, -) -> Vec { - let mut decoded_decisions: Vec = Vec::new(); - - for (_, decision) in decisions.validators_to_decisions.iter() { - let data = base64_decode(&decision.data).unwrap(); - - let data_str = String::from_utf8_lossy(&data); - let data_trimmed = data_str.trim_end_matches('\0'); - - log::debug!("data_str: {:?}", data_trimmed); - - let decoded_decision: ValidationDecision = serde_json::from_str(&data_trimmed).unwrap(); - - decoded_decisions.push(decoded_decision); - } - - decoded_decisions -} - -pub(crate) fn find_quorum_decisions( - all_decisions: IntermediateDecisions, - quorum: Vec, -) -> IntermediateDecisions { - let mut quorum_decisions: BTreeMap = BTreeMap::new(); - for (validator_id, decision) in all_decisions.validators_to_decisions.iter() { - if quorum.contains(validator_id) { - quorum_decisions.insert(validator_id.clone(), decision.clone()); - } - } - - IntermediateDecisions { validators_to_decisions: quorum_decisions } -} diff --git a/pallets/ddc-validator/src/tests.rs b/pallets/ddc-validator/src/tests.rs deleted file mode 100644 index 9493f2771..000000000 --- a/pallets/ddc-validator/src/tests.rs +++ /dev/null @@ -1,606 +0,0 @@ -#![cfg(test)] - -use super::*; -use crate::{ - mock::{Timestamp, *}, - Error as ValidatorError, -}; -use codec::Decode; -use ddc_primitives::{CDNNodePubKey, NodePubKey}; -use frame_support::{assert_noop, assert_ok}; -use pallet_ddc_customers::{BucketsDetails, Error as AccountsError}; -use pallet_ddc_staking::{DDC_ERA_DURATION_MS, DDC_ERA_START_MS}; -use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; -use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; -use sp_runtime::offchain::storage::StorageValueRef; -use std::sync::Arc; - -const OCW_PUB_KEY_STR: &str = "d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67"; -const OCW_SEED: &str = - "news slush supreme milk chapter athlete soap sausage put clutch what kitten"; - -fn last_event() -> RuntimeEvent { - System::events().pop().expect("Event expected").event.into() -} - -#[test] -fn it_sets_validation_decision_with_one_validator_in_quorum() { - let mut t = new_test_ext(); - - let (offchain, offchain_state) = testing::TestOffchainExt::new(); - t.register_extension(OffchainDbExt::new(offchain.clone())); - t.register_extension(OffchainWorkerExt::new(offchain)); - - let keystore = KeyStore::new(); - keystore.sr25519_generate_new(KEY_TYPE, Some(OCW_SEED)).unwrap(); - t.register_extension(KeystoreExt(Arc::new(keystore))); - - let (pool, pool_state) = testing::TestTransactionPoolExt::new(); - t.register_extension(TransactionPoolExt::new(pool)); - - let era_to_validate: EraIndex = 3; - let edge_stash_to_validate = AccountId::from([0x1; 32]); - let edge_stash_to_validate_str = - utils::account_to_string::(edge_stash_to_validate.clone()); - let edge_node_to_validate = NodePubKey::CDNPubKey(CDNNodePubKey::new([0x21; 32])); - let edge_node_to_validate_str = array_bytes::bytes2hex("", edge_node_to_validate.encode()); - let validator_1_stash = AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, - 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, - 0xdf, 0x67, - ]); - let validator_1_controller = AccountId::from([0xaa; 32]); - let validator_2_stash = AccountId::from([0xb; 32]); - let validator_2_controller = AccountId::from([0xbb; 32]); - let validator_3_stash = AccountId::from([0xc; 32]); - let validator_3_controller = AccountId::from([0xcc; 32]); - - { - let mut state = offchain_state.write(); - - let mut expect_request = |url: &str, response: &[u8]| { - state.expect_request(testing::PendingRequest { - method: "GET".into(), - uri: url.to_string(), - response: Some(response.to_vec()), - sent: true, - ..Default::default() - }); - }; - - expect_request( - &format!( - "{}/JSON.GET/ddc:dac:aggregation:nodes:{}/$.{}", - DEFAULT_DATA_PROVIDER_URL, era_to_validate, edge_node_to_validate_str - ), - include_bytes!("./mock-data/set-1/aggregated-node-data-for-era.json"), - ); - - expect_request( - &format!( - "{}/JSON.GET/ddc:dac:data:file:84640a53-fc1f-4ac5-921c-6695056840bc", - DEFAULT_DATA_PROVIDER_URL - ), - include_bytes!("./mock-data/set-1/file-request1.json"), - ); - - expect_request( - &format!( - "{}/JSON.GET/ddc:dac:data:file:d0a55c8b-fcb9-41b5-aa9a-8b40e9c4edf7", - DEFAULT_DATA_PROVIDER_URL - ), - include_bytes!("./mock-data/set-1/file-request2.json"), - ); - - expect_request( - &format!( - "{}/JSON.GET/ddc:dac:data:file:80a62530-fd76-40b5-bc53-dd82365e89ce", - DEFAULT_DATA_PROVIDER_URL - ), - include_bytes!("./mock-data/set-1/file-request3.json"), - ); - - let decision: ValidationDecision = - serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) - .unwrap(); - let serialized_decision = serde_json::to_string(&decision).unwrap(); - let encoded_decision_vec = - shm::base64_encode(&serialized_decision.as_bytes().to_vec()).unwrap(); - let encoded_decision_str = encoded_decision_vec.iter().cloned().collect::(); - let result_json = serde_json::json!({ - "result": decision.result, - "data": encoded_decision_str, - }); - let result_json_str = serde_json::to_string(&result_json).unwrap(); - let unescaped_result_json = utils::unescape(&result_json_str); - let url_encoded_result_json = utils::url_encode(&unescaped_result_json); - - expect_request( - &format!( - "{}/FCALL/save_validation_result_by_node/1/{}:{}:{}/{}", - DEFAULT_DATA_PROVIDER_URL, - OCW_PUB_KEY_STR, - edge_stash_to_validate_str, - era_to_validate, - url_encoded_result_json, - ), - include_bytes!("./mock-data/set-1/save-validation-decision-result.json"), - ); - - expect_request( - &format!( - "{}/JSON.GET/ddc:dac:shared:nodes:{}", - DEFAULT_DATA_PROVIDER_URL, era_to_validate - ), - include_bytes!("./mock-data/set-1/shared-validation-decisions-for-era.json"), - ); - } - - t.execute_with(|| { - let era_block_number = 20 as u32 * era_to_validate; - System::set_block_number(era_block_number); // required for randomness - assert_ok!(DdcValidator::set_validator_key( - // register validator 1 - RuntimeOrigin::signed(validator_1_controller), - validator_1_stash, - )); - assert_ok!(DdcValidator::set_validator_key( - // register validator 2 - RuntimeOrigin::signed(validator_2_controller), - validator_2_stash, - )); - assert_ok!(DdcValidator::set_validator_key( - // register validator 3 - RuntimeOrigin::signed(validator_3_controller), - validator_3_stash, - )); - Timestamp::set_timestamp( - (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, - ); - DdcStaking::on_finalize(era_block_number - 1); // set DDC era counter - DdcValidator::on_initialize(era_block_number - 1); // make assignments - - Timestamp::set_timestamp( - (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 + 1)) as u64, - ); - DdcStaking::on_finalize(era_block_number + 1); // inc DDC era counter - StorageValueRef::persistent(ENABLE_DDC_VALIDATION_KEY).set(&true); // enable validation - DdcValidator::offchain_worker(era_block_number + 1); // execute assignments - - let mut transactions = pool_state.read().transactions.clone(); - transactions.reverse(); - assert_eq!(transactions.len(), 3); - - let tx = transactions.pop().unwrap(); - let tx = Extrinsic::decode(&mut &*tx).unwrap(); - assert!(tx.signature.is_some()); - - let bucket_info = BucketsDetails { bucket_id: 5, amount: 400u128 }; - - assert_eq!( - tx.call, - crate::mock::RuntimeCall::DdcValidator(crate::Call::charge_payments_content_owners { - paying_accounts: vec![bucket_info] - }) - ); - - let tx = transactions.pop().unwrap(); - let tx = Extrinsic::decode(&mut &*tx).unwrap(); - assert!(tx.signature.is_some()); - - let common_decision: ValidationDecision = serde_json::from_slice(include_bytes!( - "./mock-data/set-1/final-validation-decision.json" - )) - .unwrap(); - let common_decisions = vec![common_decision.clone()]; - let serialized_decisions = serde_json::to_string(&common_decisions).unwrap(); - - assert_eq!( - tx.call, - crate::mock::RuntimeCall::DdcValidator(crate::Call::set_validation_decision { - era: era_to_validate, - cdn_node: edge_stash_to_validate.clone(), - validation_decision: ValidationDecision { - edge: edge_stash_to_validate_str, - result: true, - payload: utils::hash(&serialized_decisions), - totals: DacTotalAggregates { - received: common_decision.totals.received, - sent: common_decision.totals.sent, - failed_by_client: common_decision.totals.failed_by_client, - failure_rate: common_decision.totals.failure_rate, - } - } - }) - ); - - let tx = transactions.pop().unwrap(); - let tx = Extrinsic::decode(&mut &*tx).unwrap(); - - let stakers_points = vec![(edge_stash_to_validate, common_decision.totals.sent)]; - - assert!(tx.signature.is_some()); - assert_eq!( - tx.call, - crate::mock::RuntimeCall::DdcValidator(crate::Call::set_era_reward_points { - era: era_to_validate, - stakers_points, - }) - ); - }) -} - -#[test] -fn send_signal_works_as_expected() { - let mut t = new_test_ext(); - - let validator_controller = AccountId::from([0xaa; 32]); - - t.execute_with(|| { - assert_eq!(DdcValidator::signal(), None); - assert_ok!(DdcValidator::send_signal(RuntimeOrigin::signed(validator_controller))); - assert_eq!(DdcValidator::signal(), Some(true)); - DdcValidator::on_initialize(2); - System::set_block_number(2); - assert_eq!(DdcValidator::signal(), Some(false)); - }) -} - -#[test] -fn set_validation_decision_works_as_expected() { - let mut t = new_test_ext(); - - let era_to_validate: EraIndex = 3; - let cdn_node_to_validate = AccountId::from([0x1; 32]); - let not_a_cdn_node = AccountId::from([0x2; 32]); - let validator_1_stash = AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, - 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, - 0xdf, 0x67, - ]); - let validator_1_controller = AccountId::from([0xaa; 32]); - let validator_1_not_controller = AccountId::from([0xdd; 32]); - - let decision: ValidationDecision = - serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) - .unwrap(); - - t.execute_with(|| { - System::set_block_number(1); - - assert_noop!( - DdcValidator::set_validation_decision( - RuntimeOrigin::signed(validator_1_controller.clone()), - era_to_validate, - cdn_node_to_validate.clone(), - decision.clone(), - ), - ValidatorError::::DDCValidatorKeyNotRegistered - ); - - // Set a mapping from stash to not a validator - DDCValidatorToStashKeys::::insert( - validator_1_stash.clone(), - validator_1_not_controller.clone(), - ); - - assert_noop!( - DdcValidator::set_validation_decision( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - cdn_node_to_validate.clone(), - decision.clone() - ), - ValidatorError::::NotValidatorStash - ); - - assert_ok!(DdcValidator::set_validator_key( - // register validator 1 - RuntimeOrigin::signed(validator_1_controller.clone()), - validator_1_stash.clone(), - )); - - assert_noop!( - DdcValidator::set_validation_decision( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - not_a_cdn_node.clone(), - decision.clone() - ), - ValidatorError::::NodeNotActive - ); - - assert_ok!(DdcValidator::set_validation_decision( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - cdn_node_to_validate.clone(), - decision.clone() - )); - - assert_noop!( - DdcValidator::set_validation_decision( - RuntimeOrigin::signed(validator_1_stash), - era_to_validate, - cdn_node_to_validate.clone(), - decision.clone() - ), - ValidatorError::::ValidationDecisionAlreadySet - ); - - let evt = last_event(); - - assert_eq!( - evt, - crate::Event::ValidationDecision(era_to_validate, cdn_node_to_validate, decision) - .into() - ); - }) -} - -#[test] -fn set_era_reward_points_works_as_expected() { - let mut t = new_test_ext(); - - let era_to_validate: EraIndex = 3; - let cdn_node_to_validate = AccountId::from([0x1; 32]); - let not_a_cdn_node = AccountId::from([0x2; 32]); - let validator_1_stash = AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, - 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, - 0xdf, 0x67, - ]); - let validator_1_controller = AccountId::from([0xaa; 32]); - let validator_1_not_controller = AccountId::from([0xdd; 32]); - - let decision: ValidationDecision = - serde_json::from_slice(include_bytes!("./mock-data/set-1/validation-decision.json")) - .unwrap(); - - let stakers_points = vec![(cdn_node_to_validate.clone(), decision.totals.sent)]; - let fake_stakers_points = vec![(not_a_cdn_node.clone(), decision.totals.sent)]; - - t.execute_with(|| { - System::set_block_number(1); - - assert_noop!( - DdcValidator::set_era_reward_points( - RuntimeOrigin::signed(validator_1_controller.clone()), - era_to_validate, - stakers_points.clone(), - ), - ValidatorError::::DDCValidatorKeyNotRegistered - ); - - // Set a mapping from stash to not a validator - DDCValidatorToStashKeys::::insert( - validator_1_stash.clone(), - validator_1_not_controller.clone(), - ); - - assert_noop!( - DdcValidator::set_era_reward_points( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - stakers_points.clone() - ), - ValidatorError::::NotValidatorStash - ); - - assert_ok!(DdcValidator::set_validator_key( - // register validator 1 - RuntimeOrigin::signed(validator_1_controller), - validator_1_stash.clone(), - )); - - // attempting to set era reward points for account, which is not an active CDN node - assert_ok!(DdcValidator::set_era_reward_points( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - fake_stakers_points.clone() - )); - - // rewards points should not be set - assert_eq!( - DdcValidator::reward_points_set_for_node(era_to_validate, not_a_cdn_node), - false - ); - - assert_ok!(DdcValidator::set_era_reward_points( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - stakers_points.clone() - )); - - let reward_points = ddc_staking::pallet::ErasEdgesRewardPointsPerNode::::get( - cdn_node_to_validate.clone(), - ); - - assert_eq!(reward_points.len(), 1); - - // Second run will still pass, but state will not change, as for specified node era points - // were set already - assert_ok!(DdcValidator::set_era_reward_points( - RuntimeOrigin::signed(validator_1_stash.clone()), - era_to_validate, - stakers_points.clone() - )); - - let reward_points_update_attempt = - ddc_staking::pallet::ErasEdgesRewardPointsPerNode::::get( - cdn_node_to_validate.clone(), - ); - - assert_eq!(reward_points_update_attempt.len(), 1); - - assert_eq!( - DdcValidator::reward_points_set_for_node(era_to_validate, cdn_node_to_validate), - true - ); - - assert_eq!(System::events().len(), 1); - let evt = System::events().pop().expect("Event expected").event; - - assert_eq!(evt, crate::Event::EraRewardPoints(era_to_validate, stakers_points).into()); - }) -} - -#[test] -fn charge_payments_content_owners_works_as_expected() { - let mut t = new_test_ext(); - - let era_to_validate: EraIndex = 3; - let validator_1_stash = AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, - 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, - 0xdf, 0x67, - ]); - let validator_1_controller = AccountId::from([0xaa; 32]); - let validator_1_not_controller = AccountId::from([0xdd; 32]); - - let bucket_info = BucketsDetails { bucket_id: 5, amount: 600u128 }; - - t.execute_with(|| { - System::set_block_number(1); - - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_controller.clone()), - vec![bucket_info.clone()], - ), - ValidatorError::::DDCEraNotSet - ); - - let era_block_number = 20 as u32 * era_to_validate; - System::set_block_number(era_block_number); - Timestamp::set_timestamp( - (DDC_ERA_START_MS + DDC_ERA_DURATION_MS * (era_to_validate as u128 - 1)) as u64, - ); - DdcStaking::on_finalize(era_block_number - 1); - - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - ), - ValidatorError::::DDCValidatorKeyNotRegistered - ); - - // Set a mapping from stash to not a validator - DDCValidatorToStashKeys::::insert( - validator_1_stash.clone(), - validator_1_not_controller.clone(), - ); - - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - ), - ValidatorError::::NotValidatorStash - ); - - assert_ok!(DdcValidator::set_validator_key( - // register validator 1 - RuntimeOrigin::signed(validator_1_controller.clone()), - validator_1_stash.clone(), - )); - - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - ), - ValidatorError::::PricingNotSet - ); - - ddc_staking::Pricing::::set(Some(1)); // set CERE token per byte / reward - - // No buckets were created at this point - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - ), - AccountsError::::BucketDoesNotExist - ); - - // Create buckets - for range in 1..6 { - assert_ok!(ddc_customers::Pallet::::create_bucket( - RuntimeOrigin::signed(validator_1_stash.clone()), - true, - range - )); - } - - // Account to charge payments from is not created - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - ), - AccountsError::::NotOwner - ); - - // Deposit funds for account - assert_ok!(ddc_customers::Pallet::::deposit( - RuntimeOrigin::signed(validator_1_stash.clone()), - 1_000, - )); - - assert_ok!(DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - )); - - // Should not be able to charge account twice by the same validator during one era - assert_noop!( - DdcValidator::charge_payments_content_owners( - RuntimeOrigin::signed(validator_1_stash.clone()), - vec![bucket_info.clone()] - ), - ValidatorError::::ContentOwnersDoubleSpend - ); - - let last_evt = System::events().pop().expect("Event expected").event; - assert_eq!(last_evt, ddc_customers::Event::Charged(bucket_info.amount).into()); - }) -} - -#[test] -fn set_validator_key_works_as_expected() { - let mut t = new_test_ext(); - - let validator_1_stash = AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, 0x94, - 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, 0x55, 0xf4, - 0xdf, 0x67, - ]); - let validator_1_controller: AccountId32 = AccountId::from([0xaa; 32]); - - t.execute_with(|| { - assert_noop!( - DdcValidator::set_validator_key( - RuntimeOrigin::signed(validator_1_stash.clone()), - validator_1_stash.clone(), - ), - ValidatorError::::NotController - ); - - assert_ok!(DdcValidator::set_validator_key( - RuntimeOrigin::signed(validator_1_controller.clone()), - validator_1_stash.clone(), - )); - - staking::Validators::::remove(validator_1_stash.clone()); - - // If stash is not a validator anymore, action will fail - assert_noop!( - DdcValidator::set_validator_key( - RuntimeOrigin::signed(validator_1_controller), - validator_1_stash, - ), - ValidatorError::::NotValidatorStash - ); - }) -} diff --git a/pallets/ddc-validator/src/utils.rs b/pallets/ddc-validator/src/utils.rs deleted file mode 100644 index 5c5459b24..000000000 --- a/pallets/ddc-validator/src/utils.rs +++ /dev/null @@ -1,73 +0,0 @@ -use alloc::{format, string::String}; -use codec::{Decode, Encode}; -use sp_core::crypto::AccountId32; -use sp_io::hashing::blake2_256; -pub use sp_std::prelude::*; - -pub fn account_to_string(account: T::AccountId) -> String { - let to32 = T::AccountId::encode(&account); - let pub_key_str = array_bytes::bytes2hex("", to32); - - pub_key_str -} - -pub fn string_to_account(pub_key_str: String) -> T::AccountId { - let acc32: sp_core::crypto::AccountId32 = - array_bytes::hex2array::<_, 32>(pub_key_str).unwrap().into(); - let mut to32 = AccountId32::as_ref(&acc32); - let address: T::AccountId = T::AccountId::decode(&mut to32).unwrap(); - address -} - -pub(crate) fn hash(data: &String) -> [u8; 32] { - let hash = blake2_256(data.as_bytes()); - let mut result = [0u8; 32]; - result.copy_from_slice(&hash); - - result -} - -pub(crate) fn url_encode(input: &str) -> String { - let mut encoded = String::new(); - - for byte in input.bytes() { - match byte { - // Unreserved characters (alphanumeric and -_.~) - b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { - encoded.push(byte as char); - }, - _ => { - encoded.push('%'); - encoded.push_str(&format!("{:02X}", byte)); - }, - } - } - - encoded -} - -pub(crate) fn unescape(json: &str) -> String { - let mut result = String::new(); - let mut chars = json.chars().peekable(); - - while let Some(c) = chars.next() { - if c == '\\' { - match chars.peek() { - Some('u') => { - // Skip over the next 5 characters - for _ in 0..5 { - chars.next(); - } - }, - _ => { - // Skip over the next character - chars.next(); - }, - } - } else { - result.push(c); - } - } - - result -} diff --git a/pallets/ddc-validator/src/validation.rs b/pallets/ddc-validator/src/validation.rs deleted file mode 100644 index 017d90782..000000000 --- a/pallets/ddc-validator/src/validation.rs +++ /dev/null @@ -1 +0,0 @@ -//! DAC Validation implementation. diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index c5188dbd5..f5ba45aba 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -100,7 +100,6 @@ pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../. pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } -pallet-ddc-validator = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-validator" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } @@ -185,7 +184,6 @@ std = [ "pallet-ddc-staking/std", "cere-runtime-common/std", "cere-dev-runtime-constants/std", - "pallet-ddc-validator/std", "pallet-ddc-customers/std", "pallet-ddc-nodes/std", "pallet-ddc-clusters/std", diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 0637375e6..cb3ea26e3 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1349,22 +1349,6 @@ impl pallet_ddc_customers::Config for Runtime { type RuntimeEvent = RuntimeEvent; } -parameter_types! { - pub const DdcValidatorsQuorumSize: u32 = 3; - pub const ValidationThreshold: u32 = 5; - pub const ValidatorsMax: u32 = 64; -} - -impl pallet_ddc_validator::Config for Runtime { - type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; - type Randomness = RandomnessCollectiveFlip; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; - type ValidationThreshold = ValidationThreshold; - type ValidatorsMax = ValidatorsMax; -} - impl pallet_ddc_nodes::Config for Runtime { type RuntimeEvent = RuntimeEvent; } @@ -1427,7 +1411,6 @@ construct_runtime!( Erc20: pallet_erc20::{Pallet, Call, Storage, Event}, DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Storage, Event}, DdcStaking: pallet_ddc_staking, - DdcValidator: pallet_ddc_validator, DdcCustomers: pallet_ddc_customers, DdcNodes: pallet_ddc_nodes, DdcClusters: pallet_ddc_clusters @@ -1489,9 +1472,25 @@ pub type Executive = frame_executive::Executive< >, pallet_staking::migrations::v12::MigrateToV12, pallet_contracts::Migration, + custom_migration::Upgrade, ), >; +mod custom_migration { + use super::*; + + use frame_support::{traits::OnRuntimeUpgrade, weights::Weight, Twox128}; + use sp_io::{hashing::twox_128, storage::clear_prefix}; + + pub struct Upgrade; + impl OnRuntimeUpgrade for Upgrade { + fn on_runtime_upgrade() -> Weight { + clear_prefix(&twox_128(b"DdcValidator"), None); + Weight::from_ref_time(0) + } + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking; From 336e5648f03c4cb74ac04fee9a3b6af5aaaaa106 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 3 Nov 2023 14:55:22 +0100 Subject: [PATCH 440/544] remove ddc validator from lib.rs --- Cargo.lock | 258 ++++++++++++++++++++---------------- runtime/cere-dev/src/lib.rs | 2 +- 2 files changed, 147 insertions(+), 113 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3944e2252..b4063fadd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,7 +231,7 @@ checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" dependencies = [ "async-channel", "async-executor", - "async-io", + "async-io 1.13.0", "async-lock", "blocking", "futures-lite", @@ -251,13 +251,33 @@ dependencies = [ "futures-lite", "log", "parking", - "polling", - "rustix 0.37.26", + "polling 2.8.0", + "rustix 0.37.27", "slab", "socket2 0.4.10", "waker-fn", ] +[[package]] +name = "async-io" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10da8f3146014722c89e7859e1d7bb97873125d7346d10ca642ffab794355828" +dependencies = [ + "async-lock", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling 3.3.0", + "rustix 0.38.21", + "slab", + "tracing", + "waker-fn", + "windows-sys 0.48.0", +] + [[package]] name = "async-lock" version = "2.8.0" @@ -273,30 +293,30 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" dependencies = [ - "async-io", + "async-io 1.13.0", "async-lock", "async-signal", "blocking", "cfg-if", - "event-listener 3.0.0", + "event-listener 3.0.1", "futures-lite", - "rustix 0.38.20", + "rustix 0.38.21", "windows-sys 0.48.0", ] [[package]] name = "async-signal" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2a5415b7abcdc9cd7d63d6badba5288b2ca017e3fbd4173b8f405449f1a2399" +checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" dependencies = [ - "async-io", + "async-io 2.1.0", "async-lock", "atomic-waker", "cfg-if", "futures-core", "futures-io", - "rustix 0.38.20", + "rustix 0.38.21", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -310,7 +330,7 @@ checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" dependencies = [ "async-channel", "async-global-executor", - "async-io", + "async-io 1.13.0", "async-lock", "async-process", "crossbeam-utils", @@ -720,7 +740,7 @@ dependencies = [ "cargo-platform", "semver 1.0.20", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", ] [[package]] @@ -1311,9 +1331,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ "libc", ] @@ -1572,7 +1592,7 @@ dependencies = [ "cpufeatures", "curve25519-dalek-derive", "fiat-crypto", - "platforms 3.1.2", + "platforms 3.2.0", "rustc_version 0.4.0", "subtle", "zeroize", @@ -1580,9 +1600,9 @@ dependencies = [ [[package]] name = "curve25519-dalek-derive" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", @@ -1778,9 +1798,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" +checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" [[package]] name = "ecdsa" @@ -1964,9 +1984,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" +checksum = "01cec0252c2afff729ee6f00e903d479fba81784c8e2bd77447673471fdfaea1" dependencies = [ "concurrent-queue", "parking", @@ -2030,9 +2050,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" +checksum = "a481586acf778f1b1455424c343f71124b048ffa5f4fc3f8f6ae9dc432dcb3c7" [[package]] name = "file-per-thread-logger" @@ -2180,7 +2200,7 @@ dependencies = [ "sc-service", "sc-sysinfo", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "serde_nanos", "sp-api", "sp-blockchain", @@ -2412,9 +2432,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", @@ -2427,9 +2447,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", "futures-sink", @@ -2437,15 +2457,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" dependencies = [ "futures-core", "futures-task", @@ -2455,9 +2475,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" @@ -2476,9 +2496,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", @@ -2498,15 +2518,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-timer" @@ -2516,9 +2536,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-channel", "futures-core", @@ -2692,7 +2712,7 @@ dependencies = [ "pest", "pest_derive", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "thiserror", ] @@ -2955,7 +2975,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "015a7df1eb6dda30df37f34b63ada9b7b352984b0e84de2a20ed526345000791" dependencies = [ - "async-io", + "async-io 1.13.0", "core-foundation", "fnv", "futures", @@ -3009,9 +3029,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -3092,7 +3112,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.20", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -3128,9 +3148,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" dependencies = [ "wasm-bindgen", ] @@ -3194,7 +3214,7 @@ dependencies = [ "rand 0.8.5", "rustc-hash", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "soketto", "thiserror", "tokio", @@ -3215,7 +3235,7 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-types", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "tokio", "tracing", "tracing-futures", @@ -3242,7 +3262,7 @@ dependencies = [ "anyhow", "beef", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "thiserror", "tracing", ] @@ -3270,7 +3290,7 @@ dependencies = [ "http", "jsonrpsee-core", "jsonrpsee-types", - "serde_json 1.0.107", + "serde_json 1.0.108", "soketto", "tokio", "tokio-stream", @@ -3617,7 +3637,7 @@ version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66e5e5919509603281033fd16306c61df7a4428ce274b67af5e14b07de5cdcb2" dependencies = [ - "async-io", + "async-io 1.13.0", "data-encoding", "dns-parser", "futures", @@ -3838,7 +3858,7 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a6771dc19aa3c65d6af9a8c65222bfc8fcd446630ddca487acd161fa6096f3b" dependencies = [ - "async-io", + "async-io 1.13.0", "futures", "futures-timer", "if-watch", @@ -4151,7 +4171,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.20", + "rustix 0.38.21", ] [[package]] @@ -4413,7 +4433,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6471bf08e7ac0135876a9581bf3217ef0333c191c128d34878079f42ee150411" dependencies = [ - "async-io", + "async-io 1.13.0", "bytes", "futures", "libc", @@ -5866,7 +5886,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.0.2", + "indexmap 2.1.0", ] [[package]] @@ -5943,9 +5963,9 @@ checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" [[package]] name = "platforms" -version = "3.1.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" +checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" [[package]] name = "polling" @@ -5963,6 +5983,20 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "polling" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" +dependencies = [ + "cfg-if", + "concurrent-queue", + "pin-project-lite 0.2.13", + "rustix 0.38.21", + "tracing", + "windows-sys 0.48.0", +] + [[package]] name = "poly1305" version = "0.7.2" @@ -6530,7 +6564,7 @@ dependencies = [ "log", "parity-scale-codec", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-core", "sp-io", "sp-runtime", @@ -6671,9 +6705,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.35.15" +version = "0.35.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413c4d41e2f1b0814c63567d11618483de0bd64f451b452f2ca43896579486ba" +checksum = "5363f616a5244fd47fc1dd0a0b24c28a5c0154f5010c16332a7ad6f78f2e8b62" dependencies = [ "bitflags 1.3.2", "errno 0.2.8", @@ -6685,9 +6719,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.26" +version = "0.37.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f3f8f960ed3b5a59055428714943298bf3fa2d4a1d53135084e0544829d995" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno 0.3.5", @@ -6699,9 +6733,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.20" +version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" dependencies = [ "bitflags 2.4.1", "errno 0.3.5", @@ -6882,7 +6916,7 @@ dependencies = [ "sc-network-common", "sc-telemetry", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-core", "sp-runtime", ] @@ -6925,7 +6959,7 @@ dependencies = [ "sc-tracing", "sc-utils", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-blockchain", "sp-core", "sp-keyring", @@ -7196,7 +7230,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-wasm 0.45.0", - "rustix 0.35.15", + "rustix 0.35.16", "sc-allocator", "sc-executor-common", "sp-runtime-interface", @@ -7232,7 +7266,7 @@ dependencies = [ "sc-network-gossip", "sc-telemetry", "sc-utils", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-api", "sp-application-crypto", "sp-arithmetic", @@ -7260,7 +7294,7 @@ dependencies = [ "sc-finality-grandpa", "sc-rpc", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-blockchain", "sp-core", "sp-runtime", @@ -7292,7 +7326,7 @@ dependencies = [ "array-bytes", "async-trait", "parking_lot 0.12.1", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-application-crypto", "sp-core", "sp-keystore", @@ -7333,7 +7367,7 @@ dependencies = [ "sc-peerset", "sc-utils", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "smallvec", "sp-arithmetic", "sp-blockchain", @@ -7517,7 +7551,7 @@ dependencies = [ "libp2p", "log", "sc-utils", - "serde_json 1.0.107", + "serde_json 1.0.108", "wasm-timer", ] @@ -7548,7 +7582,7 @@ dependencies = [ "sc-tracing", "sc-transaction-pool-api", "sc-utils", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-api", "sp-blockchain", "sp-core", @@ -7574,7 +7608,7 @@ dependencies = [ "sc-transaction-pool-api", "scale-info", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-core", "sp-rpc", "sp-runtime", @@ -7591,7 +7625,7 @@ dependencies = [ "futures", "jsonrpsee", "log", - "serde_json 1.0.107", + "serde_json 1.0.108", "substrate-prometheus-endpoint", "tokio", ] @@ -7638,7 +7672,7 @@ dependencies = [ "sc-transaction-pool-api", "sc-utils", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-api", "sp-application-crypto", "sp-block-builder", @@ -7693,7 +7727,7 @@ dependencies = [ "sc-consensus-epochs", "sc-finality-grandpa", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-blockchain", "sp-runtime", "thiserror", @@ -7712,7 +7746,7 @@ dependencies = [ "regex", "sc-telemetry", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-core", "sp-io", "sp-std", @@ -7731,7 +7765,7 @@ dependencies = [ "pin-project", "rand 0.7.3", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "thiserror", "wasm-timer", ] @@ -8027,9 +8061,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa 1.0.9", "ryu", @@ -8963,7 +8997,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "unicode-xid", ] @@ -9050,9 +9084,9 @@ dependencies = [ [[package]] name = "substrate-bip39" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49eee6965196b32f882dd2ee85a92b1dbead41b04e53907f269de3b0dc04733c" +checksum = "e620c7098893ba667438b47169c00aacdd9e7c10e042250ce2b60b087ec97328" dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", @@ -9082,7 +9116,7 @@ dependencies = [ "sc-client-api", "sc-rpc-api", "sc-transaction-pool-api", - "serde_json 1.0.107", + "serde_json 1.0.108", "sp-api", "sp-block-builder", "sp-blockchain", @@ -9237,14 +9271,14 @@ checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" [[package]] name = "tempfile" -version = "3.8.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand 2.0.1", - "redox_syscall 0.3.5", - "rustix 0.38.20", + "redox_syscall 0.4.1", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -9511,7 +9545,7 @@ dependencies = [ "parking_lot 0.11.2", "regex", "serde", - "serde_json 1.0.107", + "serde_json 1.0.108", "sharded-slab", "smallvec", "thread_local", @@ -9816,9 +9850,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -9826,9 +9860,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", "log", @@ -9841,9 +9875,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" dependencies = [ "cfg-if", "js-sys", @@ -9853,9 +9887,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -9863,9 +9897,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", @@ -9876,9 +9910,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" [[package]] name = "wasm-gc-api" @@ -10006,7 +10040,7 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix 0.35.15", + "rustix 0.35.16", "serde", "sha2 0.9.9", "toml", @@ -10069,7 +10103,7 @@ dependencies = [ "log", "object 0.29.0", "rustc-demangle", - "rustix 0.35.15", + "rustix 0.35.16", "serde", "target-lexicon", "thiserror", @@ -10087,7 +10121,7 @@ checksum = "f671b588486f5ccec8c5a3dba6b4c07eac2e66ab8c60e6f4e53717c77f709731" dependencies = [ "object 0.29.0", "once_cell", - "rustix 0.35.15", + "rustix 0.35.16", ] [[package]] @@ -10107,7 +10141,7 @@ dependencies = [ "memoffset 0.6.5", "paste", "rand 0.8.5", - "rustix 0.35.15", + "rustix 0.35.16", "thiserror", "wasmtime-asm-macros", "wasmtime-environ", @@ -10129,9 +10163,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" dependencies = [ "js-sys", "wasm-bindgen", @@ -10165,7 +10199,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.20", + "rustix 0.38.21", ] [[package]] diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index cb3ea26e3..e460db929 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48011, + spec_version: 48012, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From cef114c9e93685e76b813fafb8be61bcf4be8839 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 18:45:49 +0100 Subject: [PATCH 441/544] extend clusters with cluster gov params --- pallets/ddc-clusters/src/cluster.rs | 39 ++++++++++++++++++++++++--- pallets/ddc-clusters/src/lib.rs | 41 +++++++++++++++++++++++++---- runtime/cere-dev/src/lib.rs | 1 + 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 862c42ddf..862124bb4 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -3,6 +3,8 @@ use codec::{Decode, Encode}; use ddc_primitives::ClusterId; use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; use scale_info::TypeInfo; +use sp_runtime::Perbill; +use sp_staking::EraIndex; use sp_std::vec::Vec; parameter_types! { @@ -10,10 +12,11 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct Cluster { +pub struct Cluster { pub cluster_id: ClusterId, pub manager_id: AccountId, pub props: ClusterProps, + pub gov_params: ClusterGovParams, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -31,12 +34,33 @@ pub struct ClusterParams { pub node_provider_auth_contract: AccountId, } -impl Cluster { +// ClusterGovParams includes Governance sensetive parameters +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterGovParams { + pub treasury_share: Perbill, + pub validators_share: Perbill, + pub cluster_reserve_share: Perbill, + #[codec(compact)] + pub edge_bond_size: Balance, + pub edge_chill_delay: EraIndex, + pub edge_unbonding_delay: EraIndex, + #[codec(compact)] + pub storage_bond_size: Balance, + pub storage_chill_delay: EraIndex, + pub storage_unbonding_delay: EraIndex, + pub unit_per_mb_stored: u128, + pub unit_per_mb_streamed: u128, + pub unit_per_put_request: u128, + pub unit_per_get_request: u128, +} + +impl Cluster { pub fn new( cluster_id: ClusterId, manager_id: AccountId, cluster_params: ClusterParams, - ) -> Result, ClusterError> { + gov_params: ClusterGovParams, + ) -> Result, ClusterError> { Ok(Cluster { cluster_id, manager_id, @@ -47,6 +71,7 @@ impl Cluster { }, node_provider_auth_contract: cluster_params.node_provider_auth_contract, }, + gov_params, }) } @@ -63,6 +88,14 @@ impl Cluster { }; Ok(()) } + + pub fn set_gov_params( + &mut self, + cluster_gov_params: ClusterGovParams, + ) -> Result<(), ClusterError> { + self.gov_params = cluster_gov_params; + Ok(()) + } } pub enum ClusterError { diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 2d389b431..b2aed6706 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -16,7 +16,7 @@ #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 use crate::{ - cluster::{Cluster, ClusterError, ClusterParams}, + cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; use ddc_primitives::{ClusterId, NodePubKey}; @@ -24,7 +24,10 @@ use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, staking::{StakingVisitor, StakingVisitorError}, }; -use frame_support::pallet_prelude::*; +use frame_support::{ + pallet_prelude::*, + traits::{Currency, LockableCurrency}, +}; use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodeRepository, NodeTrait}; @@ -33,6 +36,10 @@ use sp_std::prelude::*; mod cluster; mod node_provider_auth; +/// The balance type of this pallet. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -48,6 +55,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type NodeRepository: NodeRepository; // todo: get rid of tight coupling with nodes-pallet type StakingVisitor: StakingVisitor; + type Currency: LockableCurrency; } #[pallet::event] @@ -57,6 +65,7 @@ pub mod pallet { ClusterNodeAdded { cluster_id: ClusterId, node_pub_key: NodePubKey }, ClusterNodeRemoved { cluster_id: ClusterId, node_pub_key: NodePubKey }, ClusterParamsSet { cluster_id: ClusterId }, + ClusterGovParamsSet { cluster_id: ClusterId }, } #[pallet::error] @@ -80,7 +89,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn clusters)] pub type Clusters = - StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; + StorageMap<_, Blake2_128Concat, ClusterId, Cluster>>; #[pallet::storage] #[pallet::getter(fn clusters_nodes)] @@ -104,10 +113,12 @@ pub mod pallet { origin: OriginFor, cluster_id: ClusterId, cluster_params: ClusterParams, + cluster_gov_params: ClusterGovParams>, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + let cluster = + Cluster::new(cluster_id.clone(), caller_id, cluster_params, cluster_gov_params) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); @@ -204,6 +215,26 @@ pub mod pallet { Ok(()) } + + // Sets Governance sensetive parameters + #[pallet::weight(10_000)] + pub fn set_cluster_gov_params( + origin: OriginFor, + cluster_id: ClusterId, + cluster_gov_params: ClusterGovParams>, + ) -> DispatchResult { + let caller_id = ensure_signed(origin)?; + let mut cluster = + Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); + cluster + .set_gov_params(cluster_gov_params) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + Clusters::::insert(cluster_id.clone(), cluster); + Self::deposit_event(Event::::ClusterGovParamsSet { cluster_id }); + + Ok(()) + } } impl ClusterVisitor for Pallet { diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 0637375e6..7d678d1b6 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1373,6 +1373,7 @@ impl pallet_ddc_clusters::Config for Runtime { type RuntimeEvent = RuntimeEvent; type NodeRepository = pallet_ddc_nodes::Pallet; type StakingVisitor = pallet_ddc_staking::Pallet; + type Currency = Balances; } construct_runtime!( From 491216649e7c34d1db04d6c1b5d80b3438faf3d4 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 19:01:38 +0100 Subject: [PATCH 442/544] add separate mapping for cluster gov params --- pallets/ddc-clusters/src/cluster.rs | 17 +++-------------- pallets/ddc-clusters/src/lib.rs | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 862124bb4..12aaeda0d 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -12,11 +12,10 @@ parameter_types! { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct Cluster { +pub struct Cluster { pub cluster_id: ClusterId, pub manager_id: AccountId, pub props: ClusterProps, - pub gov_params: ClusterGovParams, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -54,13 +53,12 @@ pub struct ClusterGovParams { pub unit_per_get_request: u128, } -impl Cluster { +impl Cluster { pub fn new( cluster_id: ClusterId, manager_id: AccountId, cluster_params: ClusterParams, - gov_params: ClusterGovParams, - ) -> Result, ClusterError> { + ) -> Result, ClusterError> { Ok(Cluster { cluster_id, manager_id, @@ -71,7 +69,6 @@ impl Cluster { }, node_provider_auth_contract: cluster_params.node_provider_auth_contract, }, - gov_params, }) } @@ -88,14 +85,6 @@ impl Cluster { }; Ok(()) } - - pub fn set_gov_params( - &mut self, - cluster_gov_params: ClusterGovParams, - ) -> Result<(), ClusterError> { - self.gov_params = cluster_gov_params; - Ok(()) - } } pub enum ClusterError { diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index b2aed6706..59ce7fb52 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -89,7 +89,12 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn clusters)] pub type Clusters = - StorageMap<_, Blake2_128Concat, ClusterId, Cluster>>; + StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; + + #[pallet::storage] + #[pallet::getter(fn clusters_gov_params)] + pub type ClustersGovParams = + StorageMap<_, Twox64Concat, ClusterId, ClusterGovParams>>; #[pallet::storage] #[pallet::getter(fn clusters_nodes)] @@ -113,12 +118,10 @@ pub mod pallet { origin: OriginFor, cluster_id: ClusterId, cluster_params: ClusterParams, - cluster_gov_params: ClusterGovParams>, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let cluster = - Cluster::new(cluster_id.clone(), caller_id, cluster_params, cluster_gov_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); Clusters::::insert(cluster_id.clone(), cluster); Self::deposit_event(Event::::ClusterCreated { cluster_id }); @@ -224,13 +227,10 @@ pub mod pallet { cluster_gov_params: ClusterGovParams>, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let mut cluster = + let cluster = Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - cluster - .set_gov_params(cluster_gov_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - Clusters::::insert(cluster_id.clone(), cluster); + ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); Self::deposit_event(Event::::ClusterGovParamsSet { cluster_id }); Ok(()) From fe8745c57d6ea430f72e2129fb19f3c33327d495 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 19:13:41 +0100 Subject: [PATCH 443/544] remove remaining files for ddc validator --- pallets/ddc-validator/Cargo.toml | 65 ----- pallets/ddc-validator/src/mock.rs | 446 ------------------------------ runtime/cere-dev/src/lib.rs | 4 +- 3 files changed, 1 insertion(+), 514 deletions(-) delete mode 100644 pallets/ddc-validator/Cargo.toml delete mode 100644 pallets/ddc-validator/src/mock.rs diff --git a/pallets/ddc-validator/Cargo.toml b/pallets/ddc-validator/Cargo.toml deleted file mode 100644 index 6ddfdda06..000000000 --- a/pallets/ddc-validator/Cargo.toml +++ /dev/null @@ -1,65 +0,0 @@ -[package] -name = "pallet-ddc-validator" -version = "0.1.0" -edition = "2021" - -[dependencies] -alt_serde = { version = "1", default-features = false, features = ["derive"] } -array-bytes = "6.0.0" -base64 = { version = "0.21.0", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -lite-json = { version = "0.2.0", default-features = false } -log = { version = "0.4.17", default-features = false } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../ddc-customers" } -pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } -pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } -pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0.101", optional = true } -serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } - -[dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-staking-reward-curve = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -ddc-primitives = { version = "0.1.0", path = "../../primitives" } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-election-provider-support/std", - "frame-support/std", - "frame-system/std", - "lite-json/std", - "pallet-contracts/std", - "pallet-ddc-customers/std", - "pallet-ddc-staking/std", - "pallet-ddc-clusters/std", - "pallet-ddc-nodes/std", - "pallet-session/std", - "pallet-staking/std", - "scale-info/std", - "serde", - "sp-core/std", - "sp-io/std", - "sp-keystore", - "sp-runtime/std", - "sp-staking/std", - "sp-std/std", -] - diff --git a/pallets/ddc-validator/src/mock.rs b/pallets/ddc-validator/src/mock.rs deleted file mode 100644 index 6840c7d1d..000000000 --- a/pallets/ddc-validator/src/mock.rs +++ /dev/null @@ -1,446 +0,0 @@ -use crate::{self as pallet_ddc_validator, *}; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey}; -use ddc_traits::{ - cluster::{ClusterVisitor, ClusterVisitorError}, - staking::{StakingVisitor, StakingVisitorError}, -}; - -use frame_election_provider_support::{onchain, SequentialPhragmen}; -use frame_support::{ - parameter_types, - traits::{Everything, Nothing, U128CurrencyToVote}, - weights::Weight, - PalletId, -}; -use frame_system::offchain::SendTransactionTypes; -use pallet_contracts as contracts; -use pallet_session::ShouldEndSession; -use sp_core::H256; -use sp_io::TestExternalities; -use sp_runtime::{ - curve::PiecewiseLinear, - generic, impl_opaque_keys, - testing::{TestXt, UintAuthorityId}, - traits::{ - BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, - }, - MultiSignature, Perbill, -}; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; -type Balance = u128; -pub type Signature = MultiSignature; -pub type AccountId = <::Signer as IdentifyAccount>::AccountId; -pub type BlockNumber = u32; -pub type Moment = u64; - -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system, - Balances: pallet_balances, - Contracts: contracts, - Timestamp: pallet_timestamp, - Session: pallet_session, - Staking: pallet_staking, - DdcAccounts: pallet_ddc_customers, - DdcStaking: pallet_ddc_staking, - RandomnessCollectiveFlip: pallet_randomness_collective_flip, - DdcValidator: pallet_ddc_validator, - DdcClusters: pallet_ddc_clusters, - DdcNodes: pallet_ddc_nodes, - } -); - -parameter_types! { - pub const BlockHashCount: BlockNumber = 250; - pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); -} - -impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = H256; - type RuntimeCall = RuntimeCall; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - // u64; // sp_core::sr25519::Public; - type Lookup = IdentityLookup; - type Header = generic::Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -parameter_types! { - pub const SignedClaimHandicap: BlockNumber = 2; - pub const TombstoneDeposit: Balance = 16; - pub const StorageSizeOffset: u32 = 8; - pub const RentByteFee: Balance = 4; - pub const RentDepositOffset: Balance = 10_000; - pub const SurchargeReward: Balance = 150; - pub const MaxDepth: u32 = 100; - pub const MaxValueSize: u32 = 16_384; - pub Schedule: pallet_contracts::Schedule = Default::default(); -} - -pub struct TestWeightToFee; -impl Convert for TestWeightToFee { - fn convert(weight: u64) -> u128 { - weight as u128 - } -} - -impl contracts::Config for Test { - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; - type RuntimeCall = RuntimeCall; - type CallFilter = Nothing; - type CallStack = [pallet_contracts::Frame; 31]; - type ChainExtension = (); - type ContractAccessWeight = (); - type Currency = Balances; - type DeletionQueueDepth = (); - type DeletionWeightLimit = (); - type DepositPerByte = DepositPerByte; - type DepositPerItem = DepositPerItem; - type RuntimeEvent = RuntimeEvent; - type MaxCodeLen = ConstU32<{ 128 * 1024 }>; - type MaxStorageKeyLen = ConstU32<128>; - type Randomness = RandomnessCollectiveFlip; - type Schedule = Schedule; - type Time = Timestamp; - type WeightInfo = (); - type WeightPrice = (); -} - -parameter_types! { - pub const TransactionByteFee: u64 = 0; - pub const DepositPerItem: Balance = 0; - pub const DepositPerByte: Balance = 0; -} - -parameter_types! { - pub const MinimumPeriod: u64 = 1; -} - -impl pallet_timestamp::Config for Test { - type Moment = Moment; - type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); -} - -impl pallet_randomness_collective_flip::Config for Test {} - -pub struct TestShouldEndSession; -impl ShouldEndSession for TestShouldEndSession { - fn should_end_session(now: u32) -> bool { - now % 10 == 0 // every 10 blocks - } -} - -impl_opaque_keys! { - pub struct MockSessionKeys { - pub dummy: UintAuthorityId, - } -} - -impl From for MockSessionKeys { - fn from(dummy: UintAuthorityId) -> Self { - Self { dummy } - } -} - -impl pallet_session::Config for Test { - type RuntimeEvent = RuntimeEvent; - type ValidatorId = AccountId; - type ValidatorIdOf = (); - type ShouldEndSession = TestShouldEndSession; - type NextSessionRotation = (); - type SessionManager = (); - type SessionHandler = pallet_session::TestSessionHandler; - type Keys = MockSessionKeys; - type WeightInfo = (); -} - -impl pallet_session::historical::Config for Test { - type FullIdentification = pallet_staking::Exposure; - type FullIdentificationOf = pallet_staking::ExposureOf; -} - -pallet_staking_reward_curve::build! { - const REWARD_CURVE: PiecewiseLinear<'static> = curve!( - min_inflation: 0_000_100, - max_inflation: 0_050_000, - ideal_stake: 0_200_000, - falloff: 0_050_000, - max_piece_count: 100, - test_precision: 0_050_000, - ); -} - -pub struct OnChainSeqPhragmen; -impl onchain::Config for OnChainSeqPhragmen { - type System = Test; - type Solver = SequentialPhragmen; - type DataProvider = Staking; - type WeightInfo = frame_election_provider_support::weights::SubstrateWeight; -} - -parameter_types! { - pub const SessionsPerEra: sp_staking::SessionIndex = 6; - pub const BondingDuration: sp_staking::EraIndex = 3; - pub const SlashDeferDuration: sp_staking::EraIndex = 2; - pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; - pub const MaxNominatorRewardedPerValidator: u32 = 256; - pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); - pub OffchainRepeat: BlockNumber = 5; -} - -impl pallet_staking::Config for Test { - type MaxNominations = ConstU32<16>; - type Currency = Balances; - type UnixTime = Timestamp; - type CurrencyToVote = U128CurrencyToVote; - type RewardRemainder = (); - type RuntimeEvent = RuntimeEvent; - type Slash = (); // send the slashed funds to the treasury. - type Reward = (); // rewards are minted from the void - type SessionsPerEra = SessionsPerEra; - type BondingDuration = BondingDuration; - type SlashDeferDuration = SlashDeferDuration; - type SlashCancelOrigin = frame_system::EnsureRoot; - type SessionInterface = Self; - type EraPayout = pallet_staking::ConvertCurve; - type NextNewSession = Session; - type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; - type OffendingValidatorsThreshold = OffendingValidatorsThreshold; - type ElectionProvider = onchain::UnboundedExecution; - type GenesisElectionProvider = Self::ElectionProvider; - type VoterList = pallet_staking::UseNominatorsAndValidatorsMap; - type MaxUnlockingChunks = ConstU32<32>; - type WeightInfo = pallet_staking::weights::SubstrateWeight; - type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; - type CurrencyBalance = Balance; - type OnStakerSlash = (); - type HistoryDepth = ConstU32<84>; - type TargetList = pallet_staking::UseValidatorsMap; -} - -parameter_types! { - pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); - pub const LockingDuration: sp_staking::EraIndex = 30 * 24; -} - -impl pallet_ddc_customers::Config for Test { - type LockingDuration = LockingDuration; - type Currency = Balances; - type RuntimeEvent = RuntimeEvent; - type PalletId = DdcAccountsPalletId; -} - -parameter_types! { - pub const DefaultEdgeBondSize: Balance = 100; - pub const DefaultEdgeChillDelay: EraIndex = 2; - pub const DefaultStorageBondSize: Balance = 100; - pub const DefaultStorageChillDelay: EraIndex = 2; -} - -impl pallet_ddc_staking::Config for Test { - type BondingDuration = BondingDuration; - type Currency = Balances; - type DefaultEdgeBondSize = DefaultEdgeBondSize; - type DefaultEdgeChillDelay = DefaultEdgeChillDelay; - type DefaultStorageBondSize = DefaultStorageBondSize; - type DefaultStorageChillDelay = DefaultStorageChillDelay; - type RuntimeEvent = RuntimeEvent; - type StakersPayoutSource = DdcAccountsPalletId; - type UnixTime = Timestamp; - type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; - type ClusterVisitor = TestClusterVisitor; -} - -pub struct TestClusterVisitor; -impl ClusterVisitor for TestClusterVisitor { - fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { - true - } - fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { - Ok(()) - } -} - -impl pallet_ddc_clusters::Config for Test { - type RuntimeEvent = RuntimeEvent; - type NodeRepository = pallet_ddc_nodes::Pallet; - type StakingVisitor = TestStakingVisitor; -} - -pub struct TestStakingVisitor; -impl StakingVisitor for TestStakingVisitor { - fn node_has_stake( - _node_pub_key: &NodePubKey, - _cluster_id: &ClusterId, - ) -> Result { - Ok(true) - } - - fn node_is_chilling(_node_pub_key: &NodePubKey) -> Result { - Ok(true) - } -} - -impl pallet_ddc_nodes::Config for Test { - type RuntimeEvent = RuntimeEvent; -} - -parameter_types! { - pub const DdcValidatorsQuorumSize: u32 = 3; - pub const ValidationThreshold: u32 = 5; -} - -impl pallet_ddc_validator::Config for Test { - type DdcValidatorsQuorumSize = DdcValidatorsQuorumSize; - type RuntimeEvent = RuntimeEvent; - type Randomness = RandomnessCollectiveFlip; - type RuntimeCall = RuntimeCall; - type AuthorityId = pallet_ddc_validator::crypto::TestAuthId; - type ValidationThreshold = ValidationThreshold; - type ValidatorsMax = (); -} - -impl SendTransactionTypes for Test -where - RuntimeCall: From, -{ - type OverarchingCall = RuntimeCall; - type Extrinsic = Extrinsic; -} - -parameter_types! { - pub const ExistentialDeposit: u64 = 1; - pub const MaxLocks: u32 = 10; -} - -impl pallet_balances::Config for Test { - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = (); -} - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - let balances = vec![ - // edge stash - (AccountId::from([0x1; 32]), 1000), - // edge controller - (AccountId::from([0x11; 32]), 1000), - // validator1 stash; has to be equal to the OCW key in the current implementation - ( - AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, - 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, - 0x55, 0xf4, 0xdf, 0x67, - ]), - 10000, - ), - // validator1 controller - (AccountId::from([0xaa; 32]), 10000), - // validator2 stash - (AccountId::from([0xb; 32]), 10000), - // validator2 controller - (AccountId::from([0xbb; 32]), 10000), - // validator3 stash - (AccountId::from([0xc; 32]), 10000), - // validator3 controller - (AccountId::from([0xcc; 32]), 10000), - ]; - let _ = pallet_balances::GenesisConfig:: { balances }.assimilate_storage(&mut storage); - - let stakers = vec![ - ( - AccountId::from([ - 0xd2, 0xbf, 0x4b, 0x84, 0x4d, 0xfe, 0xfd, 0x67, 0x72, 0xa8, 0x84, 0x3e, 0x66, 0x9f, - 0x94, 0x34, 0x08, 0x96, 0x6a, 0x97, 0x7e, 0x3a, 0xe2, 0xaf, 0x1d, 0xd7, 0x8e, 0x0f, - 0x55, 0xf4, 0xdf, 0x67, - ]), - AccountId::from([0xaa; 32]), - 1000, - pallet_staking::StakerStatus::Validator, - ), - ( - AccountId::from([0xb; 32]), - AccountId::from([0xbb; 32]), - 1000, - pallet_staking::StakerStatus::Validator, - ), - ( - AccountId::from([0xc; 32]), - AccountId::from([0xcc; 32]), - 1000, - pallet_staking::StakerStatus::Validator, - ), - ]; - let _ = pallet_staking::GenesisConfig:: { stakers, ..Default::default() } - .assimilate_storage(&mut storage); - - let edges = vec![( - AccountId::from([0x1; 32]), - AccountId::from([0x11; 32]), - NodePubKey::CDNPubKey(CDNNodePubKey::new([0x21; 32])), - 100, - ClusterId::from([1; 20]), - )]; - let storages = vec![]; - let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } - .assimilate_storage(&mut storage); - - TestExternalities::new(storage) -} - -pub type Extrinsic = TestXt; - -impl SigningTypes for Test { - type Public = ::Signer; - type Signature = Signature; -} - -impl CreateSignedTransaction for Test -where - RuntimeCall: From, -{ - fn create_transaction>( - call: RuntimeCall, - _public: ::Signer, - _account: AccountId, - nonce: u64, - ) -> Option<(RuntimeCall, ::SignaturePayload)> { - Some((call, (nonce, ()))) - } -} diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index e460db929..58e95dab4 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1477,9 +1477,7 @@ pub type Executive = frame_executive::Executive< >; mod custom_migration { - use super::*; - - use frame_support::{traits::OnRuntimeUpgrade, weights::Weight, Twox128}; + use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; use sp_io::{hashing::twox_128, storage::clear_prefix}; pub struct Upgrade; From 7b8396f67145769b6e7d344717eda14f3e61e2d1 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 1 Nov 2023 11:19:46 +0100 Subject: [PATCH 444/544] update bucket_id type from u128 to u64 and add storage migration --- pallets/ddc-customers/src/lib.rs | 23 +++++++++++----- pallets/ddc-customers/src/migration.rs | 36 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 pallets/ddc-customers/src/migration.rs diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 0092bf9e0..d102d6e78 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -19,6 +19,8 @@ use sp_runtime::{ use sp_staking::EraIndex; use sp_std::prelude::*; +mod migration; + pub use pallet::*; /// The balance type of this pallet. @@ -43,7 +45,7 @@ pub struct UnlockChunk { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct Bucket { - bucket_id: u128, + bucket_id: u64, owner_id: AccountId, cluster_id: Option, public_availability: bool, @@ -52,7 +54,7 @@ pub struct Bucket { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct BucketsDetails { - pub bucket_id: u128, + pub bucket_id: u64, pub amount: Balance, } @@ -147,6 +149,13 @@ pub mod pallet { #[pallet::without_storage_info] pub struct Pallet(_); + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + migration::migrate_to_v2::() + } + } + #[pallet::config] pub trait Config: frame_system::Config + ddc_staking::Config + ddc_clusters::Config { /// The accounts's pallet id, used for deriving its sovereign account ID. @@ -166,19 +175,19 @@ pub mod pallet { StorageMap<_, Identity, T::AccountId, AccountsLedger>>; #[pallet::type_value] - pub fn DefaultBucketCount() -> u128 { - 0_u128 + pub fn DefaultBucketCount() -> u64 { + 0_u64 } #[pallet::storage] #[pallet::getter(fn buckets_count)] pub type BucketsCount = - StorageValue>; + StorageValue>; /// Map from bucket ID to to the bucket structure #[pallet::storage] #[pallet::getter(fn buckets)] pub type Buckets = - StorageMap<_, Twox64Concat, u128, Bucket, OptionQuery>; + StorageMap<_, Twox64Concat, u64, Bucket, OptionQuery>; #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] @@ -275,7 +284,7 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn allocate_bucket_to_cluster( origin: OriginFor, - bucket_id: u128, + bucket_id: u64, cluster_id: ClusterId, ) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; diff --git a/pallets/ddc-customers/src/migration.rs b/pallets/ddc-customers/src/migration.rs new file mode 100644 index 000000000..5bc3e34cc --- /dev/null +++ b/pallets/ddc-customers/src/migration.rs @@ -0,0 +1,36 @@ +use super::*; + +use frame_support::{ + storage_alias, + traits::{Get, GetStorageVersion, StorageVersion}, + weights::Weight, + BoundedVec, Twox64Concat, +}; + +// only contains V1 storage format +pub mod v1 { + use super::*; + + #[storage_alias] + pub(super) type Buckets = + StorageMap, Twox64Concat, u64, Bucket<::AccountId>>; +} + +// contains checks and transforms storage to V2 format +pub fn migrate_to_v2() -> Weight { + // We transform the storage values from the old into the new format. + Buckets::::translate::, _>(|_k: u64, bucket: Bucket| { + Some(Bucket { + bucket_id: bucket.bucket_id as u64, + owner_id: bucket.owner_id, + cluster_id: bucket.cluster_id, + public_availability: bucket.public_availability, + resources_reserved: bucket.resources_reserved, + }) + }); + + // Very inefficient, mostly here for illustration purposes. + let count = Buckets::::iter().count(); + // Return the weight consumed by the migration. + T::DbWeight::get().reads_writes(count as u64 + 1, count as u64 + 1) +} From 3602a04b791a24dbe8e8d7eae5bd28b0a84f521c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 3 Nov 2023 10:20:47 +0100 Subject: [PATCH 445/544] correct key for v1 storage format --- pallets/ddc-customers/src/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-customers/src/migration.rs b/pallets/ddc-customers/src/migration.rs index 5bc3e34cc..c25e22ec6 100644 --- a/pallets/ddc-customers/src/migration.rs +++ b/pallets/ddc-customers/src/migration.rs @@ -13,7 +13,7 @@ pub mod v1 { #[storage_alias] pub(super) type Buckets = - StorageMap, Twox64Concat, u64, Bucket<::AccountId>>; + StorageMap, Twox64Concat, u128, Bucket<::AccountId>>; } // contains checks and transforms storage to V2 format From 581b7ff2bac8822e5e73bbf827ffc3c720d2ae1e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 14:59:02 +0100 Subject: [PATCH 446/544] remove migration & resources reserved for buckets --- pallets/ddc-customers/src/lib.rs | 17 +----------- pallets/ddc-customers/src/migration.rs | 36 -------------------------- 2 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 pallets/ddc-customers/src/migration.rs diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index d102d6e78..a5a734003 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -19,8 +19,6 @@ use sp_runtime::{ use sp_staking::EraIndex; use sp_std::prelude::*; -mod migration; - pub use pallet::*; /// The balance type of this pallet. @@ -49,7 +47,6 @@ pub struct Bucket { owner_id: AccountId, cluster_id: Option, public_availability: bool, - resources_reserved: u128, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -149,13 +146,6 @@ pub mod pallet { #[pallet::without_storage_info] pub struct Pallet(_); - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - migration::migrate_to_v2::() - } - } - #[pallet::config] pub trait Config: frame_system::Config + ddc_staking::Config + ddc_clusters::Config { /// The accounts's pallet id, used for deriving its sovereign account ID. @@ -257,11 +247,7 @@ pub mod pallet { /// /// Anyone can create a bucket #[pallet::weight(10_000)] - pub fn create_bucket( - origin: OriginFor, - public_availability: bool, - resources_reserved: u128, - ) -> DispatchResult { + pub fn create_bucket(origin: OriginFor, public_availability: bool) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = Self::buckets_count(); @@ -270,7 +256,6 @@ pub mod pallet { owner_id: bucket_owner, cluster_id: None, public_availability, - resources_reserved, }; >::set(cur_bucket_id + 1); diff --git a/pallets/ddc-customers/src/migration.rs b/pallets/ddc-customers/src/migration.rs deleted file mode 100644 index c25e22ec6..000000000 --- a/pallets/ddc-customers/src/migration.rs +++ /dev/null @@ -1,36 +0,0 @@ -use super::*; - -use frame_support::{ - storage_alias, - traits::{Get, GetStorageVersion, StorageVersion}, - weights::Weight, - BoundedVec, Twox64Concat, -}; - -// only contains V1 storage format -pub mod v1 { - use super::*; - - #[storage_alias] - pub(super) type Buckets = - StorageMap, Twox64Concat, u128, Bucket<::AccountId>>; -} - -// contains checks and transforms storage to V2 format -pub fn migrate_to_v2() -> Weight { - // We transform the storage values from the old into the new format. - Buckets::::translate::, _>(|_k: u64, bucket: Bucket| { - Some(Bucket { - bucket_id: bucket.bucket_id as u64, - owner_id: bucket.owner_id, - cluster_id: bucket.cluster_id, - public_availability: bucket.public_availability, - resources_reserved: bucket.resources_reserved, - }) - }); - - // Very inefficient, mostly here for illustration purposes. - let count = Buckets::::iter().count(); - // Return the weight consumed by the migration. - T::DbWeight::get().reads_writes(count as u64 + 1, count as u64 + 1) -} From ddc828d820c2be20d521866e7488d8d0320c2abe Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 15:17:38 +0100 Subject: [PATCH 447/544] move BucketId to ddc-primitives --- pallets/ddc-customers/src/lib.rs | 16 ++++++++-------- primitives/src/lib.rs | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index a5a734003..8528b577b 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -3,7 +3,7 @@ use codec::{Decode, Encode, HasCompact}; -use ddc_primitives::ClusterId; +use ddc_primitives::{BucketId, ClusterId}; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, @@ -43,7 +43,7 @@ pub struct UnlockChunk { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct Bucket { - bucket_id: u64, + bucket_id: BucketId, owner_id: AccountId, cluster_id: Option, public_availability: bool, @@ -51,7 +51,7 @@ pub struct Bucket { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct BucketsDetails { - pub bucket_id: u64, + pub bucket_id: BucketId, pub amount: Balance, } @@ -165,19 +165,19 @@ pub mod pallet { StorageMap<_, Identity, T::AccountId, AccountsLedger>>; #[pallet::type_value] - pub fn DefaultBucketCount() -> u64 { - 0_u64 + pub fn DefaultBucketCount() -> BucketId { + 0 } #[pallet::storage] #[pallet::getter(fn buckets_count)] pub type BucketsCount = - StorageValue>; + StorageValue>; /// Map from bucket ID to to the bucket structure #[pallet::storage] #[pallet::getter(fn buckets)] pub type Buckets = - StorageMap<_, Twox64Concat, u64, Bucket, OptionQuery>; + StorageMap<_, Twox64Concat, BucketId, Bucket, OptionQuery>; #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] @@ -269,7 +269,7 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn allocate_bucket_to_cluster( origin: OriginFor, - bucket_id: u64, + bucket_id: BucketId, cluster_id: ClusterId, ) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 0f1efd446..a3abee7c4 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -9,6 +9,7 @@ use sp_core::hash::H160; use sp_runtime::{AccountId32, RuntimeDebug}; pub type ClusterId = H160; +pub type BucketId = u64; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] From 7b3c6659959ac9a4828cad8c65b56952659978e2 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 21:14:39 +0100 Subject: [PATCH 448/544] change edge to cdn prefix in naming --- pallets/ddc-clusters/src/cluster.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 12aaeda0d..7274fbf16 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -40,9 +40,9 @@ pub struct ClusterGovParams { pub validators_share: Perbill, pub cluster_reserve_share: Perbill, #[codec(compact)] - pub edge_bond_size: Balance, - pub edge_chill_delay: EraIndex, - pub edge_unbonding_delay: EraIndex, + pub cdn_bond_size: Balance, + pub cdn_chill_delay: EraIndex, + pub cdn_unbonding_delay: EraIndex, #[codec(compact)] pub storage_bond_size: Balance, pub storage_chill_delay: EraIndex, From 12a09cf2898d20f687f5c35fc4735cf350a0b960 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 6 Nov 2023 21:20:39 +0100 Subject: [PATCH 449/544] bucket can only be allocated to cluster once --- pallets/ddc-customers/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 8528b577b..4e41485a2 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -218,6 +218,8 @@ pub mod pallet { BucketDoesNotExist, /// DDC Cluster with provided id doesn't exist ClusterDoesNotExist, + /// Bucket already allocated to cluster + BucketAlreadyInCluster, } #[pallet::genesis_config] @@ -276,6 +278,7 @@ pub mod pallet { let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; + ensure!(bucket.cluster_id == None, Error::::BucketAlreadyInCluster); ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); ensure!( From fb15886700abb6f20edac6bfa01a1fa272af1cc7 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 10:28:30 +0100 Subject: [PATCH 450/544] merge create_bucket and allocate_bucket_to_cluster methods --- pallets/ddc-customers/src/lib.rs | 38 +++++++------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 4e41485a2..4adcee4b5 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -46,7 +46,6 @@ pub struct Bucket { bucket_id: BucketId, owner_id: AccountId, cluster_id: Option, - public_availability: bool, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -245,19 +244,23 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Create new bucket with provided public availability & reserved resources + /// Create new bucket with specified cluster id /// /// Anyone can create a bucket #[pallet::weight(10_000)] - pub fn create_bucket(origin: OriginFor, public_availability: bool) -> DispatchResult { + pub fn create_bucket(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = Self::buckets_count(); + ensure!( + ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), + Error::::ClusterDoesNotExist + ); + let bucket = Bucket { bucket_id: cur_bucket_id + 1, owner_id: bucket_owner, - cluster_id: None, - public_availability, + cluster_id: Some(cluster_id), }; >::set(cur_bucket_id + 1); @@ -265,31 +268,6 @@ pub mod pallet { Ok(()) } - /// Allocates specified bucket into specified cluster - /// - /// Only bucket owner can call this method - #[pallet::weight(10_000)] - pub fn allocate_bucket_to_cluster( - origin: OriginFor, - bucket_id: BucketId, - cluster_id: ClusterId, - ) -> DispatchResult { - let bucket_owner = ensure_signed(origin)?; - - let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; - - ensure!(bucket.cluster_id == None, Error::::BucketAlreadyInCluster); - ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); - - ensure!( - ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), - Error::::ClusterDoesNotExist - ); - bucket.cluster_id = Some(cluster_id); - - Ok(()) - } - /// Take the origin account as a owner and lock up `value` of its balance. `Owner` will /// be the account that controls it. /// From f5abcdb0ad830c0c454251cc150bbe61ac955045 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 15:30:54 +0100 Subject: [PATCH 451/544] substitute bond size check with cluster gov params --- pallets/ddc-clusters/src/lib.rs | 17 +++++++++++ pallets/ddc-staking/src/lib.rs | 50 +++++++++++++++++++++++++++------ traits/src/cluster.rs | 6 ++++ 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 59ce7fb52..08f246e69 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -31,6 +31,7 @@ use frame_support::{ use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodeRepository, NodeTrait}; +use sp_runtime::SaturatedConversion; use sp_std::prelude::*; mod cluster; @@ -247,6 +248,22 @@ pub mod pallet { .map(|_| ()) .ok_or(ClusterVisitorError::ClusterDoesNotExist) } + + fn get_bond_size( + cluster_id: &ClusterId, + node_pub_key: &NodePubKey, + ) -> Result { + // ensure!(ClustersNodes::::contains_key(cluster_id), + // Error::::ClusterDoesNotExist); + let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; + match node_pub_key { + NodePubKey::StoragePubKey(_node_pub_key) => + Ok(cluster_gov_params.storage_bond_size.saturated_into::()), + NodePubKey::CDNPubKey(_node_pub_key) => + Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), + } + } } impl From for Error { diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 55614769b..84c1183c0 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -49,7 +49,7 @@ use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, - RuntimeDebug, + RuntimeDebug, SaturatedConversion, }; use sp_staking::EraIndex; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -402,6 +402,7 @@ pub mod pallet { assert_ok!(Pallet::::serve( T::RuntimeOrigin::from(Some(controller.clone()).into()), cluster, + node.clone() )); } @@ -420,6 +421,7 @@ pub mod pallet { assert_ok!(Pallet::::store( T::RuntimeOrigin::from(Some(controller.clone()).into()), cluster, + node.clone(), )); } } @@ -487,6 +489,8 @@ pub mod pallet { NotNodeController, /// No stake found associated with the provided node. NodeHasNoStake, + /// No cluster governance params found for cluster + NoClusterGovParams, /// Conditions for fast chill are not met, try the regular `chill` from FastChillProhibited, } @@ -590,6 +594,7 @@ pub mod pallet { pub fn unbond( origin: OriginFor, #[pallet::compact] value: BalanceOf, + node_pub_key: NodePubKey, ) -> DispatchResult { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; @@ -609,10 +614,15 @@ pub mod pallet { ledger.active = Zero::zero(); } + // Check if stash is mapped to the node + let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; + ensure!(ledger.stash.clone() == node_stash, Error::::NotNodeController); + let min_active_bond = if let Some(cluster_id) = Self::edges(&ledger.stash) { - Self::settings(cluster_id).edge_bond_size - } else if let Some(cluster_id) = Self::storages(&ledger.stash) { - Self::settings(cluster_id).storage_bond_size + // Retrieve the respective bond size from Cluster Visitor + let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, &node_pub_key) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + bond_size.saturated_into::>() } else { Zero::zero() }; @@ -692,19 +702,31 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The /// bond size must be greater than or equal to the `EdgeBondSize`. #[pallet::weight(T::WeightInfo::serve())] - pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { + pub fn serve( + origin: OriginFor, + cluster_id: ClusterId, + node_pub_key: NodePubKey, + ) -> DispatchResult { let controller = ensure_signed(origin)?; T::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + // Retrieve the respective bond size from Cluster Visitor + let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, &node_pub_key) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + ensure!( - ledger.active >= Self::settings(cluster_id).edge_bond_size, + ledger.active >= bond_size.saturated_into::>(), Error::::InsufficientBond ); let stash = &ledger.stash; + // Check if stash is mapped to the node + let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; + ensure!(*stash == node_stash, Error::::NotNodeController); + // Can't participate in CDN if already participating in storage network. ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); @@ -729,19 +751,30 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The /// bond size must be greater than or equal to the `StorageBondSize`. #[pallet::weight(T::WeightInfo::store())] - pub fn store(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { + pub fn store( + origin: OriginFor, + cluster_id: ClusterId, + node_pub_key: NodePubKey, + ) -> DispatchResult { let controller = ensure_signed(origin)?; T::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + // Retrieve the respective bond size from Cluster Visitor + let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, &node_pub_key) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; ensure!( - ledger.active >= Self::settings(cluster_id).storage_bond_size, + ledger.active >= bond_size.saturated_into::>(), Error::::InsufficientBond ); let stash = &ledger.stash; + // Check if stash is mapped to the node + let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; + ensure!(*stash == node_stash, Error::::NotNodeController); + // Can't participate in storage network if already participating in CDN. ensure!(!Edges::::contains_key(&stash), Error::::AlreadyInRole); @@ -1197,6 +1230,7 @@ pub mod pallet { fn from(error: ClusterVisitorError) -> Self { match error { ClusterVisitorError::ClusterDoesNotExist => Error::::NodeHasNoStake, + ClusterVisitorError::ClusterGovParamsNotSet => Error::::NoClusterGovParams, } } } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index a1cae3515..505de5298 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -5,8 +5,14 @@ pub trait ClusterVisitor { fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError>; + + fn get_bond_size( + cluster_id: &ClusterId, + node_pub_key: &NodePubKey, + ) -> Result; } pub enum ClusterVisitorError { ClusterDoesNotExist, + ClusterGovParamsNotSet, } From 1b067e304abfade79d5647675e494de74be99aa4 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 16:20:39 +0100 Subject: [PATCH 452/544] remove unnecessary params & update mock --- pallets/ddc-staking/src/lib.rs | 36 ++++++++++----------------------- pallets/ddc-staking/src/mock.rs | 6 ++++++ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 84c1183c0..58bfa5b9b 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -49,7 +49,7 @@ use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, - RuntimeDebug, SaturatedConversion, + AccountId32, RuntimeDebug, SaturatedConversion, }; use sp_staking::EraIndex; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -402,7 +402,6 @@ pub mod pallet { assert_ok!(Pallet::::serve( T::RuntimeOrigin::from(Some(controller.clone()).into()), cluster, - node.clone() )); } @@ -421,7 +420,6 @@ pub mod pallet { assert_ok!(Pallet::::store( T::RuntimeOrigin::from(Some(controller.clone()).into()), cluster, - node.clone(), )); } } @@ -702,20 +700,18 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The /// bond size must be greater than or equal to the `EdgeBondSize`. #[pallet::weight(T::WeightInfo::serve())] - pub fn serve( - origin: OriginFor, - cluster_id: ClusterId, - node_pub_key: NodePubKey, - ) -> DispatchResult { + pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; + let account = AccountId32::new([0; 32]); T::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, &node_pub_key) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let bond_size = + T::ClusterVisitor::get_bond_size(&cluster_id, &NodePubKey::CDNPubKey(account)) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; ensure!( ledger.active >= bond_size.saturated_into::>(), @@ -723,10 +719,6 @@ pub mod pallet { ); let stash = &ledger.stash; - // Check if stash is mapped to the node - let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; - ensure!(*stash == node_stash, Error::::NotNodeController); - // Can't participate in CDN if already participating in storage network. ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); @@ -751,30 +743,24 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The /// bond size must be greater than or equal to the `StorageBondSize`. #[pallet::weight(T::WeightInfo::store())] - pub fn store( - origin: OriginFor, - cluster_id: ClusterId, - node_pub_key: NodePubKey, - ) -> DispatchResult { + pub fn store(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; + let account = AccountId32::new([0; 32]); T::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, &node_pub_key) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let bond_size = + T::ClusterVisitor::get_bond_size(&cluster_id, &NodePubKey::StoragePubKey(account)) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; ensure!( ledger.active >= bond_size.saturated_into::>(), Error::::InsufficientBond ); let stash = &ledger.stash; - // Check if stash is mapped to the node - let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; - ensure!(*stash == node_stash, Error::::NotNodeController); - // Can't participate in storage network if already participating in CDN. ensure!(!Edges::::contains_key(&stash), Error::::AlreadyInRole); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index cf55112b7..cac16850e 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -124,6 +124,12 @@ impl ClusterVisitor for TestClusterVisitor { fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { Ok(()) } + fn get_bond_size( + _cluster_id: &ClusterId, + _node_pub_key: &NodePubKey, + ) -> Result { + Ok(10) + } } pub struct ExtBuilder { has_edges: bool, From 9fccd392a123882dce31b9fe41df8667c17ebe6c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 16:56:37 +0100 Subject: [PATCH 453/544] change the param for getting bond size --- pallets/ddc-clusters/src/lib.rs | 9 ++++----- pallets/ddc-staking/src/lib.rs | 29 ++++++++++++----------------- pallets/ddc-staking/src/mock.rs | 2 +- traits/src/cluster.rs | 4 ++-- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 08f246e69..6bdf9fc84 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -19,7 +19,7 @@ use crate::{ cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; -use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, staking::{StakingVisitor, StakingVisitorError}, @@ -251,17 +251,16 @@ pub mod pallet { fn get_bond_size( cluster_id: &ClusterId, - node_pub_key: &NodePubKey, + node_pub_key: NodeType, ) -> Result { // ensure!(ClustersNodes::::contains_key(cluster_id), // Error::::ClusterDoesNotExist); let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_pub_key { - NodePubKey::StoragePubKey(_node_pub_key) => + NodeType::Storage => Ok(cluster_gov_params.storage_bond_size.saturated_into::()), - NodePubKey::CDNPubKey(_node_pub_key) => - Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), + NodeType::CDN => Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), } } } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 58bfa5b9b..6ef7d34af 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -29,7 +29,7 @@ pub mod weights; use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; -pub use ddc_primitives::{ClusterId, NodePubKey}; +pub use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, staking::{StakingVisitor, StakingVisitorError}, @@ -49,7 +49,7 @@ use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, - AccountId32, RuntimeDebug, SaturatedConversion, + RuntimeDebug, SaturatedConversion, }; use sp_staking::EraIndex; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -592,7 +592,6 @@ pub mod pallet { pub fn unbond( origin: OriginFor, #[pallet::compact] value: BalanceOf, - node_pub_key: NodePubKey, ) -> DispatchResult { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; @@ -612,15 +611,15 @@ pub mod pallet { ledger.active = Zero::zero(); } - // Check if stash is mapped to the node - let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; - ensure!(ledger.stash.clone() == node_stash, Error::::NotNodeController); - let min_active_bond = if let Some(cluster_id) = Self::edges(&ledger.stash) { - // Retrieve the respective bond size from Cluster Visitor - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, &node_pub_key) + let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; bond_size.saturated_into::>() + } else if let Some(cluster_id) = Self::storages(&ledger.stash) { + let bond_size = + T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + bond_size.saturated_into::>() } else { Zero::zero() }; @@ -702,16 +701,14 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::serve())] pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; - let account = AccountId32::new([0; 32]); T::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor - let bond_size = - T::ClusterVisitor::get_bond_size(&cluster_id, &NodePubKey::CDNPubKey(account)) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; ensure!( ledger.active >= bond_size.saturated_into::>(), @@ -745,16 +742,14 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::store())] pub fn store(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; - let account = AccountId32::new([0; 32]); T::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor - let bond_size = - T::ClusterVisitor::get_bond_size(&cluster_id, &NodePubKey::StoragePubKey(account)) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; ensure!( ledger.active >= bond_size.saturated_into::>(), Error::::InsufficientBond diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index cac16850e..0035892f9 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -126,7 +126,7 @@ impl ClusterVisitor for TestClusterVisitor { } fn get_bond_size( _cluster_id: &ClusterId, - _node_pub_key: &NodePubKey, + _node_pub_key: NodeType, ) -> Result { Ok(10) } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index 505de5298..e7036df66 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,4 +1,4 @@ -use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use frame_system::Config; pub trait ClusterVisitor { @@ -8,7 +8,7 @@ pub trait ClusterVisitor { fn get_bond_size( cluster_id: &ClusterId, - node_pub_key: &NodePubKey, + node_pub_key: NodeType, ) -> Result; } From 64d3eac74ebb0bf0ebb5da9ddcd2f9332b345e25 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 17:13:49 +0100 Subject: [PATCH 454/544] update to loose coupling for cluster info --- Cargo.lock | 1 + pallets/ddc-customers/Cargo.toml | 1 + pallets/ddc-customers/src/lib.rs | 10 +++++----- runtime/cere-dev/src/lib.rs | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4063fadd..261f5de39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4938,6 +4938,7 @@ name = "pallet-ddc-customers" version = "0.1.0" dependencies = [ "ddc-primitives", + "ddc-traits", "frame-support", "frame-system", "log", diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 8007013bb..8e899be0e 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 4adcee4b5..53c75f34a 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -4,6 +4,7 @@ use codec::{Decode, Encode, HasCompact}; use ddc_primitives::{BucketId, ClusterId}; +use ddc_traits::cluster::ClusterVisitor; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, @@ -146,7 +147,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + ddc_staking::Config + ddc_clusters::Config { + pub trait Config: frame_system::Config + ddc_staking::Config { /// The accounts's pallet id, used for deriving its sovereign account ID. #[pallet::constant] type PalletId: Get; @@ -155,6 +156,7 @@ pub mod pallet { /// Number of eras that staked funds must remain locked for. #[pallet::constant] type LockingDuration: Get; + type ClusterVisitor: ClusterVisitor; } /// Map from all (unlocked) "owner" accounts to the info regarding the staking. @@ -252,10 +254,8 @@ pub mod pallet { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = Self::buckets_count(); - ensure!( - ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), - Error::::ClusterDoesNotExist - ); + ::ClusterVisitor::ensure_cluster(&cluster_id) + .map_err(|_| Error::::ClusterDoesNotExist)?; let bucket = Bucket { bucket_id: cur_bucket_id + 1, diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 58e95dab4..e396168e7 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1347,6 +1347,7 @@ impl pallet_ddc_customers::Config for Runtime { type Currency = Balances; type PalletId = DdcCustomersPalletId; type RuntimeEvent = RuntimeEvent; + type ClusterVisitor = pallet_ddc_clusters::Pallet; } impl pallet_ddc_nodes::Config for Runtime { From c6522e113d6cb74b27aaf9abcd659e417e710d0e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 17:15:23 +0100 Subject: [PATCH 455/544] rename param node_pub_key to node_type --- pallets/ddc-clusters/src/lib.rs | 2 +- pallets/ddc-staking/src/mock.rs | 2 +- traits/src/cluster.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6bdf9fc84..0ed7c0e78 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -251,7 +251,7 @@ pub mod pallet { fn get_bond_size( cluster_id: &ClusterId, - node_pub_key: NodeType, + node_type: NodeType, ) -> Result { // ensure!(ClustersNodes::::contains_key(cluster_id), // Error::::ClusterDoesNotExist); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 0035892f9..f009fec41 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -126,7 +126,7 @@ impl ClusterVisitor for TestClusterVisitor { } fn get_bond_size( _cluster_id: &ClusterId, - _node_pub_key: NodeType, + _node_type: NodeType, ) -> Result { Ok(10) } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index e7036df66..99cd8be6b 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -8,7 +8,7 @@ pub trait ClusterVisitor { fn get_bond_size( cluster_id: &ClusterId, - node_pub_key: NodeType, + node_type: NodeType, ) -> Result; } From 24bb2ea4c23c8f0b716fd71a30dc5fbc681a9c21 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 17:19:09 +0100 Subject: [PATCH 456/544] fix small bug --- pallets/ddc-clusters/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 0ed7c0e78..6a7c0549b 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -257,7 +257,7 @@ pub mod pallet { // Error::::ClusterDoesNotExist); let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; - match node_pub_key { + match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_bond_size.saturated_into::()), NodeType::CDN => Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), From 3642a95d8887469852544a5387758f1b62a65e11 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 17:24:59 +0100 Subject: [PATCH 457/544] make cluster_id not an optional field in bucket struct --- pallets/ddc-customers/src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 53c75f34a..c474e9869 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -46,7 +46,7 @@ pub struct UnlockChunk { pub struct Bucket { bucket_id: BucketId, owner_id: AccountId, - cluster_id: Option, + cluster_id: ClusterId, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -257,11 +257,8 @@ pub mod pallet { ::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|_| Error::::ClusterDoesNotExist)?; - let bucket = Bucket { - bucket_id: cur_bucket_id + 1, - owner_id: bucket_owner, - cluster_id: Some(cluster_id), - }; + let bucket = + Bucket { bucket_id: cur_bucket_id + 1, owner_id: bucket_owner, cluster_id }; >::set(cur_bucket_id + 1); >::insert(cur_bucket_id + 1, bucket); From 118e27187fb792b92ef0ec7686c412220fedaf1b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 17:27:39 +0100 Subject: [PATCH 458/544] remove ddc-clusters from cargo.toml --- Cargo.lock | 1 - pallets/ddc-customers/Cargo.toml | 2 -- pallets/ddc-customers/src/lib.rs | 1 - 3 files changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 261f5de39..23c1bdd39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4942,7 +4942,6 @@ dependencies = [ "frame-support", "frame-system", "log", - "pallet-ddc-clusters", "pallet-ddc-staking", "parity-scale-codec", "scale-info", diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 8e899be0e..15e19a71f 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -9,7 +9,6 @@ ddc-primitives = { version = "0.1.0", default-features = false, path = "../../pr ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-clusters = { version = "4.7.0", default-features = false, path = "../ddc-clusters" } pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -26,7 +25,6 @@ default = ["std"] std = [ "codec/std", "ddc-primitives/std", - "pallet-ddc-clusters/std", "frame-support/std", "frame-system/std", "scale-info/std", diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index c474e9869..5ae8f64d1 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -10,7 +10,6 @@ use frame_support::{ traits::{Currency, DefensiveSaturating, ExistenceRequirement}, BoundedVec, PalletId, }; -pub use pallet_ddc_clusters::{self as ddc_clusters}; pub use pallet_ddc_staking::{self as ddc_staking}; use scale_info::TypeInfo; use sp_runtime::{ From c72a3a623b99c28e0a5d1d413cc152bc892113ef Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 20:55:20 +0100 Subject: [PATCH 459/544] remove obsolete error and add event for bucket creation --- pallets/ddc-customers/src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 5ae8f64d1..ce6bbb037 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -194,6 +194,8 @@ pub mod pallet { Withdrawn(T::AccountId, BalanceOf), /// Total amount charged from all accounts to pay CDN nodes Charged(BalanceOf), + /// Bucket with specific id created + BucketCreated(BucketId), } #[pallet::error] @@ -218,8 +220,6 @@ pub mod pallet { BucketDoesNotExist, /// DDC Cluster with provided id doesn't exist ClusterDoesNotExist, - /// Bucket already allocated to cluster - BucketAlreadyInCluster, } #[pallet::genesis_config] @@ -251,16 +251,18 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn create_bucket(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; - let cur_bucket_id = Self::buckets_count(); + let cur_bucket_id = Self::buckets_count() + 1; ::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|_| Error::::ClusterDoesNotExist)?; - let bucket = - Bucket { bucket_id: cur_bucket_id + 1, owner_id: bucket_owner, cluster_id }; + let bucket = Bucket { bucket_id: cur_bucket_id, owner_id: bucket_owner, cluster_id }; + + >::set(cur_bucket_id); + >::insert(cur_bucket_id, bucket); + + Self::deposit_event(Event::::BucketCreated(cur_bucket_id)); - >::set(cur_bucket_id + 1); - >::insert(cur_bucket_id + 1, bucket); Ok(()) } From aec8f962d4af322c1cd58b8d0f2080920aa157e5 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 21:23:30 +0100 Subject: [PATCH 460/544] add strong type params for cdn node --- pallets/ddc-nodes/src/cdn_node.rs | 33 +++++++++++++++++++++---------- pallets/ddc-nodes/src/lib.rs | 1 + pallets/ddc-nodes/src/node.rs | 2 ++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 7bec6566b..5b3954953 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -8,6 +8,7 @@ use sp_std::prelude::*; parameter_types! { pub MaxCDNNodeParamsLen: u16 = 2048; + pub MaxHostLen: u8 = 255; } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -21,14 +22,18 @@ pub struct CDNNode { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeProps { - // this is a temporal way of storing node parameters as a stringified json, - // should be replaced with specific properties for this type of node once they are defined - pub params: BoundedVec, + pub host: BoundedVec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeParams { - pub params: Vec, // should be replaced with specific parameters for this type of node + pub host: Vec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, } impl NodeTrait for CDNNode { @@ -49,10 +54,15 @@ impl NodeTrait for CDNNode { Ok(()) } fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { - self.props.params = match node_params { - NodeParams::CDNParams(cdn_params) => match cdn_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNNodeParamsExceedsLimit), + match node_params { + NodeParams::CDNParams(cdn_params) => { + self.props.host = match cdn_params.host.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), + }; + self.props.http_port = cdn_params.http_port; + self.props.grpc_port = cdn_params.grpc_port; + self.props.p2p_port = cdn_params.p2p_port; }, _ => return Err(NodeError::InvalidCDNNodeParams), }; @@ -79,10 +89,13 @@ impl NodeTrait for CDNNode { pub_key, cluster_id: None, props: CDNNodeProps { - params: match node_params.params.try_into() { + host: match node_params.host.try_into() { Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNNodeParamsExceedsLimit), + Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), }, + http_port: node_params.http_port, + grpc_port: node_params.grpc_port, + p2p_port: node_params.p2p_port, }, })), _ => Err(NodeError::InvalidCDNNodeParams), diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 70efb076f..f0e881f7f 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -61,6 +61,7 @@ pub mod pallet { NodeParamsExceedsLimit, OnlyNodeProvider, NodeIsAssignedToCluster, + HostLenExceedsLimit, } #[pallet::storage] diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index d9431c8b6..4d16b7fd8 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -137,6 +137,7 @@ pub enum NodeError { InvalidCDNNodeParams, StorageNodeParamsExceedsLimit, CDNNodeParamsExceedsLimit, + CDNHostLenExceedsLimit, InvalidCDNNodeProps, InvalidStorageNodeProps, } @@ -150,6 +151,7 @@ impl From for Error { NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, NodeError::StorageNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, NodeError::CDNNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, + NodeError::CDNHostLenExceedsLimit => Error::::HostLenExceedsLimit, NodeError::InvalidStorageNodeProps => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeProps => Error::::InvalidNodeParams, } From 6c53223c23e04f4545f2a3d89e8948df99ee8947 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 11:37:29 +0100 Subject: [PATCH 461/544] rename all mentions of edge to CDN --- pallets/ddc-staking/README.md | 2 +- pallets/ddc-staking/src/benchmarking.rs | 24 +++---- pallets/ddc-staking/src/lib.rs | 86 ++++++++++++------------ pallets/ddc-staking/src/mock.rs | 36 +++++----- pallets/ddc-staking/src/testing_utils.rs | 6 +- pallets/ddc-staking/src/tests.rs | 18 ++--- pallets/ddc-staking/src/weights.rs | 16 ++--- runtime/cere-dev/src/lib.rs | 8 +-- 8 files changed, 98 insertions(+), 98 deletions(-) diff --git a/pallets/ddc-staking/README.md b/pallets/ddc-staking/README.md index ef00bef50..f8ac2385a 100644 --- a/pallets/ddc-staking/README.md +++ b/pallets/ddc-staking/README.md @@ -11,6 +11,6 @@ The DDC Staking module is the means by which an account can voluntarily place fu - DDC Staking: The process of locking up funds for some time in order to become a participant of the DDC. - Stash account: The account holding an owner's funds used for staking. - Controller account: The account that controls an owner's funds for staking. -- Edge: CDN participant. +- CDN: CDN network participant. - Storage: Storage network participant. - Era: A time period of DDC participants activity data capture and accumulation which will further be used to calculate pay outs. diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index f5454fc99..4183f0d39 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -34,7 +34,7 @@ benchmarks! { unbond { // clean up any existing state. - clear_storages_and_edges::(); + clear_storages_and_cdns::(); let (stash, controller, _) = create_stash_controller_node::(0, 100)?; let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; @@ -74,29 +74,29 @@ benchmarks! { } serve { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultEdgeBondSize::get())?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultCDNBondSize::get())?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) verify { - assert!(Edges::::contains_key(&stash)); + assert!(CDNs::::contains_key(&stash)); } chill { // clean up any existing state. - clear_storages_and_edges::(); + clear_storages_and_cdns::(); - let (edge_stash, edge_controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultEdgeBondSize::get())?; - DdcStaking::::serve(RawOrigin::Signed(edge_controller.clone()).into(), ClusterId::from([1; 20]))?; - assert!(Edges::::contains_key(&edge_stash)); + let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultCDNBondSize::get())?; + DdcStaking::::serve(RawOrigin::Signed(cdn_controller.clone()).into(), ClusterId::from([1; 20]))?; + assert!(CDNs::::contains_key(&cdn_stash)); CurrentEra::::put(1); - DdcStaking::::chill(RawOrigin::Signed(edge_controller.clone()).into())?; - CurrentEra::::put(1 + Settings::::get(ClusterId::from([1; 20])).edge_chill_delay); + DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; + CurrentEra::::put(1 + Settings::::get(ClusterId::from([1; 20])).cdn_chill_delay); - whitelist_account!(edge_controller); - }: _(RawOrigin::Signed(edge_controller)) + whitelist_account!(cdn_controller); + }: _(RawOrigin::Signed(cdn_controller)) verify { - assert!(!Edges::::contains_key(&edge_stash)); + assert!(!CDNs::::contains_key(&cdn_stash)); } set_controller { diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 6ef7d34af..df8e6639a 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -187,9 +187,9 @@ impl { /// The bond size required to become and maintain the role of a CDN participant. #[codec(compact)] - pub edge_bond_size: BalanceOf, + pub cdn_bond_size: BalanceOf, /// Number of eras should pass before a CDN participant can chill. - pub edge_chill_delay: EraIndex, + pub cdn_chill_delay: EraIndex, /// The bond size required to become and maintain the role of a storage network participant. #[codec(compact)] pub storage_bond_size: BalanceOf, @@ -201,8 +201,8 @@ impl Default for ClusterSettings { /// Default to the values specified in the runtime config. fn default() -> Self { Self { - edge_bond_size: T::DefaultEdgeBondSize::get(), - edge_chill_delay: T::DefaultEdgeChillDelay::get(), + cdn_bond_size: T::DefaultCDNBondSize::get(), + cdn_chill_delay: T::DefaultCDNChillDelay::get(), storage_bond_size: T::DefaultStorageBondSize::get(), storage_chill_delay: T::DefaultStorageChillDelay::get(), } @@ -224,11 +224,11 @@ pub mod pallet { /// Default bond size for a CDN participant. #[pallet::constant] - type DefaultEdgeBondSize: Get>; + type DefaultCDNBondSize: Get>; /// Default number or DDC eras required to pass before a CDN participant can chill. #[pallet::constant] - type DefaultEdgeChillDelay: Get; + type DefaultCDNChillDelay: Get; /// Default bond size for a storage network participant. #[pallet::constant] @@ -274,8 +274,8 @@ pub mod pallet { /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to /// participate into. #[pallet::storage] - #[pallet::getter(fn edges)] - pub type Edges = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; + #[pallet::getter(fn cdns)] + pub type CDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// The map of (wannabe) storage network participants stash keys to the DDC cluster ID they wish /// to participate into. @@ -318,8 +318,8 @@ pub mod pallet { /// /// See also [`pallet_staking::ErasRewardPoints`]. #[pallet::storage] - #[pallet::getter(fn eras_edges_reward_points)] - pub type ErasEdgesRewardPoints = + #[pallet::getter(fn eras_cdns_reward_points)] + pub type ErasCDNsRewardPoints = StorageMap<_, Twox64Concat, EraIndex, EraRewardPoints, ValueQuery>; /// The reward each CDN participant earned in the era. @@ -327,8 +327,8 @@ pub mod pallet { /// /// P.S. Not part of Mainnet #[pallet::storage] - #[pallet::getter(fn eras_edges_reward_points_per_node)] - pub type ErasEdgesRewardPointsPerNode = + #[pallet::getter(fn eras_cdns_reward_points_per_node)] + pub type ErasCDNsRewardPointsPerNode = StorageMap<_, Identity, T::AccountId, Vec, ValueQuery>; /// Price per byte of the bucket traffic in smallest units of the currency. @@ -348,7 +348,7 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { - pub edges: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, + pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, pub settings: Vec<(ClusterId, BalanceOf, EraIndex, BalanceOf, EraIndex)>, } @@ -357,7 +357,7 @@ pub mod pallet { impl Default for GenesisConfig { fn default() -> Self { GenesisConfig { - edges: Default::default(), + cdns: Default::default(), storages: Default::default(), settings: Default::default(), } @@ -370,8 +370,8 @@ pub mod pallet { // clusters' settings for &( cluster, - edge_bond_size, - edge_chill_delay, + cdn_bond_size, + cdn_chill_delay, storage_bond_size, storage_chill_delay, ) in &self.settings @@ -379,8 +379,8 @@ pub mod pallet { Settings::::insert( cluster, ClusterSettings:: { - edge_bond_size, - edge_chill_delay, + cdn_bond_size, + cdn_chill_delay, storage_bond_size, storage_chill_delay, }, @@ -388,7 +388,7 @@ pub mod pallet { } // Add initial CDN participants - for &(ref stash, ref controller, ref node, balance, cluster) in &self.edges { + for &(ref stash, ref controller, ref node, balance, cluster) in &self.cdns { assert!( T::Currency::free_balance(&stash) >= balance, "Stash do not have enough balance to participate in CDN." @@ -460,7 +460,7 @@ pub mod pallet { AlreadyPaired, /// Cannot have a storage network or CDN participant, with the size less than defined by /// governance (see `BondSize`). If unbonding is the intention, `chill` first to remove - /// one's role as storage/edge. + /// one's role as storage/cdn node. InsufficientBond, /// Can not schedule more unlock chunks. NoMoreChunks, @@ -611,7 +611,7 @@ pub mod pallet { ledger.active = Zero::zero(); } - let min_active_bond = if let Some(cluster_id) = Self::edges(&ledger.stash) { + let min_active_bond = if let Some(cluster_id) = Self::cdns(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; bond_size.saturated_into::>() @@ -697,7 +697,7 @@ pub mod pallet { /// `cluster` is the ID of the DDC cluster the participant wishes to join. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The - /// bond size must be greater than or equal to the `EdgeBondSize`. + /// bond size must be greater than or equal to the `CDNBondSize`. #[pallet::weight(T::WeightInfo::serve())] pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; @@ -720,7 +720,7 @@ pub mod pallet { ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::edges(&stash) { + if let Some(current_cluster) = Self::cdns(&stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -728,7 +728,7 @@ pub mod pallet { return Ok(()) } - Self::do_add_edge(stash, cluster_id); + Self::do_add_cdn(stash, cluster_id); Ok(()) } @@ -757,7 +757,7 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in storage network if already participating in CDN. - ensure!(!Edges::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!CDNs::::contains_key(&stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::storages(&stash) { @@ -799,8 +799,8 @@ pub mod pallet { }; // Extract delay from the cluster settings. - let (cluster, delay) = if let Some(cluster) = Self::edges(&ledger.stash) { - (cluster, Self::settings(cluster).edge_chill_delay) + let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { + (cluster, Self::settings(cluster).cdn_chill_delay) } else if let Some(cluster) = Self::storages(&ledger.stash) { (cluster, Self::settings(cluster).storage_chill_delay) } else { @@ -967,7 +967,7 @@ pub mod pallet { } // Ensure only one node per stash during the DDC era. - ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); >::insert(new_node, stash); @@ -986,7 +986,7 @@ pub mod pallet { let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; ensure!(stash == node_stash, Error::::NotNodeController); - let cluster_id = >::get(&stash) + let cluster_id = >::get(&stash) .or(>::get(&stash)) .ok_or(Error::::NodeHasNoStake)?; @@ -1005,7 +1005,7 @@ pub mod pallet { // ToDo: check that validation is finalised for era let era_reward_points: EraRewardPoints = - >::get(&era); + >::get(&era); let price_per_byte: u128 = match Self::pricing() { Some(pricing) => pricing, @@ -1079,8 +1079,8 @@ pub mod pallet { /// Chill a stash account. fn chill_stash(stash: &T::AccountId) { let chilled_as_storage = Self::do_remove_storage(stash); - let chilled_as_edge = Self::do_remove_edge(stash); - if chilled_as_storage || chilled_as_edge { + let chilled_as_cdn = Self::do_remove_cdn(stash); + if chilled_as_storage || chilled_as_cdn { Self::deposit_event(Event::::Chilled(stash.clone())); } } @@ -1118,25 +1118,25 @@ pub mod pallet { } Self::do_remove_storage(stash); - Self::do_remove_edge(stash); + Self::do_remove_cdn(stash); frame_system::Pallet::::dec_consumers(stash); Ok(()) } - /// This function will add a CDN participant to the `Edges` storage map. + /// This function will add a CDN participant to the `CDNs` storage map. /// /// If the CDN participant already exists, their cluster will be updated. - pub fn do_add_edge(who: &T::AccountId, cluster: ClusterId) { - Edges::::insert(who, cluster); + pub fn do_add_cdn(who: &T::AccountId, cluster: ClusterId) { + CDNs::::insert(who, cluster); } - /// This function will remove a CDN participant from the `Edges` map. + /// This function will remove a CDN participant from the `CDNs` map. /// - /// Returns true if `who` was removed from `Edges`, otherwise false. - pub fn do_remove_edge(who: &T::AccountId) -> bool { - Edges::::take(who).is_some() + /// Returns true if `who` was removed from `CDNs`, otherwise false. + pub fn do_remove_cdn(who: &T::AccountId) -> bool { + CDNs::::take(who).is_some() } /// This function will add a storage network participant to the `Storages` storage map. @@ -1166,7 +1166,7 @@ pub mod pallet { era: EraIndex, stakers_points: impl IntoIterator, ) { - >::mutate(era, |era_rewards| { + >::mutate(era, |era_rewards| { for (staker, points) in stakers_points.into_iter() { *era_rewards.individual.entry(staker).or_default() += points; era_rewards.total += points; @@ -1182,10 +1182,10 @@ pub mod pallet { ) -> Result { let stash = >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; - let maybe_edge_in_cluster = Edges::::get(&stash); + let maybe_cdn_in_cluster = CDNs::::get(&stash); let maybe_storage_in_cluster = Storages::::get(&stash); - let has_stake: bool = maybe_edge_in_cluster + let has_stake: bool = maybe_cdn_in_cluster .or(maybe_storage_in_cluster) .is_some_and(|staking_cluster| staking_cluster == *cluster_id); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index f009fec41..40a08cf37 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -93,8 +93,8 @@ impl pallet_timestamp::Config for Test { parameter_types! { pub const BondingDuration: EraIndex = 10; - pub const DefaultEdgeBondSize: Balance = 100; - pub const DefaultEdgeChillDelay: EraIndex = 1; + pub const DefaultCDNBondSize: Balance = 100; + pub const DefaultCDNChillDelay: EraIndex = 1; pub const DefaultStorageBondSize: Balance = 100; pub const DefaultStorageChillDelay: EraIndex = 1; pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); @@ -103,8 +103,8 @@ parameter_types! { impl crate::pallet::Config for Test { type BondingDuration = BondingDuration; type Currency = Balances; - type DefaultEdgeBondSize = DefaultEdgeBondSize; - type DefaultEdgeChillDelay = DefaultEdgeChillDelay; + type DefaultCDNBondSize = DefaultCDNBondSize; + type DefaultCDNChillDelay = DefaultCDNChillDelay; type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; @@ -132,28 +132,28 @@ impl ClusterVisitor for TestClusterVisitor { } } pub struct ExtBuilder { - has_edges: bool, + has_cdns: bool, has_storages: bool, stakes: BTreeMap, - edges: Vec<(AccountId, AccountId, Balance, ClusterId)>, + cdns: Vec<(AccountId, AccountId, Balance, ClusterId)>, storages: Vec<(AccountId, AccountId, Balance, ClusterId)>, } impl Default for ExtBuilder { fn default() -> Self { Self { - has_edges: true, + has_cdns: true, has_storages: true, stakes: Default::default(), - edges: Default::default(), + cdns: Default::default(), storages: Default::default(), } } } impl ExtBuilder { - pub fn has_edges(mut self, has: bool) -> Self { - self.has_edges = has; + pub fn has_cdns(mut self, has: bool) -> Self { + self.has_cdns = has; self } pub fn has_storages(mut self, has: bool) -> Self { @@ -164,14 +164,14 @@ impl ExtBuilder { self.stakes.insert(who, stake); self } - pub fn add_edge( + pub fn add_cdn( mut self, stash: AccountId, controller: AccountId, stake: Balance, cluster: ClusterId, ) -> Self { - self.edges.push((stash, controller, stake, cluster)); + self.cdns.push((stash, controller, stake, cluster)); self } pub fn add_storage( @@ -194,13 +194,13 @@ impl ExtBuilder { (2, 100), (3, 100), (4, 100), - // edge controllers + // cdn controllers (10, 100), (20, 100), // storage controllers (30, 100), (40, 100), - // edge stashes + // cdn stashes (11, 100), (21, 100), // storage stashes @@ -209,9 +209,9 @@ impl ExtBuilder { ], } .assimilate_storage(&mut storage); - let mut edges = vec![]; - if self.has_edges { - edges = vec![ + let mut cdns = vec![]; + if self.has_cdns { + cdns = vec![ // (stash, controller, node, stake, cluster) ( 11, @@ -250,7 +250,7 @@ impl ExtBuilder { ]; } - let _ = pallet_ddc_staking::GenesisConfig:: { edges, storages, ..Default::default() } + let _ = pallet_ddc_staking::GenesisConfig:: { cdns, storages, ..Default::default() } .assimilate_storage(&mut storage); TestExternalities::new(storage) diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 74e61221c..05f2a2bda 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -11,11 +11,11 @@ use sp_std::prelude::*; const SEED: u32 = 0; -/// This function removes all storage and edge nodes from storage. -pub fn clear_storages_and_edges() { +/// This function removes all storage and CDN nodes from storage. +pub fn clear_storages_and_cdns() { #[allow(unused_must_use)] { - Edges::::clear(u32::MAX, None); + CDNs::::clear(u32::MAX, None); Storages::::clear(u32::MAX, None); } } diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 2af19cce0..1fd702a07 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -18,15 +18,15 @@ fn set_settings_works() { RuntimeOrigin::root(), ClusterId::from([1; 20]), Some(ClusterSettings { - edge_bond_size: 10, - edge_chill_delay: 2, + cdn_bond_size: 10, + cdn_chill_delay: 2, storage_bond_size: 10, storage_chill_delay: 2, }), )); let settings = DdcStaking::settings(ClusterId::from([1; 20])); - assert_eq!(settings.edge_bond_size, 10); - assert_eq!(settings.edge_chill_delay, 2); + assert_eq!(settings.cdn_bond_size, 10); + assert_eq!(settings.cdn_chill_delay, 2); assert_eq!(settings.storage_bond_size, 10); assert_eq!(settings.storage_chill_delay, 2); @@ -34,8 +34,8 @@ fn set_settings_works() { assert_ok!(DdcStaking::set_settings(RuntimeOrigin::root(), ClusterId::from([1; 20]), None)); let settings = DdcStaking::settings(ClusterId::from([1; 20])); let default_settings: ClusterSettings = Default::default(); - assert_eq!(settings.edge_bond_size, default_settings.edge_bond_size); - assert_eq!(settings.edge_chill_delay, default_settings.edge_chill_delay); + assert_eq!(settings.cdn_bond_size, default_settings.cdn_bond_size); + assert_eq!(settings.cdn_chill_delay, default_settings.cdn_chill_delay); assert_eq!(settings.storage_bond_size, default_settings.storage_bond_size); assert_eq!(settings.storage_chill_delay, default_settings.storage_chill_delay); }); @@ -135,7 +135,7 @@ fn staking_should_work() { unlocking: Default::default(), }) ); - assert_eq!(DdcStaking::edges(3), Some(ClusterId::from([0; 20]))); + assert_eq!(DdcStaking::cdns(3), Some(ClusterId::from([0; 20]))); assert_eq!(DdcStaking::nodes(NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32]))), Some(3)); // Set `CurrentEra`. @@ -147,7 +147,7 @@ fn staking_should_work() { // Removal is scheduled, stashed value of 4 is still lock. let chilling = DdcStaking::current_era().unwrap() + - DdcStaking::settings(ClusterId::from([0; 20])).edge_chill_delay; + DdcStaking::settings(ClusterId::from([0; 20])).cdn_chill_delay; assert_eq!( DdcStaking::ledger(&4), Some(StakingLedger { @@ -185,7 +185,7 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Account 3 is no longer a CDN participant. - assert_eq!(DdcStaking::edges(3), None); + assert_eq!(DdcStaking::cdns(3), None); }); } diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 3b69615ab..50971c029 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -53,7 +53,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(4 as u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) @@ -74,7 +74,7 @@ impl WeightInfo for SubstrateWeight { } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) - // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { Weight::from_ref_time(26_112_000 as u64) @@ -84,7 +84,7 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking Edges (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:1) fn serve() -> Weight { Weight::from_ref_time(19_892_000 as u64) .saturating_add(T::DbWeight::get().reads(4 as u64)) @@ -92,7 +92,7 @@ impl WeightInfo for SubstrateWeight { } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) - // Storage: DdcStaking Edges (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:1) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { @@ -139,7 +139,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(4 as u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) @@ -160,7 +160,7 @@ impl WeightInfo for () { } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) - // Storage: DdcStaking Edges (r:1 w:0) + // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { Weight::from_ref_time(26_112_000 as u64) @@ -170,7 +170,7 @@ impl WeightInfo for () { // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking Edges (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:1) fn serve() -> Weight { Weight::from_ref_time(19_892_000 as u64) .saturating_add(RocksDbWeight::get().reads(4 as u64)) @@ -178,7 +178,7 @@ impl WeightInfo for () { } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) - // Storage: DdcStaking Edges (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:1) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 9898aad4c..7ca70d747 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1317,8 +1317,8 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { } parameter_types! { - pub const DefaultEdgeBondSize: Balance = 100 * DOLLARS; - pub const DefaultEdgeChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era + pub const DefaultCDNBondSize: Balance = 100 * DOLLARS; + pub const DefaultCDNChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era pub const DefaultStorageBondSize: Balance = 100 * DOLLARS; pub const DefaultStorageChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era } @@ -1326,8 +1326,8 @@ parameter_types! { impl pallet_ddc_staking::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; - type DefaultEdgeBondSize = DefaultEdgeBondSize; - type DefaultEdgeChillDelay = DefaultEdgeChillDelay; + type DefaultCDNBondSize = DefaultCDNBondSize; + type DefaultCDNChillDelay = DefaultCDNChillDelay; type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; From a3778b1660fa04820c262855d564c4bc9e11f583 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 14:34:24 +0100 Subject: [PATCH 462/544] remove cluster settings from ddc-staking; add get_chill_delay for cluster visitor --- Cargo.lock | 1 + pallets/ddc-clusters/src/lib.rs | 15 ++- pallets/ddc-staking/src/benchmarking.rs | 22 +--- pallets/ddc-staking/src/lib.rs | 166 ++---------------------- pallets/ddc-staking/src/mock.rs | 17 ++- pallets/ddc-staking/src/tests.rs | 71 +--------- pallets/ddc-staking/src/weights.rs | 26 ---- runtime/cere-dev/src/lib.rs | 4 - traits/Cargo.toml | 1 + traits/src/cluster.rs | 6 + 10 files changed, 44 insertions(+), 285 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 23c1bdd39..6661c7979 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1654,6 +1654,7 @@ dependencies = [ "frame-support", "frame-system", "sp-core", + "sp-staking", "sp-std", ] diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6a7c0549b..6a3954652 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -32,6 +32,7 @@ use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodeRepository, NodeTrait}; use sp_runtime::SaturatedConversion; +use sp_staking::EraIndex; use sp_std::prelude::*; mod cluster; @@ -253,8 +254,6 @@ pub mod pallet { cluster_id: &ClusterId, node_type: NodeType, ) -> Result { - // ensure!(ClustersNodes::::contains_key(cluster_id), - // Error::::ClusterDoesNotExist); let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { @@ -263,6 +262,18 @@ pub mod pallet { NodeType::CDN => Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), } } + + fn get_chill_delay( + cluster_id: &ClusterId, + node_type: NodeType, + ) -> Result { + let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; + match node_type { + NodeType::Storage => Ok(cluster_gov_params.storage_chill_delay), + NodeType::CDN => Ok(cluster_gov_params.cdn_chill_delay), + } + } } impl From for Error { diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 4183f0d39..9e1f1510d 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -2,7 +2,7 @@ use super::*; use crate::Pallet as DdcStaking; -use ddc_primitives::CDNNodePubKey; +use ddc_primitives::{CDNNodePubKey, NodeType}; use testing_utils::*; use frame_support::traits::{Currency, Get}; @@ -91,7 +91,7 @@ benchmarks! { assert!(CDNs::::contains_key(&cdn_stash)); CurrentEra::::put(1); DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; - CurrentEra::::put(1 + Settings::::get(ClusterId::from([1; 20])).cdn_chill_delay); + CurrentEra::::put(1 + T::ClusterVisitor::get_chill_delay(ClusterId::from([1; 20]), NodeType::CDN)); whitelist_account!(cdn_controller); }: _(RawOrigin::Signed(cdn_controller)) @@ -117,22 +117,4 @@ benchmarks! { verify { assert!(Nodes::::contains_key(&new_node)); } - - allow_cluster_manager { - let new_cluster_manager = create_funded_user::("cluster_manager", USER_SEED, 100); - let new_cluster_manager_lookup = T::Lookup::unlookup(new_cluster_manager.clone()); - }: _(RawOrigin::Root, new_cluster_manager_lookup) - verify { - assert!(ClusterManagers::::get().contains(&new_cluster_manager)); - } - - disallow_cluster_manager { - let new_cluster_manager = create_funded_user::("cluster_manager", USER_SEED, 100); - let new_cluster_manager_lookup = T::Lookup::unlookup(new_cluster_manager.clone()); - DdcStaking::::allow_cluster_manager(RawOrigin::Root.into(), new_cluster_manager_lookup.clone())?; - assert!(ClusterManagers::::get().contains(&new_cluster_manager)); - }: _(RawOrigin::Root, new_cluster_manager_lookup) - verify { - assert!(!ClusterManagers::::get().contains(&new_cluster_manager)); - } } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index df8e6639a..a4ab54c0c 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -181,34 +181,6 @@ impl { - /// The bond size required to become and maintain the role of a CDN participant. - #[codec(compact)] - pub cdn_bond_size: BalanceOf, - /// Number of eras should pass before a CDN participant can chill. - pub cdn_chill_delay: EraIndex, - /// The bond size required to become and maintain the role of a storage network participant. - #[codec(compact)] - pub storage_bond_size: BalanceOf, - /// Number of eras should pass before a storage network participant can chill. - pub storage_chill_delay: EraIndex, -} - -impl Default for ClusterSettings { - /// Default to the values specified in the runtime config. - fn default() -> Self { - Self { - cdn_bond_size: T::DefaultCDNBondSize::get(), - cdn_chill_delay: T::DefaultCDNChillDelay::get(), - storage_bond_size: T::DefaultStorageBondSize::get(), - storage_chill_delay: T::DefaultStorageChillDelay::get(), - } - } -} - #[frame_support::pallet] pub mod pallet { use super::*; @@ -222,22 +194,6 @@ pub mod pallet { pub trait Config: frame_system::Config { type Currency: LockableCurrency; - /// Default bond size for a CDN participant. - #[pallet::constant] - type DefaultCDNBondSize: Get>; - - /// Default number or DDC eras required to pass before a CDN participant can chill. - #[pallet::constant] - type DefaultCDNChillDelay: Get; - - /// Default bond size for a storage network participant. - #[pallet::constant] - type DefaultStorageBondSize: Get>; - - /// Default number or DDC eras required to pass before a storage participant can chill. - #[pallet::constant] - type DefaultStorageChillDelay: Get; - type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Number of eras that staked funds must remain bonded for. #[pallet::constant] @@ -259,12 +215,6 @@ pub mod pallet { #[pallet::getter(fn bonded)] pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; - /// DDC clusters staking settings. - #[pallet::storage] - #[pallet::getter(fn settings)] - pub type Settings = - StorageMap<_, Identity, ClusterId, ClusterSettings, ValueQuery>; - /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] @@ -336,11 +286,6 @@ pub mod pallet { #[pallet::getter(fn pricing)] pub type Pricing = StorageValue<_, u128>; - /// A list of accounts allowed to become cluster managers. - #[pallet::storage] - #[pallet::getter(fn cluster_managers)] - pub type ClusterManagers = StorageValue<_, Vec, ValueQuery>; - /// Map from DDC node ID to the node operator stash account. #[pallet::storage] #[pallet::getter(fn nodes)] @@ -350,43 +295,18 @@ pub mod pallet { pub struct GenesisConfig { pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, - pub settings: Vec<(ClusterId, BalanceOf, EraIndex, BalanceOf, EraIndex)>, } #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { - cdns: Default::default(), - storages: Default::default(), - settings: Default::default(), - } + GenesisConfig { cdns: Default::default(), storages: Default::default() } } } #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { - // clusters' settings - for &( - cluster, - cdn_bond_size, - cdn_chill_delay, - storage_bond_size, - storage_chill_delay, - ) in &self.settings - { - Settings::::insert( - cluster, - ClusterSettings:: { - cdn_bond_size, - cdn_chill_delay, - storage_bond_size, - storage_chill_delay, - }, - ); - } - // Add initial CDN participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.cdns { assert!( @@ -800,9 +720,14 @@ pub mod pallet { // Extract delay from the cluster settings. let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { - (cluster, Self::settings(cluster).cdn_chill_delay) + let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::CDN) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + (cluster, chill_delay) } else if let Some(cluster) = Self::storages(&ledger.stash) { - (cluster, Self::settings(cluster).storage_chill_delay) + let chill_delay = + T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + (cluster, chill_delay) } else { return Ok(()) // already chilled }; @@ -862,31 +787,6 @@ pub mod pallet { Ok(()) } - /// Set custom DDC staking settings for a particular cluster. - /// - /// * `settings` - The new settings for the cluster. If `None`, the settings will be removed - /// from the storage and default settings will be used. - /// - /// RuntimeOrigin must be Root to call this function. - /// - /// NOTE: Existing CDN and storage network participants will not be affected by this - /// settings update. - #[pallet::weight(10_000)] - pub fn set_settings( - origin: OriginFor, - cluster: ClusterId, - settings: Option>, - ) -> DispatchResult { - ensure_root(origin)?; - - match settings { - None => Settings::::remove(cluster), - Some(settings) => Settings::::insert(cluster, settings), - } - - Ok(()) - } - /// Pay out all the stakers for a single era. #[pallet::weight(100_000)] pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { @@ -903,56 +803,6 @@ pub mod pallet { Self::do_payout_stakers(era) } - /// Set price per byte of the bucket traffic in smallest units of the currency. - /// - /// The dispatch origin for this call must be _Root_. - #[pallet::weight(10_000)] - pub fn set_pricing(origin: OriginFor, price_per_byte: u128) -> DispatchResult { - ensure_root(origin)?; - >::set(Some(price_per_byte)); - Ok(()) - } - - /// Add a new account to the list of cluster managers. - /// - /// RuntimeOrigin must be Root to call this function. - #[pallet::weight(T::WeightInfo::allow_cluster_manager())] - pub fn allow_cluster_manager( - origin: OriginFor, - grantee: ::Source, - ) -> DispatchResult { - ensure_root(origin)?; - - let grantee = T::Lookup::lookup(grantee)?; - ClusterManagers::::mutate(|grantees| { - if !grantees.contains(&grantee) { - grantees.push(grantee); - } - }); - - Ok(()) - } - - /// Remove an account from the list of cluster managers. - /// - /// RuntimeOrigin must be Root to call this function. - #[pallet::weight(T::WeightInfo::disallow_cluster_manager())] - pub fn disallow_cluster_manager( - origin: OriginFor, - revokee: ::Source, - ) -> DispatchResult { - ensure_root(origin)?; - - let revokee = T::Lookup::lookup(revokee)?; - ClusterManagers::::mutate(|grantees| { - if let Some(pos) = grantees.iter().position(|g| g == &revokee) { - grantees.remove(pos); - } - }); - - Ok(()) - } - /// (Re-)set the DDC node of a node operator stash account. Requires to chill first. /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 40a08cf37..9d02c06aa 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -17,6 +17,7 @@ use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; +use sp_staking::EraIndex; use sp_std::collections::btree_map::BTreeMap; /// The AccountId alias in this test module. @@ -93,20 +94,12 @@ impl pallet_timestamp::Config for Test { parameter_types! { pub const BondingDuration: EraIndex = 10; - pub const DefaultCDNBondSize: Balance = 100; - pub const DefaultCDNChillDelay: EraIndex = 1; - pub const DefaultStorageBondSize: Balance = 100; - pub const DefaultStorageChillDelay: EraIndex = 1; pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); } impl crate::pallet::Config for Test { type BondingDuration = BondingDuration; type Currency = Balances; - type DefaultCDNBondSize = DefaultCDNBondSize; - type DefaultCDNChillDelay = DefaultCDNChillDelay; - type DefaultStorageBondSize = DefaultStorageBondSize; - type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; type UnixTime = Timestamp; type WeightInfo = (); @@ -130,6 +123,12 @@ impl ClusterVisitor for TestClusterVisitor { ) -> Result { Ok(10) } + fn get_chill_delay( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(10) + } } pub struct ExtBuilder { has_cdns: bool, @@ -250,7 +249,7 @@ impl ExtBuilder { ]; } - let _ = pallet_ddc_staking::GenesisConfig:: { cdns, storages, ..Default::default() } + let _ = pallet_ddc_staking::GenesisConfig:: { cdns, storages } .assimilate_storage(&mut storage); TestExternalities::new(storage) diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 1fd702a07..7ca84fdda 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,7 +1,8 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::CDNNodePubKey; +use ddc_primitives::{CDNNodePubKey, NodeType}; +use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; use frame_support::{ assert_noop, assert_ok, assert_storage_noop, error::BadOrigin, traits::ReservableCurrency, }; @@ -10,37 +11,6 @@ use pallet_balances::Error as BalancesError; pub const BLOCK_TIME: u64 = 1000; pub const INIT_TIMESTAMP: u64 = 30_000; -#[test] -fn set_settings_works() { - ExtBuilder::default().build_and_execute(|| { - // setting works - assert_ok!(DdcStaking::set_settings( - RuntimeOrigin::root(), - ClusterId::from([1; 20]), - Some(ClusterSettings { - cdn_bond_size: 10, - cdn_chill_delay: 2, - storage_bond_size: 10, - storage_chill_delay: 2, - }), - )); - let settings = DdcStaking::settings(ClusterId::from([1; 20])); - assert_eq!(settings.cdn_bond_size, 10); - assert_eq!(settings.cdn_chill_delay, 2); - assert_eq!(settings.storage_bond_size, 10); - assert_eq!(settings.storage_chill_delay, 2); - - // removing works - assert_ok!(DdcStaking::set_settings(RuntimeOrigin::root(), ClusterId::from([1; 20]), None)); - let settings = DdcStaking::settings(ClusterId::from([1; 20])); - let default_settings: ClusterSettings = Default::default(); - assert_eq!(settings.cdn_bond_size, default_settings.cdn_bond_size); - assert_eq!(settings.cdn_chill_delay, default_settings.cdn_chill_delay); - assert_eq!(settings.storage_bond_size, default_settings.storage_bond_size); - assert_eq!(settings.storage_chill_delay, default_settings.storage_chill_delay); - }); -} - #[test] fn basic_setup_works() { // Verifies initial conditions of mock @@ -76,9 +46,6 @@ fn basic_setup_works() { ); // Account 1 does not control any stash assert_eq!(DdcStaking::ledger(&1), None); - - // Cluster 1 settings are default - assert_eq!(DdcStaking::settings(ClusterId::from([1; 20])), Default::default()); }); } @@ -146,8 +113,9 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. - let chilling = DdcStaking::current_era().unwrap() + - DdcStaking::settings(ClusterId::from([0; 20])).cdn_chill_delay; + let chilling = DdcStaking::current_era().unwrap() + 10u32; + // ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) + // .unwrap_or(10_u32); assert_eq!( DdcStaking::ledger(&4), Some(StakingLedger { @@ -188,32 +156,3 @@ fn staking_should_work() { assert_eq!(DdcStaking::cdns(3), None); }); } - -#[test] -fn cluster_managers_list_can_be_managed_by_governance_only() { - ExtBuilder::default().build_and_execute(|| { - // Governance can allow an account to become cluster manager. - assert_ok!(DdcStaking::allow_cluster_manager(RuntimeOrigin::root(), 1)); - - // Repeat call does nothing. - assert_storage_noop!(assert_ok!(DdcStaking::allow_cluster_manager( - RuntimeOrigin::root(), - 1, - ))); - - // Non-governance can't allow an account to become a cluster manager. - assert_noop!(DdcStaking::allow_cluster_manager(RuntimeOrigin::signed(1), 2), BadOrigin); - - // Non-governance can't disallow an account to become a cluster manager. - assert_noop!(DdcStaking::disallow_cluster_manager(RuntimeOrigin::signed(1), 1), BadOrigin); - - // Governance can disallow an account to become a cluster manager. - assert_ok!(DdcStaking::disallow_cluster_manager(RuntimeOrigin::root(), 1)); - - // Repeat call does nothing. - assert_storage_noop!(assert_ok!(DdcStaking::disallow_cluster_manager( - RuntimeOrigin::root(), - 1, - ))); - }); -} diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 50971c029..969385330 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -36,8 +36,6 @@ pub trait WeightInfo { fn chill() -> Weight; fn set_controller() -> Weight; fn set_node() -> Weight; - fn allow_cluster_manager() -> Weight; - fn disallow_cluster_manager() -> Weight; } /// Weights for pallet_ddc_staking using the Substrate node and recommended hardware. @@ -113,18 +111,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } - // Storage: DdcStaking ClusterManagers (r:1 w:1) - fn allow_cluster_manager() -> Weight { - Weight::from_ref_time(11_727_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } - // Storage: DdcStaking ClusterManagers (r:1 w:1) - fn disallow_cluster_manager() -> Weight { - Weight::from_ref_time(18_006_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) - } } // For backwards compatibility and tests @@ -199,16 +185,4 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } - // Storage: DdcStaking ClusterManagers (r:1 w:1) - fn allow_cluster_manager() -> Weight { - Weight::from_ref_time(11_727_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) - } - // Storage: DdcStaking ClusterManagers (r:1 w:1) - fn disallow_cluster_manager() -> Weight { - Weight::from_ref_time(18_006_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) - } } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 7ca70d747..43dfb06da 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1326,10 +1326,6 @@ parameter_types! { impl pallet_ddc_staking::Config for Runtime { type BondingDuration = BondingDuration; type Currency = Balances; - type DefaultCDNBondSize = DefaultCDNBondSize; - type DefaultCDNChillDelay = DefaultCDNChillDelay; - type DefaultStorageBondSize = DefaultStorageBondSize; - type DefaultStorageChillDelay = DefaultStorageChillDelay; type RuntimeEvent = RuntimeEvent; type StakersPayoutSource = DdcCustomersPalletId; type UnixTime = Timestamp; diff --git a/traits/Cargo.toml b/traits/Cargo.toml index ef2bb96e9..b224e2d28 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index 99cd8be6b..4a8211f79 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,5 +1,6 @@ use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use frame_system::Config; +use sp_staking::EraIndex; pub trait ClusterVisitor { fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; @@ -10,6 +11,11 @@ pub trait ClusterVisitor { cluster_id: &ClusterId, node_type: NodeType, ) -> Result; + + fn get_chill_delay( + cluster_id: &ClusterId, + node_type: NodeType, + ) -> Result; } pub enum ClusterVisitorError { From 6b8e6c56fc612cda9bd6d8f77dfbfa95e71fb93d Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 18:47:12 +0100 Subject: [PATCH 463/544] replace era index with block number for ddc staking; cleanup code --- pallets/ddc-clusters/src/cluster.rs | 14 +- pallets/ddc-clusters/src/lib.rs | 19 +- pallets/ddc-customers/src/lib.rs | 6 +- pallets/ddc-staking/src/lib.rs | 332 ++++++---------------------- pallets/ddc-staking/src/mock.rs | 1 - pallets/ddc-staking/src/tests.rs | 6 +- runtime/cere-dev/src/lib.rs | 3 - traits/src/cluster.rs | 8 +- 8 files changed, 94 insertions(+), 295 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 7274fbf16..f940ce57e 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -4,7 +4,6 @@ use ddc_primitives::ClusterId; use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::Perbill; -use sp_staking::EraIndex; use sp_std::vec::Vec; parameter_types! { @@ -35,18 +34,17 @@ pub struct ClusterParams { // ClusterGovParams includes Governance sensetive parameters #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct ClusterGovParams { +#[scale_info(skip_type_params(Balance, BlockNumber, T))] +pub struct ClusterGovParams { pub treasury_share: Perbill, pub validators_share: Perbill, pub cluster_reserve_share: Perbill, - #[codec(compact)] pub cdn_bond_size: Balance, - pub cdn_chill_delay: EraIndex, - pub cdn_unbonding_delay: EraIndex, - #[codec(compact)] + pub cdn_chill_delay: BlockNumber, + pub cdn_unbonding_delay: BlockNumber, pub storage_bond_size: Balance, - pub storage_chill_delay: EraIndex, - pub storage_unbonding_delay: EraIndex, + pub storage_chill_delay: BlockNumber, + pub storage_unbonding_delay: BlockNumber, pub unit_per_mb_stored: u128, pub unit_per_mb_streamed: u128, pub unit_per_put_request: u128, diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6a3954652..78b79ca77 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -32,7 +32,6 @@ use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodeRepository, NodeTrait}; use sp_runtime::SaturatedConversion; -use sp_staking::EraIndex; use sp_std::prelude::*; mod cluster; @@ -96,7 +95,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn clusters_gov_params)] pub type ClustersGovParams = - StorageMap<_, Twox64Concat, ClusterId, ClusterGovParams>>; + StorageMap<_, Twox64Concat, ClusterId, ClusterGovParams, T::BlockNumber>>; #[pallet::storage] #[pallet::getter(fn clusters_nodes)] @@ -226,7 +225,7 @@ pub mod pallet { pub fn set_cluster_gov_params( origin: OriginFor, cluster_id: ClusterId, - cluster_gov_params: ClusterGovParams>, + cluster_gov_params: ClusterGovParams, T::BlockNumber>, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = @@ -266,7 +265,7 @@ pub mod pallet { fn get_chill_delay( cluster_id: &ClusterId, node_type: NodeType, - ) -> Result { + ) -> Result { let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { @@ -274,6 +273,18 @@ pub mod pallet { NodeType::CDN => Ok(cluster_gov_params.cdn_chill_delay), } } + + fn get_unbonding_delay( + cluster_id: &ClusterId, + node_type: NodeType, + ) -> Result { + let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; + match node_type { + NodeType::Storage => Ok(cluster_gov_params.storage_unbonding_delay), + NodeType::CDN => Ok(cluster_gov_params.cdn_unbonding_delay), + } + } } impl From for Error { diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index ce6bbb037..e3efdc5b1 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -376,8 +376,7 @@ pub mod pallet { ledger.active = Zero::zero(); } - let current_era = ddc_staking::pallet::Pallet::::current_era() - .ok_or(Error::::DDCEraNotSet)?; + let current_era = 0; // Note: locking for extra era to allow for accounting let era = current_era + ::LockingDuration::get(); log::debug!("Era for the unlock: {:?}", era); @@ -416,8 +415,7 @@ pub mod pallet { let owner = ensure_signed(origin)?; let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; let (owner, old_total) = (ledger.owner.clone(), ledger.total); - let current_era = - ddc_staking::pallet::Pallet::::current_era().ok_or(Error::::DDCEraNotSet)?; + let current_era = 0; ledger = ledger.consolidate_unlocked(current_era); log::debug!("Current era: {:?}", current_era); diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index a4ab54c0c..26fac2f84 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -41,7 +41,7 @@ use frame_support::{ parameter_types, traits::{ Currency, DefensiveSaturating, ExistenceRequirement, LockIdentifier, LockableCurrency, - UnixTime, WithdrawReasons, + WithdrawReasons, }, BoundedVec, PalletId, }; @@ -51,24 +51,12 @@ use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, RuntimeDebug, SaturatedConversion, }; -use sp_staking::EraIndex; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; pub use pallet::*; -/// Two minutes. -/// -/// If you are changing this, check `on_finalize` hook to ensure `CurrentEra` is capable to hold the -/// value with the new era duration. -pub const DDC_ERA_DURATION_MS: u128 = 120_000; - -/// 2023-01-01 00:00:00 UTC -pub const DDC_ERA_START_MS: u128 = 1_672_531_200_000; const DDC_STAKING_ID: LockIdentifier = *b"ddcstake"; // DDC maintainer's stake -/// Counter for the number of "reward" points earned by a given staker. -pub type RewardPoint = u64; - /// The balance type of this pallet. pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -78,52 +66,21 @@ parameter_types! { pub MaxUnlockingChunks: u32 = 32; } -/// Reward points of an era. Used to split era total payout between stakers. -#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] -pub struct EraRewardPoints { - /// Total number of points. Equals the sum of reward points for each staker. - pub total: RewardPoint, - /// The reward points earned by a given staker. - pub individual: BTreeMap, -} - -/// Reward points for particular era. To be used in a mapping. -#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] -pub struct EraRewardPointsPerNode { - /// Era points accrued - pub era: EraIndex, - /// Total number of points for node - pub points: RewardPoint, -} - -/// Reward paid for some era. -#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] -pub struct EraRewardsPaid { - /// Era number - pub era: EraIndex, - /// Cere tokens paid - pub reward: Balance, -} - -impl Default for EraRewardPoints { - fn default() -> Self { - EraRewardPoints { total: Default::default(), individual: BTreeMap::new() } - } -} - /// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct UnlockChunk { +#[scale_info(skip_type_params(T))] +pub struct UnlockChunk { /// Amount of funds to be unlocked. #[codec(compact)] value: Balance, - /// Era number at which point it'll be unlocked. + /// Block number at which point it'll be unlocked. #[codec(compact)] - era: EraIndex, + block: T::BlockNumber, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct StakingLedger { +#[scale_info(skip_type_params(T))] +pub struct StakingLedger { /// The stash account whose balance is actually locked and at stake. pub stash: AccountId, /// The total amount of the stash's balance that we are currently accounting for. @@ -134,16 +91,19 @@ pub struct StakingLedger { /// rounds. #[codec(compact)] pub active: Balance, - /// Era number at which chilling will be allowed. - pub chilling: Option, + /// Block number at which chilling will be allowed. + pub chilling: Option, /// Any balance that is becoming free, which may eventually be transferred out of the stash /// (assuming it doesn't get slashed first). It is assumed that this will be treated as a first - /// in, first out queue where the new (higher value) eras get pushed on the back. - pub unlocking: BoundedVec, MaxUnlockingChunks>, + /// in, first out queue where the new (higher value) blocks get pushed on the back. + pub unlocking: BoundedVec, MaxUnlockingChunks>, } -impl - StakingLedger +impl< + AccountId, + Balance: HasCompact + Copy + Saturating + AtLeast32BitUnsigned + Zero, + T: Config, + > StakingLedger { /// Initializes the default object using the given stash. pub fn default_from(stash: AccountId) -> Self { @@ -158,13 +118,13 @@ impl Self { + fn consolidate_unlocked(self, current_block: T::BlockNumber) -> Self { let mut total = self.total; let unlocking: BoundedVec<_, _> = self .unlocking .into_iter() .filter(|chunk| { - if chunk.era > current_era { + if chunk.block > current_block { true } else { total = total.saturating_sub(chunk.value); @@ -195,18 +155,10 @@ pub mod pallet { type Currency: LockableCurrency; type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// Number of eras that staked funds must remain bonded for. - #[pallet::constant] - type BondingDuration: Get; - /// To derive an account for withdrawing CDN rewards. - type StakersPayoutSource: Get; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; - /// Time used for computing era index. It is guaranteed to start being called from the first - /// `on_finalize`. - type UnixTime: UnixTime; - type ClusterVisitor: ClusterVisitor; } @@ -219,7 +171,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = - StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger>>; + StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to /// participate into. @@ -233,59 +185,6 @@ pub mod pallet { #[pallet::getter(fn storages)] pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// Map from all "stash" accounts to the total paid out rewards - /// - /// P.S. Not part of Mainnet - #[pallet::storage] - #[pallet::getter(fn rewards)] - pub type Rewards = StorageMap<_, Identity, T::AccountId, BalanceOf, ValueQuery>; - - /// Map from all "stash" accounts to the paid out rewards per era - /// - /// P.S. Not part of Mainnet - #[pallet::storage] - #[pallet::getter(fn paid_eras_per_node)] - pub type PaidErasPerNode = - StorageMap<_, Identity, T::AccountId, Vec>>, ValueQuery>; - - /// Map to check if CDN participants received payments for specific era - /// - /// Used to avoid double-spend in method [payout_stakers] - #[pallet::storage] - #[pallet::getter(fn paid_eras)] - pub(super) type PaidEras = StorageMap<_, Twox64Concat, EraIndex, bool, ValueQuery>; - - /// The current era index. - /// - /// This is the latest planned era, depending on how the Session pallet queues the validator - /// set, it might be active or not. - #[pallet::storage] - #[pallet::getter(fn current_era)] - pub type CurrentEra = StorageValue<_, EraIndex>; - - /// The reward each CDN participant earned in the era. - /// Mapping from Era to vector of CDN participants and respective rewards - /// - /// See also [`pallet_staking::ErasRewardPoints`]. - #[pallet::storage] - #[pallet::getter(fn eras_cdns_reward_points)] - pub type ErasCDNsRewardPoints = - StorageMap<_, Twox64Concat, EraIndex, EraRewardPoints, ValueQuery>; - - /// The reward each CDN participant earned in the era. - /// Mapping from each CDN participant to vector of eras and rewards - /// - /// P.S. Not part of Mainnet - #[pallet::storage] - #[pallet::getter(fn eras_cdns_reward_points_per_node)] - pub type ErasCDNsRewardPointsPerNode = - StorageMap<_, Identity, T::AccountId, Vec, ValueQuery>; - - /// Price per byte of the bucket traffic in smallest units of the currency. - #[pallet::storage] - #[pallet::getter(fn pricing)] - pub type Pricing = StorageValue<_, u128>; - /// Map from DDC node ID to the node operator stash account. #[pallet::storage] #[pallet::getter(fn nodes)] @@ -362,10 +261,8 @@ pub mod pallet { /// \[stash\] Chilled(T::AccountId), /// An account has declared desire to stop participating in CDN or storage network soon. - /// \[stash, cluster, era\] - ChillSoon(T::AccountId, ClusterId, EraIndex), - // Payout CDN nodes' stash accounts - PayoutNodes(EraIndex, EraRewardPoints, u128), + /// \[stash, cluster, block\] + ChillSoon(T::AccountId, ClusterId, T::BlockNumber), } #[pallet::error] @@ -391,18 +288,6 @@ pub mod pallet { AlreadyInRole, /// Action is allowed at some point of time in future not reached yet. TooEarly, - /// We are not yet sure that era has been valdiated by this time - EraNotValidated, - /// Attempt to assign reward point for some era more than once - DuplicateRewardPoints, - /// Attempt to double spend the assigned rewards per era - DoubleSpendRewards, - /// Pricing has not been set by sudo - PricingNotSet, - /// Payout amount overflows - BudgetOverflow, - /// Current era not set during runtime - DDCEraNotSet, /// Origin of the call is not a controller of the stake associated with the provided node. NotNodeController, /// No stake found associated with the provided node. @@ -413,21 +298,6 @@ pub mod pallet { FastChillProhibited, } - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_finalize(_n: BlockNumberFor) { - // Check if we have a new era and if so bump the current era index. - let now_as_millis = T::UnixTime::now().as_millis(); - let computed_era: EraIndex = - ((now_as_millis - DDC_ERA_START_MS) / DDC_ERA_DURATION_MS) as u32; // saturated - if Self::current_era() >= Some(computed_era) { - return - } - CurrentEra::::put(computed_era); - // ToDo: add `on_initialize` hook to track `on_finalize` weight - } - } - #[pallet::call] impl Pallet { /// Take the origin account as a stash and lock up `value` of its balance. `controller` will @@ -548,17 +418,29 @@ pub mod pallet { // cluster. If a user runs into this error, they should chill first. ensure!(ledger.active >= min_active_bond, Error::::InsufficientBond); - // Note: in case there is no current era it is fine to bond one era more. - let era = Self::current_era().unwrap_or(0) + T::BondingDuration::get(); - if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { - // To keep the chunk count down, we only keep one chunk per era. Since - // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will - // be the last one. + let unbonding_delay_in_blocks = if let Some(cluster_id) = Self::cdns(&ledger.stash) + { + T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? + } else if let Some(cluster_id) = Self::storages(&ledger.stash) { + T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::Storage) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? + } else { + T::BlockNumber::from(100_00u32) + }; + + let block = >::block_number() + unbonding_delay_in_blocks; + if let Some(chunk) = + ledger.unlocking.last_mut().filter(|chunk| chunk.block == block) + { + // To keep the chunk count down, we only keep one chunk per block. Since + // `unlocking` is a FiFo queue, if a chunk exists for `block` we know that it + // will be the last one. chunk.value = chunk.value.defensive_saturating_add(value) } else { ledger .unlocking - .try_push(UnlockChunk { value, era }) + .try_push(UnlockChunk { value, block }) .map_err(|_| Error::::NoMoreChunks)?; }; @@ -584,9 +466,8 @@ pub mod pallet { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); - if let Some(current_era) = Self::current_era() { - ledger = ledger.consolidate_unlocked(current_era) - } + + ledger = ledger.consolidate_unlocked(>::block_number()); if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() { // This account must have called `unbond()` with some value that caused the active @@ -698,13 +579,13 @@ pub mod pallet { /// Only in case the delay for the role _origin_ maintains in the cluster is set to zero in /// cluster settings, it removes the participant immediately. Otherwise, it requires at /// least two invocations to effectively remove the participant. The first invocation only - /// updates the [`Ledger`] to note the DDC era at which the participant may "chill" (current - /// era + the delay from the cluster settings). The second invocation made at the noted era - /// (or any further era) will remove the participant from the list of CDN or storage network - /// participants. If the cluster settings updated significantly decreasing the delay, one - /// may invoke it again to decrease the era at with the participant may "chill". But it - /// never increases the era at which the participant may "chill" even when the cluster - /// settings updated increasing the delay. + /// updates the [`Ledger`] to note the block number at which the participant may "chill" + /// (current block + the delay from the cluster settings). The second invocation made at the + /// noted block (or any further block) will remove the participant from the list of CDN or + /// storage network participants. If the cluster settings updated significantly decreasing + /// the delay, one may invoke it again to decrease the block at with the participant may + /// "chill". But it never increases the block at which the participant may "chill" even when + /// the cluster settings updated increasing the delay. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. /// @@ -713,10 +594,7 @@ pub mod pallet { pub fn chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - let current_era = match Self::current_era() { - Some(era) => era, - None => Err(Error::::TooEarly)?, // can't chill before the first era - }; + let current_block = >::block_number(); // Extract delay from the cluster settings. let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { @@ -732,13 +610,13 @@ pub mod pallet { return Ok(()) // already chilled }; - if delay == 0 { + if delay == T::BlockNumber::from(0u32) { // No delay is set, so we can chill right away. Self::chill_stash(&ledger.stash); return Ok(()) } - let can_chill_from = current_era.defensive_saturating_add(delay); + let can_chill_from = current_block.defensive_saturating_add(delay); match ledger.chilling { None => { // No previous declarations of desire to chill. Note it to allow chilling soon. @@ -751,7 +629,7 @@ pub mod pallet { Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from); return Ok(()) }, - Some(chilling) if chilling > current_era => Err(Error::::TooEarly)?, + Some(chilling) if chilling > current_block => Err(Error::::TooEarly)?, Some(_) => (), } @@ -764,7 +642,7 @@ pub mod pallet { /// (Re-)set the controller of a stash. /// - /// Effects will be felt at the beginning of the next era. + /// Effects will be felt at the beginning of the next block. /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. #[pallet::weight(T::WeightInfo::set_controller())] @@ -787,22 +665,6 @@ pub mod pallet { Ok(()) } - /// Pay out all the stakers for a single era. - #[pallet::weight(100_000)] - pub fn payout_stakers(origin: OriginFor, era: EraIndex) -> DispatchResult { - ensure_signed(origin)?; - let current_era = Self::current_era().ok_or(Error::::DDCEraNotSet)?; - - // Makes sure this era hasn't been paid out yet - ensure!(!Self::paid_eras(era), Error::::DoubleSpendRewards); - - // This should be adjusted based on the finality of validation - ensure!(current_era >= era + 2, Error::::EraNotValidated); - - PaidEras::::insert(era, true); - Self::do_payout_stakers(era) - } - /// (Re-)set the DDC node of a node operator stash account. Requires to chill first. /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. @@ -816,7 +678,7 @@ pub mod pallet { } } - // Ensure only one node per stash during the DDC era. + // Ensure only one node per stash. ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); @@ -825,7 +687,7 @@ pub mod pallet { Ok(()) } - /// Allow cluster node candidate to chill in the next DDC era. + /// Allow cluster node candidate to chill in the next block. /// /// The dispatch origin for this call must be _Signed_ by the controller. #[pallet::weight(10_000)] @@ -843,7 +705,8 @@ pub mod pallet { let is_cluster_node = T::ClusterVisitor::cluster_has_node(&cluster_id, &node_pub_key); ensure!(!is_cluster_node, Error::::FastChillProhibited); - let can_chill_from = Self::current_era().unwrap_or(0) + 1; + let can_chill_from = + >::block_number() + T::BlockNumber::from(1u32); Self::chill_stash_soon(&stash, &controller, cluster_id, can_chill_from); Ok(()) @@ -851,71 +714,12 @@ pub mod pallet { } impl Pallet { - pub fn do_payout_stakers(era: EraIndex) -> DispatchResult { - // ToDo: check that validation is finalised for era - - let era_reward_points: EraRewardPoints = - >::get(&era); - - let price_per_byte: u128 = match Self::pricing() { - Some(pricing) => pricing, - None => Err(Error::::PricingNotSet)?, - }; - - // An account we withdraw the funds from and the amount of funds to withdraw. - let payout_source_account: T::AccountId = - T::StakersPayoutSource::get().into_account_truncating(); - - // Transfer a part of the budget to each CDN participant rewarded this era. - for (stash, points) in era_reward_points.clone().individual { - let reward: BalanceOf = match (points as u128 * price_per_byte).try_into() { - Ok(value) => value, - Err(_) => Err(Error::::BudgetOverflow)?, - }; - log::debug!( - "Rewarding {:?} with {:?} points, reward size {:?}, balance \ - on payout source account {:?}", - stash, - points, - reward, - T::Currency::free_balance(&payout_source_account) - ); - T::Currency::transfer( - &payout_source_account, - &stash, - reward, - ExistenceRequirement::AllowDeath, - )?; // ToDo: all success or noop - Rewards::::mutate(&stash, |current_balance| { - *current_balance += reward; - }); - log::debug!("Total rewards to be inserted: {:?}", Self::rewards(&stash)); - PaidErasPerNode::::mutate(&stash, |current_rewards| { - let rewards = EraRewardsPaid { era, reward }; - current_rewards.push(rewards); - }); - } - Self::deposit_event(Event::::PayoutNodes( - era, - era_reward_points.clone(), - price_per_byte, - )); - log::debug!("Payout event executed"); - - log::debug!( - "Balance left on payout source account {:?}", - T::Currency::free_balance(&payout_source_account), - ); - - Ok(()) - } - /// Update the ledger for a controller. /// /// This will also update the stash lock. fn update_ledger( controller: &T::AccountId, - ledger: &StakingLedger>, + ledger: &StakingLedger, T>, ) { T::Currency::set_lock( DDC_STAKING_ID, @@ -940,7 +744,7 @@ pub mod pallet { stash: &T::AccountId, controller: &T::AccountId, cluster: ClusterId, - can_chill_from: EraIndex, + can_chill_from: T::BlockNumber, ) { Ledger::::mutate(&controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { @@ -1003,7 +807,7 @@ pub mod pallet { Storages::::take(who).is_some() } - /// Reset the chilling era for a controller. + /// Reset the chilling block for a controller. pub fn reset_chilling(controller: &T::AccountId) { Ledger::::mutate(&controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { @@ -1011,18 +815,6 @@ pub mod pallet { } }); } - /// Add reward points to CDN participants using their stash account ID. - pub fn reward_by_ids( - era: EraIndex, - stakers_points: impl IntoIterator, - ) { - >::mutate(era, |era_rewards| { - for (staker, points) in stakers_points.into_iter() { - *era_rewards.individual.entry(staker).or_default() += points; - era_rewards.total += points; - } - }); - } } impl StakingVisitor for Pallet { diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 9d02c06aa..9c96aa000 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -17,7 +17,6 @@ use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; -use sp_staking::EraIndex; use sp_std::collections::btree_map::BTreeMap; /// The AccountId alias in this test module. diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 7ca84fdda..7bc66787d 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -113,9 +113,9 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. - let chilling = DdcStaking::current_era().unwrap() + 10u32; - // ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) - // .unwrap_or(10_u32); + let chilling = DdcStaking::current_era().unwrap() + + TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) + .unwrap_or(10_u32); assert_eq!( DdcStaking::ledger(&4), Some(StakingLedger { diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 43dfb06da..b8b8b52d9 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1324,11 +1324,8 @@ parameter_types! { } impl pallet_ddc_staking::Config for Runtime { - type BondingDuration = BondingDuration; type Currency = Balances; type RuntimeEvent = RuntimeEvent; - type StakersPayoutSource = DdcCustomersPalletId; - type UnixTime = Timestamp; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; type ClusterVisitor = pallet_ddc_clusters::Pallet; } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index 4a8211f79..bbd21ed32 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,6 +1,5 @@ use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use frame_system::Config; -use sp_staking::EraIndex; pub trait ClusterVisitor { fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; @@ -15,7 +14,12 @@ pub trait ClusterVisitor { fn get_chill_delay( cluster_id: &ClusterId, node_type: NodeType, - ) -> Result; + ) -> Result; + + fn get_unbonding_delay( + cluster_id: &ClusterId, + node_type: NodeType, + ) -> Result; } pub enum ClusterVisitorError { From 9be9df7c840a48b2c93f36b2de5334a3ab0464f4 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 20:05:35 +0100 Subject: [PATCH 464/544] update logic for customer unlocks based on unlock delay in blocks --- Cargo.lock | 1 - pallets/ddc-customers/Cargo.toml | 1 - pallets/ddc-customers/src/lib.rs | 60 ++++++++++++++++---------------- pallets/ddc-staking/src/lib.rs | 11 +++--- runtime/cere-dev/src/lib.rs | 4 +-- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6661c7979..6059b927b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4943,7 +4943,6 @@ dependencies = [ "frame-support", "frame-system", "log", - "pallet-ddc-staking", "parity-scale-codec", "scale-info", "sp-io", diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 15e19a71f..48cdf287f 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -9,7 +9,6 @@ ddc-primitives = { version = "0.1.0", default-features = false, path = "../../pr ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-staking = { version = "4.7.0", default-features = false, path = "../ddc-staking" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index e3efdc5b1..d544ced22 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -10,13 +10,11 @@ use frame_support::{ traits::{Currency, DefensiveSaturating, ExistenceRequirement}, BoundedVec, PalletId, }; -pub use pallet_ddc_staking::{self as ddc_staking}; use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, RuntimeDebug, SaturatedConversion, }; -use sp_staking::EraIndex; use sp_std::prelude::*; pub use pallet::*; @@ -32,13 +30,14 @@ parameter_types! { /// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct UnlockChunk { +#[scale_info(skip_type_params(T))] +pub struct UnlockChunk { /// Amount of funds to be unlocked. #[codec(compact)] value: Balance, - /// Era number at which point it'll be unlocked. + /// Block number at which point it'll be unlocked. #[codec(compact)] - era: EraIndex, + block: T::BlockNumber, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -55,7 +54,8 @@ pub struct BucketsDetails { } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct AccountsLedger { +#[scale_info(skip_type_params(T))] +pub struct AccountsLedger { /// The owner account whose balance is actually locked and can be used for CDN usage. pub owner: AccountId, /// The total amount of the owner's balance that we are currently accounting for. @@ -70,11 +70,14 @@ pub struct AccountsLedger { /// (assuming that the content owner has to pay for network usage). It is assumed that this /// will be treated as a first in, first out queue where the new (higher value) eras get pushed /// on the back. - pub unlocking: BoundedVec, MaxUnlockingChunks>, + pub unlocking: BoundedVec, MaxUnlockingChunks>, } -impl - AccountsLedger +impl< + AccountId, + Balance: HasCompact + Copy + Saturating + AtLeast32BitUnsigned + Zero, + T: Config, + > AccountsLedger { /// Initializes the default object using the given owner. pub fn default_from(owner: AccountId) -> Self { @@ -83,14 +86,14 @@ impl Self { + fn consolidate_unlocked(self, current_block: T::BlockNumber) -> Self { let mut total = self.total; let unlocking: BoundedVec<_, _> = self .unlocking .into_iter() .filter(|chunk| { - log::debug!("Chunk era: {:?}", chunk.era); - if chunk.era > current_era { + log::debug!("Chunk era: {:?}", chunk.block); + if chunk.block > current_block { true } else { total = total.saturating_sub(chunk.value); @@ -146,7 +149,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + ddc_staking::Config { + pub trait Config: frame_system::Config { /// The accounts's pallet id, used for deriving its sovereign account ID. #[pallet::constant] type PalletId: Get; @@ -154,7 +157,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Number of eras that staked funds must remain locked for. #[pallet::constant] - type LockingDuration: Get; + type UnlockingDelay: Get<::BlockNumber>; type ClusterVisitor: ClusterVisitor; } @@ -162,7 +165,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = - StorageMap<_, Identity, T::AccountId, AccountsLedger>>; + StorageMap<_, Identity, T::AccountId, AccountsLedger, T>>; #[pallet::type_value] pub fn DefaultBucketCount() -> BucketId { @@ -214,8 +217,6 @@ pub mod pallet { NoBucketWithId, /// Internal state has become somehow corrupted and the operation cannot continue. BadState, - /// Current era not set during runtime - DDCEraNotSet, /// Bucket with specified id doesn't exist BucketDoesNotExist, /// DDC Cluster with provided id doesn't exist @@ -376,12 +377,14 @@ pub mod pallet { ledger.active = Zero::zero(); } - let current_era = 0; - // Note: locking for extra era to allow for accounting - let era = current_era + ::LockingDuration::get(); - log::debug!("Era for the unlock: {:?}", era); + let current_block = >::block_number(); + // Note: locking for extra block to allow for accounting + let block = current_block + ::UnlockingDelay::get(); + log::debug!("Block for the unlock: {:?}", block); - if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.era == era) { + if let Some(chunk) = + ledger.unlocking.last_mut().filter(|chunk| chunk.block == block) + { // To keep the chunk count down, we only keep one chunk per era. Since // `unlocking` is a FiFo queue, if a chunk exists for `era` we know that it will // be the last one. @@ -389,7 +392,7 @@ pub mod pallet { } else { ledger .unlocking - .try_push(UnlockChunk { value, era }) + .try_push(UnlockChunk { value, block }) .map_err(|_| Error::::NoMoreChunks)?; }; @@ -415,9 +418,8 @@ pub mod pallet { let owner = ensure_signed(origin)?; let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; let (owner, old_total) = (ledger.owner.clone(), ledger.total); - let current_era = 0; - ledger = ledger.consolidate_unlocked(current_era); - log::debug!("Current era: {:?}", current_era); + let current_block = >::block_number(); + ledger = ledger.consolidate_unlocked(current_block); if ledger.unlocking.is_empty() && ledger.active < ::Currency::minimum_balance() @@ -468,7 +470,7 @@ pub mod pallet { /// This will also deposit the funds to pallet. fn update_ledger_and_deposit( owner: &T::AccountId, - ledger: &AccountsLedger>, + ledger: &AccountsLedger, T>, ) -> DispatchResult { let account_id = Self::account_id(); @@ -486,7 +488,7 @@ pub mod pallet { /// Update the ledger for a owner. fn update_ledger( owner: &T::AccountId, - ledger: &AccountsLedger>, + ledger: &AccountsLedger, T>, ) { >::insert(owner, ledger); } @@ -523,7 +525,6 @@ pub mod pallet { ledger.total -= amount; ledger.active -= amount; total_charged += amount; - log::debug!("Ledger updated state: {:?}", &ledger); Self::update_ledger(&content_owner, &ledger); } else { let diff = amount - ledger.active; @@ -531,7 +532,6 @@ pub mod pallet { ledger.total -= ledger.active; ledger.active = BalanceOf::::zero(); let (ledger, charged) = ledger.charge_unlocking(diff); - log::debug!("Ledger updated state: {:?}", &ledger); Self::update_ledger(&content_owner, &ledger); total_charged += charged; } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 26fac2f84..fbc82d69b 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -39,19 +39,16 @@ use frame_support::{ assert_ok, pallet_prelude::*, parameter_types, - traits::{ - Currency, DefensiveSaturating, ExistenceRequirement, LockIdentifier, LockableCurrency, - WithdrawReasons, - }, - BoundedVec, PalletId, + traits::{Currency, DefensiveSaturating, LockIdentifier, LockableCurrency, WithdrawReasons}, + BoundedVec, }; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ - traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, + traits::{AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, RuntimeDebug, SaturatedConversion, }; -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +use sp_std::prelude::*; pub use pallet::*; diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index b8b8b52d9..6b2e35137 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1332,11 +1332,11 @@ impl pallet_ddc_staking::Config for Runtime { parameter_types! { pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake - pub const LockingDuration: sp_staking::EraIndex = 30 * 24; // 1 hour * 24 = 1 day; (1 era is 2 mins) + pub const UnlockingDelay: BlockNumber = 5256000u32; // 1 hour * 24 * 365 = 1 day; (1 hour is 600 blocks) } impl pallet_ddc_customers::Config for Runtime { - type LockingDuration = LockingDuration; + type UnlockingDelay = UnlockingDelay; type Currency = Balances; type PalletId = DdcCustomersPalletId; type RuntimeEvent = RuntimeEvent; From 21f5e5f513e69bbf342c1376eb090115f5f2df77 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 20:18:32 +0100 Subject: [PATCH 465/544] update error and storage params --- pallets/ddc-nodes/src/node.rs | 6 ++--- pallets/ddc-nodes/src/storage_node.rs | 33 +++++++++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 4d16b7fd8..25ab35f44 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -135,8 +135,7 @@ pub enum NodeError { InvalidCDNNodePubKey, InvalidStorageNodeParams, InvalidCDNNodeParams, - StorageNodeParamsExceedsLimit, - CDNNodeParamsExceedsLimit, + StorageHostLenExceedsLimit, CDNHostLenExceedsLimit, InvalidCDNNodeProps, InvalidStorageNodeProps, @@ -149,8 +148,7 @@ impl From for Error { NodeError::InvalidCDNNodePubKey => Error::::InvalidNodePubKey, NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, - NodeError::StorageNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, - NodeError::CDNNodeParamsExceedsLimit => Error::::NodeParamsExceedsLimit, + NodeError::StorageHostLenExceedsLimit => Error::::HostLenExceedsLimit, NodeError::CDNHostLenExceedsLimit => Error::::HostLenExceedsLimit, NodeError::InvalidStorageNodeProps => Error::::InvalidNodeParams, NodeError::InvalidCDNNodeProps => Error::::InvalidNodeParams, diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index f847c119f..578afeb09 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -8,6 +8,7 @@ use sp_std::prelude::Vec; parameter_types! { pub MaxStorageNodeParamsLen: u16 = 2048; + pub MaxHostLen: u8 = 255; } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -21,14 +22,18 @@ pub struct StorageNode { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeProps { - // this is a temporal way of storing node parameters as a stringified json, - // should be replaced with specific properties for this type of node once they are defined - pub params: BoundedVec, + pub host: BoundedVec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeParams { - pub params: Vec, // should be replaced with specific parameters for this type of node + pub host: Vec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, } impl NodeTrait for StorageNode { @@ -49,10 +54,15 @@ impl NodeTrait for StorageNode { Ok(()) } fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { - self.props.params = match node_params { - NodeParams::StorageParams(cdn_params) => match cdn_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), + match node_params { + NodeParams::StorageParams(storage_params) => { + self.props.host = match storage_params.host.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), + }; + self.props.http_port = storage_params.http_port; + self.props.grpc_port = storage_params.grpc_port; + self.props.p2p_port = storage_params.p2p_port; }, _ => return Err(NodeError::InvalidStorageNodeParams), }; @@ -79,10 +89,13 @@ impl NodeTrait for StorageNode { pub_key, cluster_id: None, props: StorageNodeProps { - params: match node_params.params.try_into() { + host: match node_params.host.try_into() { Ok(vec) => vec, - Err(_) => return Err(NodeError::StorageNodeParamsExceedsLimit), + Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), }, + http_port: node_params.http_port, + grpc_port: node_params.grpc_port, + p2p_port: node_params.p2p_port, }, })), _ => Err(NodeError::InvalidStorageNodeParams), From 9dbebe8f4d937c5694a91b6c0c77e703f084868c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 21:01:10 +0100 Subject: [PATCH 466/544] fix bechmarks & tests --- pallets/ddc-staking/src/mock.rs | 18 ++++++++---------- pallets/ddc-staking/src/tests.rs | 8 ++++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 9c96aa000..041a719a3 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -91,18 +91,10 @@ impl pallet_timestamp::Config for Test { type WeightInfo = (); } -parameter_types! { - pub const BondingDuration: EraIndex = 10; - pub const DdcAccountsPalletId: PalletId = PalletId(*b"accounts"); -} - impl crate::pallet::Config for Test { - type BondingDuration = BondingDuration; type Currency = Balances; type RuntimeEvent = RuntimeEvent; - type UnixTime = Timestamp; type WeightInfo = (); - type StakersPayoutSource = DdcAccountsPalletId; type ClusterVisitor = TestClusterVisitor; } @@ -125,8 +117,14 @@ impl ClusterVisitor for TestClusterVisitor { fn get_chill_delay( _cluster_id: &ClusterId, _node_type: NodeType, - ) -> Result { - Ok(10) + ) -> Result { + Ok(T::BlockNumber::from(10u32)) + } + fn get_unbonding_delay( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(T::BlockNumber::from(10u32)) } } pub struct ExtBuilder { diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 7bc66787d..10f325b46 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -113,9 +113,9 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. - let chilling = DdcStaking::current_era().unwrap() + - TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) - .unwrap_or(10_u32); + let chilling = System::block_number() + BlockNumber::from(10u64); + // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) + // .unwrap_or(10_u64); assert_eq!( DdcStaking::ledger(&4), Some(StakingLedger { @@ -131,7 +131,7 @@ fn staking_should_work() { assert_ok!(Balances::reserve(&3, 409)); // Set `CurrentEra` to the value allows us to chill. - while DdcStaking::current_era().unwrap() < chilling { + while System::block_number() < chilling { System::set_block_number(System::block_number() + 1); Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); DdcStaking::on_finalize(System::block_number()); From e991c83b6f387c09d2f9417a63b5411fabb76e7b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 8 Nov 2023 21:35:55 +0100 Subject: [PATCH 467/544] fix benchmarking for ddc-staking --- pallets/ddc-staking/src/benchmarking.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 9e1f1510d..d682ec9c0 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -53,7 +53,7 @@ benchmarks! { let (stash, controller, _) = create_stash_controller_node::(0, 100)?; let amount = T::Currency::minimum_balance() * 5u32.into(); // Half of total DdcStaking::::unbond(RawOrigin::Signed(controller.clone()).into(), amount)?; - CurrentEra::::put(EraIndex::max_value()); + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1000u32)); let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_total: BalanceOf = ledger.total; whitelist_account!(controller); @@ -65,7 +65,7 @@ benchmarks! { } store { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultStorageBondSize::get())?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -74,7 +74,7 @@ benchmarks! { } serve { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultCDNBondSize::get())?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -86,12 +86,12 @@ benchmarks! { // clean up any existing state. clear_storages_and_cdns::(); - let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::DefaultCDNBondSize::get())?; + let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; DdcStaking::::serve(RawOrigin::Signed(cdn_controller.clone()).into(), ClusterId::from([1; 20]))?; assert!(CDNs::::contains_key(&cdn_stash)); - CurrentEra::::put(1); + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; - CurrentEra::::put(1 + T::ClusterVisitor::get_chill_delay(ClusterId::from([1; 20]), NodeType::CDN)); + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(T::BlockNumber::from(10u32))); whitelist_account!(cdn_controller); }: _(RawOrigin::Signed(cdn_controller)) From 6d15896362c0c53c2bf3ec34951c68e1adadab68 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Thu, 9 Nov 2023 00:43:45 +0200 Subject: [PATCH 468/544] validation + node rewards --- pallets/ddc-payouts/src/lib.rs | 290 +++++++++++++++++++++++++++------ runtime/cere-dev/src/lib.rs | 1 + 2 files changed, 245 insertions(+), 46 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index f647f7047..8f7aefa98 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -15,21 +15,62 @@ #![recursion_limit = "256"] use ddc_primitives::{ClusterId, DdcEra}; -use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; +use frame_support::{ + pallet_prelude::*, + parameter_types, + sp_runtime::SaturatedConversion, + traits::{Currency, ExistenceRequirement, LockableCurrency}, + BoundedBTreeSet, +}; use frame_system::pallet_prelude::*; pub use pallet::*; use sp_runtime::Perbill; -use sp_std::{ops::Mul, prelude::*}; +use sp_std::prelude::*; type BatchIndex = u16; +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] +pub struct CustomerUsage { + pub transferred_bytes: u128, + pub stored_bytes: u128, + pub number_of_puts: u128, + pub number_of_gets: u128, +} + +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] +pub struct NodeUsage { + pub transferred_bytes: u128, + pub stored_bytes: u128, + pub number_of_puts: u128, + pub number_of_gets: u128, +} + +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] +pub struct NodeReward { + pub transfer: u128, + pub storage: u128, + pub puts: u128, + pub gets: u128, +} + +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] +pub struct CustomerCharge { + pub transfer: u128, + pub storage: u128, + pub puts: u128, + pub gets: u128, +} + +/// The balance type of this pallet. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + parameter_types! { pub MaxBatchesCount: u16 = 1000; } #[frame_support::pallet] pub mod pallet { - use super::*; use frame_support::PalletId; use sp_io::hashing::blake2_128; @@ -45,6 +86,8 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; #[pallet::constant] type PalletId: Get; + + type Currency: LockableCurrency; } #[pallet::event] @@ -52,22 +95,27 @@ pub mod pallet { pub enum Event { BillingReportInitialized { cluster_id: ClusterId, era: DdcEra }, ChargingStarted { cluster_id: ClusterId, era: DdcEra }, + Charged { cluster_id: ClusterId, era: DdcEra, customer_id: T::AccountId, amount: u128 }, ChargingFinished { cluster_id: ClusterId, era: DdcEra }, RewardingStarted { cluster_id: ClusterId, era: DdcEra }, + Rewarded { cluster_id: ClusterId, era: DdcEra, node_id: T::AccountId, amount: u128 }, RewardingFinished { cluster_id: ClusterId, era: DdcEra }, BillingReportFinalized { cluster_id: ClusterId, era: DdcEra }, } #[pallet::error] + #[derive(PartialEq)] pub enum Error { BillingReportDoesNotExist, NotExpectedState, + Unauthorised, BatchIndexAlreadyProcessed, BatchIndexIsOutOfRange, BatchesMissed, NotDistributedBalance, BatchIndexOverflow, BoundedVecOverflow, + ArithmeticOverflow, } #[pallet::storage] @@ -82,19 +130,26 @@ pub mod pallet { ValueQuery, >; + #[pallet::storage] + #[pallet::getter(fn dac_account)] + pub type DACAccount = StorageValue<_, T::AccountId>; + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(T))] pub struct BillingReport { state: State, vault: T::AccountId, - total_balance: u128, - distributed_balance: u128, + dac_account: Option, + total_charged_balance: u128, + total_distributed_balance: u128, + total_node_expected_reward: NodeReward, + total_node_expected_usage: NodeUsage, // stage 1 charging_max_batch_index: BatchIndex, - charging_processed_batches: BoundedVec, + charging_processed_batches: BoundedBTreeSet, // stage 2 rewarding_max_batch_index: BatchIndex, - rewarding_processed_batches: BoundedVec, + rewarding_processed_batches: BoundedBTreeSet, } impl Default for BillingReport { @@ -102,12 +157,15 @@ pub mod pallet { Self { state: State::default(), vault: T::PalletId::get().into_account_truncating(), - total_balance: Zero::zero(), - distributed_balance: Zero::zero(), + dac_account: Option::None, + total_charged_balance: Zero::zero(), + total_distributed_balance: Zero::zero(), + total_node_expected_usage: NodeUsage::default(), + total_node_expected_reward: NodeReward::default(), charging_max_batch_index: Zero::zero(), - charging_processed_batches: BoundedVec::default(), + charging_processed_batches: BoundedBTreeSet::default(), rewarding_max_batch_index: Zero::zero(), - rewarding_processed_batches: BoundedVec::default(), + rewarding_processed_batches: BoundedBTreeSet::default(), } } } @@ -132,7 +190,11 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, ) -> DispatchResult { - ensure_signed(origin)?; // todo: check that the caller is DAC account + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); let mut billing_report = BillingReport::default(); billing_report.vault = Self::sub_account_id(cluster_id.clone(), era); @@ -151,7 +213,11 @@ pub mod pallet { era: DdcEra, max_batch_index: BatchIndex, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); ensure!( max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), @@ -178,9 +244,13 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, batch_index: BatchIndex, - payers: Vec<(T::AccountId, u128)>, + payers: Vec<(T::AccountId, CustomerUsage)>, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -197,14 +267,31 @@ pub mod pallet { let mut updated_billing_report = billing_report.clone(); for payer in payers { - let _customer = payer.0; // todo: charge customer - let amount = payer.1; - updated_billing_report.total_balance += amount; + let customer_charge = + get_customer_charge(&payer.1).ok_or(Error::::ArithmeticOverflow)?; + let amount = (|| -> Option { + customer_charge + .transfer + .checked_add(customer_charge.storage)? + .checked_add(customer_charge.puts)? + .checked_add(customer_charge.gets) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + // todo: charge customer + let customer_id = payer.0; + + updated_billing_report + .total_charged_balance + .checked_add(amount) + .ok_or(Error::::ArithmeticOverflow)?; + + Self::deposit_event(Event::::Charged { cluster_id, era, customer_id, amount }); } updated_billing_report .charging_processed_batches - .try_push(batch_index) + .try_insert(batch_index) .map_err(|_| Error::::BoundedVecOverflow)?; ActiveBillingReports::::insert(cluster_id, era, updated_billing_report); @@ -218,17 +305,20 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ChargingCustomers, Error::::NotExpectedState); - ensure!( - billing_report.charging_max_batch_index as usize == - billing_report.charging_processed_batches.len() - 1usize, - Error::::BatchesMissed - ); + validate_batches::( + &billing_report.charging_processed_batches, + &billing_report.charging_max_batch_index, + )?; billing_report.state = State::CustomersCharged; ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); @@ -244,8 +334,13 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, max_batch_index: BatchIndex, + total_node_usage: NodeUsage, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); ensure!( max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), @@ -257,7 +352,12 @@ pub mod pallet { ensure!(billing_report.state == State::CustomersCharged, Error::::NotExpectedState); + let total = + get_total_usage_reward(&total_node_usage).ok_or(Error::::ArithmeticOverflow)?; + + billing_report.total_node_expected_usage = total_node_usage; billing_report.rewarding_max_batch_index = max_batch_index; + billing_report.total_node_expected_reward = total; billing_report.state = State::RewardingProviders; ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); @@ -272,9 +372,13 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, batch_index: BatchIndex, - payees: Vec<(T::AccountId, Perbill)>, + payees: Vec<(T::AccountId, NodeUsage)>, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -294,15 +398,41 @@ pub mod pallet { let mut updated_billing_report = billing_report.clone(); for payee in payees { - let _provider = payee.0; // todo: reward provider - let share = payee.1; - let amount = share.mul(billing_report.total_balance); - updated_billing_report.distributed_balance += amount; + let node_reward = get_node_reward( + &payee.1, + &billing_report.total_node_expected_usage, + &billing_report.total_node_expected_reward, + ); + let amount = (|| -> Option { + node_reward + .transfer + .checked_add(node_reward.storage)? + .checked_add(node_reward.puts)? + .checked_add(node_reward.gets) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + let node_id = payee.0; + let charge: BalanceOf = amount.saturated_into::>(); + + ::Currency::transfer( + &updated_billing_report.vault, + &node_id, + charge, + ExistenceRequirement::KeepAlive, + )?; + + updated_billing_report + .total_distributed_balance + .checked_add(amount) + .ok_or(Error::::ArithmeticOverflow)?; + + Self::deposit_event(Event::::Rewarded { cluster_id, era, node_id, amount }); } updated_billing_report .rewarding_processed_batches - .try_push(batch_index) + .try_insert(batch_index) .map_err(|_| Error::::BoundedVecOverflow)?; ActiveBillingReports::::insert(cluster_id, era, updated_billing_report); @@ -316,7 +446,11 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -325,11 +459,11 @@ pub mod pallet { billing_report.state == State::RewardingProviders, Error::::NotExpectedState ); - ensure!( - billing_report.rewarding_max_batch_index as usize == - billing_report.rewarding_processed_batches.len() - 1usize, - Error::::BatchesMissed - ); + + validate_batches::( + &billing_report.rewarding_processed_batches, + &billing_report.rewarding_max_batch_index, + )?; billing_report.state = State::ProvidersRewarded; ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); @@ -345,27 +479,91 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, ) -> DispatchResult { - ensure_signed(origin)?; + let caller = ensure_signed(origin)?; + ensure!( + Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Error::::Unauthorised + ); - let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ProvidersRewarded, Error::::NotExpectedState); ensure!( - billing_report.total_balance == billing_report.distributed_balance, + billing_report.total_charged_balance == billing_report.total_distributed_balance, Error::::NotDistributedBalance ); - billing_report.state = State::Finalized; - // todo: clear and archive billing_report - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); - + ActiveBillingReports::::remove(cluster_id.clone(), era); Self::deposit_event(Event::::BillingReportFinalized { cluster_id, era }); Ok(()) } } + fn get_node_reward( + node_usage: &NodeUsage, + total_usage: &NodeUsage, + total_reward: &NodeReward, + ) -> NodeReward { + let mut node_reward = NodeReward::default(); + + let mut ratio = + Perbill::from_rational(node_usage.transferred_bytes, total_usage.transferred_bytes); + node_reward.transfer = (ratio * total_reward.transfer) as u128; + + ratio = Perbill::from_rational(node_usage.stored_bytes, total_usage.stored_bytes); + node_reward.storage = (ratio * total_reward.storage) as u128; + + ratio = Perbill::from_rational(node_usage.number_of_puts, total_usage.number_of_puts); + node_reward.puts = (ratio * total_reward.puts) as u128; + + ratio = Perbill::from_rational(node_usage.number_of_gets, total_usage.number_of_gets); + node_reward.gets = (ratio * total_reward.gets) as u128; + + node_reward + } + + // todo: to calculate actual charge based on the metrics + fn get_total_usage_reward(total_usage: &NodeUsage) -> Option { + let mut total = NodeReward::default(); + + total.transfer = 1; + total.storage = 2; + total.puts = 3; + total.gets = 4; + + Option::Some(total) + } + + // todo: to calculate actual charge based on the metrics + fn get_customer_charge(usage: &CustomerUsage) -> Option { + let mut total = CustomerCharge::default(); + + total.transfer = 1; + total.storage = 2; + total.puts = 3; + total.gets = 4; + + Option::Some(total) + } + + fn validate_batches( + batches: &BoundedBTreeSet, + max_batch_index: &BatchIndex, + ) -> DispatchResult { + // Check if the Vec contains all integers between 1 and rewarding_max_batch_index + ensure!(!batches.is_empty(), Error::::BatchesMissed); + + ensure!(*max_batch_index as usize == batches.len() - 1usize, Error::::BatchesMissed); + + for index in 0..*max_batch_index { + ensure!(batches.contains(&index), Error::::BatchesMissed); + } + + Ok(()) + } + impl Pallet { fn account_id() -> T::AccountId { T::PalletId::get().into_account_truncating() diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 886ea9f25..4a2f02f63 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1381,6 +1381,7 @@ parameter_types! { impl pallet_ddc_payouts::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletId = PayoutsPalletId; + type Currency = Balances; } construct_runtime!( From 245f51e0a6f17a5ca3edbc193e96d06f7fa0694a Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Wed, 8 Nov 2023 23:58:28 +0100 Subject: [PATCH 469/544] chore: unused parameters removed --- runtime/cere-dev/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 6b2e35137..810c26d37 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -77,7 +77,6 @@ use sp_runtime::{ transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, }; -use sp_staking::EraIndex; use sp_std::prelude::*; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -1316,13 +1315,6 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { type RuntimeCall = RuntimeCall; } -parameter_types! { - pub const DefaultCDNBondSize: Balance = 100 * DOLLARS; - pub const DefaultCDNChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era - pub const DefaultStorageBondSize: Balance = 100 * DOLLARS; - pub const DefaultStorageChillDelay: EraIndex = 7 * 24 * 60 / 2; // approx. 1 week with 2 min DDC era -} - impl pallet_ddc_staking::Config for Runtime { type Currency = Balances; type RuntimeEvent = RuntimeEvent; From 4a939e1dce242037bda7b5c3b087db20a1ecae4b Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 9 Nov 2023 01:40:19 +0100 Subject: [PATCH 470/544] feat: cluster missing parameters added --- pallets/ddc-clusters/src/cluster.rs | 18 ++++-------------- pallets/ddc-clusters/src/lib.rs | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 7274fbf16..fa50f2411 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -1,11 +1,10 @@ use crate::pallet::Error; use codec::{Decode, Encode}; use ddc_primitives::ClusterId; -use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; +use frame_support::{pallet_prelude::*, parameter_types}; use scale_info::TypeInfo; use sp_runtime::Perbill; use sp_staking::EraIndex; -use sp_std::vec::Vec; parameter_types! { pub MaxClusterParamsLen: u16 = 2048; @@ -15,21 +14,18 @@ parameter_types! { pub struct Cluster { pub cluster_id: ClusterId, pub manager_id: AccountId, + pub reserve_id: AccountId, pub props: ClusterProps, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterProps { - // this is a temporal way of storing cluster parameters as a stringified json, - // should be replaced with specific properties for cluster - pub params: BoundedVec, pub node_provider_auth_contract: AccountId, } // ClusterParams includes Governance non-sensetive parameters only #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterParams { - pub params: Vec, pub node_provider_auth_contract: AccountId, } @@ -57,16 +53,14 @@ impl Cluster { pub fn new( cluster_id: ClusterId, manager_id: AccountId, + reserve_id: AccountId, cluster_params: ClusterParams, ) -> Result, ClusterError> { Ok(Cluster { cluster_id, manager_id, + reserve_id, props: ClusterProps { - params: match cluster_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(ClusterError::ClusterParamsExceedsLimit), - }, node_provider_auth_contract: cluster_params.node_provider_auth_contract, }, }) @@ -77,10 +71,6 @@ impl Cluster { cluster_params: ClusterParams, ) -> Result<(), ClusterError> { self.props = ClusterProps { - params: match cluster_params.params.try_into() { - Ok(vec) => vec, - Err(_) => return Err(ClusterError::ClusterParamsExceedsLimit), - }, node_provider_auth_contract: cluster_params.node_provider_auth_contract, }; Ok(()) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 6a7c0549b..b927958e1 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -118,14 +118,25 @@ pub mod pallet { pub fn create_cluster( origin: OriginFor, cluster_id: ClusterId, + cluster_manager_id: T::AccountId, + cluster_reserve_id: T::AccountId, cluster_params: ClusterParams, + cluster_gov_params: ClusterGovParams>, ) -> DispatchResult { - let caller_id = ensure_signed(origin)?; - let cluster = Cluster::new(cluster_id.clone(), caller_id, cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; + ensure_root(origin)?; // requires Governance approval + let cluster = Cluster::new( + cluster_id.clone(), + cluster_manager_id, + cluster_reserve_id, + cluster_params, + ) + .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); + Clusters::::insert(cluster_id.clone(), cluster); + ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); Self::deposit_event(Event::::ClusterCreated { cluster_id }); + Ok(()) } @@ -220,17 +231,16 @@ pub mod pallet { Ok(()) } - // Sets Governance sensetive parameters + // Requires Governance approval #[pallet::weight(10_000)] pub fn set_cluster_gov_params( origin: OriginFor, cluster_id: ClusterId, cluster_gov_params: ClusterGovParams>, ) -> DispatchResult { - let caller_id = ensure_signed(origin)?; - let cluster = + ensure_root(origin)?; // requires Governance approval + let _cluster = Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; - ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); Self::deposit_event(Event::::ClusterGovParamsSet { cluster_id }); @@ -253,8 +263,6 @@ pub mod pallet { cluster_id: &ClusterId, node_type: NodeType, ) -> Result { - // ensure!(ClustersNodes::::contains_key(cluster_id), - // Error::::ClusterDoesNotExist); let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { From 651ca808a65c9d0527b9b7fcb93944d1c1598f82 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Thu, 9 Nov 2023 19:20:46 +0100 Subject: [PATCH 471/544] add tests for ddc-node --- pallets/ddc-nodes/Cargo.toml | 2 + pallets/ddc-nodes/src/lib.rs | 5 + pallets/ddc-nodes/src/mock.rs | 114 ++++++++++++++++++++ pallets/ddc-nodes/src/tests.rs | 183 +++++++++++++++++++++++++++++++++ 4 files changed, 304 insertions(+) create mode 100644 pallets/ddc-nodes/src/mock.rs create mode 100644 pallets/ddc-nodes/src/tests.rs diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 607ab47fa..f3cc63163 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -18,6 +18,8 @@ sp-std = { version = "4.0.0-dev", default-features = false, git = "https://githu sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } [dev-dependencies] +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f0e881f7f..5dc0766ce 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -14,6 +14,11 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +#[cfg(test)] +pub(crate) mod mock; +#[cfg(test)] +mod tests; + use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, StorageNodePubKey}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; diff --git a/pallets/ddc-nodes/src/mock.rs b/pallets/ddc-nodes/src/mock.rs new file mode 100644 index 000000000..8a8002c0c --- /dev/null +++ b/pallets/ddc-nodes/src/mock.rs @@ -0,0 +1,114 @@ +//! Test utilities + +#![allow(dead_code)] + +use crate::{self as pallet_ddc_nodes, *}; +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64, Everything}, + weights::constants::RocksDbWeight, +}; +use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; +use sp_core::H256; +use sp_io::TestExternalities; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; + +/// The AccountId alias in this test module. +pub(crate) type AccountId = u64; +pub(crate) type AccountIndex = u64; +pub(crate) type BlockNumber = u64; +pub(crate) type Balance = u128; + +type UncheckedExtrinsic = MockUncheckedExtrinsic; +type Block = MockBlock; + +construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + DdcNodes: pallet_ddc_nodes::{Pallet, Call, Storage, Event}, + } +); + +parameter_types! { + pub static ExistentialDeposit: Balance = 1; +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = RocksDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type MaxLocks = ConstU32<1024>; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<5>; + type WeightInfo = (); +} + +impl crate::pallet::Config for Test { + type RuntimeEvent = RuntimeEvent; +} + +pub(crate) type TestRuntimeCall = ::RuntimeCall; + +pub struct ExtBuilder; + +impl ExtBuilder { + fn build(self) -> TestExternalities { + sp_tracing::try_init_simple(); + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let _ = pallet_balances::GenesisConfig:: { balances: vec![(1, 100), (2, 100)] } + .assimilate_storage(&mut storage); + + TestExternalities::new(storage) + } + pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + sp_tracing::try_init_simple(); + let mut ext = self.build(); + ext.execute_with(test); + } +} diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs new file mode 100644 index 000000000..9cbdc526c --- /dev/null +++ b/pallets/ddc-nodes/src/tests.rs @@ -0,0 +1,183 @@ +//! Tests for the module. + +use super::{mock::*, *}; +use crate::{cdn_node::CDNNodeParams, storage_node::StorageNodeParams}; +use ddc_primitives::NodePubKey; +use frame_support::{assert_noop, assert_ok}; +use sp_runtime::AccountId32; + +#[test] +fn create_node_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node params are not valid + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::StorageParams(StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::InvalidNodeParams + ); + + // Node created + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + )); + + // Node already exists + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params) + ), + Error::::NodeAlreadyExists + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 1); + System::assert_last_event( + Event::NodeCreated { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), + ) + }) +} + +#[test] +fn set_node_params_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let storage_node_params = StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node doesn't exist + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + ), + Error::::NodeDoesNotExist + ); + + // Node created + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + )); + + // Set node params + assert_ok!(DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + )); + + // Node params are not valid + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params) + ), + Error::::InvalidNodeParams + ); + + // Only node provider can set params + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(2), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + ), + Error::::OnlyNodeProvider + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event( + Event::NodeParamsChanged { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), + ) + }) +} + +#[test] +fn set_delete_node_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node doesn't exist + assert_noop!( + DdcNodes::delete_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()) + ), + Error::::NodeDoesNotExist + ); + + // Create node + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + )); + + // Only node provider can delete + assert_noop!( + DdcNodes::delete_node( + RuntimeOrigin::signed(2), + NodePubKey::CDNPubKey(node_pub_key.clone()) + ), + Error::::OnlyNodeProvider + ); + + // Delete node + assert_ok!(DdcNodes::delete_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + )); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event( + Event::NodeDeleted { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), + ) + }) +} From d30f4de6b2821c4e7aef5beb437af6b64b3ed579 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 9 Nov 2023 21:20:23 +0100 Subject: [PATCH 472/544] feat: checking node cluster_id while node provider chilling --- Cargo.lock | 1 + pallets/ddc-nodes/Cargo.toml | 1 + pallets/ddc-nodes/src/lib.rs | 11 +++++++++ pallets/ddc-staking/src/lib.rs | 45 ++++++++++++++++++++++++++++------ runtime/cere-dev/src/lib.rs | 1 + traits/src/lib.rs | 1 + traits/src/node.rs | 10 ++++++++ 7 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 traits/src/node.rs diff --git a/Cargo.lock b/Cargo.lock index 6059b927b..149864ce3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4983,6 +4983,7 @@ name = "pallet-ddc-nodes" version = "4.8.1" dependencies = [ "ddc-primitives", + "ddc-traits", "frame-benchmarking", "frame-support", "frame-system", diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 607ab47fa..65f5d098b 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f0e881f7f..6da1c7076 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -15,6 +15,7 @@ #![recursion_limit = "256"] use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, StorageNodePubKey}; +use ddc_traits::node::{NodeVisitor, NodeVisitorError}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_std::prelude::*; @@ -209,4 +210,14 @@ pub mod pallet { } } } + + impl NodeVisitor for Pallet { + fn get_cluster_id( + node_pub_key: &NodePubKey, + ) -> Result, NodeVisitorError> { + let node = + Self::get(node_pub_key.clone()).map_err(|_| NodeVisitorError::NodeDoesNotExist)?; + Ok(*node.get_cluster_id()) + } + } } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index fbc82d69b..3c00316c0 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -32,6 +32,7 @@ use codec::{Decode, Encode, HasCompact}; pub use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, + node::NodeVisitor, staking::{StakingVisitor, StakingVisitorError}, }; @@ -157,6 +158,8 @@ pub mod pallet { type WeightInfo: WeightInfo; type ClusterVisitor: ClusterVisitor; + + type NodeVisitor: NodeVisitor; } /// Map from all locked "stash" accounts to the controller account. @@ -187,6 +190,11 @@ pub mod pallet { #[pallet::getter(fn nodes)] pub type Nodes = StorageMap<_, Twox64Concat, NodePubKey, T::AccountId>; + /// Map from operator stash account to DDC node ID. + #[pallet::storage] + #[pallet::getter(fn providers)] + pub type Providers = StorageMap<_, Twox64Concat, T::AccountId, NodePubKey>; + #[pallet::genesis_config] pub struct GenesisConfig { pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, @@ -330,13 +338,14 @@ pub mod pallet { } // Reject a bond with a known DDC node. - if Nodes::::contains_key(&node) { + if Nodes::::contains_key(&node) || Providers::::contains_key(&stash) { Err(Error::::AlreadyPaired)? } frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; Nodes::::insert(&node, &stash); + Providers::::insert(&stash, &node); // You're auto-bonded forever, here. We might improve this by only bonding when // you actually store/serve and remove once you unbond __everything__. @@ -423,7 +432,27 @@ pub mod pallet { T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::Storage) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? } else { - T::BlockNumber::from(100_00u32) + let node_pub_key = + >::get(&ledger.stash).ok_or(Error::::BadState)?; + + match T::NodeVisitor::get_cluster_id(&node_pub_key) { + // If node is chilling within some cluster, the unbonding period should be + // set according to the cluster's settings + Ok(Some(cluster_id)) => match node_pub_key { + NodePubKey::CDNPubKey(_) => + T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, + NodePubKey::StoragePubKey(_) => T::ClusterVisitor::get_unbonding_delay( + &cluster_id, + NodeType::Storage, + ) + .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, + }, + // If node is not a member of any cluster, allow immediate unbonding. + // It is possible if node provider hasn't called 'store/serve' yet, or after + // the 'fast_chill' and subsequent 'chill' calls. + _ => T::BlockNumber::from(0u32), + } }; let block = >::block_number() + unbonding_delay_in_blocks; @@ -679,7 +708,8 @@ pub mod pallet { ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); - >::insert(new_node, stash); + >::insert(new_node.clone(), stash.clone()); + >::insert(stash, new_node); Ok(()) } @@ -688,10 +718,11 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller. #[pallet::weight(10_000)] - pub fn fast_chill(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { + pub fn fast_chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; let stash = >::get(&controller).ok_or(Error::::NotController)?.stash; + let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; ensure!(stash == node_stash, Error::::NotNodeController); @@ -764,9 +795,9 @@ pub mod pallet { >::remove(stash); >::remove(&controller); - if let Some((node, _)) = >::iter().find(|(_, v)| v == stash) { - >::remove(node); - } + if let Some(node_pub_key) = >::take(stash) { + >::remove(node_pub_key); + }; Self::do_remove_storage(stash); Self::do_remove_cdn(stash); diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 810c26d37..83331e687 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1320,6 +1320,7 @@ impl pallet_ddc_staking::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; type ClusterVisitor = pallet_ddc_clusters::Pallet; + type NodeVisitor = pallet_ddc_nodes::Pallet; } parameter_types! { diff --git a/traits/src/lib.rs b/traits/src/lib.rs index f6eb2b0a4..35d286602 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod cluster; +pub mod node; pub mod staking; diff --git a/traits/src/node.rs b/traits/src/node.rs new file mode 100644 index 000000000..af22b5a8b --- /dev/null +++ b/traits/src/node.rs @@ -0,0 +1,10 @@ +use ddc_primitives::{ClusterId, NodePubKey}; +use frame_system::Config; + +pub trait NodeVisitor { + fn get_cluster_id(node_pub_key: &NodePubKey) -> Result, NodeVisitorError>; +} + +pub enum NodeVisitorError { + NodeDoesNotExist, +} From 4553d156c9e5cf2c516d33b44e911d6062f8e923 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 9 Nov 2023 21:24:25 +0100 Subject: [PATCH 473/544] chore: version bump --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 83331e687..7e8be086a 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -129,7 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48012, + spec_version: 48013, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From ce406bf6e6fdf7850c705b13d32d2d0a690487f6 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Thu, 9 Nov 2023 22:36:21 +0100 Subject: [PATCH 474/544] fix: test compilation error is fixed --- pallets/ddc-staking/src/mock.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 041a719a3..c76b90dcb 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -4,7 +4,11 @@ use crate::{self as pallet_ddc_staking, *}; use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; -use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; +use ddc_traits::{ + cluster::{ClusterVisitor, ClusterVisitorError}, + node::{NodeVisitor, NodeVisitorError}, +}; + use frame_support::{ construct_runtime, traits::{ConstU32, ConstU64, Everything, GenesisBuild}, @@ -96,6 +100,7 @@ impl crate::pallet::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type ClusterVisitor = TestClusterVisitor; + type NodeVisitor = TestNodeVisitor; } pub(crate) type DdcStakingCall = crate::Call; @@ -127,6 +132,14 @@ impl ClusterVisitor for TestClusterVisitor { Ok(T::BlockNumber::from(10u32)) } } + +pub struct TestNodeVisitor; +impl NodeVisitor for TestNodeVisitor { + fn get_cluster_id(_node_pub_key: &NodePubKey) -> Result, NodeVisitorError> { + Ok(None) + } +} + pub struct ExtBuilder { has_cdns: bool, has_storages: bool, From 7e0fa8aee958c000f846a1d4041ec6b600f1ae46 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 12:40:08 +0300 Subject: [PATCH 475/544] Rerun cargo clippy fix --- .github/workflows/check.yaml | 2 +- pallets/ddc-clusters/src/lib.rs | 50 +++++++--------- pallets/ddc-customers/src/lib.rs | 4 +- pallets/ddc-nodes/src/lib.rs | 18 +++--- pallets/ddc-staking/src/lib.rs | 47 +++++++-------- pallets/ddc-staking/src/tests.rs | 10 ++-- pallets/ddc-staking/src/weights.rs | 96 +++++++++++++++--------------- runtime/cere-dev/src/lib.rs | 28 ++++----- runtime/cere/src/lib.rs | 28 ++++----- 9 files changed, 134 insertions(+), 149 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 27070bd99..1ecb04c4b 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -37,7 +37,7 @@ jobs: - name: Check with Clippy run: | - cargo clippy --all --all-targets -- -D warnings + cargo clippy --no-deps --all-targets --features runtime-benchmarks --workspace -- --deny warnings - name: Check Build run: | diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index cb4aafb7b..55d668f69 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -16,7 +16,7 @@ #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 use crate::{ - cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, + cluster::{Cluster, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; use ddc_primitives::{ClusterId, NodePubKey, NodeType}; @@ -124,17 +124,13 @@ pub mod pallet { cluster_gov_params: ClusterGovParams, T::BlockNumber>, ) -> DispatchResult { ensure_root(origin)?; // requires Governance approval - let cluster = Cluster::new( - cluster_id.clone(), - cluster_manager_id, - cluster_reserve_id, - cluster_params, - ) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); - - Clusters::::insert(cluster_id.clone(), cluster); - ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); + let cluster = + Cluster::new(cluster_id, cluster_manager_id, cluster_reserve_id, cluster_params) + .map_err(Into::>::into)?; + ensure!(!Clusters::::contains_key(cluster_id), Error::::ClusterAlreadyExists); + + Clusters::::insert(cluster_id, cluster); + ClustersGovParams::::insert(cluster_id, cluster_gov_params); Self::deposit_event(Event::::ClusterCreated { cluster_id }); Ok(()) @@ -148,7 +144,7 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); // Node with this node with this public key exists. @@ -158,12 +154,12 @@ pub mod pallet { // Sufficient funds are locked at the DDC Staking module. let has_stake = T::StakingVisitor::node_has_stake(&node_pub_key, &cluster_id) - .map_err(|e| Into::>::into(StakingVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!(has_stake, Error::::NodeHasNoStake); // Candidate is not planning to pause operations any time soon. let is_chilling = T::StakingVisitor::node_is_chilling(&node_pub_key) - .map_err(|e| Into::>::into(StakingVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!(!is_chilling, Error::::NodeChillingIsProhibited); // Cluster extension smart contract allows joining. @@ -177,13 +173,13 @@ pub mod pallet { node.get_pub_key().to_owned(), node.get_type(), ) - .map_err(|e| Into::>::into(NodeProviderAuthContractError::from(e)))?; + .map_err(Into::>::into)?; ensure!(is_authorized, Error::::NodeIsNotAuthorized); // Add node to the cluster. - node.set_cluster_id(Some(cluster_id.clone())); + node.set_cluster_id(Some(cluster_id)); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; - ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); + ClustersNodes::::insert(cluster_id, node_pub_key.clone(), true); Self::deposit_event(Event::::ClusterNodeAdded { cluster_id, node_pub_key }); Ok(()) @@ -197,7 +193,7 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; @@ -205,7 +201,7 @@ pub mod pallet { node.set_cluster_id(None); T::NodeRepository::update(node) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; - ClustersNodes::::remove(cluster_id.clone(), node_pub_key.clone()); + ClustersNodes::::remove(cluster_id, node_pub_key.clone()); Self::deposit_event(Event::::ClusterNodeRemoved { cluster_id, node_pub_key }); Ok(()) @@ -220,12 +216,10 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let mut cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - cluster - .set_params(cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - Clusters::::insert(cluster_id.clone(), cluster); + cluster.set_params(cluster_params).map_err(Into::>::into)?; + Clusters::::insert(cluster_id, cluster); Self::deposit_event(Event::::ClusterParamsSet { cluster_id }); Ok(()) @@ -240,8 +234,8 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; // requires Governance approval let _cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; - ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ClustersGovParams::::insert(cluster_id, cluster_gov_params); Self::deposit_event(Event::::ClusterGovParamsSet { cluster_id }); Ok(()) @@ -254,7 +248,7 @@ pub mod pallet { } fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { - Clusters::::get(&cluster_id) + Clusters::::get(cluster_id) .map(|_| ()) .ok_or(ClusterVisitorError::ClusterDoesNotExist) } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index d544ced22..f807f0985 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -333,7 +333,7 @@ pub mod pallet { Self::update_ledger_and_deposit(&owner, &ledger)?; - Self::deposit_event(Event::::Deposited(owner.clone(), extra)); + Self::deposit_event(Event::::Deposited(owner, extra)); Ok(()) } @@ -500,7 +500,7 @@ pub mod pallet { /// This is called: /// - after a `withdraw_unlocked_deposit()` call that frees all of a owner's locked balance. fn kill_owner(owner: &T::AccountId) -> DispatchResult { - >::remove(&owner); + >::remove(owner); frame_system::Pallet::::dec_consumers(owner); diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f0e881f7f..433aa114f 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -83,8 +83,8 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let node = Node::::new(node_pub_key.clone(), caller_id, node_params) - .map_err(|e| Into::>::into(NodeError::from(e)))?; - Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; + Self::create(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeCreated { node_pub_key }); Ok(()) } @@ -92,12 +92,10 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn delete_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let node = Self::get(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + let node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); - Self::delete(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + Self::delete(node_pub_key.clone()).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeDeleted { node_pub_key }); Ok(()) } @@ -109,12 +107,10 @@ pub mod pallet { node_params: NodeParams, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let mut node = Self::get(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + let mut node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); - node.set_params(node_params) - .map_err(|e| Into::>::into(NodeError::from(e)))?; - Self::update(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + node.set_params(node_params).map_err(Into::>::into)?; + Self::update(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeParamsChanged { node_pub_key }); Ok(()) } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index fbc82d69b..1eb4176a8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -206,7 +206,7 @@ pub mod pallet { // Add initial CDN participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.cdns { assert!( - T::Currency::free_balance(&stash) >= balance, + T::Currency::free_balance(stash) >= balance, "Stash do not have enough balance to participate in CDN." ); assert_ok!(Pallet::::bond( @@ -224,7 +224,7 @@ pub mod pallet { // Add initial storage network participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.storages { assert!( - T::Currency::free_balance(&stash) >= balance, + T::Currency::free_balance(stash) >= balance, "Stash do not have enough balance to participate in storage network." ); assert_ok!(Pallet::::bond( @@ -400,12 +400,12 @@ pub mod pallet { let min_active_bond = if let Some(cluster_id) = Self::cdns(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; bond_size.saturated_into::>() } else if let Some(cluster_id) = Self::storages(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; bond_size.saturated_into::>() } else { Zero::zero() @@ -418,12 +418,12 @@ pub mod pallet { let unbonding_delay_in_blocks = if let Some(cluster_id) = Self::cdns(&ledger.stash) { T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? + .map_err(Into::>::into)? } else if let Some(cluster_id) = Self::storages(&ledger.stash) { T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? + .map_err(Into::>::into)? } else { - T::BlockNumber::from(100_00u32) + T::BlockNumber::from(10_000_u32) }; let block = >::block_number() + unbonding_delay_in_blocks; @@ -500,13 +500,12 @@ pub mod pallet { pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; - T::ClusterVisitor::ensure_cluster(&cluster_id) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + T::ClusterVisitor::ensure_cluster(&cluster_id).map_err(Into::>::into)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!( ledger.active >= bond_size.saturated_into::>(), @@ -515,10 +514,10 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in CDN if already participating in storage network. - ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::cdns(&stash) { + if let Some(current_cluster) = Self::cdns(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -541,13 +540,12 @@ pub mod pallet { pub fn store(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; - T::ClusterVisitor::ensure_cluster(&cluster_id) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + T::ClusterVisitor::ensure_cluster(&cluster_id).map_err(Into::>::into)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!( ledger.active >= bond_size.saturated_into::>(), Error::::InsufficientBond @@ -555,10 +553,10 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in storage network if already participating in CDN. - ensure!(!CDNs::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::storages(&stash) { + if let Some(current_cluster) = Self::storages(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -596,12 +594,11 @@ pub mod pallet { // Extract delay from the cluster settings. let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; (cluster, chill_delay) } else if let Some(cluster) = Self::storages(&ledger.stash) { - let chill_delay = - T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) + .map_err(Into::>::into)?; (cluster, chill_delay) } else { return Ok(()) // already chilled @@ -743,7 +740,7 @@ pub mod pallet { cluster: ClusterId, can_chill_from: T::BlockNumber, ) { - Ledger::::mutate(&controller, |maybe_ledger| { + Ledger::::mutate(controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { ledger.chilling = Some(can_chill_from) } @@ -806,7 +803,7 @@ pub mod pallet { /// Reset the chilling block for a controller. pub fn reset_chilling(controller: &T::AccountId) { - Ledger::::mutate(&controller, |maybe_ledger| { + Ledger::::mutate(controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { ledger.chilling = None } @@ -820,7 +817,7 @@ pub mod pallet { cluster_id: &ClusterId, ) -> Result { let stash = - >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; + >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; let maybe_cdn_in_cluster = CDNs::::get(&stash); let maybe_storage_in_cluster = Storages::::get(&stash); @@ -833,7 +830,7 @@ pub mod pallet { fn node_is_chilling(node_pub_key: &NodePubKey) -> Result { let stash = - >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; + >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; let controller = >::get(&stash).ok_or(StakingVisitorError::NodeStakeIsInBadState)?; diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 10f325b46..37d971bca 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,11 +1,9 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{CDNNodePubKey, NodeType}; -use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; -use frame_support::{ - assert_noop, assert_ok, assert_storage_noop, error::BadOrigin, traits::ReservableCurrency, -}; +use ddc_primitives::CDNNodePubKey; + +use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; pub const BLOCK_TIME: u64 = 1000; @@ -113,7 +111,7 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. - let chilling = System::block_number() + BlockNumber::from(10u64); + let chilling = System::block_number() + 10u64; // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) // .unwrap_or(10_u64); assert_eq!( diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 969385330..efca88632 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -46,9 +46,9 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) + Weight::from_ref_time(55_007_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) @@ -57,36 +57,36 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000 as u64) - .saturating_add(T::DbWeight::get().reads(6 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(47_727_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(69_750_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(26_112_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(26_112_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(19_892_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(19_892_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) @@ -94,22 +94,22 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000 as u64) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + Weight::from_ref_time(77_450_000_u64) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(38_521_000_u64) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:1) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(21_779_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -120,9 +120,9 @@ impl WeightInfo for () { // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(4 as u64)) + Weight::from_ref_time(55_007_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) @@ -131,36 +131,36 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000 as u64) - .saturating_add(RocksDbWeight::get().reads(6 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(47_727_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(69_750_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(26_112_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(26_112_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(19_892_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(19_892_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) @@ -168,21 +168,21 @@ impl WeightInfo for () { // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000 as u64) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + Weight::from_ref_time(77_450_000_u64) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000 as u64) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(38_521_000_u64) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:1) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(21_779_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 810c26d37..d81288bfa 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -405,7 +405,7 @@ impl pallet_indices::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * DOLLARS; + pub const ExistentialDeposit: Balance = DOLLARS; // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; @@ -565,9 +565,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = 1 * DOLLARS; - pub const SignedDepositBase: Balance = 1 * DOLLARS; - pub const SignedDepositByte: Balance = 1 * CENTS; + pub const SignedRewardBase: Balance = DOLLARS; + pub const SignedDepositBase: Balance = DOLLARS; + pub const SignedDepositByte: Balance = CENTS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -722,11 +722,11 @@ impl pallet_bags_list::Config for Runtime { } parameter_types! { - pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; - pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const LaunchPeriod: BlockNumber = 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; pub const MinimumDeposit: Balance = 50_000 * DOLLARS; - pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const EnactmentPeriod: BlockNumber = 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; } @@ -804,7 +804,7 @@ parameter_types! { pub const CandidacyBond: Balance = 5_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); - pub const VotingBondFactor: Balance = 1 * DOLLARS; + pub const VotingBondFactor: Balance = DOLLARS; pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -876,12 +876,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 50_000 * DOLLARS; - pub const SpendPeriod: BlockNumber = 1 * DAYS; + pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(0); - pub const TipCountdown: BlockNumber = 1 * DAYS; + pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 50_000 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * DOLLARS; + pub const DataDepositPerByte: Balance = DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; @@ -917,7 +917,7 @@ parameter_types! { pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const BountyDepositBase: Balance = 50_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = 1 * DOLLARS; + pub const CuratorDepositMin: Balance = DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; pub const BountyDepositPayoutDelay: BlockNumber = 8 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; @@ -939,7 +939,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = 1 * DOLLARS; + pub const ChildBountyValueMinimum: Balance = DOLLARS; } impl pallet_child_bounties::Config for Runtime { @@ -1192,7 +1192,7 @@ impl pallet_society::Config for Runtime { } parameter_types! { - pub const MinVestedTransfer: Balance = 1 * DOLLARS; + pub const MinVestedTransfer: Balance = DOLLARS; } impl pallet_vesting::Config for Runtime { diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index be5ab085d..984ffb7bc 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -401,7 +401,7 @@ impl pallet_indices::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * DOLLARS; + pub const ExistentialDeposit: Balance = DOLLARS; // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; @@ -562,9 +562,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = 1 * DOLLARS; - pub const SignedDepositBase: Balance = 1 * DOLLARS; - pub const SignedDepositByte: Balance = 1 * CENTS; + pub const SignedRewardBase: Balance = DOLLARS; + pub const SignedDepositBase: Balance = DOLLARS; + pub const SignedDepositByte: Balance = CENTS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -719,11 +719,11 @@ impl pallet_bags_list::Config for Runtime { } parameter_types! { - pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; - pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const LaunchPeriod: BlockNumber = 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; pub const MinimumDeposit: Balance = 50_000 * DOLLARS; - pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const EnactmentPeriod: BlockNumber = 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; } @@ -801,7 +801,7 @@ parameter_types! { pub const CandidacyBond: Balance = 5_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); - pub const VotingBondFactor: Balance = 1 * DOLLARS; + pub const VotingBondFactor: Balance = DOLLARS; pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -873,12 +873,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 50_000 * DOLLARS; - pub const SpendPeriod: BlockNumber = 1 * DAYS; + pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(0); - pub const TipCountdown: BlockNumber = 1 * DAYS; + pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 50_000 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * DOLLARS; + pub const DataDepositPerByte: Balance = DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; @@ -914,7 +914,7 @@ parameter_types! { pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const BountyDepositBase: Balance = 50_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = 1 * DOLLARS; + pub const CuratorDepositMin: Balance = DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; pub const BountyDepositPayoutDelay: BlockNumber = 8 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; @@ -936,7 +936,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = 1 * DOLLARS; + pub const ChildBountyValueMinimum: Balance = DOLLARS; } impl pallet_child_bounties::Config for Runtime { @@ -1189,7 +1189,7 @@ impl pallet_society::Config for Runtime { } parameter_types! { - pub const MinVestedTransfer: Balance = 1 * DOLLARS; + pub const MinVestedTransfer: Balance = DOLLARS; } impl pallet_vesting::Config for Runtime { From 6b4b4ff2ed42f978ab5c8bcafe962c8bd5622b5a Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 10 Nov 2023 11:58:27 +0100 Subject: [PATCH 476/544] chore: using if/else instead of match --- pallets/ddc-staking/src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 3c00316c0..786962dd8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -435,10 +435,8 @@ pub mod pallet { let node_pub_key = >::get(&ledger.stash).ok_or(Error::::BadState)?; - match T::NodeVisitor::get_cluster_id(&node_pub_key) { - // If node is chilling within some cluster, the unbonding period should be - // set according to the cluster's settings - Ok(Some(cluster_id)) => match node_pub_key { + if let Ok(Some(cluster_id)) = T::NodeVisitor::get_cluster_id(&node_pub_key) { + match node_pub_key { NodePubKey::CDNPubKey(_) => T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, @@ -447,11 +445,10 @@ pub mod pallet { NodeType::Storage, ) .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, - }, + } + } else { // If node is not a member of any cluster, allow immediate unbonding. - // It is possible if node provider hasn't called 'store/serve' yet, or after - // the 'fast_chill' and subsequent 'chill' calls. - _ => T::BlockNumber::from(0u32), + T::BlockNumber::from(0u32) } }; From 9391237bc64467120a0ecb37c6e78df0e3730c7a Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 14:10:50 +0300 Subject: [PATCH 477/544] Refactor new method and remove lifetimes --- pallets/ddc-clusters/src/lib.rs | 2 +- pallets/ddc-nodes/src/cdn_node.rs | 65 ++++++++++++++------------- pallets/ddc-nodes/src/node.rs | 60 +++++++++---------------- pallets/ddc-nodes/src/storage_node.rs | 65 ++++++++++++++------------- primitives/src/lib.rs | 6 +-- 5 files changed, 93 insertions(+), 105 deletions(-) diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 55d668f69..4c52afd96 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -170,7 +170,7 @@ pub mod pallet { let is_authorized = auth_contract .is_authorized( node.get_provider_id().to_owned(), - node.get_pub_key().to_owned(), + node.get_pub_key(), node.get_type(), ) .map_err(Into::>::into)?; diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 5b3954953..1c8f19de1 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,4 +1,4 @@ -use crate::node::{Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait}; +use crate::node::{NodeError, NodeParams, NodeProps, NodePropsRef, NodeTrait}; use codec::{Decode, Encode}; use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; @@ -36,15 +36,44 @@ pub struct CDNNodeParams { pub p2p_port: u16, } +impl CDNNode { + pub fn new( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> Result { + match node_pub_key { + NodePubKey::CDNPubKey(pub_key) => match node_params { + NodeParams::CDNParams(node_params) => Ok(CDNNode:: { + provider_id, + pub_key, + cluster_id: None, + props: CDNNodeProps { + host: match node_params.host.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), + }, + http_port: node_params.http_port, + grpc_port: node_params.grpc_port, + p2p_port: node_params.p2p_port, + }, + }), + _ => Err(NodeError::InvalidCDNNodeParams), + }, + _ => Err(NodeError::InvalidCDNNodePubKey), + } + } +} + impl NodeTrait for CDNNode { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - NodePubKeyRef::CDNPubKeyRef(&self.pub_key) + fn get_pub_key(&self) -> NodePubKey { + NodePubKey::CDNPubKey(self.pub_key.clone()) } fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - NodePropsRef::CDNPropsRef(&self.props) + fn get_props(&self) -> NodePropsRef { + NodePropsRef::CDNPropsRef(self.props.clone()) } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { @@ -77,30 +106,4 @@ impl NodeTrait for CDNNode { fn get_type(&self) -> NodeType { NodeType::CDN } - fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result, NodeError> { - match node_pub_key { - NodePubKey::CDNPubKey(pub_key) => match node_params { - NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { - provider_id, - pub_key, - cluster_id: None, - props: CDNNodeProps { - host: match node_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), - }, - http_port: node_params.http_port, - grpc_port: node_params.grpc_port, - p2p_port: node_params.p2p_port, - }, - })), - _ => Err(NodeError::InvalidCDNNodeParams), - }, - _ => Err(NodeError::InvalidCDNNodePubKey), - } - } } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 3ea06bcf7..fbf962d1f 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -7,7 +7,7 @@ use crate::{ ClusterId, }; use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, NodePubKey, NodeType, StorageNodePubKey}; +use ddc_primitives::{NodePubKey, NodeType}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -32,46 +32,39 @@ pub enum NodeProps { } #[derive(Clone, RuntimeDebug, PartialEq)] -pub enum NodePubKeyRef<'a> { - StoragePubKeyRef(&'a StorageNodePubKey), - CDNPubKeyRef(&'a CDNNodePubKey), -} - -impl<'a> NodePubKeyRef<'a> { - pub fn to_owned(&self) -> NodePubKey { - match &self { - NodePubKeyRef::StoragePubKeyRef(pub_key_ref) => - NodePubKey::StoragePubKey((**pub_key_ref).clone()), - NodePubKeyRef::CDNPubKeyRef(pub_key_ref) => - NodePubKey::CDNPubKey((**pub_key_ref).clone()), - } - } -} - -#[derive(Clone, RuntimeDebug, PartialEq)] -pub enum NodePropsRef<'a> { - StoragePropsRef(&'a StorageNodeProps), - CDNPropsRef(&'a CDNNodeProps), +pub enum NodePropsRef { + StoragePropsRef(StorageNodeProps), + CDNPropsRef(CDNNodeProps), } pub trait NodeTrait { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; + fn get_pub_key(&self) -> NodePubKey; fn get_provider_id(&self) -> &T::AccountId; - fn get_props<'a>(&'a self) -> NodePropsRef<'a>; + fn get_props(&self) -> NodePropsRef; fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; fn get_cluster_id(&self) -> &Option; fn set_cluster_id(&mut self, cluster_id: Option); fn get_type(&self) -> NodeType; - fn new( +} + +impl Node { + pub fn new( node_pub_key: NodePubKey, provider_id: T::AccountId, - params: NodeParams, - ) -> Result, NodeError>; + node_params: NodeParams, + ) -> Result { + match node_pub_key { + NodePubKey::StoragePubKey(_) => + StorageNode::new(node_pub_key, provider_id, node_params).map(|n| Node::Storage(n)), + NodePubKey::CDNPubKey(_) => + CDNNode::new(node_pub_key, provider_id, node_params).map(|n| Node::CDN(n)), + } + } } impl NodeTrait for Node { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + fn get_pub_key(&self) -> NodePubKey { match &self { Node::Storage(node) => node.get_pub_key(), Node::CDN(node) => node.get_pub_key(), @@ -83,7 +76,7 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_provider_id(), } } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + fn get_props(&self) -> NodePropsRef { match &self { Node::Storage(node) => node.get_props(), Node::CDN(node) => node.get_props(), @@ -119,17 +112,6 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_type(), } } - fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result, NodeError> { - match node_pub_key { - NodePubKey::StoragePubKey(_) => - StorageNode::new(node_pub_key, provider_id, node_params), - NodePubKey::CDNPubKey(_) => CDNNode::new(node_pub_key, provider_id, node_params), - } - } } pub enum NodeError { diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 578afeb09..83fd2b11f 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,4 +1,4 @@ -use crate::node::{Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait}; +use crate::node::{NodeError, NodeParams, NodeProps, NodePropsRef, NodeTrait}; use codec::{Decode, Encode}; use ddc_primitives::{ClusterId, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; @@ -36,15 +36,44 @@ pub struct StorageNodeParams { pub p2p_port: u16, } +impl StorageNode { + pub fn new( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> Result { + match node_pub_key { + NodePubKey::StoragePubKey(pub_key) => match node_params { + NodeParams::StorageParams(node_params) => Ok(StorageNode:: { + provider_id, + pub_key, + cluster_id: None, + props: StorageNodeProps { + host: match node_params.host.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), + }, + http_port: node_params.http_port, + grpc_port: node_params.grpc_port, + p2p_port: node_params.p2p_port, + }, + }), + _ => Err(NodeError::InvalidStorageNodeParams), + }, + _ => Err(NodeError::InvalidStorageNodePubKey), + } + } +} + impl NodeTrait for StorageNode { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - NodePubKeyRef::StoragePubKeyRef(&self.pub_key) + fn get_pub_key(&self) -> NodePubKey { + NodePubKey::StoragePubKey(self.pub_key.clone()) } fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - NodePropsRef::StoragePropsRef(&self.props) + fn get_props(&self) -> NodePropsRef { + NodePropsRef::StoragePropsRef(self.props.clone()) } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { @@ -77,30 +106,4 @@ impl NodeTrait for StorageNode { fn get_type(&self) -> NodeType { NodeType::Storage } - fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result, NodeError> { - match node_pub_key { - NodePubKey::StoragePubKey(pub_key) => match node_params { - NodeParams::StorageParams(node_params) => Ok(Node::Storage(StorageNode:: { - provider_id, - pub_key, - cluster_id: None, - props: StorageNodeProps { - host: match node_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), - }, - http_port: node_params.http_port, - grpc_port: node_params.grpc_port, - p2p_port: node_params.p2p_port, - }, - })), - _ => Err(NodeError::InvalidStorageNodeParams), - }, - _ => Err(NodeError::InvalidStorageNodePubKey), - } - } } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index a3abee7c4..0564f3c16 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -11,6 +11,9 @@ use sp_runtime::{AccountId32, RuntimeDebug}; pub type ClusterId = H160; pub type BucketId = u64; +pub type StorageNodePubKey = AccountId32; +pub type CDNNodePubKey = AccountId32; + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { @@ -18,9 +21,6 @@ pub enum NodePubKey { CDNPubKey(CDNNodePubKey), } -pub type StorageNodePubKey = AccountId32; -pub type CDNNodePubKey = AccountId32; - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeType { Storage = 1, From 1f6a317b5e97ec105dc6817205dc8a1f0b991d77 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 14:11:02 +0300 Subject: [PATCH 478/544] Resolve clippy warnings --- node/service/src/lib.rs | 2 ++ pallets/ddc-staking/src/benchmarking.rs | 4 ++-- pallets/ddc-staking/src/lib.rs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 68e5386a6..ee62d08d1 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -103,6 +103,7 @@ where Ok(Basics { task_manager, client, backend, keystore_container, telemetry }) } +#[allow(clippy::type_complexity)] fn new_partial( config: &Configuration, Basics { task_manager, backend, client, keystore_container, telemetry }: Basics< @@ -628,6 +629,7 @@ macro_rules! chain_ops { }}; } +#[allow(clippy::type_complexity)] pub fn new_chain_ops( config: &Configuration, ) -> Result< diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index d682ec9c0..6353e4a5d 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -5,7 +5,7 @@ use crate::Pallet as DdcStaking; use ddc_primitives::{CDNNodePubKey, NodeType}; use testing_utils::*; -use frame_support::traits::{Currency, Get}; +use frame_support::traits::Currency; use sp_runtime::traits::StaticLookup; use sp_std::prelude::*; @@ -91,7 +91,7 @@ benchmarks! { assert!(CDNs::::contains_key(&cdn_stash)); frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; - frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(T::BlockNumber::from(10u32))); + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or_else(|_| T::BlockNumber::from(10u32))); whitelist_account!(cdn_controller); }: _(RawOrigin::Signed(cdn_controller)) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 1eb4176a8..9c270570c 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -189,7 +189,9 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { + #[allow(clippy::type_complexity)] pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, + #[allow(clippy::type_complexity)] pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, } @@ -693,7 +695,7 @@ pub mod pallet { ensure!(stash == node_stash, Error::::NotNodeController); let cluster_id = >::get(&stash) - .or(>::get(&stash)) + .or_else(|| >::get(&stash)) .ok_or(Error::::NodeHasNoStake)?; let is_cluster_node = T::ClusterVisitor::cluster_has_node(&cluster_id, &node_pub_key); From 8107abc1125ed2965426e6059f5c59ee3cfdeac9 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 14:44:49 +0300 Subject: [PATCH 479/544] Check for unused dependencies --- .github/workflows/check.yaml | 3 + Cargo.lock | 73 ------------------- Cargo.toml | 1 - node/client/Cargo.toml | 3 - node/service/Cargo.toml | 8 +- pallets/chainbridge/Cargo.toml | 8 -- pallets/ddc-clusters/Cargo.toml | 9 --- pallets/ddc-customers/Cargo.toml | 4 - .../ddc-metrics-offchain-worker/Cargo.toml | 4 - pallets/ddc-nodes/Cargo.toml | 9 --- pallets/ddc-staking/Cargo.toml | 3 - pallets/ddc/Cargo.toml | 3 + pallets/erc20/Cargo.toml | 9 +-- pallets/erc721/Cargo.toml | 6 -- runtime/cere-dev/Cargo.toml | 2 - runtime/cere-dev/constants/Cargo.toml | 3 +- runtime/cere/Cargo.toml | 3 +- runtime/cere/constants/Cargo.toml | 3 +- traits/Cargo.toml | 4 - 19 files changed, 13 insertions(+), 145 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 1ecb04c4b..9bdc50136 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -32,6 +32,9 @@ jobs: run: | cargo fmt -- --check + - name: Unused dependencies + uses: bnjbvr/cargo-machete@main + - name: Rust Cache uses: Swatinem/rust-cache@v2 diff --git a/Cargo.lock b/Cargo.lock index 6059b927b..861333611 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -759,7 +759,6 @@ version = "4.8.1" dependencies = [ "cere-cli", "sc-cli", - "ss58-registry", "substrate-build-script-utils", ] @@ -785,7 +784,6 @@ dependencies = [ "cere-dev-runtime", "cere-runtime", "frame-benchmarking", - "frame-benchmarking-cli", "frame-system", "frame-system-rpc-runtime-api", "node-primitives", @@ -801,10 +799,8 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-core", "sp-finality-grandpa", "sp-inherents", - "sp-keyring", "sp-offchain", "sp-runtime", "sp-session", @@ -880,7 +876,6 @@ dependencies = [ "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", - "pallet-transaction-storage", "pallet-treasury", "pallet-utility", "pallet-vesting", @@ -909,7 +904,6 @@ name = "cere-dev-runtime-constants" version = "4.8.1" dependencies = [ "node-primitives", - "sp-runtime", ] [[package]] @@ -1005,7 +999,6 @@ dependencies = [ "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", - "pallet-transaction-storage", "pallet-treasury", "pallet-utility", "pallet-vesting", @@ -1044,7 +1037,6 @@ name = "cere-runtime-constants" version = "4.8.1" dependencies = [ "node-primitives", - "sp-runtime", ] [[package]] @@ -1056,17 +1048,14 @@ dependencies = [ "cere-dev-runtime-constants", "cere-rpc", "cere-runtime", - "cere-runtime-constants", "futures", "jsonrpsee", "node-primitives", "pallet-im-online", - "parity-scale-codec", "rand 0.8.5", "sc-authority-discovery", "sc-basic-authorship", "sc-chain-spec", - "sc-cli", "sc-client-api", "sc-consensus", "sc-consensus-babe", @@ -1087,7 +1076,6 @@ dependencies = [ "sp-authority-discovery", "sp-authorship", "sp-blockchain", - "sp-consensus", "sp-consensus-babe", "sp-core", "sp-finality-grandpa", @@ -1651,11 +1639,7 @@ name = "ddc-traits" version = "0.1.0" dependencies = [ "ddc-primitives", - "frame-support", "frame-system", - "sp-core", - "sp-staking", - "sp-std", ] [[package]] @@ -4045,24 +4029,6 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" -[[package]] -name = "lite-json" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0e787ffe1153141a0f6f6d759fdf1cc34b1226e088444523812fd412a5cca2" -dependencies = [ - "lite-parser", -] - -[[package]] -name = "lite-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d5f9dc37c52d889a21fd701983d02bb6a84f852c5140a6c80ef4557f7dc29e" -dependencies = [ - "paste", -] - [[package]] name = "lock_api" version = "0.4.11" @@ -4778,16 +4744,13 @@ dependencies = [ name = "pallet-chainbridge" version = "4.8.1" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", - "lite-json", "pallet-balances", "parity-scale-codec", "scale-info", "sp-core", "sp-io", - "sp-keystore", "sp-runtime", "sp-std", ] @@ -4917,18 +4880,14 @@ version = "4.8.1" dependencies = [ "ddc-primitives", "ddc-traits", - "frame-benchmarking", "frame-support", "frame-system", - "log", "pallet-contracts", "pallet-ddc-nodes", "parity-scale-codec", "scale-info", "sp-core", - "sp-io", "sp-runtime", - "sp-staking", "sp-std", "sp-tracing", "substrate-test-utils", @@ -4945,9 +4904,7 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", "sp-runtime", - "sp-staking", "sp-std", "substrate-test-utils", ] @@ -4961,7 +4918,6 @@ dependencies = [ "frame-system", "hex", "hex-literal", - "lite-json", "pallet-balances", "pallet-contracts", "pallet-randomness-collective-flip", @@ -4969,7 +4925,6 @@ dependencies = [ "parity-scale-codec", "pretty_assertions", "scale-info", - "serde", "serde_json 1.0.44", "sp-core", "sp-io", @@ -4983,16 +4938,12 @@ name = "pallet-ddc-nodes" version = "4.8.1" dependencies = [ "ddc-primitives", - "frame-benchmarking", "frame-support", "frame-system", - "log", "parity-scale-codec", "scale-info", "sp-core", - "sp-io", "sp-runtime", - "sp-staking", "sp-std", "sp-tracing", "substrate-test-utils", @@ -5007,7 +4958,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "log", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -5015,7 +4965,6 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-staking", "sp-std", "sp-tracing", "substrate-test-utils", @@ -5096,7 +5045,6 @@ dependencies = [ name = "pallet-erc20" version = "4.8.1" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "pallet-balances", @@ -5104,7 +5052,6 @@ dependencies = [ "pallet-erc721", "parity-scale-codec", "scale-info", - "serde", "sp-arithmetic", "sp-core", "sp-io", @@ -5116,14 +5063,12 @@ dependencies = [ name = "pallet-erc721" version = "4.8.1" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "pallet-balances", "pallet-chainbridge", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-io", "sp-runtime", @@ -5584,24 +5529,6 @@ dependencies = [ "sp-runtime", ] -[[package]] -name = "pallet-transaction-storage" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" -dependencies = [ - "frame-support", - "frame-system", - "log", - "pallet-balances", - "parity-scale-codec", - "scale-info", - "sp-inherents", - "sp-io", - "sp-runtime", - "sp-std", - "sp-transaction-storage-proof", -] - [[package]] name = "pallet-treasury" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 3d7599231..27cff6711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ build = "build.rs" [dependencies] cere-cli = { path = "cli", features = [ "cere-dev-native" ] } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -ss58-registry = { version = "1.38.0", default-features = false } [build-dependencies] substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index dbafa5fa8..d83bb5b03 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -8,7 +8,6 @@ sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/subs sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -29,8 +28,6 @@ sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/su sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } # Local cere-runtime = { path = "../../runtime/cere", optional = true } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index d444e3244..c6c8abdfb 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -4,13 +4,10 @@ version = "4.8.1" edition = "2021" [dependencies] -codec = { package = "parity-scale-codec", version = "3.1.5" } serde = { version = "1.0.136", features = ["derive"] } rand = "0.8" futures = "0.3.21" jsonrpsee = { version = "0.15.1", features = ["server"] } - -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } @@ -18,7 +15,6 @@ sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/sub sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -47,8 +43,6 @@ sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/su # Local cere-client = { path = "../client", default-features = false, optional = true } cere-rpc = { path = "../../rpc" } - -cere-runtime-constants = { path = "../../runtime/cere/constants", optional = true } cere-dev-runtime-constants = { path = "../../runtime/cere-dev/constants", optional = true } cere-runtime = { path = "../../runtime/cere", optional = true } @@ -57,7 +51,7 @@ cere-dev-runtime = { path = "../../runtime/cere-dev", optional = true } [features] default = ["cere-native"] -cere-native = [ "cere-runtime", "cere-runtime-constants", "cere-client/cere" ] +cere-native = [ "cere-runtime", "cere-client/cere" ] cere-dev-native = [ "cere-dev-runtime", "cere-dev-runtime-constants", "cere-client/cere-dev" ] runtime-benchmarks = [ diff --git a/pallets/chainbridge/Cargo.toml b/pallets/chainbridge/Cargo.toml index de714f861..455a0aa8a 100644 --- a/pallets/chainbridge/Cargo.toml +++ b/pallets/chainbridge/Cargo.toml @@ -20,26 +20,18 @@ sp-core = { version = "6.0.0", default-features = false, git = "https://github.c sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -lite-json = { version = "0.2.0", default-features = false } -sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } - [features] default = ["std"] std = [ "codec/std", "sp-runtime/std", - "frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-balances/std", "sp-io/std", "sp-std/std", "sp-core/std", - "lite-json/std", - "sp-keystore", ] -runtime-benchmarks = ["frame-benchmarking"] diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 62f59dd67..0ef556a69 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -7,16 +7,11 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } @@ -32,14 +27,10 @@ std = [ "ddc-primitives/std", "frame-support/std", "frame-system/std", - "frame-benchmarking/std", "pallet-contracts/std", "pallet-ddc-nodes/std", "scale-info/std", "sp-core/std", - "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", ] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 48cdf287f..8d60ba44f 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -10,9 +10,7 @@ ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } @@ -27,8 +25,6 @@ std = [ "frame-support/std", "frame-system/std", "scale-info/std", - "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", ] diff --git a/pallets/ddc-metrics-offchain-worker/Cargo.toml b/pallets/ddc-metrics-offchain-worker/Cargo.toml index 74747a397..3ab61de26 100644 --- a/pallets/ddc-metrics-offchain-worker/Cargo.toml +++ b/pallets/ddc-metrics-offchain-worker/Cargo.toml @@ -16,14 +16,12 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["full"] } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -serde = { version = "1.0.136", optional = true } sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -lite-json = { version = "0.2.0", default-features = false } alt_serde = { version = "1", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } # pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -38,8 +36,6 @@ std = [ "sp-keystore", "frame-support/std", "frame-system/std", - "serde", - "lite-json/std", "sp-core/std", "sp-io/std", "sp-runtime/std", diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 607ab47fa..54bc35070 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -6,16 +6,11 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -29,12 +24,8 @@ std = [ "ddc-primitives/std", "frame-support/std", "frame-system/std", - "frame-benchmarking/std", "scale-info/std", - "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", "sp-core/std", ] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index 9fbcc154e..0f9c57433 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -10,11 +10,9 @@ ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] @@ -35,7 +33,6 @@ std = [ "scale-info/std", "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc/Cargo.toml b/pallets/ddc/Cargo.toml index 9c89014d1..867c36f52 100644 --- a/pallets/ddc/Cargo.toml +++ b/pallets/ddc/Cargo.toml @@ -35,3 +35,6 @@ std = [ 'frame-support/std', 'frame-system/std', ] + +[package.metadata.cargo-machete] +ignored = ["scale-info", "codec"] diff --git a/pallets/erc20/Cargo.toml b/pallets/erc20/Cargo.toml index 6cce2c8d4..3bf27fea6 100644 --- a/pallets/erc20/Cargo.toml +++ b/pallets/erc20/Cargo.toml @@ -13,7 +13,6 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -27,15 +26,11 @@ pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../c pallet-erc721 = { version = "4.2.0", default-features = false, path = "../erc721" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } - [features] default = ["std"] std = [ - "serde", "codec/std", "sp-runtime/std", - "frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -46,4 +41,6 @@ std = [ "pallet-chainbridge/std", "pallet-erc721/std" ] -runtime-benchmarks = ["frame-benchmarking"] + +[package.metadata.cargo-machete] +ignored = ["scale-info"] diff --git a/pallets/erc721/Cargo.toml b/pallets/erc721/Cargo.toml index 3f586f103..e6e12c37f 100644 --- a/pallets/erc721/Cargo.toml +++ b/pallets/erc721/Cargo.toml @@ -13,7 +13,6 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -25,15 +24,11 @@ sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.gi pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } - [features] default = ["std"] std = [ - "serde", "codec/std", "sp-runtime/std", - "frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -42,4 +37,3 @@ std = [ "sp-core/std", "pallet-chainbridge/std" ] -runtime-benchmarks = ["frame-benchmarking"] diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index f5ba45aba..e78c7dd17 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -92,7 +92,6 @@ pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "http pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-dev-runtime-constants = { path = "./constants", default-features = false } @@ -197,7 +196,6 @@ runtime-benchmarks = [ "pallet-bags-list/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-bounties/runtime-benchmarks", - "pallet-chainbridge/runtime-benchmarks", "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", diff --git a/runtime/cere-dev/constants/Cargo.toml b/runtime/cere-dev/constants/Cargo.toml index 5fdb89737..201630962 100644 --- a/runtime/cere-dev/constants/Cargo.toml +++ b/runtime/cere-dev/constants/Cargo.toml @@ -6,10 +6,9 @@ edition = "2021" [dependencies] node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } [features] default = ["std"] std = [ - "sp-runtime/std" + "node-primitives/std" ] diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 59a2668cd..698fa079b 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -92,7 +92,6 @@ pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "http pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-runtime-constants = { path = "./constants", default-features = false } @@ -189,7 +188,6 @@ runtime-benchmarks = [ "pallet-bags-list/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-bounties/runtime-benchmarks", - "pallet-chainbridge/runtime-benchmarks", "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", @@ -260,3 +258,4 @@ try-runtime = [ "pallet-utility/try-runtime", "pallet-vesting/try-runtime", ] + diff --git a/runtime/cere/constants/Cargo.toml b/runtime/cere/constants/Cargo.toml index 2188486ef..629d01bcb 100644 --- a/runtime/cere/constants/Cargo.toml +++ b/runtime/cere/constants/Cargo.toml @@ -6,10 +6,9 @@ edition = "2021" [dependencies] node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } [features] default = ["std"] std = [ - "sp-runtime/std" + "node-primitives/std" ] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index b224e2d28..202996ef0 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -4,9 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } From 6e9da2e5533c420689dbfbe4486328d52c487a3a Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 14:56:10 +0300 Subject: [PATCH 480/544] Cargo machete does not support --locked install yet --- .github/workflows/check.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 9bdc50136..1ecb04c4b 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -32,9 +32,6 @@ jobs: run: | cargo fmt -- --check - - name: Unused dependencies - uses: bnjbvr/cargo-machete@main - - name: Rust Cache uses: Swatinem/rust-cache@v2 From 051fe25e5c565586e6465ef054feabf278094e40 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 15:01:20 +0300 Subject: [PATCH 481/544] Fix clippy warning --- pallets/ddc-staking/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 93a23f324..587f2d6c5 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -441,12 +441,12 @@ pub mod pallet { match node_pub_key { NodePubKey::CDNPubKey(_) => T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, + .map_err(|e| Into::>::into(e))?, NodePubKey::StoragePubKey(_) => T::ClusterVisitor::get_unbonding_delay( &cluster_id, NodeType::Storage, ) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, + .map_err(|e| Into::>::into(e))?, } } else { // If node is not a member of any cluster, allow immediate unbonding. From bbb08680a0116242fd0652f058b4019e30caf633 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 15:10:51 +0300 Subject: [PATCH 482/544] Resolve redundancy --- pallets/ddc-staking/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 587f2d6c5..9c8469785 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -441,12 +441,12 @@ pub mod pallet { match node_pub_key { NodePubKey::CDNPubKey(_) => T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(e))?, + .map_err(Into::>::into)?, NodePubKey::StoragePubKey(_) => T::ClusterVisitor::get_unbonding_delay( &cluster_id, NodeType::Storage, ) - .map_err(|e| Into::>::into(e))?, + .map_err(Into::>::into)?, } } else { // If node is not a member of any cluster, allow immediate unbonding. From a52c241ea4812d291792c2767c50a8409ceb8255 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 16:01:12 +0300 Subject: [PATCH 483/544] Increase call_size for tests --- runtime/cere/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 984ffb7bc..6e68d7106 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -1844,7 +1844,7 @@ mod tests { fn call_size() { let size = core::mem::size_of::(); assert!( - size <= 208, + size <= 256, "size of RuntimeCall {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the size of RuntimeCall. If the limit is too strong, maybe consider increase the limit to 300.", From d5d6a89539a939aff8607e32a33e4959984743a2 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 10 Nov 2023 15:03:23 +0100 Subject: [PATCH 484/544] chore: unused node related type removed --- pallets/ddc-nodes/src/cdn_node.rs | 6 +++--- pallets/ddc-nodes/src/node.rs | 10 ++-------- pallets/ddc-nodes/src/storage_node.rs | 6 +++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 1c8f19de1..eafe6cd27 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,4 +1,4 @@ -use crate::node::{NodeError, NodeParams, NodeProps, NodePropsRef, NodeTrait}; +use crate::node::{NodeError, NodeParams, NodeProps, NodeTrait}; use codec::{Decode, Encode}; use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; @@ -72,8 +72,8 @@ impl NodeTrait for CDNNode { fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } - fn get_props(&self) -> NodePropsRef { - NodePropsRef::CDNPropsRef(self.props.clone()) + fn get_props(&self) -> NodeProps { + NodeProps::CDNProps(self.props.clone()) } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index fbf962d1f..042d13be3 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -31,16 +31,10 @@ pub enum NodeProps { CDNProps(CDNNodeProps), } -#[derive(Clone, RuntimeDebug, PartialEq)] -pub enum NodePropsRef { - StoragePropsRef(StorageNodeProps), - CDNPropsRef(CDNNodeProps), -} - pub trait NodeTrait { fn get_pub_key(&self) -> NodePubKey; fn get_provider_id(&self) -> &T::AccountId; - fn get_props(&self) -> NodePropsRef; + fn get_props(&self) -> NodeProps; fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; fn get_cluster_id(&self) -> &Option; @@ -76,7 +70,7 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_provider_id(), } } - fn get_props(&self) -> NodePropsRef { + fn get_props(&self) -> NodeProps { match &self { Node::Storage(node) => node.get_props(), Node::CDN(node) => node.get_props(), diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 83fd2b11f..902739771 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,4 +1,4 @@ -use crate::node::{NodeError, NodeParams, NodeProps, NodePropsRef, NodeTrait}; +use crate::node::{NodeError, NodeParams, NodeProps, NodeTrait}; use codec::{Decode, Encode}; use ddc_primitives::{ClusterId, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; @@ -72,8 +72,8 @@ impl NodeTrait for StorageNode { fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } - fn get_props(&self) -> NodePropsRef { - NodePropsRef::StoragePropsRef(self.props.clone()) + fn get_props(&self) -> NodeProps { + NodeProps::StorageProps(self.props.clone()) } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { From 918474e2e27399fa5d75dbb7fed760474148be36 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Fri, 10 Nov 2023 17:56:34 +0300 Subject: [PATCH 485/544] Update both runtimes --- runtime/cere-dev/src/lib.rs | 4 ++-- runtime/cere/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 518b398dc..fb260b4ed 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1898,8 +1898,8 @@ mod tests { fn call_size() { let size = core::mem::size_of::(); assert!( - size <= 208, - "size of RuntimeCall {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the + size <= 256, + "size of RuntimeCall {} is more than 256 bytes: some calls have too big arguments, use Box to reduce the size of RuntimeCall. If the limit is too strong, maybe consider increase the limit to 300.", size, diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 6e68d7106..f7eef4df6 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -1845,7 +1845,7 @@ mod tests { let size = core::mem::size_of::(); assert!( size <= 256, - "size of RuntimeCall {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the + "size of RuntimeCall {} is more than 256 bytes: some calls have too big arguments, use Box to reduce the size of RuntimeCall. If the limit is too strong, maybe consider increase the limit to 300.", size, From 996f80d80caffce0fa27a9cff0ffc2274aa6933d Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 10 Nov 2023 17:21:21 +0100 Subject: [PATCH 486/544] add tests for ddc-clusters --- Cargo.lock | 7 +++++++ pallets/ddc-clusters/Cargo.toml | 5 +++++ pallets/ddc-clusters/src/lib.rs | 5 +++++ pallets/ddc-nodes/src/lib.rs | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 6059b927b..c427ac8e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4920,9 +4920,14 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "hex", + "hex-literal", "log", + "pallet-balances", "pallet-contracts", "pallet-ddc-nodes", + "pallet-randomness-collective-flip", + "pallet-timestamp", "parity-scale-codec", "scale-info", "sp-core", @@ -4987,6 +4992,8 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-balances", + "pallet-timestamp", "parity-scale-codec", "scale-info", "sp-core", diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 62f59dd67..42673b26c 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -19,11 +19,16 @@ sp-std = { version = "4.0.0-dev", default-features = false, git = "https://githu sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } +hex-literal = "^0.3.1" +hex = { version = "0.4", default-features = false } [dev-dependencies] +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index cb4aafb7b..f7c543954 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -15,6 +15,11 @@ #![recursion_limit = "256"] #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 +#[cfg(test)] +pub(crate) mod mock; +#[cfg(test)] +mod tests; + use crate::{ cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 5dc0766ce..42d45be03 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -30,7 +30,7 @@ mod node; mod storage_node; pub use crate::{ - cdn_node::CDNNode, + cdn_node::{CDNNode, CDNNodeParams}, node::{Node, NodeError, NodeParams, NodeTrait}, storage_node::StorageNode, }; From d91c04f3e4b6c70bc7d29b2c0fedb360daa8384e Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 10 Nov 2023 17:31:54 +0100 Subject: [PATCH 487/544] added missing files --- pallets/ddc-clusters/src/mock.rs | 232 ++++++++++ .../ddc-clusters/src/test_data/metadata.json | 365 ++++++++++++++++ .../node_provider_auth_white_list.wasm | Bin 0 -> 4489 bytes pallets/ddc-clusters/src/tests.rs | 412 ++++++++++++++++++ 4 files changed, 1009 insertions(+) create mode 100644 pallets/ddc-clusters/src/mock.rs create mode 100644 pallets/ddc-clusters/src/test_data/metadata.json create mode 100644 pallets/ddc-clusters/src/test_data/node_provider_auth_white_list.wasm create mode 100644 pallets/ddc-clusters/src/tests.rs diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs new file mode 100644 index 000000000..ceaa921a5 --- /dev/null +++ b/pallets/ddc-clusters/src/mock.rs @@ -0,0 +1,232 @@ +//! Test utilities + +#![allow(dead_code)] + +use crate::{self as pallet_ddc_clusters, *}; +use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_traits::staking::{StakingVisitor, StakingVisitorError}; +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64, Everything, Nothing}, + weights::constants::RocksDbWeight, +}; +use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; +use pallet_contracts as contracts; +use sp_core::H256; +use sp_io::TestExternalities; +use sp_runtime::{ + testing::{Header, TestXt}, + traits::{ + BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, + }, + MultiSignature, +}; + +/// The AccountId alias in this test module. +pub type AccountId = <::Signer as IdentifyAccount>::AccountId; +pub(crate) type AccountIndex = u64; +pub(crate) type BlockNumber = u64; +pub(crate) type Balance = u128; + +pub type Signature = MultiSignature; +type UncheckedExtrinsic = MockUncheckedExtrinsic; +type Block = MockBlock; + +construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + Contracts: contracts::{Pallet, Call, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + DdcNodes: pallet_ddc_nodes::{Pallet, Call, Storage, Event}, + DdcClusters: pallet_ddc_clusters::{Pallet, Call, Storage, Event}, + Randomness: pallet_randomness_collective_flip::{Pallet, Storage}, + } +); + +parameter_types! { + pub const DepositPerItem: Balance = 0; + pub const DepositPerByte: Balance = 0; + pub const SignedClaimHandicap: BlockNumber = 2; + pub const TombstoneDeposit: Balance = 16; + pub const StorageSizeOffset: u32 = 8; + pub const RentByteFee: Balance = 4; + pub const RentDepositOffset: Balance = 10_000; + pub const SurchargeReward: Balance = 150; + pub const MaxDepth: u32 = 100; + pub const MaxValueSize: u32 = 16_384; + pub Schedule: pallet_contracts::Schedule = Default::default(); +} + +impl Convert> for Test { + fn convert(w: Weight) -> BalanceOf { + w.ref_time().into() + } +} + +use contracts::Config as contractsConfig; + +type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +impl contracts::Config for Test { + type Time = Timestamp; + type Randomness = Randomness; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type CallStack = [pallet_contracts::Frame; 31]; + type WeightPrice = Self; //pallet_transaction_payment::Module; + type WeightInfo = (); + type ChainExtension = (); + type DeletionQueueDepth = (); + type DeletionWeightLimit = (); + type Schedule = Schedule; + type RuntimeCall = RuntimeCall; + type CallFilter = Nothing; + type DepositPerByte = DepositPerByte; + type DepositPerItem = DepositPerItem; + type AddressGenerator = pallet_contracts::DefaultAddressGenerator; + type ContractAccessWeight = (); + type MaxCodeLen = ConstU32<{ 128 * 1024 }>; + type MaxStorageKeyLen = ConstU32<128>; +} + +use frame_system::offchain::{ + AppCrypto, CreateSignedTransaction, SendTransactionTypes, SigningTypes, +}; + +pub type Extrinsic = TestXt; + +impl SigningTypes for Test { + type Public = ::Signer; + type Signature = Signature; +} + +impl SendTransactionTypes for Test +where + RuntimeCall: From, +{ + type OverarchingCall = RuntimeCall; + type Extrinsic = Extrinsic; +} +impl pallet_randomness_collective_flip::Config for Test {} + +impl CreateSignedTransaction for Test +where + RuntimeCall: From, +{ + fn create_transaction>( + call: RuntimeCall, + _public: ::Signer, + _account: AccountId, + nonce: u64, + ) -> Option<(RuntimeCall, ::SignaturePayload)> { + Some((call, (nonce, ()))) + } +} + +parameter_types! { + pub static ExistentialDeposit: Balance = 1; +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = RocksDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type MaxLocks = ConstU32<1024>; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<5>; + type WeightInfo = (); +} + +impl pallet_ddc_nodes::Config for Test { + type RuntimeEvent = RuntimeEvent; +} + +impl crate::pallet::Config for Test { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type NodeRepository = DdcNodes; + type StakingVisitor = TestStakingVisitor; +} + +pub(crate) type DdcStakingCall = crate::Call; +pub(crate) type TestRuntimeCall = ::RuntimeCall; +pub struct TestStakingVisitor; +impl StakingVisitor for TestStakingVisitor { + fn node_has_stake( + _node_pub_key: &NodePubKey, + _cluster_id: &ClusterId, + ) -> Result { + Ok(true) + } + fn node_is_chilling(_node_pub_key: &NodePubKey) -> Result { + Ok(false) + } +} + +pub struct ExtBuilder; + +impl ExtBuilder { + fn build(self) -> TestExternalities { + sp_tracing::try_init_simple(); + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let _ = pallet_balances::GenesisConfig:: { + balances: vec![ + (AccountId::from([1; 32]), 100), + (AccountId::from([2; 32]), 100), + (AccountId::from([3; 32]), 100), + (AccountId::from([4; 32]), 100), + ], + } + .assimilate_storage(&mut storage); + + TestExternalities::new(storage) + } + pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + sp_tracing::try_init_simple(); + let mut ext = self.build(); + ext.execute_with(test); + } +} diff --git a/pallets/ddc-clusters/src/test_data/metadata.json b/pallets/ddc-clusters/src/test_data/metadata.json new file mode 100644 index 000000000..4ffe526d6 --- /dev/null +++ b/pallets/ddc-clusters/src/test_data/metadata.json @@ -0,0 +1,365 @@ +{ + "source": { + "hash": "0x26d3338336a945f457e19992f37947659b0b7e4b2962369fe2f97ca7ebb95a09", + "language": "ink! 3.4.0", + "compiler": "rustc 1.69.0-nightly" + }, + "contract": { + "name": "node_provider_auth_white_list", + "version": "0.1.0", + "authors": [ + "Yahor Tsaryk " + ], + "description": "Node provider authorization layer based on admin approval", + "license": "Apache-2.0" + }, + "V3": { + "spec": { + "constructors": [ + { + "args": [], + "docs": [], + "label": "new", + "payable": false, + "selector": "0x9bae9d5e" + } + ], + "docs": [], + "events": [], + "messages": [ + { + "args": [ + { + "label": "_node_provider", + "type": { + "displayName": [ + "AccountId" + ], + "type": 0 + } + }, + { + "label": "node_pub_key", + "type": { + "displayName": [ + "NodePubKey" + ], + "type": 4 + } + }, + { + "label": "_node_variant", + "type": { + "displayName": [ + "NodeType" + ], + "type": 2 + } + } + ], + "docs": [], + "label": "is_authorized", + "mutates": false, + "payable": false, + "returnType": { + "displayName": [ + "bool" + ], + "type": 5 + }, + "selector": "0x96b0453e" + }, + { + "args": [ + { + "label": "node_pub_key", + "type": { + "displayName": [ + "NodePubKey" + ], + "type": 4 + } + } + ], + "docs": [], + "label": "add_node_pub_key", + "mutates": true, + "payable": false, + "returnType": { + "displayName": [ + "Result" + ], + "type": 7 + }, + "selector": "0x7a04093d" + }, + { + "args": [ + { + "label": "node_pub_key", + "type": { + "displayName": [ + "NodePubKey" + ], + "type": 4 + } + } + ], + "docs": [], + "label": "remove_node_pub_key", + "mutates": true, + "payable": false, + "returnType": { + "displayName": [ + "Result" + ], + "type": 7 + }, + "selector": "0xed3668b6" + }, + { + "args": [ + { + "label": "node_pub_key", + "type": { + "displayName": [ + "NodePubKey" + ], + "type": 4 + } + } + ], + "docs": [], + "label": "has_node_pub_key", + "mutates": false, + "payable": false, + "returnType": { + "displayName": [ + "bool" + ], + "type": 5 + }, + "selector": "0x9b868ecf" + }, + { + "args": [], + "docs": [], + "label": "get_admin", + "mutates": false, + "payable": false, + "returnType": { + "displayName": [ + "AccountId" + ], + "type": 0 + }, + "selector": "0x57b8a8a7" + } + ] + }, + "storage": { + "struct": { + "fields": [ + { + "layout": { + "cell": { + "key": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ty": 0 + } + }, + "name": "admin" + }, + { + "layout": { + "cell": { + "key": "0x0100000000000000000000000000000000000000000000000000000000000000", + "ty": 3 + } + }, + "name": "list" + } + ] + } + }, + "types": [ + { + "id": 0, + "type": { + "def": { + "composite": { + "fields": [ + { + "type": 1, + "typeName": "[u8; 32]" + } + ] + } + }, + "path": [ + "ink_env", + "types", + "AccountId" + ] + } + }, + { + "id": 1, + "type": { + "def": { + "array": { + "len": 32, + "type": 2 + } + } + } + }, + { + "id": 2, + "type": { + "def": { + "primitive": "u8" + } + } + }, + { + "id": 3, + "type": { + "def": { + "composite": { + "fields": [ + { + "name": "offset_key", + "type": 6, + "typeName": "Key" + } + ] + } + }, + "params": [ + { + "name": "K", + "type": 4 + }, + { + "name": "V", + "type": 5 + } + ], + "path": [ + "ink_storage", + "lazy", + "mapping", + "Mapping" + ] + } + }, + { + "id": 4, + "type": { + "def": { + "sequence": { + "type": 2 + } + } + } + }, + { + "id": 5, + "type": { + "def": { + "primitive": "bool" + } + } + }, + { + "id": 6, + "type": { + "def": { + "composite": { + "fields": [ + { + "type": 1, + "typeName": "[u8; 32]" + } + ] + } + }, + "path": [ + "ink_primitives", + "Key" + ] + } + }, + { + "id": 7, + "type": { + "def": { + "variant": { + "variants": [ + { + "fields": [ + { + "type": 8 + } + ], + "index": 0, + "name": "Ok" + }, + { + "fields": [ + { + "type": 9 + } + ], + "index": 1, + "name": "Err" + } + ] + } + }, + "params": [ + { + "name": "T", + "type": 8 + }, + { + "name": "E", + "type": 9 + } + ], + "path": [ + "Result" + ] + } + }, + { + "id": 8, + "type": { + "def": { + "tuple": [] + } + } + }, + { + "id": 9, + "type": { + "def": { + "variant": { + "variants": [ + { + "index": 0, + "name": "OnlyAdmin" + } + ] + } + }, + "path": [ + "node_provider_auth_white_list", + "node_provider_auth_white_list", + "Error" + ] + } + } + ] + } +} \ No newline at end of file diff --git a/pallets/ddc-clusters/src/test_data/node_provider_auth_white_list.wasm b/pallets/ddc-clusters/src/test_data/node_provider_auth_white_list.wasm new file mode 100644 index 0000000000000000000000000000000000000000..39d305f7f09c5124a444c92f60f9e84e42604e4a GIT binary patch literal 4489 zcmaJ^O^94s6+ZXpRln|6)wzkCOePcYzGov9B%~R%qdll~!z4Xn2x&1&c1bx?&dlph zCtclX7zkGRgSe6igPYm75S>|w5kzKoS&T3{XCdfDa5)=6MMOkszwh2xRo#-AZm4(v z-ud~?Ip4WY`nz|Oh^TY9pnI*6v_$x}gqlymDy6q>Y96#%tU6?(d1D zr6Mj32YdI2+tR$h6xUwu@4kBLn_KHA!&sl9-Ilu|yu`T9~>(dH#A)n4Ksf(sd z(Bgp{Vk4w0USEnJe-3*Z{zK;?2Ea#mweZI}?({Zc#CKK+&qUF;EWrA6^@c@=lr<;qQ0+_ACf7MRV`=xFhI-%F(B&>jWOPC=94l{X9oy7ye zwBamMdZ`1qFQ~JSeW0#kqLT>y(IQs$VG$N0w6|SN5ulu_m^Cs`5<1xH9hFcp0h@6w zRn|oS5DqwC8&I-ffh+MHj6!c}=3n~&5&dCcM8-6;5ZUNHBk<6Q` zSo&F9@)_d=w+;+;g4^%mR2W@>N-XVovp($Lh2Zw^at5Ujb{Yv8CHO2FgY-&bvx2J9 zs=3?&qOh#YNMzZI9i(B3D(rCcWec9c=*Bb9Z1fDi#l-O~ra_!Z8$e4y5!l2n907XJ z!*a~3AG2h=Tu>k`9$XWIw6rll5d0kg5;L)4f)WMduhNo=Wf7SPe&+imc9zWaERv_f z3y2AF@$fsaiMbfDxd4{}EAxgHK zW1>izMf2yN_CW2RHs(;G2mvc8s4PfPAr(@aoe@oIN;E*7z_KeX z3*06{kO9G#;3RiSiUI)89hXUQW7-;MBcll{@e0r&MxYW}fGTSALhDQ^)}F|2UnFH9 z05KS;qs6K|T=)%~v@PWUtd`>IQ(jasN6 z2t#_a5j+vuyb&#S9X!UWsmUY;6sicBL9IP)xDuA5Y zY8|(rIQ*Tg`&Rh!`f%v;;IEQnX}~fnAgN!D>P?vAT@#F8E};Fv)HWJ29(jq`d9g4G z=m>Mt)$SAY^+wgYOmSVk#OEBSdk6uTZ5W(55c2zrkXRNLdeLDspIU1g>!>`A-xhP5~>+tTOX}1oKr&AN} z@)fG>oY|-r`MCF>a(?l~FCSEkEN|o;2&p>eJAUySSnO~y_c<1^bd2YYMH*nG)7ZBg z;m47N4sOt3CLTiu2Jz`MSjk6G624ITs3{&_Va2Qoon65P(WFFm&lkLTS)-NMVpg%l z0?6UFTl1?V5)yF5f}bq_bu8fW+?=4Fv@P*;B$ZU{&Z|jN<;MUr1UI*s5^fP!TM$eh zS%$rBW&~X0P534r;D#G`#LPm$3_4WCDZKRPP>Q54=V;A8A1P-s-@TF{Q} z{FKK6A;C}E>2_=C=9P}YZ6L6PpPW6Rbs@oo3mIXW2RH?S&_j@#7M{Q z-8ez)::ClusterAlreadyExists + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 1); + System::assert_last_event( + Event::ClusterCreated { cluster_id: ClusterId::from([1; 20]) }.into(), + ) + }) +} + +#[test] +fn add_and_delete_node_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let contract_id = deploy_contract(); + + // Cluster doesn't exist + assert_noop!( + DdcClusters::add_node( + RuntimeOrigin::signed(AccountId::from([2; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + ), + Error::::ClusterDoesNotExist + ); + + // Creating 1 cluster should work fine + assert_ok!(DdcClusters::create_cluster( + RuntimeOrigin::root(), + ClusterId::from([1; 20]), + AccountId::from([1; 32]), + AccountId::from([2; 32]), + ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + ClusterGovParams { + treasury_share: Perbill::from_float(0.05), + validators_share: Perbill::from_float(0.01), + cluster_reserve_share: Perbill::from_float(0.02), + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + } + )); + + // Not Cluster Manager + assert_noop!( + DdcClusters::add_node( + RuntimeOrigin::signed(AccountId::from([2; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + ), + Error::::OnlyClusterManager + ); + + // Node doesn't exist + assert_noop!( + DdcClusters::add_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + ), + Error::::AttemptToAddNonExistentNode + ); + + // Create node + let bytes = [4u8; 32]; + let node_pub_key = AccountId32::from(bytes); + + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node created + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params.clone()) + )); + + // Node doesn't exist + assert_noop!( + DdcClusters::add_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + ), + Error::::NodeAuthContractCallFailed + ); + + // Set the correct address for auth contract + assert_ok!(DdcClusters::set_cluster_params( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + cluster::ClusterParams { node_provider_auth_contract: contract_id }, + )); + + // Node doesn't exist + assert_ok!(DdcClusters::add_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + )); + + // Node already assigned + assert_noop!( + DdcClusters::add_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + ), + Error::::NodeIsAlreadyAssigned + ); + + // Checking that event was emitted + System::assert_last_event( + Event::ClusterNodeAdded { + cluster_id: ClusterId::from([1; 20]), + node_pub_key: NodePubKey::CDNPubKey(AccountId::from([4; 32])), + } + .into(), + ); + + // Remove node + assert_ok!(DdcClusters::remove_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + )); + + // Checking that event was emitted + System::assert_last_event( + Event::ClusterNodeRemoved { + cluster_id: ClusterId::from([1; 20]), + node_pub_key: NodePubKey::CDNPubKey(AccountId::from([4; 32])), + } + .into(), + ); + + // Remove node should fail + assert_noop!( + DdcClusters::remove_node( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + NodePubKey::CDNPubKey(AccountId::from([4; 32])), + ), + Error::::NodeIsNotAssigned + ); + + pub const CTOR_SELECTOR: [u8; 4] = hex!("9bae9d5e"); + + fn encode_constructor() -> Vec { + let mut call_data = CTOR_SELECTOR.to_vec(); + let x = 0 as u128; + for _ in 0..9 { + x.encode_to(&mut call_data); + } + call_data + } + + fn deploy_contract() -> AccountId { + // Admin account who deploys the contract. + let alice = AccountId::from([1; 32]); + let _ = Balances::deposit_creating(&alice, 1_000_000_000_000); + + // Load the contract code. + let wasm = &include_bytes!("./test_data/node_provider_auth_white_list.wasm")[..]; + let wasm_hash = ::Hashing::hash(wasm); + let contract_args = encode_constructor(); + + // Deploy the contract. + const GAS_LIMIT: frame_support::weights::Weight = + Weight::from_ref_time(100_000_000_000); + const ENDOWMENT: Balance = 0; + Contracts::instantiate_with_code( + RuntimeOrigin::signed(alice.clone()), + ENDOWMENT, + GAS_LIMIT, + None, + wasm.to_vec(), + contract_args.clone(), + vec![], + ) + .unwrap(); + + // Configure worker with the contract address. + let contract_id = Contracts::contract_address(&alice, &wasm_hash, &vec![]); + + pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("7a04093d"); + let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([4; 32])); + + let call_data = { + // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool + let args: ([u8; 4], Vec) = + (ADD_DDC_NODE_SELECTOR, node_pub_key.encode()[1..].to_vec()); + args.encode() + }; + + let results = Contracts::call( + RuntimeOrigin::signed(alice.clone()), + contract_id.clone(), + 0, + Weight::from_ref_time(1_000_000_000_000), + None, + call_data, + ); + + results.unwrap(); + + contract_id + } + }) +} + +#[test] +fn set_cluster_params_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + // Cluster doesn't exist + assert_noop!( + DdcClusters::set_cluster_params( + RuntimeOrigin::signed(AccountId::from([2; 32])), + ClusterId::from([2; 20]), + ClusterParams { node_provider_auth_contract: AccountId::from([2; 32]) }, + ), + Error::::ClusterDoesNotExist + ); + + // Creating 1 cluster should work fine + assert_ok!(DdcClusters::create_cluster( + RuntimeOrigin::root(), + ClusterId::from([1; 20]), + AccountId::from([1; 32]), + AccountId::from([2; 32]), + ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + ClusterGovParams { + treasury_share: Perbill::from_float(0.05), + validators_share: Perbill::from_float(0.01), + cluster_reserve_share: Perbill::from_float(0.02), + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + } + )); + + assert_noop!( + DdcClusters::set_cluster_params( + RuntimeOrigin::signed(AccountId::from([2; 32])), + ClusterId::from([1; 20]), + ClusterParams { node_provider_auth_contract: AccountId::from([2; 32]) }, + ), + Error::::OnlyClusterManager + ); + + assert_ok!(DdcClusters::set_cluster_params( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + ClusterParams { node_provider_auth_contract: AccountId::from([2; 32]) }, + )); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event( + Event::ClusterParamsSet { cluster_id: ClusterId::from([1; 20]) }.into(), + ) + }) +} + +#[test] +fn set_cluster_gov_params_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_gov_params = ClusterGovParams { + treasury_share: Perbill::from_float(0.05), + validators_share: Perbill::from_float(0.01), + cluster_reserve_share: Perbill::from_float(0.02), + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + // Cluster doesn't exist + assert_noop!( + DdcClusters::set_cluster_gov_params( + RuntimeOrigin::root(), + ClusterId::from([2; 20]), + cluster_gov_params.clone() + ), + Error::::ClusterDoesNotExist + ); + + assert_ok!(DdcClusters::create_cluster( + RuntimeOrigin::root(), + ClusterId::from([1; 20]), + AccountId::from([1; 32]), + AccountId::from([2; 32]), + ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_gov_params.clone() + )); + + assert_noop!( + DdcClusters::set_cluster_gov_params( + RuntimeOrigin::signed(AccountId::from([1; 32])), + ClusterId::from([1; 20]), + cluster_gov_params.clone() + ), + BadOrigin + ); + + assert_ok!(DdcClusters::set_cluster_gov_params( + RuntimeOrigin::root(), + ClusterId::from([1; 20]), + cluster_gov_params + )); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event( + Event::ClusterGovParamsSet { cluster_id: ClusterId::from([1; 20]) }.into(), + ) + }) +} From 90e163ea070815983d4d0983accf715c2d5fa4a9 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Sun, 12 Nov 2023 14:05:09 +0300 Subject: [PATCH 488/544] dprint fmt --- .cargo/config.toml | 32 +- Cargo.toml | 38 +- cli/Cargo.toml | 18 +- dprint.json | 11 + node/client/Cargo.toml | 28 +- node/service/Cargo.toml | 69 ++-- pallets/chainbridge/Cargo.toml | 24 +- pallets/ddc-clusters/Cargo.toml | 4 +- pallets/ddc-customers/Cargo.toml | 2 +- .../ddc-metrics-offchain-worker/Cargo.toml | 42 +- pallets/ddc/Cargo.toml | 28 +- pallets/erc20/Cargo.toml | 36 +- pallets/erc721/Cargo.toml | 30 +- primitives/Cargo.toml | 12 +- rpc/Cargo.toml | 28 +- runtime/cere-dev/Cargo.toml | 374 +++++++++--------- runtime/cere-dev/constants/Cargo.toml | 2 +- runtime/cere/Cargo.toml | 357 +++++++++-------- runtime/cere/constants/Cargo.toml | 2 +- runtime/common/Cargo.toml | 4 +- rust-toolchain.toml | 4 +- rustfmt.toml | 10 +- traits/Cargo.toml | 2 +- .../0000-block-building/block-building.toml | 8 +- .../0001-ddc-validation/ddc-validation.toml | 26 +- 25 files changed, 596 insertions(+), 595 deletions(-) create mode 100644 dprint.json diff --git a/.cargo/config.toml b/.cargo/config.toml index fc82ca587..b283a2801 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -11,21 +11,21 @@ rustflags = [ "-Aclippy::if-same-then-else", "-Aclippy::clone-double-ref", "-Dclippy::complexity", - "-Aclippy::zero-prefixed-literal", # 00_1000_000 - "-Aclippy::type_complexity", # raison d'etre - "-Aclippy::nonminimal-bool", # maybe - "-Aclippy::borrowed-box", # Reasonable to fix this one - "-Aclippy::too-many-arguments", # (Turning this on would lead to) - "-Aclippy::unnecessary_cast", # Types may change - "-Aclippy::identity-op", # One case where we do 0 + - "-Aclippy::useless_conversion", # Types may change - "-Aclippy::unit_arg", # styalistic. - "-Aclippy::option-map-unit-fn", # styalistic - "-Aclippy::bind_instead_of_map", # styalistic - "-Aclippy::erasing_op", # E.g. 0 * DOLLARS - "-Aclippy::eq_op", # In tests we test equality. + "-Aclippy::zero-prefixed-literal", # 00_1000_000 + "-Aclippy::type_complexity", # raison d'etre + "-Aclippy::nonminimal-bool", # maybe + "-Aclippy::borrowed-box", # Reasonable to fix this one + "-Aclippy::too-many-arguments", # (Turning this on would lead to) + "-Aclippy::unnecessary_cast", # Types may change + "-Aclippy::identity-op", # One case where we do 0 + + "-Aclippy::useless_conversion", # Types may change + "-Aclippy::unit_arg", # styalistic. + "-Aclippy::option-map-unit-fn", # styalistic + "-Aclippy::bind_instead_of_map", # styalistic + "-Aclippy::erasing_op", # E.g. 0 * DOLLARS + "-Aclippy::eq_op", # In tests we test equality. "-Aclippy::while_immutable_condition", # false positives - "-Aclippy::needless_option_as_deref", # false positives - "-Aclippy::derivable_impls", # false positives - "-Aclippy::stable_sort_primitive", # prefer stable sort + "-Aclippy::needless_option_as_deref", # false positives + "-Aclippy::derivable_impls", # false positives + "-Aclippy::stable_sort_primitive", # prefer stable sort ] diff --git a/Cargo.toml b/Cargo.toml index 27cff6711..a9da35ba1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,13 @@ path = "src/main.rs" [package] name = "cere" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" version = "4.8.1" -edition = "2021" build = "build.rs" +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -cere-cli = { path = "cli", features = [ "cere-dev-native" ] } +cere-cli = { path = "cli", features = ["cere-dev-native"] } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } [build-dependencies] @@ -18,22 +18,22 @@ substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/pa [workspace] members = [ - "cli", - "node/client", - "node/service", - "rpc", - "runtime/cere", - "runtime/cere-dev", - "pallets/chainbridge", - "pallets/ddc", - "pallets/ddc-staking", - "pallets/erc721", - "pallets/erc20", - "pallets/ddc-metrics-offchain-worker", - "pallets/ddc-customers", - "pallets/ddc-nodes", - "pallets/ddc-clusters", - "primitives", + "cli", + "node/client", + "node/service", + "rpc", + "runtime/cere", + "runtime/cere-dev", + "pallets/chainbridge", + "pallets/ddc", + "pallets/ddc-staking", + "pallets/erc721", + "pallets/erc20", + "pallets/ddc-metrics-offchain-worker", + "pallets/ddc-customers", + "pallets/ddc-nodes", + "pallets/ddc-clusters", + "primitives", ] [profile.release] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 77f4d290d..648c6e2fa 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,15 +13,15 @@ crate-type = ["cdylib", "rlib"] [dependencies] clap = { version = "3.1", features = ["derive"], optional = true } +frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.30" } +try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } url = "2.4.1" # Local -cere-service = { path = "../node/service", default-features = false, optional = true } cere-client = { path = "../node/client", optional = true } +cere-service = { path = "../node/service", default-features = false, optional = true } [build-dependencies] substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } @@ -29,12 +29,12 @@ substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/pa [features] default = ["cli", "cere-native"] cli = [ - "clap", - "sc-cli", - "sc-service", - "frame-benchmarking-cli", - "try-runtime-cli", - "cere-client", + "clap", + "sc-cli", + "sc-service", + "frame-benchmarking-cli", + "try-runtime-cli", + "cere-client", ] runtime-benchmarks = ["cere-service/runtime-benchmarks"] try-runtime = ["cere-service/try-runtime"] diff --git a/dprint.json b/dprint.json new file mode 100644 index 000000000..82c59d3ee --- /dev/null +++ b/dprint.json @@ -0,0 +1,11 @@ +{ + "includes": [ + "**/*.{toml}" + ], + "excludes": [ + "**/target" + ], + "plugins": [ + "https://plugins.dprint.dev/toml-0.5.3.wasm" + ] + } \ No newline at end of file diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index d83bb5b03..e310ce7d1 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -4,34 +4,34 @@ version = "4.8.1" edition = "2021" [dependencies] -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # Local -cere-runtime = { path = "../../runtime/cere", optional = true } cere-dev-runtime = { path = "../../runtime/cere-dev", optional = true } +cere-runtime = { path = "../../runtime/cere", optional = true } [features] default = ["cere"] diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index c6c8abdfb..dbde60843 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -4,63 +4,62 @@ version = "4.8.1" edition = "2021" [dependencies] -serde = { version = "1.0.136", features = ["derive"] } -rand = "0.8" futures = "0.3.21" jsonrpsee = { version = "0.15.1", features = ["server"] } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } -sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +rand = "0.8" +sc-authority-discovery = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-authority-discovery = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +serde = { version = "1.0.136", features = ["derive"] } sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-trie = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-trie = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } # Local cere-client = { path = "../client", default-features = false, optional = true } -cere-rpc = { path = "../../rpc" } cere-dev-runtime-constants = { path = "../../runtime/cere-dev/constants", optional = true } +cere-rpc = { path = "../../rpc" } -cere-runtime = { path = "../../runtime/cere", optional = true } cere-dev-runtime = { path = "../../runtime/cere-dev", optional = true } - +cere-runtime = { path = "../../runtime/cere", optional = true } [features] default = ["cere-native"] -cere-native = [ "cere-runtime", "cere-client/cere" ] -cere-dev-native = [ "cere-dev-runtime", "cere-dev-runtime-constants", "cere-client/cere-dev" ] +cere-native = ["cere-runtime", "cere-client/cere"] +cere-dev-native = ["cere-dev-runtime", "cere-dev-runtime-constants", "cere-client/cere-dev"] runtime-benchmarks = [ - "cere-runtime/runtime-benchmarks", - "cere-dev-runtime/runtime-benchmarks", - "sc-service/runtime-benchmarks", + "cere-runtime/runtime-benchmarks", + "cere-dev-runtime/runtime-benchmarks", + "sc-service/runtime-benchmarks", ] try-runtime = [ - "cere-runtime/try-runtime", - "cere-dev-runtime/try-runtime", + "cere-runtime/try-runtime", + "cere-dev-runtime/try-runtime", ] diff --git a/pallets/chainbridge/Cargo.toml b/pallets/chainbridge/Cargo.toml index 455a0aa8a..617e76b9b 100644 --- a/pallets/chainbridge/Cargo.toml +++ b/pallets/chainbridge/Cargo.toml @@ -3,11 +3,11 @@ name = "pallet-chainbridge" version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" -license = "Unlicense" homepage = "https://substrate.io" +license = "Unlicense" +readme = "README.md" repository = "https://github.com/paritytech/substrate/" description = "" -readme = "README.md" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -16,22 +16,22 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } [features] default = ["std"] std = [ - "codec/std", - "sp-runtime/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "sp-io/std", - "sp-std/std", - "sp-core/std", + "codec/std", + "sp-runtime/std", + "frame-support/std", + "frame-system/std", + "pallet-balances/std", + "sp-io/std", + "sp-std/std", + "sp-core/std", ] diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 0ef556a69..7bd5018b4 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -9,11 +9,11 @@ ddc-primitives = { version = "0.1.0", default-features = false, path = "../../pr ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 8d60ba44f..89faf08a5 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -9,10 +9,10 @@ ddc-primitives = { version = "0.1.0", default-features = false, path = "../../pr ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } [dev-dependencies] substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-metrics-offchain-worker/Cargo.toml b/pallets/ddc-metrics-offchain-worker/Cargo.toml index 3ab61de26..d56726763 100644 --- a/pallets/ddc-metrics-offchain-worker/Cargo.toml +++ b/pallets/ddc-metrics-offchain-worker/Cargo.toml @@ -3,49 +3,49 @@ name = "pallet-ddc-metrics-offchain-worker" version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" -license = "Unlicense" homepage = "https://substrate.dev" +license = "Unlicense" +readme = "README.md" repository = "https://github.com/paritytech/substrate/" description = "FRAME example pallet for offchain worker" -readme = "README.md" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [dependencies] +alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["full"] } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +hex = { version = "0.4", default-features = false } +# pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +hex-literal = "^0.3.1" +pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -alt_serde = { version = "1", default-features = false, features = ["derive"] } -serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -# pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -hex-literal = "^0.3.1" -hex = { version = "0.4", default-features = false } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } [features] default = ["std"] std = [ - "codec/std", - "sp-keystore", - "frame-support/std", - "frame-system/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", - "pallet-contracts/std", - # "pallet-contracts-rpc-runtime-api/std", + "codec/std", + "sp-keystore", + "frame-support/std", + "frame-system/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "pallet-contracts/std", + # "pallet-contracts-rpc-runtime-api/std", ] [dev-dependencies] pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pretty_assertions = "0.6.1" diff --git a/pallets/ddc/Cargo.toml b/pallets/ddc/Cargo.toml index 867c36f52..f25de5056 100644 --- a/pallets/ddc/Cargo.toml +++ b/pallets/ddc/Cargo.toml @@ -1,13 +1,13 @@ [package] +name = 'pallet-cere-ddc' +version = '4.8.1' authors = ['Substrate DevHub '] -description = 'FRAME pallet template for defining custom runtime logic.' edition = '2021' homepage = 'https://www.cere.network/' license = 'Unlicense' -name = 'pallet-cere-ddc' -repository = 'https://github.com/Cerebellum-Network/ddc-pallet' -version = '4.8.1' readme = 'README.md' +repository = 'https://github.com/Cerebellum-Network/ddc-pallet' +description = 'FRAME pallet template for defining custom runtime logic.' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] @@ -16,24 +16,24 @@ targets = ['x86_64-unknown-linux-gnu'] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } serde = { version = "1.0.101" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ['std'] std = [ - 'codec/std', - 'sp-io/std', - 'sp-std/std', - 'sp-runtime/std', - 'frame-support/std', - 'frame-system/std', + 'codec/std', + 'sp-io/std', + 'sp-std/std', + 'sp-runtime/std', + 'frame-support/std', + 'frame-system/std', ] [package.metadata.cargo-machete] diff --git a/pallets/erc20/Cargo.toml b/pallets/erc20/Cargo.toml index 3bf27fea6..580ba103f 100644 --- a/pallets/erc20/Cargo.toml +++ b/pallets/erc20/Cargo.toml @@ -3,11 +3,11 @@ name = "pallet-erc20" version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" -license = "Unlicense" homepage = "https://substrate.dev" +license = "Unlicense" +readme = "README.md" repository = "https://github.com/paritytech/substrate/" description = "FRAME example pallet" -readme = "README.md" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -17,29 +17,29 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features = frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -sp-arithmetic = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } pallet-erc721 = { version = "4.2.0", default-features = false, path = "../erc721" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-arithmetic = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] std = [ - "codec/std", - "sp-runtime/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "sp-io/std", - "sp-std/std", - "sp-core/std", - "sp-arithmetic/std", - "pallet-chainbridge/std", - "pallet-erc721/std" + "codec/std", + "sp-runtime/std", + "frame-support/std", + "frame-system/std", + "pallet-balances/std", + "sp-io/std", + "sp-std/std", + "sp-core/std", + "sp-arithmetic/std", + "pallet-chainbridge/std", + "pallet-erc721/std", ] [package.metadata.cargo-machete] diff --git a/pallets/erc721/Cargo.toml b/pallets/erc721/Cargo.toml index e6e12c37f..08e9b531a 100644 --- a/pallets/erc721/Cargo.toml +++ b/pallets/erc721/Cargo.toml @@ -3,11 +3,11 @@ name = "pallet-erc721" version = "4.8.1" authors = ["Parity Technologies "] edition = "2021" -license = "Unlicense" homepage = "https://substrate.dev" +license = "Unlicense" +readme = "README.md" repository = "https://github.com/paritytech/substrate/" description = "FRAME example pallet" -readme = "README.md" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -17,23 +17,23 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features = frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false,git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] std = [ - "codec/std", - "sp-runtime/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "sp-io/std", - "sp-std/std", - "sp-core/std", - "pallet-chainbridge/std" + "codec/std", + "sp-runtime/std", + "frame-support/std", + "frame-system/std", + "pallet-balances/std", + "sp-io/std", + "sp-std/std", + "sp-core/std", + "pallet-chainbridge/std", ] diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 178800a4b..607c87512 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -serde = { version = "1.0.136", default-features = false, features = [ "derive" ], optional = true } +serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -14,10 +14,10 @@ sp-runtime = { version = "6.0.0", default-features = false, git = "https://githu [features] default = ["std"] std = [ - "codec/std", - "scale-info/std", - "serde", - "sp-core/std", - "sp-runtime/std", + "codec/std", + "scale-info/std", + "serde", + "sp-core/std", + "sp-runtime/std", ] runtime-benchmarks = [] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index e037f35f4..92f3e9a6f 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -5,26 +5,26 @@ edition = "2021" [dependencies] jsonrpsee = { version = "0.15.1", features = ["server"] } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-consensus-babe-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-consensus-epochs = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-finality-grandpa-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } substrate-state-trie-migration-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index e78c7dd17..9d47b5f64 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -2,51 +2,49 @@ name = "cere-dev-runtime" version = "4.8.1" authors = ["Parity Technologies "] -edition = "2021" build = "build.rs" -license = "Apache-2.0" +edition = "2021" homepage = "https://substrate.io" +license = "Apache-2.0" repository = "https://github.com/paritytech/substrate/" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [dependencies] - # third-party dependencies -codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = [ - "derive", - "max-encoded-len", -] } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -static_assertions = "1.1.0" +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "max-encoded-len"] } hex-literal = { version = "0.3.4", optional = true } log = { version = "0.4.16", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +static_assertions = "1.1.0" # primitives +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } +sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +cere-dev-runtime-constants = { path = "./constants", default-features = false } +cere-runtime-common = { path = "../common", default-features = false } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -55,55 +53,53 @@ pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https:// pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } +pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } +pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } +pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } -pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } -pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.30" } +pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-session = { version = "4.0.0-dev", features = ["historical"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -cere-runtime-common = { path = "../common", default-features = false } -cere-dev-runtime-constants = { path = "./constants", default-features = false } -pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } -pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } -pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } -pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } -pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } -pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } -pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } -pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -112,158 +108,158 @@ substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/pari default = ["std"] with-tracing = ["frame-executive/with-tracing"] std = [ - "sp-authority-discovery/std", - "pallet-authority-discovery/std", - "pallet-authorship/std", - "sp-consensus-babe/std", - "pallet-babe/std", - "pallet-bags-list/std", - "pallet-balances/std", - "pallet-bounties/std", - "sp-block-builder/std", - "codec/std", - "scale-info/std", - "pallet-collective/std", - "pallet-contracts/std", - "pallet-contracts-primitives/std", - "pallet-contracts-rpc-runtime-api/std", - "pallet-democracy/std", - "pallet-fast-unstake/std", - "pallet-elections-phragmen/std", - "frame-executive/std", - "pallet-cere-ddc/std", - "pallet-chainbridge/std", - "pallet-erc721/std", - "pallet-erc20/std", - "pallet-grandpa/std", - "pallet-im-online/std", - "pallet-indices/std", - "sp-inherents/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-nomination-pools/std", - "pallet-nomination-pools-runtime-api/std", - "pallet-identity/std", - "pallet-scheduler/std", - "node-primitives/std", - "sp-offchain/std", - "pallet-offences/std", - "pallet-proxy/std", - "sp-core/std", - "pallet-randomness-collective-flip/std", - "sp-std/std", - "pallet-session/std", - "sp-api/std", - "sp-runtime/std", - "sp-staking/std", - "pallet-staking/std", - "sp-session/std", - "pallet-sudo/std", - "frame-support/std", - "frame-benchmarking/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "pallet-election-provider-multi-phase/std", - "pallet-timestamp/std", - "pallet-tips/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-treasury/std", - "sp-transaction-pool/std", - "pallet-utility/std", - "sp-version/std", - "pallet-society/std", - "pallet-recovery/std", - "pallet-vesting/std", - "log/std", - "frame-try-runtime/std", - "sp-io/std", - "pallet-child-bounties/std", - "pallet-ddc-metrics-offchain-worker/std", - "pallet-ddc-staking/std", - "cere-runtime-common/std", - "cere-dev-runtime-constants/std", - "pallet-ddc-customers/std", - "pallet-ddc-nodes/std", - "pallet-ddc-clusters/std", + "sp-authority-discovery/std", + "pallet-authority-discovery/std", + "pallet-authorship/std", + "sp-consensus-babe/std", + "pallet-babe/std", + "pallet-bags-list/std", + "pallet-balances/std", + "pallet-bounties/std", + "sp-block-builder/std", + "codec/std", + "scale-info/std", + "pallet-collective/std", + "pallet-contracts/std", + "pallet-contracts-primitives/std", + "pallet-contracts-rpc-runtime-api/std", + "pallet-democracy/std", + "pallet-fast-unstake/std", + "pallet-elections-phragmen/std", + "frame-executive/std", + "pallet-cere-ddc/std", + "pallet-chainbridge/std", + "pallet-erc721/std", + "pallet-erc20/std", + "pallet-grandpa/std", + "pallet-im-online/std", + "pallet-indices/std", + "sp-inherents/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-nomination-pools/std", + "pallet-nomination-pools-runtime-api/std", + "pallet-identity/std", + "pallet-scheduler/std", + "node-primitives/std", + "sp-offchain/std", + "pallet-offences/std", + "pallet-proxy/std", + "sp-core/std", + "pallet-randomness-collective-flip/std", + "sp-std/std", + "pallet-session/std", + "sp-api/std", + "sp-runtime/std", + "sp-staking/std", + "pallet-staking/std", + "sp-session/std", + "pallet-sudo/std", + "frame-support/std", + "frame-benchmarking/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "pallet-election-provider-multi-phase/std", + "pallet-timestamp/std", + "pallet-tips/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "sp-transaction-pool/std", + "pallet-utility/std", + "sp-version/std", + "pallet-society/std", + "pallet-recovery/std", + "pallet-vesting/std", + "log/std", + "frame-try-runtime/std", + "sp-io/std", + "pallet-child-bounties/std", + "pallet-ddc-metrics-offchain-worker/std", + "pallet-ddc-staking/std", + "cere-runtime-common/std", + "cere-dev-runtime-constants/std", + "pallet-ddc-customers/std", + "pallet-ddc-nodes/std", + "pallet-ddc-clusters/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "pallet-babe/runtime-benchmarks", - "pallet-bags-list/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-bounties/runtime-benchmarks", - "pallet-child-bounties/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", - "pallet-contracts/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-election-provider-multi-phase/runtime-benchmarks", - "pallet-election-provider-support-benchmarking/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-fast-unstake/runtime-benchmarks", - "pallet-grandpa/runtime-benchmarks", - "pallet-identity/runtime-benchmarks", - "pallet-im-online/runtime-benchmarks", - "pallet-indices/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", - "pallet-nomination-pools/runtime-benchmarks", - "pallet-nomination-pools-benchmarking/runtime-benchmarks", - "pallet-offences-benchmarking/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-session-benchmarking/runtime-benchmarks", - "pallet-society/runtime-benchmarks", - "pallet-staking/runtime-benchmarks", - "pallet-ddc-staking/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-tips/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "hex-literal", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "pallet-babe/runtime-benchmarks", + "pallet-bags-list/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-bounties/runtime-benchmarks", + "pallet-child-bounties/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-contracts/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-election-provider-multi-phase/runtime-benchmarks", + "pallet-election-provider-support-benchmarking/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-fast-unstake/runtime-benchmarks", + "pallet-grandpa/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-im-online/runtime-benchmarks", + "pallet-indices/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-nomination-pools/runtime-benchmarks", + "pallet-nomination-pools-benchmarking/runtime-benchmarks", + "pallet-offences-benchmarking/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-session-benchmarking/runtime-benchmarks", + "pallet-society/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "pallet-ddc-staking/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-tips/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "hex-literal", ] try-runtime = [ - "frame-executive/try-runtime", - "frame-try-runtime", - "frame-system/try-runtime", - "pallet-authority-discovery/try-runtime", - "pallet-authorship/try-runtime", - "pallet-babe/try-runtime", - "pallet-bags-list/try-runtime", - "pallet-balances/try-runtime", - "pallet-bounties/try-runtime", - "pallet-child-bounties/try-runtime", - "pallet-collective/try-runtime", - "pallet-contracts/try-runtime", - "pallet-democracy/try-runtime", - "pallet-election-provider-multi-phase/try-runtime", - "pallet-elections-phragmen/try-runtime", - "pallet-fast-unstake/try-runtime", - "pallet-grandpa/try-runtime", - "pallet-identity/try-runtime", - "pallet-im-online/try-runtime", - "pallet-indices/try-runtime", - "pallet-membership/try-runtime", - "pallet-multisig/try-runtime", - "pallet-nomination-pools/try-runtime", - "pallet-offences/try-runtime", - "pallet-proxy/try-runtime", - "pallet-randomness-collective-flip/try-runtime", - "pallet-recovery/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-society/try-runtime", - "pallet-staking/try-runtime", - "pallet-sudo/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-tips/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-treasury/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", + "frame-executive/try-runtime", + "frame-try-runtime", + "frame-system/try-runtime", + "pallet-authority-discovery/try-runtime", + "pallet-authorship/try-runtime", + "pallet-babe/try-runtime", + "pallet-bags-list/try-runtime", + "pallet-balances/try-runtime", + "pallet-bounties/try-runtime", + "pallet-child-bounties/try-runtime", + "pallet-collective/try-runtime", + "pallet-contracts/try-runtime", + "pallet-democracy/try-runtime", + "pallet-election-provider-multi-phase/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-fast-unstake/try-runtime", + "pallet-grandpa/try-runtime", + "pallet-identity/try-runtime", + "pallet-im-online/try-runtime", + "pallet-indices/try-runtime", + "pallet-membership/try-runtime", + "pallet-multisig/try-runtime", + "pallet-nomination-pools/try-runtime", + "pallet-offences/try-runtime", + "pallet-proxy/try-runtime", + "pallet-randomness-collective-flip/try-runtime", + "pallet-recovery/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-society/try-runtime", + "pallet-staking/try-runtime", + "pallet-sudo/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-tips/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-treasury/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", ] diff --git a/runtime/cere-dev/constants/Cargo.toml b/runtime/cere-dev/constants/Cargo.toml index 201630962..d42c6c5b2 100644 --- a/runtime/cere-dev/constants/Cargo.toml +++ b/runtime/cere-dev/constants/Cargo.toml @@ -10,5 +10,5 @@ node-primitives = { version = "2.0.0", default-features = false, git = "https:// [features] default = ["std"] std = [ - "node-primitives/std" + "node-primitives/std", ] diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 698fa079b..95cfa8a4b 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -2,51 +2,49 @@ name = "cere-runtime" version = "4.8.1" authors = ["Parity Technologies "] -edition = "2021" build = "build.rs" -license = "Apache-2.0" +edition = "2021" homepage = "https://substrate.io" +license = "Apache-2.0" repository = "https://github.com/paritytech/substrate/" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [dependencies] - # third-party dependencies -codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = [ - "derive", - "max-encoded-len", -] } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -static_assertions = "1.1.0" +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "max-encoded-len"] } hex-literal = { version = "0.3.4", optional = true } log = { version = "0.4.16", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +static_assertions = "1.1.0" # primitives +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } +sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +cere-runtime-common = { path = "../common", default-features = false } +cere-runtime-constants = { path = "./constants", default-features = false } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -55,51 +53,49 @@ pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https:// pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } +pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } +pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } +pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } +pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } -pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } -pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.30" } +pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-session = { version = "4.0.0-dev", features = [ "historical" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-session = { version = "4.0.0-dev", features = ["historical"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -cere-runtime-common = { path = "../common", default-features = false } -cere-runtime-constants = { path = "./constants", default-features = false } -pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } -pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } -pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } -pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -108,154 +104,153 @@ substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/pari default = ["std"] with-tracing = ["frame-executive/with-tracing"] std = [ - "sp-authority-discovery/std", - "pallet-authority-discovery/std", - "pallet-authorship/std", - "sp-consensus-babe/std", - "pallet-babe/std", - "pallet-bags-list/std", - "pallet-balances/std", - "pallet-bounties/std", - "sp-block-builder/std", - "codec/std", - "scale-info/std", - "pallet-collective/std", - "pallet-contracts/std", - "pallet-contracts-primitives/std", - "pallet-contracts-rpc-runtime-api/std", - "pallet-democracy/std", - "pallet-fast-unstake/std", - "pallet-elections-phragmen/std", - "frame-executive/std", - "pallet-cere-ddc/std", - "pallet-chainbridge/std", - "pallet-erc721/std", - "pallet-erc20/std", - "pallet-grandpa/std", - "pallet-im-online/std", - "pallet-indices/std", - "sp-inherents/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-nomination-pools/std", - "pallet-nomination-pools-runtime-api/std", - "pallet-identity/std", - "pallet-scheduler/std", - "node-primitives/std", - "sp-offchain/std", - "pallet-offences/std", - "pallet-proxy/std", - "sp-core/std", - "pallet-randomness-collective-flip/std", - "sp-std/std", - "pallet-session/std", - "sp-api/std", - "sp-runtime/std", - "sp-staking/std", - "pallet-staking/std", - "sp-session/std", - "pallet-sudo/std", - "frame-support/std", - "frame-benchmarking/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "pallet-election-provider-multi-phase/std", - "pallet-timestamp/std", - "pallet-tips/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-treasury/std", - "sp-transaction-pool/std", - "pallet-utility/std", - "sp-version/std", - "pallet-society/std", - "pallet-recovery/std", - "pallet-vesting/std", - "log/std", - "frame-try-runtime/std", - "sp-io/std", - "pallet-child-bounties/std", - "pallet-ddc-metrics-offchain-worker/std", - "cere-runtime-common/std", - "cere-runtime-constants/std" + "sp-authority-discovery/std", + "pallet-authority-discovery/std", + "pallet-authorship/std", + "sp-consensus-babe/std", + "pallet-babe/std", + "pallet-bags-list/std", + "pallet-balances/std", + "pallet-bounties/std", + "sp-block-builder/std", + "codec/std", + "scale-info/std", + "pallet-collective/std", + "pallet-contracts/std", + "pallet-contracts-primitives/std", + "pallet-contracts-rpc-runtime-api/std", + "pallet-democracy/std", + "pallet-fast-unstake/std", + "pallet-elections-phragmen/std", + "frame-executive/std", + "pallet-cere-ddc/std", + "pallet-chainbridge/std", + "pallet-erc721/std", + "pallet-erc20/std", + "pallet-grandpa/std", + "pallet-im-online/std", + "pallet-indices/std", + "sp-inherents/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-nomination-pools/std", + "pallet-nomination-pools-runtime-api/std", + "pallet-identity/std", + "pallet-scheduler/std", + "node-primitives/std", + "sp-offchain/std", + "pallet-offences/std", + "pallet-proxy/std", + "sp-core/std", + "pallet-randomness-collective-flip/std", + "sp-std/std", + "pallet-session/std", + "sp-api/std", + "sp-runtime/std", + "sp-staking/std", + "pallet-staking/std", + "sp-session/std", + "pallet-sudo/std", + "frame-support/std", + "frame-benchmarking/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "pallet-election-provider-multi-phase/std", + "pallet-timestamp/std", + "pallet-tips/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "sp-transaction-pool/std", + "pallet-utility/std", + "sp-version/std", + "pallet-society/std", + "pallet-recovery/std", + "pallet-vesting/std", + "log/std", + "frame-try-runtime/std", + "sp-io/std", + "pallet-child-bounties/std", + "pallet-ddc-metrics-offchain-worker/std", + "cere-runtime-common/std", + "cere-runtime-constants/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "pallet-babe/runtime-benchmarks", - "pallet-bags-list/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-bounties/runtime-benchmarks", - "pallet-child-bounties/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", - "pallet-contracts/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-election-provider-multi-phase/runtime-benchmarks", - "pallet-election-provider-support-benchmarking/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-fast-unstake/runtime-benchmarks", - "pallet-grandpa/runtime-benchmarks", - "pallet-identity/runtime-benchmarks", - "pallet-im-online/runtime-benchmarks", - "pallet-indices/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", - "pallet-nomination-pools/runtime-benchmarks", - "pallet-nomination-pools-benchmarking/runtime-benchmarks", - "pallet-offences-benchmarking/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-session-benchmarking/runtime-benchmarks", - "pallet-society/runtime-benchmarks", - "pallet-staking/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-tips/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "hex-literal", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "pallet-babe/runtime-benchmarks", + "pallet-bags-list/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-bounties/runtime-benchmarks", + "pallet-child-bounties/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-contracts/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-election-provider-multi-phase/runtime-benchmarks", + "pallet-election-provider-support-benchmarking/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-fast-unstake/runtime-benchmarks", + "pallet-grandpa/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-im-online/runtime-benchmarks", + "pallet-indices/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-nomination-pools/runtime-benchmarks", + "pallet-nomination-pools-benchmarking/runtime-benchmarks", + "pallet-offences-benchmarking/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-session-benchmarking/runtime-benchmarks", + "pallet-society/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-tips/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "hex-literal", ] try-runtime = [ - "frame-executive/try-runtime", - "frame-try-runtime", - "frame-system/try-runtime", - "pallet-authority-discovery/try-runtime", - "pallet-authorship/try-runtime", - "pallet-babe/try-runtime", - "pallet-bags-list/try-runtime", - "pallet-balances/try-runtime", - "pallet-bounties/try-runtime", - "pallet-child-bounties/try-runtime", - "pallet-collective/try-runtime", - "pallet-contracts/try-runtime", - "pallet-democracy/try-runtime", - "pallet-election-provider-multi-phase/try-runtime", - "pallet-elections-phragmen/try-runtime", - "pallet-fast-unstake/try-runtime", - "pallet-grandpa/try-runtime", - "pallet-identity/try-runtime", - "pallet-im-online/try-runtime", - "pallet-indices/try-runtime", - "pallet-membership/try-runtime", - "pallet-multisig/try-runtime", - "pallet-nomination-pools/try-runtime", - "pallet-offences/try-runtime", - "pallet-proxy/try-runtime", - "pallet-randomness-collective-flip/try-runtime", - "pallet-recovery/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-society/try-runtime", - "pallet-staking/try-runtime", - "pallet-sudo/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-tips/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-treasury/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", + "frame-executive/try-runtime", + "frame-try-runtime", + "frame-system/try-runtime", + "pallet-authority-discovery/try-runtime", + "pallet-authorship/try-runtime", + "pallet-babe/try-runtime", + "pallet-bags-list/try-runtime", + "pallet-balances/try-runtime", + "pallet-bounties/try-runtime", + "pallet-child-bounties/try-runtime", + "pallet-collective/try-runtime", + "pallet-contracts/try-runtime", + "pallet-democracy/try-runtime", + "pallet-election-provider-multi-phase/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-fast-unstake/try-runtime", + "pallet-grandpa/try-runtime", + "pallet-identity/try-runtime", + "pallet-im-online/try-runtime", + "pallet-indices/try-runtime", + "pallet-membership/try-runtime", + "pallet-multisig/try-runtime", + "pallet-nomination-pools/try-runtime", + "pallet-offences/try-runtime", + "pallet-proxy/try-runtime", + "pallet-randomness-collective-flip/try-runtime", + "pallet-recovery/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-society/try-runtime", + "pallet-staking/try-runtime", + "pallet-sudo/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-tips/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-treasury/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", ] - diff --git a/runtime/cere/constants/Cargo.toml b/runtime/cere/constants/Cargo.toml index 629d01bcb..592358dfa 100644 --- a/runtime/cere/constants/Cargo.toml +++ b/runtime/cere/constants/Cargo.toml @@ -10,5 +10,5 @@ node-primitives = { version = "2.0.0", default-features = false, git = "https:// [features] default = ["std"] std = [ - "node-primitives/std" + "node-primitives/std", ] diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 15c08df07..5aff0c986 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -10,7 +10,7 @@ no_std = [] std = [] [dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } frame-support = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } -sp-core = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } node-primitives = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index bcf909e27..7e60322a9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2022-10-09" -components = [ "clippy", "rustfmt" ] -targets = [ "wasm32-unknown-unknown" ] +components = ["clippy", "rustfmt"] +targets = ["wasm32-unknown-unknown"] diff --git a/rustfmt.toml b/rustfmt.toml index f58198d98..2797c252b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -23,9 +23,9 @@ trailing_semicolon = false use_field_init_shorthand = true ignore = [ - "pallets/chainbridge", - "pallets/ddc-metrics-offchain-worker", - "pallets/ddc", - "pallets/erc20", - "pallets/erc721", + "pallets/chainbridge", + "pallets/ddc-metrics-offchain-worker", + "pallets/ddc", + "pallets/erc20", + "pallets/erc721", ] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 202996ef0..63f8cbd4e 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/zombienet/0000-block-building/block-building.toml b/zombienet/0000-block-building/block-building.toml index b9d662117..10b9955de 100644 --- a/zombienet/0000-block-building/block-building.toml +++ b/zombienet/0000-block-building/block-building.toml @@ -2,8 +2,8 @@ default_command = "./target/release/cere" chain = "local" - [[relaychain.nodes]] - name = "alice" +[[relaychain.nodes]] +name = "alice" - [[relaychain.nodes]] - name = "bob" +[[relaychain.nodes]] +name = "bob" diff --git a/zombienet/0001-ddc-validation/ddc-validation.toml b/zombienet/0001-ddc-validation/ddc-validation.toml index 64b4111ed..e5d7ae40a 100644 --- a/zombienet/0001-ddc-validation/ddc-validation.toml +++ b/zombienet/0001-ddc-validation/ddc-validation.toml @@ -3,21 +3,21 @@ default_command = "./target/release/cere" default_args = ["--enable-ddc-validation --dac-url {{DAC_URL}}"] chain = "local" - [[relaychain.nodes]] - name = "alice" +[[relaychain.nodes]] +name = "alice" - [[relaychain.nodes]] - name = "bob" +[[relaychain.nodes]] +name = "bob" - [[relaychain.nodes]] - name = "charlie" +[[relaychain.nodes]] +name = "charlie" - [[relaychain.nodes]] - name = "dave" +[[relaychain.nodes]] +name = "dave" - [[relaychain.nodes]] - name = "eve" +[[relaychain.nodes]] +name = "eve" - [[relaychain.nodes]] - name = "ferdie" - validator = false +[[relaychain.nodes]] +name = "ferdie" +validator = false From 9f783c0d6a5464b0b9ef390f45d44479faf12846 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Sun, 12 Nov 2023 14:07:05 +0300 Subject: [PATCH 489/544] Add github action --- .github/workflows/check.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 1ecb04c4b..04af2420e 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -28,6 +28,9 @@ jobs: rustup update stable --no-self-update rustup target add wasm32-unknown-unknown + - name: Check TOML + uses: dprint/check@v2.2 + - name: Check Format run: | cargo fmt -- --check From be5c9999f52570ef5e02f9e27f0e7d88b18170f1 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Sun, 12 Nov 2023 14:37:18 +0300 Subject: [PATCH 490/544] Fix indent --- pallets/ddc-clusters/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs index ceaa921a5..c4055dfbc 100644 --- a/pallets/ddc-clusters/src/mock.rs +++ b/pallets/ddc-clusters/src/mock.rs @@ -42,7 +42,7 @@ construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - DdcNodes: pallet_ddc_nodes::{Pallet, Call, Storage, Event}, + DdcNodes: pallet_ddc_nodes::{Pallet, Call, Storage, Event}, DdcClusters: pallet_ddc_clusters::{Pallet, Call, Storage, Event}, Randomness: pallet_randomness_collective_flip::{Pallet, Storage}, } From 1f259aa96e7034f66e4bd81fa133662a96161b54 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Mon, 13 Nov 2023 14:29:11 +0300 Subject: [PATCH 491/544] Add auto-assign to github PRs --- .github/auto_assign.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/auto_assign.yml diff --git a/.github/auto_assign.yml b/.github/auto_assign.yml new file mode 100644 index 000000000..ab48497b9 --- /dev/null +++ b/.github/auto_assign.yml @@ -0,0 +1,12 @@ +addReviewers: true +addAssignees: author +reviewers: + - rakanalh + - MRamanenkau + - Raid5594 + - aie0 + - yahortsaryk + - khssnv +skipKeywords: + - wip +numberOfReviewers: 2 From 7ca5bf0553fba24f12bbe0b3b25a4211a29dd14b Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Mon, 13 Nov 2023 14:41:15 +0200 Subject: [PATCH 492/544] payout<->customers --- Cargo.lock | 2 + pallets/ddc-customers/src/lib.rs | 84 +++++++++++--------- pallets/ddc-payouts/Cargo.toml | 1 + pallets/ddc-payouts/src/lib.rs | 132 ++++++++++++++++++++++++------- primitives/Cargo.toml | 1 - primitives/src/lib.rs | 1 - runtime/cere-dev/src/lib.rs | 2 + traits/Cargo.toml | 1 + traits/src/customer.rs | 8 ++ traits/src/lib.rs | 1 + 10 files changed, 163 insertions(+), 70 deletions(-) create mode 100644 traits/src/customer.rs diff --git a/Cargo.lock b/Cargo.lock index f38bc9c18..1505a42b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1655,6 +1655,7 @@ dependencies = [ "frame-support", "frame-system", "sp-core", + "sp-runtime", "sp-staking", "sp-std", ] @@ -5004,6 +5005,7 @@ name = "pallet-ddc-payouts" version = "4.8.1" dependencies = [ "ddc-primitives", + "ddc-traits", "frame-benchmarking", "frame-support", "frame-system", diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index d544ced22..e29902af8 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -4,7 +4,7 @@ use codec::{Decode, Encode, HasCompact}; use ddc_primitives::{BucketId, ClusterId}; -use ddc_traits::cluster::ClusterVisitor; +use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger}; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, @@ -171,6 +171,11 @@ pub mod pallet { pub fn DefaultBucketCount() -> BucketId { 0 } + + #[pallet::storage] + #[pallet::getter(fn dac_account)] + pub type DACAccount = StorageValue<_, T::AccountId>; + #[pallet::storage] #[pallet::getter(fn buckets_count)] pub type BucketsCount = @@ -191,12 +196,12 @@ pub mod pallet { /// it will not be emitted for staking rewards when they are added to stake. Deposited(T::AccountId, BalanceOf), /// An account has initiated unlock for amount. \[owner, amount\] - InitiatDepositUnlock(T::AccountId, BalanceOf), + InitialDepositUnlock(T::AccountId, BalanceOf), /// An account has called `withdraw_unlocked_deposit` and removed unlocking chunks worth /// `Balance` from the unlocking queue. \[owner, amount\] Withdrawn(T::AccountId, BalanceOf), - /// Total amount charged from all accounts to pay CDN nodes - Charged(BalanceOf), + /// The acconut has been charged for the usage + Charged(T::AccountId, BalanceOf), /// Bucket with specific id created BucketCreated(BucketId), } @@ -221,6 +226,10 @@ pub mod pallet { BucketDoesNotExist, /// DDC Cluster with provided id doesn't exist ClusterDoesNotExist, + // unauthorised operation + Unauthorised, + // Arithmetic underflow + ArithmeticUnderflow, } #[pallet::genesis_config] @@ -351,7 +360,7 @@ pub mod pallet { /// can co-exists at the same time. In that case, [`Call::withdraw_unlocked_deposit`] need /// to be called first to remove some of the chunks (if possible). /// - /// Emits `InitiatDepositUnlock`. + /// Emits `InitialDepositUnlock`. /// /// See also [`Call::withdraw_unlocked_deposit`]. #[pallet::weight(10_000)] @@ -380,7 +389,6 @@ pub mod pallet { let current_block = >::block_number(); // Note: locking for extra block to allow for accounting let block = current_block + ::UnlockingDelay::get(); - log::debug!("Block for the unlock: {:?}", block); if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.block == block) @@ -398,7 +406,7 @@ pub mod pallet { Self::update_ledger(&owner, &ledger); - Self::deposit_event(Event::::InitiatDepositUnlock(ledger.owner, value)); + Self::deposit_event(Event::::InitialDepositUnlock(ledger.owner, value)); } Ok(()) } @@ -451,7 +459,7 @@ pub mod pallet { ::Currency::transfer( &account_id, &owner, - value, + value.clone(), ExistenceRequirement::KeepAlive, )?; Self::deposit_event(Event::::Withdrawn(owner, value)); @@ -506,40 +514,38 @@ pub mod pallet { Ok(()) } + } - // Charge payments from content owners - pub fn charge_content_owners( - paying_accounts: Vec>>, - pricing: u128, + impl CustomerCharger for Pallet { + fn charge_content_owner( + content_owner: T::AccountId, + billing_vault: T::AccountId, + amount: u128, ) -> DispatchResult { - let mut total_charged = BalanceOf::::zero(); - - for bucket_details in paying_accounts.iter() { - let bucket: Bucket = Self::buckets(bucket_details.bucket_id) - .ok_or(Error::::BucketDoesNotExist)?; - let content_owner = bucket.owner_id; - let amount = bucket_details.amount * pricing.saturated_into::>(); - - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; - if ledger.active >= amount { - ledger.total -= amount; - ledger.active -= amount; - total_charged += amount; - Self::update_ledger(&content_owner, &ledger); - } else { - let diff = amount - ledger.active; - total_charged += ledger.active; - ledger.total -= ledger.active; - ledger.active = BalanceOf::::zero(); - let (ledger, charged) = ledger.charge_unlocking(diff); - Self::update_ledger(&content_owner, &ledger); - total_charged += charged; - } - } - log::debug!("Total charged: {:?}", &total_charged); + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; + let mut amount_to_deduct = amount.saturated_into::>(); + + ensure!(ledger.total >= ledger.active, Error::::ArithmeticUnderflow); + if ledger.active >= amount_to_deduct { + ledger.active -= amount_to_deduct; + ledger.total -= amount_to_deduct; + Self::update_ledger(&content_owner, &ledger); + } else { + let diff = amount_to_deduct - ledger.active; + ledger.total -= ledger.active; + amount_to_deduct = ledger.active; + ledger.active = BalanceOf::::zero(); + let (ledger, _charged) = ledger.charge_unlocking(diff); + Self::update_ledger(&content_owner, &ledger); + }; - Self::deposit_event(Event::::Charged(total_charged)); - log::debug!("Deposit event executed"); + ::Currency::transfer( + &Self::account_id(), + &billing_vault, + amount_to_deduct, + ExistenceRequirement::KeepAlive, + )?; + Self::deposit_event(Event::::Charged(content_owner, amount_to_deduct)); Ok(()) } diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml index 8f171e21b..ffba7a6d5 100644 --- a/pallets/ddc-payouts/Cargo.toml +++ b/pallets/ddc-payouts/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 8f7aefa98..e44d93de3 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -15,6 +15,7 @@ #![recursion_limit = "256"] use ddc_primitives::{ClusterId, DdcEra}; +use ddc_traits::customer::CustomerCharger; use frame_support::{ pallet_prelude::*, parameter_types, @@ -88,19 +89,55 @@ pub mod pallet { type PalletId: Get; type Currency: LockableCurrency; + + type CustomerCharger: CustomerCharger; } #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - BillingReportInitialized { cluster_id: ClusterId, era: DdcEra }, - ChargingStarted { cluster_id: ClusterId, era: DdcEra }, - Charged { cluster_id: ClusterId, era: DdcEra, customer_id: T::AccountId, amount: u128 }, - ChargingFinished { cluster_id: ClusterId, era: DdcEra }, - RewardingStarted { cluster_id: ClusterId, era: DdcEra }, - Rewarded { cluster_id: ClusterId, era: DdcEra, node_id: T::AccountId, amount: u128 }, - RewardingFinished { cluster_id: ClusterId, era: DdcEra }, - BillingReportFinalized { cluster_id: ClusterId, era: DdcEra }, + BillingReportInitialized { + cluster_id: ClusterId, + era: DdcEra, + }, + ChargingStarted { + cluster_id: ClusterId, + era: DdcEra, + }, + Charged { + cluster_id: ClusterId, + era: DdcEra, + customer_id: T::AccountId, + amount: u128, + }, + ChargeFailed { + cluster_id: ClusterId, + era: DdcEra, + customer_id: T::AccountId, + amount: u128, + }, + ChargingFinished { + cluster_id: ClusterId, + era: DdcEra, + }, + RewardingStarted { + cluster_id: ClusterId, + era: DdcEra, + }, + Rewarded { + cluster_id: ClusterId, + era: DdcEra, + node_provider_id: T::AccountId, + amount: u128, + }, + RewardingFinished { + cluster_id: ClusterId, + era: DdcEra, + }, + BillingReportFinalized { + cluster_id: ClusterId, + era: DdcEra, + }, } #[pallet::error] @@ -131,7 +168,7 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn dac_account)] + #[pallet::getter(fn authorised_caller)] pub type DACAccount = StorageValue<_, T::AccountId>; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -139,7 +176,7 @@ pub mod pallet { pub struct BillingReport { state: State, vault: T::AccountId, - dac_account: Option, + authorised_caller: Option, total_charged_balance: u128, total_distributed_balance: u128, total_node_expected_reward: NodeReward, @@ -157,7 +194,7 @@ pub mod pallet { Self { state: State::default(), vault: T::PalletId::get().into_account_truncating(), - dac_account: Option::None, + authorised_caller: Option::None, total_charged_balance: Zero::zero(), total_distributed_balance: Zero::zero(), total_node_expected_usage: NodeUsage::default(), @@ -192,7 +229,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -215,7 +252,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -248,7 +285,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -278,15 +315,45 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - // todo: charge customer let customer_id = payer.0; - updated_billing_report - .total_charged_balance - .checked_add(amount) - .ok_or(Error::::ArithmeticOverflow)?; - - Self::deposit_event(Event::::Charged { cluster_id, era, customer_id, amount }); + // todo: decouple AccountId from [u8; 32] + let vault_temp: Vec = vec![0; 32]; + let customer_temp: Vec = vec![0; 32]; + let mut customer_addr: [u8; 32] = [0; 32]; + customer_addr.copy_from_slice(&customer_temp[0..32]); + let mut vault_addr: [u8; 32] = [0; 32]; + vault_addr.copy_from_slice(&vault_temp[0..32]); + + match T::CustomerCharger::charge_content_owner( + customer_id.clone(), + updated_billing_report.vault.clone(), + amount, + ) { + Ok(_) => { + updated_billing_report + .total_charged_balance + .checked_add(amount) + .ok_or(Error::::ArithmeticOverflow)?; + + Self::deposit_event(Event::::Charged { + cluster_id, + era, + customer_id, + amount, + }); + }, + Err(e) => { + // todo: save problematic charge + // todo: add logs + Self::deposit_event(Event::::ChargeFailed { + cluster_id, + era, + customer_id, + amount, + }); + }, + } } updated_billing_report @@ -307,7 +374,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -338,7 +405,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -376,7 +443,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -412,12 +479,12 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - let node_id = payee.0; + let node_provider_id = payee.0; let charge: BalanceOf = amount.saturated_into::>(); ::Currency::transfer( &updated_billing_report.vault, - &node_id, + &node_provider_id, charge, ExistenceRequirement::KeepAlive, )?; @@ -427,7 +494,12 @@ pub mod pallet { .checked_add(amount) .ok_or(Error::::ArithmeticOverflow)?; - Self::deposit_event(Event::::Rewarded { cluster_id, era, node_id, amount }); + Self::deposit_event(Event::::Rewarded { + cluster_id, + era, + node_provider_id, + amount, + }); } updated_billing_report @@ -448,7 +520,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -481,7 +553,7 @@ pub mod pallet { ) -> DispatchResult { let caller = ensure_signed(origin)?; ensure!( - Self::dac_account().ok_or(Error::::Unauthorised)? == caller, + Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, Error::::Unauthorised ); @@ -574,6 +646,8 @@ pub mod pallet { bytes.extend_from_slice(&cluster_id[..]); bytes.extend_from_slice(&era.encode()); let hash = blake2_128(&bytes); + // todo: assumes AccountId is 32 bytes, which is not ideal + // "modl" + "payouts_" + hash is 28 bytes, the T::AccountId is 32 bytes, so we should be // safe from the truncation and possible collisions caused by it. The rest 4 bytes will // be fulfilled with trailing zeros. diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 178800a4b..2656e5487 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", default-features = false, features = [ "derive" ], optional = true } - sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 16998c344..f9732f7ce 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -4,7 +4,6 @@ use codec::{Decode, Encode}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; - use sp_core::hash::H160; use sp_runtime::{AccountId32, RuntimeDebug}; diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 1e24cd1ae..f0274265c 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1355,6 +1355,8 @@ impl pallet_ddc_payouts::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletId = PayoutsPalletId; type Currency = Balances; + + type CustomerCharger = DdcCustomers; } construct_runtime!( diff --git a/traits/Cargo.toml b/traits/Cargo.toml index b224e2d28..cf6f08ee7 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -10,3 +10,4 @@ sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://g frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/traits/src/customer.rs b/traits/src/customer.rs new file mode 100644 index 000000000..73bbf784a --- /dev/null +++ b/traits/src/customer.rs @@ -0,0 +1,8 @@ +pub trait CustomerCharger { + // todo: WIP for decoupling payout and customers + fn charge_content_owner( + content_owner: T::AccountId, + billing_vault: T::AccountId, + amount: u128, + ) -> sp_runtime::DispatchResult; +} diff --git a/traits/src/lib.rs b/traits/src/lib.rs index f6eb2b0a4..b3b4f9787 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod cluster; +pub mod customer; pub mod staking; From 6939d9e82a2ff3f006e7be0b38a966311b24b1ae Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Mon, 13 Nov 2023 19:03:29 +0200 Subject: [PATCH 493/544] payout <> clusters --- Cargo.lock | 16 ++ pallets/ddc-clusters/src/cluster.rs | 7 +- pallets/ddc-clusters/src/lib.rs | 10 +- pallets/ddc-payouts/Cargo.toml | 15 +- pallets/ddc-payouts/src/lib.rs | 243 +++++++++++++++++++--------- primitives/src/lib.rs | 7 + runtime/cere-dev/src/lib.rs | 2 +- traits/src/cluster.rs | 6 +- 8 files changed, 206 insertions(+), 100 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1505a42b9..204e0fe17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -689,6 +689,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +[[package]] +name = "byte-unit" +version = "4.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da78b32057b8fdfc352504708feeba7216dcd65a2c9ab02978cbd288d1279b6c" +dependencies = [ + "utf8-width", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -5004,6 +5013,7 @@ dependencies = [ name = "pallet-ddc-payouts" version = "4.8.1" dependencies = [ + "byte-unit", "ddc-primitives", "ddc-traits", "frame-benchmarking", @@ -9804,6 +9814,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" + [[package]] name = "valuable" version = "0.1.0" diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 4be19d73f..7fc6e07e4 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -1,6 +1,6 @@ use crate::pallet::Error; use codec::{Decode, Encode}; -use ddc_primitives::ClusterId; +use ddc_primitives::{ClusterId, ClusterPricingParams}; use frame_support::{pallet_prelude::*, parameter_types}; use scale_info::TypeInfo; use sp_runtime::Perbill; @@ -41,10 +41,7 @@ pub struct ClusterGovParams { pub storage_bond_size: Balance, pub storage_chill_delay: BlockNumber, pub storage_unbonding_delay: BlockNumber, - pub unit_per_mb_stored: u128, - pub unit_per_mb_streamed: u128, - pub unit_per_put_request: u128, - pub unit_per_get_request: u128, + pub pricing: ClusterPricingParams, } impl Cluster { diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index cb4aafb7b..ee410b7db 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -19,7 +19,7 @@ use crate::{ cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; -use ddc_primitives::{ClusterId, NodePubKey, NodeType}; +use ddc_primitives::{ClusterId, ClusterPricingParams, NodePubKey, NodeType}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, staking::{StakingVisitor, StakingVisitorError}, @@ -272,6 +272,14 @@ pub mod pallet { } } + fn get_pricing_params( + cluster_id: &ClusterId, + ) -> Result { + let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; + Ok(cluster_gov_params.pricing) + } + fn get_chill_delay( cluster_id: &ClusterId, node_type: NodeType, diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml index ffba7a6d5..d10c1b690 100644 --- a/pallets/ddc-payouts/Cargo.toml +++ b/pallets/ddc-payouts/Cargo.toml @@ -17,6 +17,7 @@ sp-runtime = { version = "6.0.0", default-features = false, git = "https://githu sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +byte-unit = { version = "4.0.19", default-features = false, features = ["u128"] } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -25,17 +26,5 @@ substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/parity [features] default = ["std"] -std = [ - "codec/std", - "ddc-primitives/std", - "frame-support/std", - "frame-system/std", - "frame-benchmarking/std", - "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "sp-staking/std", - "sp-std/std", - "sp-core/std", -] +std = ["codec/std", "ddc-primitives/std", "frame-support/std", "frame-system/std", "frame-benchmarking/std", "scale-info/std", "sp-io/std", "sp-runtime/std", "sp-staking/std", "sp-std/std", "sp-core/std"] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index e44d93de3..77a66aa45 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -15,13 +15,13 @@ #![recursion_limit = "256"] use ddc_primitives::{ClusterId, DdcEra}; -use ddc_traits::customer::CustomerCharger; +use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger}; use frame_support::{ pallet_prelude::*, parameter_types, sp_runtime::SaturatedConversion, traits::{Currency, ExistenceRequirement, LockableCurrency}, - BoundedBTreeSet, + BoundedBTreeMap, BoundedBTreeSet, }; use frame_system::pallet_prelude::*; pub use pallet::*; @@ -54,6 +54,14 @@ pub struct NodeReward { pub gets: u128, } +#[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] +pub struct BillingReportDebt { + pub cluster_id: ClusterId, + pub era: DdcEra, + pub batch_index: BatchIndex, + pub amount: u128, +} + #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct CustomerCharge { pub transfer: u128, @@ -91,6 +99,7 @@ pub mod pallet { type Currency: LockableCurrency; type CustomerCharger: CustomerCharger; + type ClusterVisitor: ClusterVisitor; } #[pallet::event] @@ -153,6 +162,7 @@ pub mod pallet { BatchIndexOverflow, BoundedVecOverflow, ArithmeticOverflow, + NotExpectedClusterState, } #[pallet::storage] @@ -171,16 +181,25 @@ pub mod pallet { #[pallet::getter(fn authorised_caller)] pub type DACAccount = StorageValue<_, T::AccountId>; + #[pallet::storage] + #[pallet::getter(fn debtor_customers)] + pub type DebtorCustomers = StorageMap< + _, + Blake2_128Concat, + T::AccountId, + BoundedBTreeMap, + ValueQuery, + >; + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(T))] pub struct BillingReport { state: State, vault: T::AccountId, authorised_caller: Option, - total_charged_balance: u128, - total_distributed_balance: u128, - total_node_expected_reward: NodeReward, - total_node_expected_usage: NodeUsage, + total_customer_charge: CustomerCharge, + total_distributed_reward: u128, + total_node_usage: NodeUsage, // stage 1 charging_max_batch_index: BatchIndex, charging_processed_batches: BoundedBTreeSet, @@ -195,10 +214,9 @@ pub mod pallet { state: State::default(), vault: T::PalletId::get().into_account_truncating(), authorised_caller: Option::None, - total_charged_balance: Zero::zero(), - total_distributed_balance: Zero::zero(), - total_node_expected_usage: NodeUsage::default(), - total_node_expected_reward: NodeReward::default(), + total_customer_charge: CustomerCharge::default(), + total_distributed_reward: Zero::zero(), + total_node_usage: NodeUsage::default(), charging_max_batch_index: Zero::zero(), charging_processed_batches: BoundedBTreeSet::default(), rewarding_max_batch_index: Zero::zero(), @@ -233,6 +251,11 @@ pub mod pallet { Error::::Unauthorised ); + ensure!( + ActiveBillingReports::::try_get(cluster_id.clone(), era).is_ok() == false, + Error::::NotExpectedState + ); + let mut billing_report = BillingReport::default(); billing_report.vault = Self::sub_account_id(cluster_id.clone(), era); billing_report.state = State::Initialized; @@ -304,9 +327,8 @@ pub mod pallet { let mut updated_billing_report = billing_report.clone(); for payer in payers { - let customer_charge = - get_customer_charge(&payer.1).ok_or(Error::::ArithmeticOverflow)?; - let amount = (|| -> Option { + let customer_charge = get_customer_charge::(cluster_id, &payer.1)?; + let total_customer_charge = (|| -> Option { customer_charge .transfer .checked_add(customer_charge.storage)? @@ -315,42 +337,82 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - let customer_id = payer.0; + let temp_total_customer_storage_charge = updated_billing_report + .total_customer_charge + .storage + .checked_add(customer_charge.storage) + .ok_or(Error::::ArithmeticOverflow)?; + + let temp_total_customer_transfer_charge = updated_billing_report + .total_customer_charge + .transfer + .checked_add(customer_charge.transfer) + .ok_or(Error::::ArithmeticOverflow)?; + + let temp_total_customer_puts_charge = updated_billing_report + .total_customer_charge + .puts + .checked_add(customer_charge.puts) + .ok_or(Error::::ArithmeticOverflow)?; - // todo: decouple AccountId from [u8; 32] - let vault_temp: Vec = vec![0; 32]; - let customer_temp: Vec = vec![0; 32]; - let mut customer_addr: [u8; 32] = [0; 32]; - customer_addr.copy_from_slice(&customer_temp[0..32]); - let mut vault_addr: [u8; 32] = [0; 32]; - vault_addr.copy_from_slice(&vault_temp[0..32]); + let temp_total_customer_gets_charge = updated_billing_report + .total_customer_charge + .gets + .checked_add(customer_charge.gets) + .ok_or(Error::::ArithmeticOverflow)?; + let customer_id = payer.0; match T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), - amount, + total_customer_charge, ) { Ok(_) => { - updated_billing_report - .total_charged_balance - .checked_add(amount) - .ok_or(Error::::ArithmeticOverflow)?; + updated_billing_report.total_customer_charge.storage = + temp_total_customer_storage_charge; + updated_billing_report.total_customer_charge.transfer = + temp_total_customer_transfer_charge; + updated_billing_report.total_customer_charge.puts = + temp_total_customer_puts_charge; + updated_billing_report.total_customer_charge.gets = + temp_total_customer_gets_charge; Self::deposit_event(Event::::Charged { cluster_id, era, customer_id, - amount, + amount: total_customer_charge, }); }, Err(e) => { // todo: save problematic charge // todo: add logs + updated_billing_report + .charging_processed_batches + .try_insert(batch_index) + .map_err(|_| Error::::BoundedVecOverflow)?; + + /* --- + DebtorCustomers = StorageMap< + _, + Blake2_128Concat, + T::AccountId, + BoundedBTreeMap, + let mut debtor_customers = DebtorCustomers::::try_get(cluster_id.clone(), era) + .map_err(|_| Error::::BillingReportDoesNotExist)?; + + ensure!(billing_report.state == State::Initialized, Error::::NotExpectedState); + + billing_report.charging_max_batch_index = max_batch_index; + billing_report.state = State::ChargingCustomers; + ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + --- */ + Self::deposit_event(Event::::ChargeFailed { cluster_id, era, customer_id, - amount, + amount: total_customer_charge, }); }, } @@ -419,12 +481,8 @@ pub mod pallet { ensure!(billing_report.state == State::CustomersCharged, Error::::NotExpectedState); - let total = - get_total_usage_reward(&total_node_usage).ok_or(Error::::ArithmeticOverflow)?; - - billing_report.total_node_expected_usage = total_node_usage; + billing_report.total_node_usage = total_node_usage; billing_report.rewarding_max_batch_index = max_batch_index; - billing_report.total_node_expected_reward = total; billing_report.state = State::RewardingProviders; ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); @@ -465,12 +523,13 @@ pub mod pallet { let mut updated_billing_report = billing_report.clone(); for payee in payees { - let node_reward = get_node_reward( + let node_reward = get_node_reward::( &payee.1, - &billing_report.total_node_expected_usage, - &billing_report.total_node_expected_reward, - ); - let amount = (|| -> Option { + &billing_report.total_node_usage, + &billing_report.total_customer_charge, + ) + .ok_or(Error::::ArithmeticOverflow)?; + let amount_to_reward = (|| -> Option { node_reward .transfer .checked_add(node_reward.storage)? @@ -480,25 +539,25 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; let node_provider_id = payee.0; - let charge: BalanceOf = amount.saturated_into::>(); + let reward: BalanceOf = amount_to_reward.saturated_into::>(); ::Currency::transfer( &updated_billing_report.vault, &node_provider_id, - charge, + reward, ExistenceRequirement::KeepAlive, )?; updated_billing_report - .total_distributed_balance - .checked_add(amount) + .total_distributed_reward + .checked_add(amount_to_reward) .ok_or(Error::::ArithmeticOverflow)?; Self::deposit_event(Event::::Rewarded { cluster_id, era, node_provider_id, - amount, + amount: amount_to_reward, }); } @@ -561,8 +620,18 @@ pub mod pallet { .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ProvidersRewarded, Error::::NotExpectedState); + let expected_amount_to_reward = (|| -> Option { + billing_report + .total_customer_charge + .transfer + .checked_add(billing_report.total_customer_charge.storage)? + .checked_add(billing_report.total_customer_charge.puts)? + .checked_add(billing_report.total_customer_charge.gets) + })() + .ok_or(Error::::ArithmeticOverflow)?; + ensure!( - billing_report.total_charged_balance == billing_report.total_distributed_balance, + expected_amount_to_reward == billing_report.total_distributed_reward, Error::::NotDistributedBalance ); @@ -573,51 +642,67 @@ pub mod pallet { } } - fn get_node_reward( + fn get_node_reward( node_usage: &NodeUsage, - total_usage: &NodeUsage, - total_reward: &NodeReward, - ) -> NodeReward { + total_nodes_usage: &NodeUsage, + total_customer_charge: &CustomerCharge, + ) -> Option { let mut node_reward = NodeReward::default(); - let mut ratio = - Perbill::from_rational(node_usage.transferred_bytes, total_usage.transferred_bytes); - node_reward.transfer = (ratio * total_reward.transfer) as u128; - - ratio = Perbill::from_rational(node_usage.stored_bytes, total_usage.stored_bytes); - node_reward.storage = (ratio * total_reward.storage) as u128; + let mut ratio = Perbill::from_rational( + node_usage.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + node_reward.transfer = (ratio * total_customer_charge.transfer) as u128; - ratio = Perbill::from_rational(node_usage.number_of_puts, total_usage.number_of_puts); - node_reward.puts = (ratio * total_reward.puts) as u128; + ratio = Perbill::from_rational(node_usage.stored_bytes, total_nodes_usage.stored_bytes); + node_reward.storage = (ratio * total_customer_charge.storage) as u128; - ratio = Perbill::from_rational(node_usage.number_of_gets, total_usage.number_of_gets); - node_reward.gets = (ratio * total_reward.gets) as u128; + ratio = Perbill::from_rational(node_usage.number_of_puts, total_nodes_usage.number_of_puts); + node_reward.puts = (ratio * total_customer_charge.puts) as u128; - node_reward - } - - // todo: to calculate actual charge based on the metrics - fn get_total_usage_reward(total_usage: &NodeUsage) -> Option { - let mut total = NodeReward::default(); + ratio = Perbill::from_rational(node_usage.number_of_gets, total_nodes_usage.number_of_gets); + node_reward.gets = (ratio * total_customer_charge.gets) as u128; - total.transfer = 1; - total.storage = 2; - total.puts = 3; - total.gets = 4; - - Option::Some(total) + Some(node_reward) } - // todo: to calculate actual charge based on the metrics - fn get_customer_charge(usage: &CustomerUsage) -> Option { + fn get_customer_charge( + cluster_id: ClusterId, + usage: &CustomerUsage, + ) -> Result> { let mut total = CustomerCharge::default(); - total.transfer = 1; - total.storage = 2; - total.puts = 3; - total.gets = 4; - - Option::Some(total) + let pricing = T::ClusterVisitor::get_pricing_params(&cluster_id) + .map_err(|_| Error::::NotExpectedClusterState)?; + + total.transfer = (|| -> Option { + usage + .transferred_bytes + .checked_mul(pricing.unit_per_mb_streamed)? + .checked_div(byte_unit::MEBIBYTE) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + total.storage = (|| -> Option { + usage + .stored_bytes + .checked_mul(pricing.unit_per_mb_stored)? + .checked_div(byte_unit::MEBIBYTE) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + total.gets = usage + .number_of_gets + .checked_mul(pricing.unit_per_get_request) + .ok_or(Error::::ArithmeticOverflow)?; + + total.puts = usage + .number_of_puts + .checked_mul(pricing.unit_per_put_request) + .ok_or(Error::::ArithmeticOverflow)?; + + Ok(total) } fn validate_batches( @@ -646,7 +731,7 @@ pub mod pallet { bytes.extend_from_slice(&cluster_id[..]); bytes.extend_from_slice(&era.encode()); let hash = blake2_128(&bytes); - // todo: assumes AccountId is 32 bytes, which is not ideal + // todo: assumes AccountId is 32 bytes, which is not ideal -> rewrite it // "modl" + "payouts_" + hash is 28 bytes, the T::AccountId is 32 bytes, so we should be // safe from the truncation and possible collisions caused by it. The rest 4 bytes will diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index f9732f7ce..0ec6c6924 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -11,6 +11,13 @@ pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterPricingParams { + pub unit_per_mb_stored: u128, + pub unit_per_mb_streamed: u128, + pub unit_per_put_request: u128, + pub unit_per_get_request: u128, +} #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index f0274265c..dcac54c46 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1355,8 +1355,8 @@ impl pallet_ddc_payouts::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletId = PayoutsPalletId; type Currency = Balances; - type CustomerCharger = DdcCustomers; + type ClusterVisitor = DdcClusters; } construct_runtime!( diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index bbd21ed32..cdb3a5e21 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,4 +1,4 @@ -use ddc_primitives::{ClusterId, NodePubKey, NodeType}; +use ddc_primitives::{ClusterId, ClusterPricingParams, NodePubKey, NodeType}; use frame_system::Config; pub trait ClusterVisitor { @@ -11,6 +11,10 @@ pub trait ClusterVisitor { node_type: NodeType, ) -> Result; + fn get_pricing_params( + cluster_id: &ClusterId, + ) -> Result; + fn get_chill_delay( cluster_id: &ClusterId, node_type: NodeType, From fca97a3c5ab4874a26a7600becb7ecd8def317f9 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Mon, 13 Nov 2023 20:16:44 +0200 Subject: [PATCH 494/544] customer debtors --- pallets/ddc-payouts/src/lib.rs | 48 ++++++++++++++++------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 77a66aa45..bf1a286dc 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -183,11 +183,13 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn debtor_customers)] - pub type DebtorCustomers = StorageMap< + pub type DebtorCustomers = StorageDoubleMap< _, Blake2_128Concat, + ClusterId, + Blake2_128Concat, T::AccountId, - BoundedBTreeMap, + u128, ValueQuery, >; @@ -361,7 +363,7 @@ pub mod pallet { .checked_add(customer_charge.gets) .ok_or(Error::::ArithmeticOverflow)?; - let customer_id = payer.0; + let customer_id = payer.0.clone(); match T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), @@ -385,28 +387,24 @@ pub mod pallet { }); }, Err(e) => { - // todo: save problematic charge - // todo: add logs - updated_billing_report - .charging_processed_batches - .try_insert(batch_index) - .map_err(|_| Error::::BoundedVecOverflow)?; - - /* --- - DebtorCustomers = StorageMap< - _, - Blake2_128Concat, - T::AccountId, - BoundedBTreeMap, - let mut debtor_customers = DebtorCustomers::::try_get(cluster_id.clone(), era) - .map_err(|_| Error::::BillingReportDoesNotExist)?; - - ensure!(billing_report.state == State::Initialized, Error::::NotExpectedState); - - billing_report.charging_max_batch_index = max_batch_index; - billing_report.state = State::ChargingCustomers; - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); - --- */ + let customer_debt = BillingReportDebt { + cluster_id, + era, + batch_index, + amount: total_customer_charge, + }; + let mut customer_dept = + DebtorCustomers::::try_get(cluster_id, customer_id.clone()) + .unwrap_or(Zero::zero()); + + customer_dept = customer_dept + .checked_add(total_customer_charge) + .ok_or(Error::::ArithmeticOverflow)?; + DebtorCustomers::::insert( + cluster_id, + customer_id.clone(), + customer_dept, + ); Self::deposit_event(Event::::ChargeFailed { cluster_id, From 54953240c6ce931e47d0a10cb8f9510714bf6032 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 13 Nov 2023 20:41:38 +0100 Subject: [PATCH 495/544] fix(pallet_ddc_staking): checking node type before making node active for specific ddc action --- pallets/ddc-staking/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 9c8469785..d68cadab8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -303,6 +303,10 @@ pub mod pallet { NoClusterGovParams, /// Conditions for fast chill are not met, try the regular `chill` from FastChillProhibited, + /// Serving operation is called for non-CDN node + ServingProhibited, + /// Storing operation is called for non-Storage node + StoringProhibited, } #[pallet::call] @@ -544,6 +548,13 @@ pub mod pallet { // Can't participate in CDN if already participating in storage network. ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); + // Only CDN node can perform serving (i.e. streaming content) + let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; + ensure!( + matches!(node_pub_key, NodePubKey::CDNPubKey(_)), + Error::::ServingProhibited + ); + // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::cdns(stash) { // Switching the cluster is prohibited. The user should chill first. @@ -583,6 +594,13 @@ pub mod pallet { // Can't participate in storage network if already participating in CDN. ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); + // Only Storage node can perform storing (i.e. saving content) + let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; + ensure!( + matches!(node_pub_key, NodePubKey::StoragePubKey(_)), + Error::::StoringProhibited + ); + // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::storages(stash) { // Switching the cluster is prohibited. The user should chill first. From 6a53b71e7678d23727d5ecd26d6b89c5c792783d Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 13 Nov 2023 21:07:59 +0100 Subject: [PATCH 496/544] fix: clippy issue is fixed and runtime version is upgraded --- pallets/ddc-staking/src/lib.rs | 4 ++-- runtime/cere-dev/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index d68cadab8..6ccaabfd0 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -549,7 +549,7 @@ pub mod pallet { ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); // Only CDN node can perform serving (i.e. streaming content) - let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; + let node_pub_key = >::get(stash).ok_or(Error::::BadState)?; ensure!( matches!(node_pub_key, NodePubKey::CDNPubKey(_)), Error::::ServingProhibited @@ -595,7 +595,7 @@ pub mod pallet { ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); // Only Storage node can perform storing (i.e. saving content) - let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; + let node_pub_key = >::get(stash).ok_or(Error::::BadState)?; ensure!( matches!(node_pub_key, NodePubKey::StoragePubKey(_)), Error::::StoringProhibited diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index fb260b4ed..d584730e4 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -129,7 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48013, + spec_version: 48014, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From b6c7951877286e012af5101d7902596c43476a87 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Mon, 13 Nov 2023 22:53:57 +0200 Subject: [PATCH 497/544] dprint fmt --- Cargo.toml | 34 ++++---- pallets/ddc-payouts/Cargo.toml | 18 +++- primitives/Cargo.toml | 2 +- runtime/cere-dev/Cargo.toml | 152 ++++++++++++++++----------------- traits/Cargo.toml | 2 +- 5 files changed, 110 insertions(+), 98 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa71105e8..aacb4cf63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,23 +18,23 @@ substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/pa [workspace] members = [ - "cli", - "node/client", - "node/service", - "rpc", - "runtime/cere", - "runtime/cere-dev", - "pallets/chainbridge", - "pallets/ddc", - "pallets/ddc-staking", - "pallets/erc721", - "pallets/erc20", - "pallets/ddc-metrics-offchain-worker", - "pallets/ddc-customers", - "pallets/ddc-nodes", - "pallets/ddc-clusters", - "pallets/ddc-payouts", - "primitives", + "cli", + "node/client", + "node/service", + "rpc", + "runtime/cere", + "runtime/cere-dev", + "pallets/chainbridge", + "pallets/ddc", + "pallets/ddc-staking", + "pallets/erc721", + "pallets/erc20", + "pallets/ddc-metrics-offchain-worker", + "pallets/ddc-customers", + "pallets/ddc-nodes", + "pallets/ddc-clusters", + "pallets/ddc-payouts", + "primitives", ] [profile.release] diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml index d10c1b690..ed77fa188 100644 --- a/pallets/ddc-payouts/Cargo.toml +++ b/pallets/ddc-payouts/Cargo.toml @@ -4,6 +4,7 @@ version = "4.8.1" edition = "2021" [dependencies] +byte-unit = { version = "4.0.19", default-features = false, features = ["u128"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } @@ -12,12 +13,11 @@ frame-support = { version = "4.0.0-dev", default-features = false, git = "https: frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -byte-unit = { version = "4.0.19", default-features = false, features = ["u128"] } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -26,5 +26,17 @@ substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/parity [features] default = ["std"] -std = ["codec/std", "ddc-primitives/std", "frame-support/std", "frame-system/std", "frame-benchmarking/std", "scale-info/std", "sp-io/std", "sp-runtime/std", "sp-staking/std", "sp-std/std", "sp-core/std"] +std = [ + "codec/std", + "ddc-primitives/std", + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-staking/std", + "sp-std/std", + "sp-core/std", +] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index a7b80e589..3986f6b98 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -serde = { version = "1.0.136", default-features = false, features = [ "derive" ], optional = true } +serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 88c42e493..dc83eeb30 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -64,6 +64,7 @@ pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../ pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-payouts = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-payouts" } pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -100,7 +101,6 @@ pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-fe pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-payouts = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-payouts" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -109,81 +109,81 @@ substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/pari default = ["std"] with-tracing = ["frame-executive/with-tracing"] std = [ - "sp-authority-discovery/std", - "pallet-authority-discovery/std", - "pallet-authorship/std", - "sp-consensus-babe/std", - "pallet-babe/std", - "pallet-bags-list/std", - "pallet-balances/std", - "pallet-bounties/std", - "sp-block-builder/std", - "codec/std", - "scale-info/std", - "pallet-collective/std", - "pallet-contracts/std", - "pallet-contracts-primitives/std", - "pallet-contracts-rpc-runtime-api/std", - "pallet-democracy/std", - "pallet-fast-unstake/std", - "pallet-elections-phragmen/std", - "frame-executive/std", - "pallet-cere-ddc/std", - "pallet-chainbridge/std", - "pallet-erc721/std", - "pallet-erc20/std", - "pallet-grandpa/std", - "pallet-im-online/std", - "pallet-indices/std", - "sp-inherents/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-nomination-pools/std", - "pallet-nomination-pools-runtime-api/std", - "pallet-identity/std", - "pallet-scheduler/std", - "node-primitives/std", - "sp-offchain/std", - "pallet-offences/std", - "pallet-proxy/std", - "sp-core/std", - "pallet-randomness-collective-flip/std", - "sp-std/std", - "pallet-session/std", - "sp-api/std", - "sp-runtime/std", - "sp-staking/std", - "pallet-staking/std", - "sp-session/std", - "pallet-sudo/std", - "frame-support/std", - "frame-benchmarking/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "pallet-election-provider-multi-phase/std", - "pallet-timestamp/std", - "pallet-tips/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-treasury/std", - "sp-transaction-pool/std", - "pallet-utility/std", - "sp-version/std", - "pallet-society/std", - "pallet-recovery/std", - "pallet-vesting/std", - "log/std", - "frame-try-runtime/std", - "sp-io/std", - "pallet-child-bounties/std", - "pallet-ddc-metrics-offchain-worker/std", - "pallet-ddc-staking/std", - "cere-runtime-common/std", - "cere-dev-runtime-constants/std", - "pallet-ddc-customers/std", - "pallet-ddc-nodes/std", - "pallet-ddc-clusters/std", - "pallet-ddc-payouts/std", + "sp-authority-discovery/std", + "pallet-authority-discovery/std", + "pallet-authorship/std", + "sp-consensus-babe/std", + "pallet-babe/std", + "pallet-bags-list/std", + "pallet-balances/std", + "pallet-bounties/std", + "sp-block-builder/std", + "codec/std", + "scale-info/std", + "pallet-collective/std", + "pallet-contracts/std", + "pallet-contracts-primitives/std", + "pallet-contracts-rpc-runtime-api/std", + "pallet-democracy/std", + "pallet-fast-unstake/std", + "pallet-elections-phragmen/std", + "frame-executive/std", + "pallet-cere-ddc/std", + "pallet-chainbridge/std", + "pallet-erc721/std", + "pallet-erc20/std", + "pallet-grandpa/std", + "pallet-im-online/std", + "pallet-indices/std", + "sp-inherents/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-nomination-pools/std", + "pallet-nomination-pools-runtime-api/std", + "pallet-identity/std", + "pallet-scheduler/std", + "node-primitives/std", + "sp-offchain/std", + "pallet-offences/std", + "pallet-proxy/std", + "sp-core/std", + "pallet-randomness-collective-flip/std", + "sp-std/std", + "pallet-session/std", + "sp-api/std", + "sp-runtime/std", + "sp-staking/std", + "pallet-staking/std", + "sp-session/std", + "pallet-sudo/std", + "frame-support/std", + "frame-benchmarking/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "pallet-election-provider-multi-phase/std", + "pallet-timestamp/std", + "pallet-tips/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "sp-transaction-pool/std", + "pallet-utility/std", + "sp-version/std", + "pallet-society/std", + "pallet-recovery/std", + "pallet-vesting/std", + "log/std", + "frame-try-runtime/std", + "sp-io/std", + "pallet-child-bounties/std", + "pallet-ddc-metrics-offchain-worker/std", + "pallet-ddc-staking/std", + "cere-runtime-common/std", + "cere-dev-runtime-constants/std", + "pallet-ddc-customers/std", + "pallet-ddc-nodes/std", + "pallet-ddc-clusters/std", + "pallet-ddc-payouts/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/traits/Cargo.toml b/traits/Cargo.toml index aa4110332..21512a39f 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" [dependencies] ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } From dd4eb362134198dd68e42d7e09a41c048aad1114 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Tue, 14 Nov 2023 01:54:40 +0200 Subject: [PATCH 498/544] clippy --- pallets/ddc-customers/src/lib.rs | 2 +- pallets/ddc-payouts/src/lib.rs | 66 +++++++++++++++----------------- pallets/ddc-staking/src/mock.rs | 13 ++++++- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 94255b20c..2454eae19 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -459,7 +459,7 @@ pub mod pallet { ::Currency::transfer( &account_id, &owner, - value.clone(), + value, ExistenceRequirement::KeepAlive, )?; Self::deposit_event(Event::::Withdrawn(owner, value)); diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index bf1a286dc..60cc3ab75 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -15,13 +15,13 @@ #![recursion_limit = "256"] use ddc_primitives::{ClusterId, DdcEra}; -use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger}; +use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger as ICustomerCharger}; use frame_support::{ pallet_prelude::*, parameter_types, sp_runtime::SaturatedConversion, traits::{Currency, ExistenceRequirement, LockableCurrency}, - BoundedBTreeMap, BoundedBTreeSet, + BoundedBTreeSet, }; use frame_system::pallet_prelude::*; pub use pallet::*; @@ -98,7 +98,7 @@ pub mod pallet { type Currency: LockableCurrency; - type CustomerCharger: CustomerCharger; + type CustomerCharger: ICustomerCharger; type ClusterVisitor: ClusterVisitor; } @@ -254,14 +254,18 @@ pub mod pallet { ); ensure!( - ActiveBillingReports::::try_get(cluster_id.clone(), era).is_ok() == false, + ActiveBillingReports::::try_get(cluster_id, era).is_err(), Error::::NotExpectedState ); - let mut billing_report = BillingReport::default(); - billing_report.vault = Self::sub_account_id(cluster_id.clone(), era); + let mut billing_report = BillingReport:: { + vault: Self::sub_account_id(cluster_id, era), + state: State::Initialized, + ..Default::default() + }; + billing_report.vault = Self::sub_account_id(cluster_id, era); billing_report.state = State::Initialized; - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::BillingReportInitialized { cluster_id, era }); @@ -286,14 +290,14 @@ pub mod pallet { Error::::BatchIndexOverflow ); - let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::Initialized, Error::::NotExpectedState); billing_report.charging_max_batch_index = max_batch_index; billing_report.state = State::ChargingCustomers; - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::ChargingStarted { cluster_id, era }); @@ -314,7 +318,7 @@ pub mod pallet { Error::::Unauthorised ); - let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ChargingCustomers, Error::::NotExpectedState); @@ -327,7 +331,7 @@ pub mod pallet { Error::::BatchIndexAlreadyProcessed ); - let mut updated_billing_report = billing_report.clone(); + let mut updated_billing_report = billing_report; for payer in payers { let customer_charge = get_customer_charge::(cluster_id, &payer.1)?; let total_customer_charge = (|| -> Option { @@ -386,16 +390,10 @@ pub mod pallet { amount: total_customer_charge, }); }, - Err(e) => { - let customer_debt = BillingReportDebt { - cluster_id, - era, - batch_index, - amount: total_customer_charge, - }; + Err(_e) => { let mut customer_dept = DebtorCustomers::::try_get(cluster_id, customer_id.clone()) - .unwrap_or(Zero::zero()); + .unwrap_or_else(|_| Zero::zero()); customer_dept = customer_dept .checked_add(total_customer_charge) @@ -438,7 +436,7 @@ pub mod pallet { Error::::Unauthorised ); - let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ChargingCustomers, Error::::NotExpectedState); @@ -448,7 +446,7 @@ pub mod pallet { )?; billing_report.state = State::CustomersCharged; - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::ChargingFinished { cluster_id, era }); @@ -474,7 +472,7 @@ pub mod pallet { Error::::BatchIndexOverflow ); - let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::CustomersCharged, Error::::NotExpectedState); @@ -482,7 +480,7 @@ pub mod pallet { billing_report.total_node_usage = total_node_usage; billing_report.rewarding_max_batch_index = max_batch_index; billing_report.state = State::RewardingProviders; - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::RewardingStarted { cluster_id, era }); @@ -503,7 +501,7 @@ pub mod pallet { Error::::Unauthorised ); - let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!( @@ -581,7 +579,7 @@ pub mod pallet { Error::::Unauthorised ); - let mut billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!( @@ -595,7 +593,7 @@ pub mod pallet { )?; billing_report.state = State::ProvidersRewarded; - ActiveBillingReports::::insert(cluster_id.clone(), era, billing_report); + ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::RewardingFinished { cluster_id, era }); @@ -614,7 +612,7 @@ pub mod pallet { Error::::Unauthorised ); - let billing_report = ActiveBillingReports::::try_get(cluster_id.clone(), era) + let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ProvidersRewarded, Error::::NotExpectedState); @@ -633,7 +631,7 @@ pub mod pallet { Error::::NotDistributedBalance ); - ActiveBillingReports::::remove(cluster_id.clone(), era); + ActiveBillingReports::::remove(cluster_id, era); Self::deposit_event(Event::::BillingReportFinalized { cluster_id, era }); Ok(()) @@ -651,16 +649,16 @@ pub mod pallet { node_usage.transferred_bytes, total_nodes_usage.transferred_bytes, ); - node_reward.transfer = (ratio * total_customer_charge.transfer) as u128; + node_reward.transfer = ratio * total_customer_charge.transfer; ratio = Perbill::from_rational(node_usage.stored_bytes, total_nodes_usage.stored_bytes); - node_reward.storage = (ratio * total_customer_charge.storage) as u128; + node_reward.storage = ratio * total_customer_charge.storage; ratio = Perbill::from_rational(node_usage.number_of_puts, total_nodes_usage.number_of_puts); - node_reward.puts = (ratio * total_customer_charge.puts) as u128; + node_reward.puts = ratio * total_customer_charge.puts; ratio = Perbill::from_rational(node_usage.number_of_gets, total_nodes_usage.number_of_gets); - node_reward.gets = (ratio * total_customer_charge.gets) as u128; + node_reward.gets = ratio * total_customer_charge.gets; Some(node_reward) } @@ -720,10 +718,6 @@ pub mod pallet { } impl Pallet { - fn account_id() -> T::AccountId { - T::PalletId::get().into_account_truncating() - } - fn sub_account_id(cluster_id: ClusterId, era: DdcEra) -> T::AccountId { let mut bytes = Vec::new(); bytes.extend_from_slice(&cluster_id[..]); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 549653b92..a047f30c1 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -3,7 +3,7 @@ #![allow(dead_code)] use crate::{self as pallet_ddc_staking, *}; -use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; +use ddc_primitives::{CDNNodePubKey, ClusterPricingParams, StorageNodePubKey}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, node::{NodeVisitor, NodeVisitorError}, @@ -131,6 +131,17 @@ impl ClusterVisitor for TestClusterVisitor { ) -> Result { Ok(T::BlockNumber::from(10u32)) } + + fn get_pricing_params( + _cluster_id: &ClusterId, + ) -> Result { + Ok(ClusterPricingParams { + unit_per_mb_stored: 2, + unit_per_mb_streamed: 3, + unit_per_put_request: 4, + unit_per_get_request: 5, + }) + } } pub struct TestNodeVisitor; From efb480dd632f5172a77ba1e9eb75554ccd76ac95 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 14 Nov 2023 01:49:09 +0100 Subject: [PATCH 499/544] feat: adding an event that indicates the stake as active --- pallets/ddc-staking/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 6ccaabfd0..d773f6130 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -173,14 +173,14 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; - /// The map of (wannabe) CDN participants stash keys to the DDC cluster ID they wish to + /// The map of (wannable) CDN participants stash keys to the DDC cluster ID they wish to /// participate into. #[pallet::storage] #[pallet::getter(fn cdns)] pub type CDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// The map of (wannabe) storage network participants stash keys to the DDC cluster ID they wish - /// to participate into. + /// The map of (wannable) storage network participants stash keys to the DDC cluster ID they + /// wish to participate into. #[pallet::storage] #[pallet::getter(fn storages)] pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; @@ -270,6 +270,9 @@ pub mod pallet { /// An account has declared desire to stop participating in CDN or storage network soon. /// \[stash, cluster, block\] ChillSoon(T::AccountId, ClusterId, T::BlockNumber), + /// An account that started participating as either a storage network or CDN participant. + /// \[stash\] + Activated(T::AccountId), } #[pallet::error] @@ -564,7 +567,9 @@ pub mod pallet { return Ok(()) } - Self::do_add_cdn(stash, cluster_id); + Self::do_add_cdn(&stash, cluster_id); + Self::deposit_event(Event::::Activated(stash.clone())); + Ok(()) } @@ -610,7 +615,8 @@ pub mod pallet { return Ok(()) } - Self::do_add_storage(stash, cluster_id); + Self::do_add_storage(&stash, cluster_id); + Self::deposit_event(Event::::Activated(stash.clone())); Ok(()) } From bb6c83a0d0c2c3cce70a50b826b7d59ca9fdf96f Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 14 Nov 2023 01:58:33 +0100 Subject: [PATCH 500/544] fix: clippy --- pallets/ddc-staking/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index d773f6130..10ba3ff36 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -567,7 +567,7 @@ pub mod pallet { return Ok(()) } - Self::do_add_cdn(&stash, cluster_id); + Self::do_add_cdn(stash, cluster_id); Self::deposit_event(Event::::Activated(stash.clone())); Ok(()) @@ -615,7 +615,7 @@ pub mod pallet { return Ok(()) } - Self::do_add_storage(&stash, cluster_id); + Self::do_add_storage(stash, cluster_id); Self::deposit_event(Event::::Activated(stash.clone())); Ok(()) From 904ccd4920ea494baa871c8f2dfa731da6777dc6 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 14 Nov 2023 11:26:59 +0100 Subject: [PATCH 501/544] add unit tests for customers --- Cargo.lock | 5 + pallets/ddc-customers/Cargo.toml | 5 + pallets/ddc-customers/src/lib.rs | 5 + pallets/ddc-customers/src/mock.rs | 154 +++++++++++++++ pallets/ddc-customers/src/tests.rs | 290 +++++++++++++++++++++++++++++ 5 files changed, 459 insertions(+) create mode 100644 pallets/ddc-customers/src/mock.rs create mode 100644 pallets/ddc-customers/src/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 025b489bf..5ae2e22e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4902,10 +4902,15 @@ dependencies = [ "frame-support", "frame-system", "log", + "pallet-balances", + "pallet-timestamp", "parity-scale-codec", "scale-info", + "sp-core", + "sp-io", "sp-runtime", "sp-std", + "sp-tracing", "substrate-test-utils", ] diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 89faf08a5..580ca33a0 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -11,10 +11,15 @@ frame-support = { version = "4.0.0-dev", default-features = false, git = "https: frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index f807f0985..c010b0b2f 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -1,6 +1,11 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +#[cfg(test)] +pub(crate) mod mock; +#[cfg(test)] +mod tests; + use codec::{Decode, Encode, HasCompact}; use ddc_primitives::{BucketId, ClusterId}; diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs new file mode 100644 index 000000000..589e76f31 --- /dev/null +++ b/pallets/ddc-customers/src/mock.rs @@ -0,0 +1,154 @@ +//! Test utilities + +#![allow(dead_code)] + +use crate::{self as pallet_ddc_customers, *}; +use ddc_primitives::{NodePubKey, NodeType}; +use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; + +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64, Everything}, + weights::constants::RocksDbWeight, +}; +use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; +use sp_core::H256; +use sp_io::TestExternalities; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; + +/// The AccountId alias in this test module. +pub(crate) type AccountId = u64; +pub(crate) type AccountIndex = u64; +pub(crate) type BlockNumber = u64; +pub(crate) type Balance = u128; + +type UncheckedExtrinsic = MockUncheckedExtrinsic; +type Block = MockBlock; + +construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + DdcCustomers: pallet_ddc_customers::{Pallet, Call, Storage, Config, Event}, + } +); + +parameter_types! { + pub static ExistentialDeposit: Balance = 1; +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = RocksDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type MaxLocks = ConstU32<1024>; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<5>; + type WeightInfo = (); +} + +parameter_types! { + pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake + pub const UnlockingDelay: BlockNumber = 10u64; // 10 blocks for test +} + +impl crate::pallet::Config for Test { + type UnlockingDelay = UnlockingDelay; + type Currency = Balances; + type PalletId = DdcCustomersPalletId; + type RuntimeEvent = RuntimeEvent; + type ClusterVisitor = TestClusterVisitor; +} + +pub struct TestClusterVisitor; +impl ClusterVisitor for TestClusterVisitor { + fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { + true + } + fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { + Ok(()) + } + fn get_bond_size( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(10) + } + fn get_chill_delay( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(T::BlockNumber::from(10u32)) + } + fn get_unbonding_delay( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(T::BlockNumber::from(10u32)) + } +} + +pub(crate) type TestRuntimeCall = ::RuntimeCall; + +pub struct ExtBuilder; + +impl ExtBuilder { + fn build(self) -> TestExternalities { + sp_tracing::try_init_simple(); + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let _ = pallet_balances::GenesisConfig:: { balances: vec![(1, 100), (2, 100)] } + .assimilate_storage(&mut storage); + + TestExternalities::new(storage) + } + pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + sp_tracing::try_init_simple(); + let mut ext = self.build(); + ext.execute_with(test); + } +} diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs new file mode 100644 index 000000000..43bc29c55 --- /dev/null +++ b/pallets/ddc-customers/src/tests.rs @@ -0,0 +1,290 @@ +//! Tests for the module. + +use super::{mock::*, *}; +use ddc_primitives::ClusterId; + +use frame_support::{assert_noop, assert_ok}; +use pallet_balances::Error as BalancesError; + +#[test] +fn create_bucket_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + + // Bucket created + assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(1), cluster_id.clone())); + + // Check storage + assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!( + DdcCustomers::buckets(&1), + Some(Bucket { bucket_id: 1, owner_id: 1, cluster_id }) + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 1); + System::assert_last_event(Event::BucketCreated { 0: 1u64.into() }.into()) + + // let bytes = [0u8; 32]; + // let node_pub_key = AccountId32::from(bytes); + // let cdn_node_params = CDNNodeParams { + // host: vec![1u8, 255], + // http_port: 35000u16, + // grpc_port: 25000u16, + // p2p_port: 15000u16, + // }; + + // // Node params are not valid + // assert_noop!( + // DdcNodes::create_node( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // NodeParams::StorageParams(StorageNodeParams { + // host: vec![1u8, 255], + // http_port: 35000u16, + // grpc_port: 25000u16, + // p2p_port: 15000u16, + // }) + // ), + // Error::::InvalidNodeParams + // ); + + // // Node already exists + // assert_noop!( + // DdcNodes::create_node( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // NodeParams::CDNParams(cdn_node_params) + // ), + // Error::::NodeAlreadyExists + // ); + + // // Checking that event was emitted + // assert_eq!(System::events().len(), 1); + // System::assert_last_event( + // Event::NodeCreated { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), + // ) + }) +} + +#[test] +fn deposit_and_deposit_extra_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + // let bytes = [0u8; 32]; + // let node_pub_key = AccountId32::from(bytes); + // let storage_node_params = StorageNodeParams { + // host: vec![1u8, 255], + // http_port: 35000u16, + // grpc_port: 25000u16, + // p2p_port: 15000u16, + // }; + // let cdn_node_params = CDNNodeParams { + // host: vec![1u8, 255], + // http_port: 35000u16, + // grpc_port: 25000u16, + // p2p_port: 15000u16, + // }; + + // Deposit dust + assert_noop!( + DdcCustomers::deposit(RuntimeOrigin::signed(1), 0_u128.into()), + Error::::InsufficientDeposit + ); + + // Deposit all tokens fails (should not kill account) + assert_noop!( + DdcCustomers::deposit(RuntimeOrigin::signed(1), 100_u128.into()), + BalancesError::::KeepAlive + ); + + // Deposited + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128.into())); + + // Check storage + assert_eq!( + DdcCustomers::ledger(&1), + Some(AccountsLedger { + owner: 1, + total: 10_u128.into(), + active: 10_u128.into(), + unlocking: Default::default(), + }) + ); + + // Checking that event was emitted + System::assert_last_event(Event::Deposited { 0: 1, 1: 10 }.into()); + + // Deposit should fail when called the second time + assert_noop!( + DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128.into()), + Error::::AlreadyPaired + ); + + // Deposit extra fails if not owner + assert_noop!( + DdcCustomers::deposit_extra(RuntimeOrigin::signed(2), 10_u128.into()), + Error::::NotOwner + ); + + // Deposited extra + assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(1), 20_u128.into())); + + // Check storage + assert_eq!( + DdcCustomers::ledger(&1), + Some(AccountsLedger { + owner: 1, + total: 30_u128.into(), + active: 30_u128.into(), + unlocking: Default::default(), + }) + ); + + // Checking that event was emitted + System::assert_last_event(Event::Deposited { 0: 1, 1: 20 }.into()); + + // // Set node params + // assert_ok!(DdcNodes::set_node_params( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // NodeParams::CDNParams(cdn_node_params.clone()) + // )); + + // // Node params are not valid + // assert_noop!( + // DdcNodes::set_node_params( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // NodeParams::StorageParams(storage_node_params) + // ), + // Error::::InvalidNodeParams + // ); + + // // Only node provider can set params + // assert_noop!( + // DdcNodes::set_node_params( + // RuntimeOrigin::signed(2), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // NodeParams::CDNParams(cdn_node_params.clone()) + // ), + // Error::::OnlyNodeProvider + // ); + }) +} + +#[test] +fn unlock_and_withdraw_deposit_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + // Deposited + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 35_u128.into())); + // So there is always positive balance within pallet + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(2), 10_u128.into())); + + // Unlock chunk + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128.into())); + System::set_block_number(2); + + let mut unlocking_chunks: BoundedVec, MaxUnlockingChunks> = + Default::default(); + match unlocking_chunks.try_push(UnlockChunk { value: 1, block: 11 }) { + Ok(_) => (), + Err(_) => println!("No more chunks"), + }; + // Check storage + assert_eq!( + DdcCustomers::ledger(&1), + Some(AccountsLedger { + owner: 1, + total: 35_u128.into(), + active: 34_u128.into(), + unlocking: unlocking_chunks.clone(), + }) + ); + + // Reach max unlock chunks + for i in 1..32 { + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128.into())); + System::set_block_number(i + 2); + } + + // No more chunks can be added + assert_noop!( + DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128.into()), + Error::::NoMoreChunks + ); + + // Set the block to withdraw all unlocked chunks + System::set_block_number(42); + + assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(1))); + // Check storage + assert_eq!( + DdcCustomers::ledger(&1), + Some(AccountsLedger { + owner: 1, + total: 3_u128.into(), + active: 3_u128.into(), + unlocking: Default::default(), + }) + ); + + // Unlock remaining chuncks & withdraw + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 3_u128.into())); + System::set_block_number(52); + assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(1))); + + // Check storage + assert_eq!(DdcCustomers::ledger(&1), None); + + // let bytes = [0u8; 32]; + // let node_pub_key = AccountId32::from(bytes); + // let cdn_node_params = CDNNodeParams { + // host: vec![1u8, 255], + // http_port: 35000u16, + // grpc_port: 25000u16, + // p2p_port: 15000u16, + // }; + + // // Node doesn't exist + // assert_noop!( + // DdcNodes::delete_node( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()) + // ), + // Error::::NodeDoesNotExist + // ); + + // // Create node + // assert_ok!(DdcNodes::create_node( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // NodeParams::CDNParams(cdn_node_params.clone()) + // )); + + // // Only node provider can delete + // assert_noop!( + // DdcNodes::delete_node( + // RuntimeOrigin::signed(2), + // NodePubKey::CDNPubKey(node_pub_key.clone()) + // ), + // Error::::OnlyNodeProvider + // ); + + // // Delete node + // assert_ok!(DdcNodes::delete_node( + // RuntimeOrigin::signed(1), + // NodePubKey::CDNPubKey(node_pub_key.clone()), + // )); + + // // Checking that event was emitted + // assert_eq!(System::events().len(), 2); + // System::assert_last_event( + // Event::NodeDeleted { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), + // ) + }) +} From 50a3d129139c6c0fe00a7020746a6df714ee0b69 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 14 Nov 2023 11:47:43 +0100 Subject: [PATCH 502/544] docs(pallet_ddc_staking): comments improved --- pallets/ddc-staking/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 10ba3ff36..005b39c8d 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -173,13 +173,13 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; - /// The map of (wannable) CDN participants stash keys to the DDC cluster ID they wish to + /// The map of (wannabe) CDN nodes participants stash keys to the DDC cluster ID they wish to /// participate into. #[pallet::storage] #[pallet::getter(fn cdns)] pub type CDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// The map of (wannable) storage network participants stash keys to the DDC cluster ID they + /// The map of (wannabe) Storage nodes participants stash keys to the DDC cluster ID they /// wish to participate into. #[pallet::storage] #[pallet::getter(fn storages)] From d8811d6a9304a0660bf19d783574f02892c089bb Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 14 Nov 2023 12:42:58 +0100 Subject: [PATCH 503/544] remove irrelevant comments & improve formatting (clippy) --- pallets/ddc-customers/src/mock.rs | 2 +- pallets/ddc-customers/src/tests.rs | 177 ++++------------------------- 2 files changed, 26 insertions(+), 153 deletions(-) diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 589e76f31..7a097ea67 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -146,7 +146,7 @@ impl ExtBuilder { TestExternalities::new(storage) } - pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + pub fn build_and_execute(self, test: impl FnOnce()) { sp_tracing::try_init_simple(); let mut ext = self.build(); ext.execute_with(test); diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 43bc29c55..032351e4d 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -14,58 +14,18 @@ fn create_bucket_works() { let cluster_id = ClusterId::from([1; 20]); // Bucket created - assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(1), cluster_id.clone())); + assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(1), cluster_id)); // Check storage assert_eq!(DdcCustomers::buckets_count(), 1); assert_eq!( - DdcCustomers::buckets(&1), + DdcCustomers::buckets(1), Some(Bucket { bucket_id: 1, owner_id: 1, cluster_id }) ); // Checking that event was emitted assert_eq!(System::events().len(), 1); - System::assert_last_event(Event::BucketCreated { 0: 1u64.into() }.into()) - - // let bytes = [0u8; 32]; - // let node_pub_key = AccountId32::from(bytes); - // let cdn_node_params = CDNNodeParams { - // host: vec![1u8, 255], - // http_port: 35000u16, - // grpc_port: 25000u16, - // p2p_port: 15000u16, - // }; - - // // Node params are not valid - // assert_noop!( - // DdcNodes::create_node( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // NodeParams::StorageParams(StorageNodeParams { - // host: vec![1u8, 255], - // http_port: 35000u16, - // grpc_port: 25000u16, - // p2p_port: 15000u16, - // }) - // ), - // Error::::InvalidNodeParams - // ); - - // // Node already exists - // assert_noop!( - // DdcNodes::create_node( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // NodeParams::CDNParams(cdn_node_params) - // ), - // Error::::NodeAlreadyExists - // ); - - // // Checking that event was emitted - // assert_eq!(System::events().len(), 1); - // System::assert_last_event( - // Event::NodeCreated { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - // ) + System::assert_last_event(Event::BucketCreated(1u64).into()) }) } @@ -73,105 +33,64 @@ fn create_bucket_works() { fn deposit_and_deposit_extra_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - // let bytes = [0u8; 32]; - // let node_pub_key = AccountId32::from(bytes); - // let storage_node_params = StorageNodeParams { - // host: vec![1u8, 255], - // http_port: 35000u16, - // grpc_port: 25000u16, - // p2p_port: 15000u16, - // }; - // let cdn_node_params = CDNNodeParams { - // host: vec![1u8, 255], - // http_port: 35000u16, - // grpc_port: 25000u16, - // p2p_port: 15000u16, - // }; // Deposit dust assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(1), 0_u128.into()), + DdcCustomers::deposit(RuntimeOrigin::signed(1), 0_u128), Error::::InsufficientDeposit ); // Deposit all tokens fails (should not kill account) assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(1), 100_u128.into()), + DdcCustomers::deposit(RuntimeOrigin::signed(1), 100_u128), BalancesError::::KeepAlive ); // Deposited - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128.into())); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128)); // Check storage assert_eq!( DdcCustomers::ledger(&1), Some(AccountsLedger { owner: 1, - total: 10_u128.into(), - active: 10_u128.into(), + total: 10_u128, + active: 10_u128, unlocking: Default::default(), }) ); // Checking that event was emitted - System::assert_last_event(Event::Deposited { 0: 1, 1: 10 }.into()); + System::assert_last_event(Event::Deposited(1, 10).into()); // Deposit should fail when called the second time assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128.into()), + DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128), Error::::AlreadyPaired ); // Deposit extra fails if not owner assert_noop!( - DdcCustomers::deposit_extra(RuntimeOrigin::signed(2), 10_u128.into()), + DdcCustomers::deposit_extra(RuntimeOrigin::signed(2), 10_u128), Error::::NotOwner ); // Deposited extra - assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(1), 20_u128.into())); + assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(1), 20_u128)); // Check storage assert_eq!( DdcCustomers::ledger(&1), Some(AccountsLedger { owner: 1, - total: 30_u128.into(), - active: 30_u128.into(), + total: 30_u128, + active: 30_u128, unlocking: Default::default(), }) ); // Checking that event was emitted - System::assert_last_event(Event::Deposited { 0: 1, 1: 20 }.into()); - - // // Set node params - // assert_ok!(DdcNodes::set_node_params( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // NodeParams::CDNParams(cdn_node_params.clone()) - // )); - - // // Node params are not valid - // assert_noop!( - // DdcNodes::set_node_params( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // NodeParams::StorageParams(storage_node_params) - // ), - // Error::::InvalidNodeParams - // ); - - // // Only node provider can set params - // assert_noop!( - // DdcNodes::set_node_params( - // RuntimeOrigin::signed(2), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // NodeParams::CDNParams(cdn_node_params.clone()) - // ), - // Error::::OnlyNodeProvider - // ); + System::assert_last_event(Event::Deposited(1, 20).into()); }) } @@ -181,12 +100,12 @@ fn unlock_and_withdraw_deposit_works() { System::set_block_number(1); // Deposited - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 35_u128.into())); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 35_u128)); // So there is always positive balance within pallet - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(2), 10_u128.into())); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(2), 10_u128)); // Unlock chunk - assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128.into())); + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128)); System::set_block_number(2); let mut unlocking_chunks: BoundedVec, MaxUnlockingChunks> = @@ -200,21 +119,21 @@ fn unlock_and_withdraw_deposit_works() { DdcCustomers::ledger(&1), Some(AccountsLedger { owner: 1, - total: 35_u128.into(), - active: 34_u128.into(), + total: 35_u128, + active: 34_u128, unlocking: unlocking_chunks.clone(), }) ); // Reach max unlock chunks for i in 1..32 { - assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128.into())); + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128)); System::set_block_number(i + 2); } // No more chunks can be added assert_noop!( - DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128.into()), + DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128), Error::::NoMoreChunks ); @@ -227,64 +146,18 @@ fn unlock_and_withdraw_deposit_works() { DdcCustomers::ledger(&1), Some(AccountsLedger { owner: 1, - total: 3_u128.into(), - active: 3_u128.into(), + total: 3_u128, + active: 3_u128, unlocking: Default::default(), }) ); // Unlock remaining chuncks & withdraw - assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 3_u128.into())); + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 3_u128)); System::set_block_number(52); assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(1))); // Check storage assert_eq!(DdcCustomers::ledger(&1), None); - - // let bytes = [0u8; 32]; - // let node_pub_key = AccountId32::from(bytes); - // let cdn_node_params = CDNNodeParams { - // host: vec![1u8, 255], - // http_port: 35000u16, - // grpc_port: 25000u16, - // p2p_port: 15000u16, - // }; - - // // Node doesn't exist - // assert_noop!( - // DdcNodes::delete_node( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()) - // ), - // Error::::NodeDoesNotExist - // ); - - // // Create node - // assert_ok!(DdcNodes::create_node( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // NodeParams::CDNParams(cdn_node_params.clone()) - // )); - - // // Only node provider can delete - // assert_noop!( - // DdcNodes::delete_node( - // RuntimeOrigin::signed(2), - // NodePubKey::CDNPubKey(node_pub_key.clone()) - // ), - // Error::::OnlyNodeProvider - // ); - - // // Delete node - // assert_ok!(DdcNodes::delete_node( - // RuntimeOrigin::signed(1), - // NodePubKey::CDNPubKey(node_pub_key.clone()), - // )); - - // // Checking that event was emitted - // assert_eq!(System::events().len(), 2); - // System::assert_last_event( - // Event::NodeDeleted { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - // ) }) } From fbe764a696747651d453fd8126c7f366769c2521 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Tue, 14 Nov 2023 19:30:24 +0200 Subject: [PATCH 504/544] cluster payment refactoring --- pallets/ddc-clusters/src/cluster.rs | 7 +++++-- pallets/ddc-clusters/src/lib.rs | 7 ++++++- pallets/ddc-customers/src/lib.rs | 2 +- pallets/ddc-payouts/src/lib.rs | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 7fc6e07e4..4be19d73f 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -1,6 +1,6 @@ use crate::pallet::Error; use codec::{Decode, Encode}; -use ddc_primitives::{ClusterId, ClusterPricingParams}; +use ddc_primitives::ClusterId; use frame_support::{pallet_prelude::*, parameter_types}; use scale_info::TypeInfo; use sp_runtime::Perbill; @@ -41,7 +41,10 @@ pub struct ClusterGovParams { pub storage_bond_size: Balance, pub storage_chill_delay: BlockNumber, pub storage_unbonding_delay: BlockNumber, - pub pricing: ClusterPricingParams, + pub unit_per_mb_stored: u128, + pub unit_per_mb_streamed: u128, + pub unit_per_put_request: u128, + pub unit_per_get_request: u128, } impl Cluster { diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 121640d84..a8cbf3535 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -271,7 +271,12 @@ pub mod pallet { ) -> Result { let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; - Ok(cluster_gov_params.pricing) + Ok(ClusterPricingParams { + unit_per_mb_stored: cluster_gov_params.unit_per_mb_stored, + unit_per_mb_streamed: cluster_gov_params.unit_per_mb_streamed, + unit_per_put_request: cluster_gov_params.unit_per_put_request, + unit_per_get_request: cluster_gov_params.unit_per_get_request, + }) } fn get_chill_delay( diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 2454eae19..30a2b9d36 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -200,7 +200,7 @@ pub mod pallet { /// An account has called `withdraw_unlocked_deposit` and removed unlocking chunks worth /// `Balance` from the unlocking queue. \[owner, amount\] Withdrawn(T::AccountId, BalanceOf), - /// The acconut has been charged for the usage + /// The account has been charged for the usage Charged(T::AccountId, BalanceOf), /// Bucket with specific id created BucketCreated(BucketId), diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 60cc3ab75..bc8aa5d50 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -234,6 +234,7 @@ pub mod pallet { Initialized, ChargingCustomers, CustomersCharged, + DeductingFees, RewardingProviders, ProvidersRewarded, Finalized, From ebde37109db26cff987d15925e48fa22dcef65ab Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 14 Nov 2023 18:55:49 +0100 Subject: [PATCH 505/544] add extra tests & checks --- pallets/ddc-staking/src/tests.rs | 144 ++++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 4 deletions(-) diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 37d971bca..d0756f3d4 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -70,14 +70,117 @@ fn change_controller_works() { }) } +#[test] +fn not_enough_inital_bond_flow() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + + // Add new CDN participant, account 3 controlled by 4 with node 5. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 5 + )); + + // Not enough tokens bonded to serve + assert_noop!( + DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), + Error::::InsufficientBond + ); + + // Can not bond extra + assert_noop!( + DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 5 + ), + Error::::AlreadyBonded + ); + + // Unbond all bonded amount + assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(4), 5)); + System::assert_last_event(Event::Unbonded(3, 5).into()); + System::set_block_number(11); + // Withdraw unbonded tokens to clear up the stash controller pair + assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(4))); + System::assert_last_event(Event::Withdrawn(3, 5).into()); + + // Bond sufficient amount + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 10 + )); + + // Serving should work + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + }) +} + +#[test] +fn set_node_works() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + // 10 and 11 are bonded as stash controller. + assert_eq!(DdcStaking::bonded(&11), Some(10)); + + // Node is already paired + assert_noop!( + DdcStaking::set_node( + RuntimeOrigin::signed(10), + NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])) + ), + Error::::AlreadyPaired + ); + + // Node cannot be changed + assert_noop!( + DdcStaking::set_node( + RuntimeOrigin::signed(11), + NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])) + ), + Error::::AlreadyInRole + ); + + // Schedule CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(10))); + System::set_block_number(11); + // Actual CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(10))); + + // Setting node should work + assert_ok!(DdcStaking::set_node( + RuntimeOrigin::signed(11), + NodePubKey::CDNPubKey(CDNNodePubKey::new([13; 32])) + )); + }) +} + #[test] fn staking_should_work() { ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + // Put some money in account that we'll use. for i in 1..5 { let _ = Balances::make_free_balance_be(&i, 2000); } + // Bond dust should fail + assert_noop!( + DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 0 + ), + Error::::InsufficientBond + ); + // Add new CDN participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), @@ -85,7 +188,31 @@ fn staking_should_work() { NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), 1500 )); + System::assert_last_event(Event::Bonded(3, 1500).into()); assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([0; 20]))); + System::assert_last_event(Event::Activated(3).into()); + + // Controller already paired + assert_noop!( + DdcStaking::bond( + RuntimeOrigin::signed(5), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([10; 32])), + 10 + ), + Error::::AlreadyPaired + ); + + // Node already paired + assert_noop!( + DdcStaking::bond( + RuntimeOrigin::signed(5), + 6, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 10 + ), + Error::::AlreadyPaired + ); // Account 4 controls the stash from account 3, which is 1500 units, 3 is a CDN // participant, 5 is a DDC node. @@ -103,12 +230,12 @@ fn staking_should_work() { assert_eq!(DdcStaking::cdns(3), Some(ClusterId::from([0; 20]))); assert_eq!(DdcStaking::nodes(NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32]))), Some(3)); - // Set `CurrentEra`. + // Set initial block timestamp. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - DdcStaking::on_finalize(System::block_number()); // Schedule CDN participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); + System::assert_last_event(Event::ChillSoon(3, ClusterId::from([0; 20]), 11).into()); // Removal is scheduled, stashed value of 4 is still lock. let chilling = System::block_number() + 10u64; @@ -128,11 +255,19 @@ fn staking_should_work() { assert_noop!(Balances::reserve(&3, 501), BalancesError::::LiquidityRestrictions); assert_ok!(Balances::reserve(&3, 409)); - // Set `CurrentEra` to the value allows us to chill. + // Too early to call chill the second time + assert_noop!(DdcStaking::chill(RuntimeOrigin::signed(4)), Error::::TooEarly); + + // Fast chill should not be allowed + assert_noop!( + DdcStaking::fast_chill(RuntimeOrigin::signed(4)), + Error::::FastChillProhibited + ); + + // Set the block number that allows us to chill. while System::block_number() < chilling { System::set_block_number(System::block_number() + 1); Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - DdcStaking::on_finalize(System::block_number()); } // Ledger is not changed until we make another call to `chill`. @@ -149,6 +284,7 @@ fn staking_should_work() { // Actual CDN participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); + System::assert_last_event(Event::Chilled(3).into()); // Account 3 is no longer a CDN participant. assert_eq!(DdcStaking::cdns(3), None); From 93e7625e4ef552189808d2cc087fea204fcaaa0f Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 14 Nov 2023 19:09:48 +0100 Subject: [PATCH 506/544] resolve clippy & fix error in toml --- Cargo.lock | 2 ++ pallets/ddc-clusters/Cargo.toml | 3 +-- pallets/ddc-clusters/src/mock.rs | 2 +- pallets/ddc-clusters/src/tests.rs | 12 ++++++------ pallets/ddc-nodes/Cargo.toml | 1 + pallets/ddc-nodes/src/mock.rs | 2 +- pallets/ddc-nodes/src/tests.rs | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e9a2ca07..b1d1fad6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4892,6 +4892,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", + "sp-io", "sp-runtime", "sp-std", "sp-tracing", @@ -4951,6 +4952,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", + "sp-io", "sp-runtime", "sp-std", "sp-tracing", diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 9b1d889b3..ea4cdf5d6 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -9,9 +9,8 @@ ddc-primitives = { version = "0.1.0", default-features = false, path = "../../pr ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs index c4055dfbc..b6c2e4fd2 100644 --- a/pallets/ddc-clusters/src/mock.rs +++ b/pallets/ddc-clusters/src/mock.rs @@ -224,7 +224,7 @@ impl ExtBuilder { TestExternalities::new(storage) } - pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + pub fn build_and_execute(self, test: impl FnOnce()) { sp_tracing::try_init_simple(); let mut ext = self.build(); ext.execute_with(test); diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index 543a4bbb2..922ad7a7a 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -148,8 +148,8 @@ fn add_and_delete_node_works() { // Node created assert_ok!(DdcNodes::create_node( RuntimeOrigin::signed(AccountId::from([1; 32])), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) + NodePubKey::CDNPubKey(node_pub_key), + NodeParams::CDNParams(cdn_node_params) )); // Node doesn't exist @@ -225,7 +225,7 @@ fn add_and_delete_node_works() { fn encode_constructor() -> Vec { let mut call_data = CTOR_SELECTOR.to_vec(); - let x = 0 as u128; + let x = 0_u128; for _ in 0..9 { x.encode_to(&mut call_data); } @@ -252,13 +252,13 @@ fn add_and_delete_node_works() { GAS_LIMIT, None, wasm.to_vec(), - contract_args.clone(), + contract_args, vec![], ) .unwrap(); // Configure worker with the contract address. - let contract_id = Contracts::contract_address(&alice, &wasm_hash, &vec![]); + let contract_id = Contracts::contract_address(&alice, &wasm_hash, &[]); pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("7a04093d"); let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([4; 32])); @@ -271,7 +271,7 @@ fn add_and_delete_node_works() { }; let results = Contracts::call( - RuntimeOrigin::signed(alice.clone()), + RuntimeOrigin::signed(alice), contract_id.clone(), 0, Weight::from_ref_time(1_000_000_000_000), diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 9ca3ff088..10bf74d9e 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -10,6 +10,7 @@ ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-nodes/src/mock.rs b/pallets/ddc-nodes/src/mock.rs index 8a8002c0c..18377ac58 100644 --- a/pallets/ddc-nodes/src/mock.rs +++ b/pallets/ddc-nodes/src/mock.rs @@ -106,7 +106,7 @@ impl ExtBuilder { TestExternalities::new(storage) } - pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + pub fn build_and_execute(self, test: impl FnOnce()) { sp_tracing::try_init_simple(); let mut ext = self.build(); ext.execute_with(test); diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index 9cbdc526c..1c5a80137 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -117,7 +117,7 @@ fn set_node_params_works() { DdcNodes::set_node_params( RuntimeOrigin::signed(2), NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) + NodeParams::CDNParams(cdn_node_params) ), Error::::OnlyNodeProvider ); @@ -156,7 +156,7 @@ fn set_delete_node_works() { assert_ok!(DdcNodes::create_node( RuntimeOrigin::signed(1), NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) + NodeParams::CDNParams(cdn_node_params) )); // Only node provider can delete From 94ff242d1ecd00ee7270715113c21405d99facf4 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Tue, 14 Nov 2023 19:25:21 +0100 Subject: [PATCH 507/544] chore: runtime version for 'cere_dev' is upgraded --- runtime/cere-dev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 2e4d8e1a0..2aeb530df 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48014, + spec_version: 48015, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 5, From b176f405adae334846bbc56d921c63d98bc0b097 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Wed, 15 Nov 2023 11:07:45 +0200 Subject: [PATCH 508/544] authorise account change --- pallets/ddc-customers/src/lib.rs | 4 --- pallets/ddc-payouts/src/lib.rs | 57 ++++++++++++-------------------- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 30a2b9d36..058799a9f 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -172,10 +172,6 @@ pub mod pallet { 0 } - #[pallet::storage] - #[pallet::getter(fn dac_account)] - pub type DACAccount = StorageValue<_, T::AccountId>; - #[pallet::storage] #[pallet::getter(fn buckets_count)] pub type BucketsCount = diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index bc8aa5d50..c3365fcc4 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -179,7 +179,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn authorised_caller)] - pub type DACAccount = StorageValue<_, T::AccountId>; + pub type AuthorisedCaller = StorageValue<_, T::AccountId>; #[pallet::storage] #[pallet::getter(fn debtor_customers)] @@ -198,7 +198,6 @@ pub mod pallet { pub struct BillingReport { state: State, vault: T::AccountId, - authorised_caller: Option, total_customer_charge: CustomerCharge, total_distributed_reward: u128, total_node_usage: NodeUsage, @@ -215,7 +214,6 @@ pub mod pallet { Self { state: State::default(), vault: T::PalletId::get().into_account_truncating(), - authorised_caller: Option::None, total_customer_charge: CustomerCharge::default(), total_distributed_reward: Zero::zero(), total_node_usage: NodeUsage::default(), @@ -242,6 +240,18 @@ pub mod pallet { #[pallet::call] impl Pallet { + #[pallet::weight(10_000)] + pub fn set_authorised_caller( + origin: OriginFor, + authorised_caller: T::AccountId, + ) -> DispatchResult { + ensure_root(origin)?; // requires Governance approval + + AuthorisedCaller::::put(authorised_caller); + + Ok(()) + } + #[pallet::weight(10_000)] pub fn begin_billing_report( origin: OriginFor, @@ -249,10 +259,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); ensure!( ActiveBillingReports::::try_get(cluster_id, era).is_err(), @@ -281,10 +288,7 @@ pub mod pallet { max_batch_index: BatchIndex, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); ensure!( max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), @@ -314,10 +318,7 @@ pub mod pallet { payers: Vec<(T::AccountId, CustomerUsage)>, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -432,10 +433,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -463,10 +461,7 @@ pub mod pallet { total_node_usage: NodeUsage, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); ensure!( max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), @@ -497,10 +492,7 @@ pub mod pallet { payees: Vec<(T::AccountId, NodeUsage)>, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -575,10 +567,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -608,10 +597,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!( - Self::authorised_caller().ok_or(Error::::Unauthorised)? == caller, - Error::::Unauthorised - ); + ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -724,7 +710,6 @@ pub mod pallet { bytes.extend_from_slice(&cluster_id[..]); bytes.extend_from_slice(&era.encode()); let hash = blake2_128(&bytes); - // todo: assumes AccountId is 32 bytes, which is not ideal -> rewrite it // "modl" + "payouts_" + hash is 28 bytes, the T::AccountId is 32 bytes, so we should be // safe from the truncation and possible collisions caused by it. The rest 4 bytes will From e93e28ffd57cdecd235c5eb9d2b6156e958fec02 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 15 Nov 2023 11:52:21 +0100 Subject: [PATCH 509/544] remove old node when setting new one --- pallets/ddc-staking/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 005b39c8d..cfd3a966f 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -724,6 +724,11 @@ pub mod pallet { } } + // Remove previously owned node from storage + if let Some(current_node) = Providers::::get(&stash) { + >::remove(current_node); + } + // Ensure only one node per stash. ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); From 649beccd9fbea81e16bc85f2d9f40d3217df66c3 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 15 Nov 2023 11:55:12 +0100 Subject: [PATCH 510/544] dprint fix --- pallets/ddc-clusters/Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index ea4cdf5d6..1a3e0aa16 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -9,22 +9,22 @@ ddc-primitives = { version = "0.1.0", default-features = false, path = "../../pr ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +hex = { version = "0.4", default-features = false } +hex-literal = "^0.3.1" +pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } -hex-literal = "^0.3.1" -hex = { version = "0.4", default-features = false } [dev-dependencies] pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] From a476914cd2f32962cdcba7327fc088e339a33c03 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Wed, 15 Nov 2023 17:04:33 +0200 Subject: [PATCH 511/544] code cleanup --- pallets/ddc-customers/src/lib.rs | 73 ++++++++++++++++++++++---------- pallets/ddc-payouts/src/lib.rs | 25 ++++++----- pallets/ddc-staking/src/lib.rs | 17 ++++++-- 3 files changed, 79 insertions(+), 36 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 058799a9f..fb4353f35 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -12,7 +12,7 @@ use frame_support::{ }; use scale_info::TypeInfo; use sp_runtime::{ - traits::{AccountIdConversion, AtLeast32BitUnsigned, Saturating, Zero}, + traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedSub, Saturating, Zero, CheckedAdd}, RuntimeDebug, SaturatedConversion, }; use sp_std::prelude::*; @@ -112,20 +112,28 @@ impl< /// Charge funds that were scheduled for unlocking. /// /// Returns the updated ledger, and the amount actually charged. - fn charge_unlocking(mut self, value: Balance) -> (Self, Balance) { + fn charge_unlocking(mut self, value: Balance) -> Result<(Self, Balance), Error> { let mut unlocking_balance = Balance::zero(); while let Some(last) = self.unlocking.last_mut() { - if unlocking_balance + last.value <= value { - unlocking_balance += last.value; - self.active -= last.value; + let temp = unlocking_balance + .checked_add(&last.value) + .ok_or(Error::::ArithmeticOverflow)?; + if temp <= value { + unlocking_balance = temp; + self.active = + self.active.checked_sub(&last.value).ok_or(Error::::ArithmeticUnderflow)?; self.unlocking.pop(); } else { - let diff = value - unlocking_balance; - - unlocking_balance += diff; - self.active -= diff; - last.value -= diff; + let diff = + value.checked_sub(&unlocking_balance).ok_or(Error::::ArithmeticUnderflow)?; + + unlocking_balance = + unlocking_balance.checked_add(&diff).ok_or(Error::::ArithmeticOverflow)?; + self.active = + self.active.checked_sub(&diff).ok_or(Error::::ArithmeticUnderflow)?; + last.value = + last.value.checked_sub(&diff).ok_or(Error::::ArithmeticUnderflow)?; } if unlocking_balance >= value { @@ -133,7 +141,7 @@ impl< } } - (self, unlocking_balance) + Ok((self, unlocking_balance)) } } @@ -224,6 +232,8 @@ pub mod pallet { ClusterDoesNotExist, // unauthorised operation Unauthorised, + // Arithmetic overflow + ArithmeticOverflow, // Arithmetic underflow ArithmeticUnderflow, } @@ -257,7 +267,8 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn create_bucket(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; - let cur_bucket_id = Self::buckets_count() + 1; + let cur_bucket_id = + Self::buckets_count().checked_add(1).ok_or(Error::::ArithmeticOverflow)?; ::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|_| Error::::ClusterDoesNotExist)?; @@ -328,8 +339,11 @@ pub mod pallet { let owner_balance = ::Currency::free_balance(&owner); let extra = owner_balance.min(max_additional); - ledger.total += extra; - ledger.active += extra; + ledger.total = + ledger.total.checked_add(&extra).ok_or(Error::::ArithmeticOverflow)?; + ledger.active = + ledger.active.checked_add(&extra).ok_or(Error::::ArithmeticOverflow)?; + // Last check: the new active amount of ledger must be more than ED. ensure!( ledger.active >= ::Currency::minimum_balance(), @@ -374,16 +388,19 @@ pub mod pallet { let mut value = value.min(ledger.active); if !value.is_zero() { - ledger.active -= value; + ledger.active = + ledger.active.checked_sub(&value).ok_or(Error::::ArithmeticUnderflow)?; // Avoid there being a dust balance left in the accounts system. if ledger.active < ::Currency::minimum_balance() { - value += ledger.active; + value = + value.checked_add(&ledger.active).ok_or(Error::::ArithmeticOverflow)?; ledger.active = Zero::zero(); } let current_block = >::block_number(); // Note: locking for extra block to allow for accounting + // block + configurable value - shouldn't overflow let block = current_block + ::UnlockingDelay::get(); if let Some(chunk) = @@ -448,7 +465,8 @@ pub mod pallet { if ledger.total < old_total { log::debug!("Preparing for transfer"); // Already checked that this won't overflow by entry condition. - let value = old_total - ledger.total; + let value = + old_total.checked_sub(&ledger.total).ok_or(Error::::ArithmeticUnderflow)?; let account_id = Self::account_id(); @@ -523,15 +541,26 @@ pub mod pallet { ensure!(ledger.total >= ledger.active, Error::::ArithmeticUnderflow); if ledger.active >= amount_to_deduct { - ledger.active -= amount_to_deduct; - ledger.total -= amount_to_deduct; + ledger.active = ledger + .active + .checked_sub(&amount_to_deduct) + .ok_or(Error::::ArithmeticUnderflow)?; + ledger.total = ledger + .total + .checked_sub(&amount_to_deduct) + .ok_or(Error::::ArithmeticUnderflow)?; Self::update_ledger(&content_owner, &ledger); } else { - let diff = amount_to_deduct - ledger.active; - ledger.total -= ledger.active; + let diff = amount_to_deduct + .checked_sub(&ledger.active) + .ok_or(Error::::ArithmeticUnderflow)?; + ledger.total = ledger + .total + .checked_sub(&ledger.active) + .ok_or(Error::::ArithmeticUnderflow)?; amount_to_deduct = ledger.active; ledger.active = BalanceOf::::zero(); - let (ledger, _charged) = ledger.charge_unlocking(diff); + let (ledger, _charged) = ledger.charge_unlocking(diff)?; Self::update_ledger(&content_owner, &ledger); }; diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index c3365fcc4..8143622bb 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -15,7 +15,7 @@ #![recursion_limit = "256"] use ddc_primitives::{ClusterId, DdcEra}; -use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger as ICustomerCharger}; +use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger as CustomerChargerType}; use frame_support::{ pallet_prelude::*, parameter_types, @@ -30,6 +30,7 @@ use sp_std::prelude::*; type BatchIndex = u16; +/// Stores usage of customers #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct CustomerUsage { pub transferred_bytes: u128, @@ -38,6 +39,7 @@ pub struct CustomerUsage { pub number_of_gets: u128, } +/// Stores usage of node provider #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct NodeUsage { pub transferred_bytes: u128, @@ -46,12 +48,13 @@ pub struct NodeUsage { pub number_of_gets: u128, } +/// Stores reward in tokens(units) of node provider as per NodeUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct NodeReward { - pub transfer: u128, - pub storage: u128, - pub puts: u128, - pub gets: u128, + pub transfer: u128, // for transferred_bytes + pub storage: u128, // for stored_bytes + pub puts: u128, // for number_of_puts + pub gets: u128, // for number_of_gets } #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] @@ -62,12 +65,13 @@ pub struct BillingReportDebt { pub amount: u128, } +/// Stores charge in tokens(units) of customer as per CustomerUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct CustomerCharge { - pub transfer: u128, - pub storage: u128, - pub puts: u128, - pub gets: u128, + pub transfer: u128, // for transferred_bytes + pub storage: u128, // for stored_bytes + pub puts: u128, // for number_of_puts + pub gets: u128, // for number_of_gets } /// The balance type of this pallet. @@ -98,7 +102,7 @@ pub mod pallet { type Currency: LockableCurrency; - type CustomerCharger: ICustomerCharger; + type CustomerCharger: CustomerChargerType; type ClusterVisitor: ClusterVisitor; } @@ -636,6 +640,7 @@ pub mod pallet { node_usage.transferred_bytes, total_nodes_usage.transferred_bytes, ); + // ratio multiplied by X will be > 0, < X no overflow node_reward.transfer = ratio * total_customer_charge.transfer; ratio = Perbill::from_rational(node_usage.stored_bytes, total_nodes_usage.stored_bytes); diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 005b39c8d..2e977dd1d 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -46,7 +46,7 @@ use frame_support::{ use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::{ - traits::{AtLeast32BitUnsigned, Saturating, StaticLookup, Zero}, + traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, StaticLookup, Zero}, RuntimeDebug, SaturatedConversion, }; use sp_std::prelude::*; @@ -310,6 +310,10 @@ pub mod pallet { ServingProhibited, /// Storing operation is called for non-Storage node StoringProhibited, + /// Arithmetic overflow occurred + ArithmeticOverflow, + /// Arithmetic underflow occurred + ArithmeticUnderflow, } #[pallet::call] @@ -408,11 +412,13 @@ pub mod pallet { let mut value = value.min(ledger.active); if !value.is_zero() { - ledger.active -= value; + ledger.active = + ledger.active.checked_sub(&value).ok_or(Error::::ArithmeticUnderflow)?; // Avoid there being a dust balance left in the staking system. if ledger.active < T::Currency::minimum_balance() { - value += ledger.active; + value = + value.checked_add(&ledger.active).ok_or(Error::::ArithmeticOverflow)?; ledger.active = Zero::zero(); } @@ -461,6 +467,7 @@ pub mod pallet { } }; + // block number + configuration -> no overflow let block = >::block_number() + unbonding_delay_in_blocks; if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.block == block) @@ -517,7 +524,8 @@ pub mod pallet { // `consolidate_unlocked` strictly subtracts balance. if ledger.total < old_total { // Already checked that this won't overflow by entry condition. - let value = old_total - ledger.total; + let value = + old_total.checked_sub(&ledger.total).ok_or(Error::::ArithmeticUnderflow)?; Self::deposit_event(Event::::Withdrawn(stash, value)); } @@ -753,6 +761,7 @@ pub mod pallet { let is_cluster_node = T::ClusterVisitor::cluster_has_node(&cluster_id, &node_pub_key); ensure!(!is_cluster_node, Error::::FastChillProhibited); + // block number + 1 => no overflow let can_chill_from = >::block_number() + T::BlockNumber::from(1u32); Self::chill_stash_soon(&stash, &controller, cluster_id, can_chill_from); From c78667cff26033f8c00c75fd2acd7a9960a72c7f Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Wed, 15 Nov 2023 17:10:55 +0200 Subject: [PATCH 512/544] formattign --- pallets/ddc-customers/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index fb4353f35..8c06fbef9 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -12,7 +12,7 @@ use frame_support::{ }; use scale_info::TypeInfo; use sp_runtime::{ - traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedSub, Saturating, Zero, CheckedAdd}, + traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, Zero}, RuntimeDebug, SaturatedConversion, }; use sp_std::prelude::*; From b767e8ab4b6f3c8a8abe86e8367bdbf53a5de41b Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 15 Nov 2023 16:19:52 +0100 Subject: [PATCH 513/544] update dev-deps; remove dead-code; add test with 2 buckets --- pallets/ddc-customers/Cargo.toml | 2 +- pallets/ddc-customers/src/mock.rs | 4 -- pallets/ddc-customers/src/tests.rs | 82 +++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 580ca33a0..363c47a11 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -11,13 +11,13 @@ frame-support = { version = "4.0.0-dev", default-features = false, git = "https: frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 7a097ea67..ae07269b8 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -1,7 +1,5 @@ //! Test utilities -#![allow(dead_code)] - use crate::{self as pallet_ddc_customers, *}; use ddc_primitives::{NodePubKey, NodeType}; use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; @@ -132,8 +130,6 @@ impl ClusterVisitor for TestClusterVisitor { } } -pub(crate) type TestRuntimeCall = ::RuntimeCall; - pub struct ExtBuilder; impl ExtBuilder { diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 032351e4d..869115e3b 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -12,15 +12,16 @@ fn create_bucket_works() { System::set_block_number(1); let cluster_id = ClusterId::from([1; 20]); + let account_1 = 1; // Bucket created - assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(1), cluster_id)); + assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(account_1), cluster_id)); // Check storage assert_eq!(DdcCustomers::buckets_count(), 1); assert_eq!( DdcCustomers::buckets(1), - Some(Bucket { bucket_id: 1, owner_id: 1, cluster_id }) + Some(Bucket { bucket_id: 1, owner_id: account_1, cluster_id }) ); // Checking that event was emitted @@ -29,29 +30,61 @@ fn create_bucket_works() { }) } +#[test] +fn create_two_buckets_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + let account_1 = 1; + + // Buckets created + assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(account_1), cluster_id)); + assert_eq!(System::events().len(), 1); + System::assert_last_event(Event::BucketCreated(1u64).into()); + assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(account_1), cluster_id)); + assert_eq!(System::events().len(), 2); + System::assert_last_event(Event::BucketCreated(2u64).into()); + + // Check storage + assert_eq!(DdcCustomers::buckets_count(), 2); + assert_eq!( + DdcCustomers::buckets(1), + Some(Bucket { bucket_id: 1, owner_id: account_1, cluster_id }) + ); + assert_eq!( + DdcCustomers::buckets(2), + Some(Bucket { bucket_id: 2, owner_id: account_1, cluster_id }) + ); + }) +} + #[test] fn deposit_and_deposit_extra_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); + let account_1 = 1; + let account_2 = 2; + // Deposit dust assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(1), 0_u128), + DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 0_u128), Error::::InsufficientDeposit ); // Deposit all tokens fails (should not kill account) assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(1), 100_u128), + DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 100_u128), BalancesError::::KeepAlive ); // Deposited - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128)); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 10_u128)); // Check storage assert_eq!( - DdcCustomers::ledger(&1), + DdcCustomers::ledger(&account_1), Some(AccountsLedger { owner: 1, total: 10_u128, @@ -61,26 +94,26 @@ fn deposit_and_deposit_extra_works() { ); // Checking that event was emitted - System::assert_last_event(Event::Deposited(1, 10).into()); + System::assert_last_event(Event::Deposited(account_1, 10).into()); // Deposit should fail when called the second time assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(1), 10_u128), + DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 10_u128), Error::::AlreadyPaired ); // Deposit extra fails if not owner assert_noop!( - DdcCustomers::deposit_extra(RuntimeOrigin::signed(2), 10_u128), + DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_2), 10_u128), Error::::NotOwner ); // Deposited extra - assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(1), 20_u128)); + assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_1), 20_u128)); // Check storage assert_eq!( - DdcCustomers::ledger(&1), + DdcCustomers::ledger(&account_1), Some(AccountsLedger { owner: 1, total: 30_u128, @@ -90,7 +123,7 @@ fn deposit_and_deposit_extra_works() { ); // Checking that event was emitted - System::assert_last_event(Event::Deposited(1, 20).into()); + System::assert_last_event(Event::Deposited(account_1, 20).into()); }) } @@ -99,13 +132,16 @@ fn unlock_and_withdraw_deposit_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); + let account_1 = 1; + let account_2 = 2; + // Deposited - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(1), 35_u128)); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 35_u128)); // So there is always positive balance within pallet - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(2), 10_u128)); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_2), 10_u128)); // Unlock chunk - assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128)); + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(account_1), 1_u128)); System::set_block_number(2); let mut unlocking_chunks: BoundedVec, MaxUnlockingChunks> = @@ -118,7 +154,7 @@ fn unlock_and_withdraw_deposit_works() { assert_eq!( DdcCustomers::ledger(&1), Some(AccountsLedger { - owner: 1, + owner: account_1, total: 35_u128, active: 34_u128, unlocking: unlocking_chunks.clone(), @@ -127,25 +163,25 @@ fn unlock_and_withdraw_deposit_works() { // Reach max unlock chunks for i in 1..32 { - assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128)); + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(account_1), 1_u128)); System::set_block_number(i + 2); } // No more chunks can be added assert_noop!( - DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 1_u128), + DdcCustomers::unlock_deposit(RuntimeOrigin::signed(account_1), 1_u128), Error::::NoMoreChunks ); // Set the block to withdraw all unlocked chunks System::set_block_number(42); - assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(1))); + assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); // Check storage assert_eq!( DdcCustomers::ledger(&1), Some(AccountsLedger { - owner: 1, + owner: account_1, total: 3_u128, active: 3_u128, unlocking: Default::default(), @@ -153,11 +189,11 @@ fn unlock_and_withdraw_deposit_works() { ); // Unlock remaining chuncks & withdraw - assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(1), 3_u128)); + assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(account_1), 3_u128)); System::set_block_number(52); - assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(1))); + assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); // Check storage - assert_eq!(DdcCustomers::ledger(&1), None); + assert_eq!(DdcCustomers::ledger(&account_1), None); }) } From a37b07df575da16e991b9acb14439a66634cb3ad Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 15 Nov 2023 16:22:36 +0100 Subject: [PATCH 514/544] apply dprint --- pallets/ddc-customers/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 363c47a11..4a3a982c0 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -17,8 +17,8 @@ sp-std = { version = "4.0.0-dev", default-features = false, git = "https://githu [dev-dependencies] pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } From dbc9b349a281999f347e1b5b965be263e460a7aa Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Thu, 16 Nov 2023 11:09:53 +0300 Subject: [PATCH 515/544] Remove redundant 0.10.0-dev versions --- cli/Cargo.toml | 6 +++--- node/client/Cargo.toml | 8 ++++---- node/service/Cargo.toml | 24 ++++++++++++------------ rpc/Cargo.toml | 18 +++++++++--------- runtime/cere-dev/Cargo.toml | 4 ++-- runtime/cere/Cargo.toml | 4 ++-- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 648c6e2fa..60b4a4624 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -14,9 +14,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] clap = { version = "3.1", features = ["derive"], optional = true } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +sc-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +sc-service = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } url = "2.4.1" # Local diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index e310ce7d1..edd3ad1ac 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -12,14 +12,14 @@ pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/parity pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-service = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index dbde60843..2a5f12e0e 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -9,21 +9,21 @@ jsonrpsee = { version = "0.15.1", features = ["server"] } node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } rand = "0.8" -sc-authority-discovery = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-authority-discovery = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-consensus-uncles = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } -sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-slots = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-uncles = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-executor = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-network = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } -sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-service = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } +sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -32,7 +32,7 @@ sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 92f3e9a6f..e0e64e7f9 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -10,20 +10,20 @@ pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/parity pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus-babe-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus-epochs = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-finality-grandpa-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus-epochs = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-sync-state-rpc = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 9d47b5f64..61e14a6a7 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -24,7 +24,7 @@ node-primitives = { version = "2.0.0", default-features = false, git = "https:// sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -46,7 +46,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, git = "https: frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 95cfa8a4b..2ede9e2e8 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -24,7 +24,7 @@ node-primitives = { version = "2.0.0", default-features = false, git = "https:// sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } -sp-consensus-babe = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -46,7 +46,7 @@ frame-support = { version = "4.0.0-dev", default-features = false, git = "https: frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } From 839c07a9a69376a62e1651bfd2da9f4e516b967c Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Thu, 16 Nov 2023 11:11:35 +0300 Subject: [PATCH 516/544] Remove redundant version attributes --- Cargo.toml | 4 +- cli/Cargo.toml | 4 +- node/client/Cargo.toml | 40 +++--- node/service/Cargo.toml | 36 +++--- pallets/chainbridge/Cargo.toml | 14 +- pallets/ddc-clusters/Cargo.toml | 24 ++-- pallets/ddc-customers/Cargo.toml | 20 +-- .../ddc-metrics-offchain-worker/Cargo.toml | 23 ++-- pallets/ddc-nodes/Cargo.toml | 20 +-- pallets/ddc-staking/Cargo.toml | 22 ++-- pallets/ddc/Cargo.toml | 12 +- pallets/ddc/README.md | 2 +- pallets/erc20/Cargo.toml | 16 +-- pallets/erc721/Cargo.toml | 14 +- primitives/Cargo.toml | 4 +- rpc/Cargo.toml | 26 ++-- runtime/cere-dev/Cargo.toml | 122 +++++++++--------- runtime/cere-dev/constants/Cargo.toml | 2 +- runtime/cere/Cargo.toml | 122 +++++++++--------- runtime/cere/constants/Cargo.toml | 2 +- traits/Cargo.toml | 2 +- 21 files changed, 265 insertions(+), 266 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9da35ba1..54d85719a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] cere-cli = { path = "cli", features = ["cere-dev-native"] } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } [build-dependencies] -substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [workspace] members = [ diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 60b4a4624..806829886 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,7 +13,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] clap = { version = "3.1", features = ["derive"], optional = true } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } sc-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } sc-service = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } @@ -24,7 +24,7 @@ cere-client = { path = "../node/client", optional = true } cere-service = { path = "../node/service", default-features = false, optional = true } [build-dependencies] -substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } [features] default = ["cli", "cere-native"] diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index edd3ad1ac..b77734e7f 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -4,30 +4,30 @@ version = "4.8.1" edition = "2021" [dependencies] -frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-service = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # Local cere-dev-runtime = { path = "../../runtime/cere-dev", optional = true } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 2a5f12e0e..d817c4f7d 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -6,13 +6,13 @@ edition = "2021" [dependencies] futures = "0.3.21" jsonrpsee = { version = "0.15.1", features = ["server"] } -node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } rand = "0.8" sc-authority-discovery = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-chain-spec = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus-slots = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -21,24 +21,24 @@ sc-executor = { git = "https://github.com/paritytech/substrate.git", branch = "p sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-network = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-service = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-sysinfo = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-telemetry = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } serde = { version = "1.0.136", features = ["derive"] } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authority-discovery = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authorship = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-trie = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-storage-proof = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } # Local cere-client = { path = "../client", default-features = false, optional = true } diff --git a/pallets/chainbridge/Cargo.toml b/pallets/chainbridge/Cargo.toml index 617e76b9b..9664b4a6a 100644 --- a/pallets/chainbridge/Cargo.toml +++ b/pallets/chainbridge/Cargo.toml @@ -14,14 +14,14 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 1a3e0aa16..ac1c569aa 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -7,24 +7,24 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } hex = { version = "0.4", default-features = false } hex-literal = "^0.3.1" -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 4a3a982c0..28fc87408 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -7,20 +7,20 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-metrics-offchain-worker/Cargo.toml b/pallets/ddc-metrics-offchain-worker/Cargo.toml index d56726763..99c821064 100644 --- a/pallets/ddc-metrics-offchain-worker/Cargo.toml +++ b/pallets/ddc-metrics-offchain-worker/Cargo.toml @@ -15,19 +15,18 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] alt_serde = { version = "1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["full"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } hex = { version = "0.4", default-features = false } -# pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } hex-literal = "^0.3.1" -pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-keystore = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] @@ -45,7 +44,7 @@ std = [ ] [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pretty_assertions = "0.6.1" diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 10bf74d9e..589bcc7e9 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -7,19 +7,19 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index 0f9c57433..67dddf18a 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -7,20 +7,20 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] -pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/ddc/Cargo.toml b/pallets/ddc/Cargo.toml index f25de5056..57970e3f3 100644 --- a/pallets/ddc/Cargo.toml +++ b/pallets/ddc/Cargo.toml @@ -14,16 +14,16 @@ targets = ['x86_64-unknown-linux-gnu'] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] serde = { version = "1.0.101" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ['std'] diff --git a/pallets/ddc/README.md b/pallets/ddc/README.md index 9a6144ff4..f943ea5be 100644 --- a/pallets/ddc/README.md +++ b/pallets/ddc/README.md @@ -58,7 +58,7 @@ Import the CereDDCModule and derive your runtime configuration traits from the C 1. In ./bin/node/runtime/Cargo.toml add: ```rust - frame-executive = { version = "4.0.0-dev", default-features = false, path = "../../../frame/executive" } + frame-executive = { default-features = false, path = "../../../frame/executive" } ... pallet-cere-ddc = { version = "7.3.0", default-features = false, path = "../../../frame/ddc-pallet" } ``` diff --git a/pallets/erc20/Cargo.toml b/pallets/erc20/Cargo.toml index 580ba103f..98e88b80e 100644 --- a/pallets/erc20/Cargo.toml +++ b/pallets/erc20/Cargo.toml @@ -14,17 +14,17 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } pallet-erc721 = { version = "4.2.0", default-features = false, path = "../erc721" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-arithmetic = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-arithmetic = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/pallets/erc721/Cargo.toml b/pallets/erc721/Cargo.toml index 08e9b531a..752f61229 100644 --- a/pallets/erc721/Cargo.toml +++ b/pallets/erc721/Cargo.toml @@ -14,15 +14,15 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 607c87512..37cf636d1 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -8,8 +8,8 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features = scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index e0e64e7f9..9ec4ab69d 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -5,26 +5,26 @@ edition = "2021" [dependencies] jsonrpsee = { version = "0.15.1", features = ["server"] } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-consensus-epochs = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -substrate-state-trie-migration-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 61e14a6a7..83cfc9954 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -20,89 +20,89 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive" static_assertions = "1.1.0" # primitives -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } sp-consensus-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-inherents = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies cere-dev-runtime-constants = { path = "./constants", default-features = false } cere-runtime-common = { path = "../common", default-features = false } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-authorship = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bags-list = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } -pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-child-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-collective = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } -pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-multi-phase = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-support-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-indices = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-membership = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-multisig = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } -pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-session = { version = "4.0.0-dev", features = ["historical"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } -pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-proxy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-recovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-scheduler = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-session = { features = ["historical"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-society = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking-reward-curve = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-tips = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-treasury = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [build-dependencies] -substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/runtime/cere-dev/constants/Cargo.toml b/runtime/cere-dev/constants/Cargo.toml index d42c6c5b2..fe8398eb4 100644 --- a/runtime/cere-dev/constants/Cargo.toml +++ b/runtime/cere-dev/constants/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2021" [dependencies] -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 2ede9e2e8..27829db86 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -20,85 +20,85 @@ scale-info = { version = "2.1.2", default-features = false, features = ["derive" static_assertions = "1.1.0" # primitives -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, version = "4.0.0-dev" } sp-consensus-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-inherents = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-offchain = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-session = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies cere-runtime-common = { path = "../common", default-features = false } cere-runtime-constants = { path = "./constants", default-features = false } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-bags-list = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-authorship = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bags-list = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } -pallet-child-bounties = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-collective = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-child-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-collective = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } -pallet-democracy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } -pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-multi-phase = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-election-provider-support-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-identity = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-im-online = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-indices = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-indices = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-membership = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-multisig = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -pallet-offences = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-offences-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } -pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-recovery = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-session = { version = "4.0.0-dev", features = ["historical"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } -pallet-session-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } -pallet-society = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-tips = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-proxy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-recovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-scheduler = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-session = { features = ["historical"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } +pallet-society = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-staking-reward-curve = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-tips = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-treasury = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [build-dependencies] -substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/runtime/cere/constants/Cargo.toml b/runtime/cere/constants/Cargo.toml index 592358dfa..fce93a1aa 100644 --- a/runtime/cere/constants/Cargo.toml +++ b/runtime/cere/constants/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2021" [dependencies] -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["std"] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 63f8cbd4e..de7fe1136 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [dependencies] ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } From 5fdb3fa11b983e74f5b2bd50bc5b7d178ebcd382 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Thu, 16 Nov 2023 11:28:50 +0300 Subject: [PATCH 517/544] Use substrate.git in cargo files for consistency --- Cargo.toml | 2 +- cli/Cargo.toml | 10 +++++----- node/client/Cargo.toml | 8 ++++---- node/service/Cargo.toml | 4 ++-- rpc/Cargo.toml | 38 ++++++++++++++++++------------------- runtime/cere-dev/Cargo.toml | 8 ++++---- runtime/cere/Cargo.toml | 8 ++++---- runtime/common/Cargo.toml | 2 +- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54d85719a..0703a78a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] cere-cli = { path = "cli", features = ["cere-dev-native"] } -sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-cli = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [build-dependencies] substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 806829886..0bf45a4db 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,10 +13,10 @@ crate-type = ["cdylib", "rlib"] [dependencies] clap = { version = "3.1", features = ["derive"], optional = true } -frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -sc-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -sc-service = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } -try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" } +frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate.git", optional = true, branch = "polkadot-v0.9.30" } +sc-cli = { git = "https://github.com/paritytech/substrate.git", optional = true, branch = "polkadot-v0.9.30" } +sc-service = { git = "https://github.com/paritytech/substrate.git", optional = true, branch = "polkadot-v0.9.30" } +try-runtime-cli = { git = "https://github.com/paritytech/substrate.git", optional = true, branch = "polkadot-v0.9.30" } url = "2.4.1" # Local @@ -24,7 +24,7 @@ cere-client = { path = "../node/client", optional = true } cere-service = { path = "../node/service", default-features = false, optional = true } [build-dependencies] -substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] default = ["cli", "cere-native"] diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index b77734e7f..f4798e201 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -12,11 +12,11 @@ pallet-contracts-rpc = { git = "https://github.com/paritytech/substrate.git", br pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-service = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sc-executor = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-service = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-authority-discovery = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -25,7 +25,7 @@ sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = " sp-offchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-session = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-storage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index d817c4f7d..326461ae8 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -20,7 +20,7 @@ sc-consensus-uncles = { git = "https://github.com/paritytech/substrate.git", bra sc-executor = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-network = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-network-common = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-service = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -38,7 +38,7 @@ sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", bra sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-transaction-storage-proof = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # Local cere-client = { path = "../client", default-features = false, optional = true } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 9ec4ab69d..a05ef9559 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -7,24 +7,24 @@ edition = "2021" jsonrpsee = { version = "0.15.1", features = ["server"] } node-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus-epochs = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-chain-spec = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-consensus-epochs = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sc-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-consensus-babe = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 83cfc9954..c55e73286 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -71,16 +71,16 @@ pallet-election-provider-support-benchmarking = { default-features = false, git pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } -pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-fast-unstake = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-indices = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-membership = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-multisig = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } -pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-nomination-pools = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate.git", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } pallet-proxy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 27829db86..2ce9a430f 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -67,16 +67,16 @@ pallet-election-provider-support-benchmarking = { default-features = false, git pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } -pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-fast-unstake = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-indices = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-membership = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-multisig = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } -pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } -pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-nomination-pools = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate.git", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false, optional = true } pallet-proxy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 5aff0c986..04ba5c0b1 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -13,4 +13,4 @@ std = [] frame-support = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } node-primitives = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } sp-core = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } From fa2d45b86c0c1851ab781569ca1a0e5fbdf184a6 Mon Sep 17 00:00:00 2001 From: Rakan Alhneiti Date: Thu, 16 Nov 2023 11:29:24 +0300 Subject: [PATCH 518/544] Update Cargo.lock --- Cargo.lock | 328 ++++++++++++++++++++++++++--------------------------- 1 file changed, 164 insertions(+), 164 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf8ab1e3d..60546e115 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2115,7 +2115,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", ] @@ -2132,7 +2132,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2155,7 +2155,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "array-bytes", @@ -2206,7 +2206,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2217,7 +2217,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2233,7 +2233,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -2262,7 +2262,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-metadata", @@ -2294,7 +2294,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "cfg-expr", @@ -2308,7 +2308,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2320,7 +2320,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -2330,7 +2330,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "log", @@ -2348,7 +2348,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -2372,7 +2372,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "parity-scale-codec", @@ -4421,7 +4421,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system", "parity-scale-codec", @@ -4620,7 +4620,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4636,7 +4636,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -4651,7 +4651,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4675,7 +4675,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4695,7 +4695,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4710,7 +4710,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4758,7 +4758,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4777,7 +4777,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -4794,7 +4794,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -4822,7 +4822,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -4837,7 +4837,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -4847,7 +4847,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-contracts-primitives", @@ -4864,7 +4864,7 @@ dependencies = [ [[package]] name = "pallet-contracts-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-contracts-primitives", "parity-scale-codec", @@ -4988,7 +4988,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5004,7 +5004,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5028,7 +5028,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5041,7 +5041,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5093,7 +5093,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5114,7 +5114,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5137,7 +5137,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5153,7 +5153,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5173,7 +5173,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5190,7 +5190,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5207,7 +5207,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5222,7 +5222,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5239,7 +5239,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5259,7 +5259,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -5269,7 +5269,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5286,7 +5286,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5309,7 +5309,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5324,7 +5324,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5338,7 +5338,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5353,7 +5353,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5369,7 +5369,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5390,7 +5390,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5406,7 +5406,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5420,7 +5420,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5443,7 +5443,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5454,7 +5454,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5468,7 +5468,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5486,7 +5486,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5505,7 +5505,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support", "frame-system", @@ -5521,7 +5521,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5536,7 +5536,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5547,7 +5547,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5564,7 +5564,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -5580,7 +5580,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-benchmarking", "frame-support", @@ -6499,7 +6499,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "env_logger 0.9.3", "jsonrpsee", @@ -6772,7 +6772,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -6783,7 +6783,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6810,7 +6810,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -6833,7 +6833,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -6849,7 +6849,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -6866,7 +6866,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6877,7 +6877,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "chrono", @@ -6917,7 +6917,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fnv", "futures", @@ -6945,7 +6945,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "kvdb", @@ -6970,7 +6970,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -6994,7 +6994,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "fork-tree", @@ -7036,7 +7036,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7058,7 +7058,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "fork-tree", "parity-scale-codec", @@ -7071,7 +7071,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -7095,7 +7095,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sc-client-api", "sp-authorship", @@ -7106,7 +7106,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "lru", @@ -7133,7 +7133,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -7149,7 +7149,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7164,7 +7164,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cfg-if", "libc", @@ -7184,7 +7184,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "array-bytes", @@ -7225,7 +7225,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "futures", @@ -7246,7 +7246,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "futures", @@ -7263,7 +7263,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "async-trait", @@ -7278,7 +7278,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "async-trait", @@ -7325,7 +7325,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "cid", "futures", @@ -7345,7 +7345,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -7371,7 +7371,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "futures", @@ -7389,7 +7389,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "futures", @@ -7410,7 +7410,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "fork-tree", @@ -7438,7 +7438,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "futures", @@ -7457,7 +7457,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "bytes", @@ -7487,7 +7487,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libp2p", @@ -7500,7 +7500,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -7509,7 +7509,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "hash-db", @@ -7539,7 +7539,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7562,7 +7562,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "jsonrpsee", @@ -7575,7 +7575,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "directories", @@ -7645,7 +7645,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -7659,7 +7659,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -7678,7 +7678,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "libc", @@ -7697,7 +7697,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "chrono", "futures", @@ -7715,7 +7715,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7746,7 +7746,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7757,7 +7757,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -7783,7 +7783,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -7796,7 +7796,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "futures-timer", @@ -8209,7 +8209,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8227,7 +8227,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "proc-macro-crate", @@ -8239,7 +8239,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8252,7 +8252,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "integer-sqrt", "num-traits", @@ -8267,7 +8267,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8280,7 +8280,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "parity-scale-codec", @@ -8292,7 +8292,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-api", @@ -8304,7 +8304,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "log", @@ -8322,7 +8322,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8341,7 +8341,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "merlin", @@ -8364,7 +8364,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8378,7 +8378,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8391,7 +8391,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "array-bytes", "base58", @@ -8437,7 +8437,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", "byteorder", @@ -8451,7 +8451,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8462,7 +8462,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -8471,7 +8471,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro2", "quote", @@ -8481,7 +8481,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "environmental", "parity-scale-codec", @@ -8492,7 +8492,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "finality-grandpa", "log", @@ -8510,7 +8510,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8524,7 +8524,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "futures", @@ -8550,7 +8550,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "lazy_static", "sp-core", @@ -8561,7 +8561,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures", @@ -8578,7 +8578,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "thiserror", "zstd", @@ -8587,7 +8587,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8601,7 +8601,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-core", @@ -8611,7 +8611,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "backtrace", "lazy_static", @@ -8621,7 +8621,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "rustc-hash", "serde", @@ -8631,7 +8631,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "either", "hash256-std-hasher", @@ -8654,7 +8654,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8672,7 +8672,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", "proc-macro-crate", @@ -8684,7 +8684,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "parity-scale-codec", @@ -8698,7 +8698,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8712,7 +8712,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "scale-info", @@ -8723,7 +8723,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "hash-db", "log", @@ -8745,12 +8745,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8763,7 +8763,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "log", "sp-core", @@ -8776,7 +8776,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "futures-timer", @@ -8792,7 +8792,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "sp-std", @@ -8804,7 +8804,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "sp-api", "sp-runtime", @@ -8813,7 +8813,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "async-trait", "log", @@ -8829,7 +8829,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ahash", "hash-db", @@ -8852,7 +8852,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8869,7 +8869,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8880,7 +8880,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "log", @@ -8893,7 +8893,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -9040,7 +9040,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "platforms 2.0.0", ] @@ -9048,7 +9048,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -9069,7 +9069,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures-util", "hyper", @@ -9082,7 +9082,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "jsonrpsee", "log", @@ -9103,7 +9103,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "futures", "substrate-test-utils-derive", @@ -9113,7 +9113,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9124,7 +9124,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "ansi_term 0.12.1", "build-helper", @@ -9571,7 +9571,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "clap", "frame-try-runtime", From a109f38c85134dd1f98c2eb6447f612d7481a9ca Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Thu, 16 Nov 2023 13:45:09 +0200 Subject: [PATCH 519/544] add missing mocks --- pallets/ddc-customers/src/mock.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index ae07269b8..025f76fa4 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -128,6 +128,17 @@ impl ClusterVisitor for TestClusterVisitor { ) -> Result { Ok(T::BlockNumber::from(10u32)) } + + fn get_pricing_params( + cluster_id: &ClusterId, + ) -> Result { + Ok(ClusterPricingParams { + unit_per_mb_stored: 1, + unit_per_mb_streamed: 2, + unit_per_put_request: 3, + unit_per_get_request: 4, + }) + } } pub struct ExtBuilder; From 3ba8265caf172648bd9b4246d1a945fefc8bf4fa Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Thu, 16 Nov 2023 14:53:36 +0200 Subject: [PATCH 520/544] some CI fixes --- pallets/ddc-customers/src/mock.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 025f76fa4..0ff1957d5 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -1,7 +1,7 @@ //! Test utilities use crate::{self as pallet_ddc_customers, *}; -use ddc_primitives::{NodePubKey, NodeType}; +use ddc_primitives::{NodePubKey, NodeType, ClusterPricingParams}; use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; use frame_support::{ @@ -130,7 +130,7 @@ impl ClusterVisitor for TestClusterVisitor { } fn get_pricing_params( - cluster_id: &ClusterId, + _cluster_id: &ClusterId, ) -> Result { Ok(ClusterPricingParams { unit_per_mb_stored: 1, From 96a2212cbfb3df26fc067b7be267b28306ca0843 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Thu, 16 Nov 2023 15:00:50 +0200 Subject: [PATCH 521/544] CI fixes --- pallets/ddc-customers/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 0ff1957d5..5113b1e69 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -1,7 +1,7 @@ //! Test utilities use crate::{self as pallet_ddc_customers, *}; -use ddc_primitives::{NodePubKey, NodeType, ClusterPricingParams}; +use ddc_primitives::{ClusterPricingParams, NodePubKey, NodeType}; use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; use frame_support::{ From 91c16e2d2332c19a2e832d8d9c8be918e2a13fcd Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Fri, 17 Nov 2023 15:51:39 +0100 Subject: [PATCH 522/544] fix(pallet_ddc_customers): 'StorageHasher' type for Ledger map is changed to a more secure one --- pallets/ddc-customers/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index e010065dc..1263db707 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -177,8 +177,12 @@ pub mod pallet { /// Map from all (unlocked) "owner" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] - pub type Ledger = - StorageMap<_, Identity, T::AccountId, AccountsLedger, T>>; + pub type Ledger = StorageMap< + _, + Blake2_128Concat, + T::AccountId, + AccountsLedger, T>, + >; #[pallet::type_value] pub fn DefaultBucketCount() -> BucketId { From 73f202318829195d83ba372cc012bb5dfae14738 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:52:25 +0200 Subject: [PATCH 523/544] backporting PR 152 to v0.9.30 (#164) Backports #152 to be merged into the `deployment-0.9.30` branch. --- Cargo.lock | 3 + pallets/ddc-clusters/src/lib.rs | 23 +- pallets/ddc-customers/src/lib.rs | 31 +- pallets/ddc-customers/src/mock.rs | 17 +- pallets/ddc-payouts/Cargo.toml | 3 + pallets/ddc-payouts/src/lib.rs | 324 ++++-- pallets/ddc-payouts/src/mock.rs | 304 ++++++ pallets/ddc-payouts/src/tests.rs | 1590 +++++++++++++++++++++++++++++ pallets/ddc-staking/src/mock.rs | 17 +- primitives/src/lib.rs | 10 +- runtime/cere-dev/Cargo.toml | 1 + runtime/cere-dev/src/lib.rs | 14 +- traits/src/cluster.rs | 6 +- traits/src/customer.rs | 10 +- traits/src/lib.rs | 1 + traits/src/pallet.rs | 5 + 16 files changed, 2243 insertions(+), 116 deletions(-) create mode 100644 pallets/ddc-payouts/src/mock.rs create mode 100644 pallets/ddc-payouts/src/tests.rs create mode 100644 traits/src/pallet.rs diff --git a/Cargo.lock b/Cargo.lock index 812e4de16..52d3cfc98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -847,6 +847,7 @@ version = "4.8.1" dependencies = [ "cere-dev-runtime-constants", "cere-runtime-common", + "ddc-traits", "frame-benchmarking", "frame-election-provider-support", "frame-executive", @@ -5020,9 +5021,11 @@ dependencies = [ "ddc-primitives", "ddc-traits", "frame-benchmarking", + "frame-election-provider-support", "frame-support", "frame-system", "log", + "pallet-balances", "parity-scale-codec", "scale-info", "sp-core", diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index c7786861b..99b8e1448 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -24,7 +24,7 @@ use crate::{ cluster::{Cluster, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; -use ddc_primitives::{ClusterId, ClusterPricingParams, NodePubKey, NodeType}; +use ddc_primitives::{ClusterFeesParams, ClusterId, ClusterPricingParams, NodePubKey, NodeType}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, staking::{StakingVisitor, StakingVisitorError}, @@ -284,6 +284,27 @@ pub mod pallet { }) } + fn get_fees_params( + cluster_id: &ClusterId, + ) -> Result { + let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; + + Ok(ClusterFeesParams { + treasury_share: cluster_gov_params.treasury_share, + validators_share: cluster_gov_params.validators_share, + cluster_reserve_share: cluster_gov_params.cluster_reserve_share, + }) + } + + fn get_reserve_account_id( + cluster_id: &ClusterId, + ) -> Result { + let cluster = Clusters::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterDoesNotExist)?; + Ok(cluster.reserve_id) + } + fn get_chill_delay( cluster_id: &ClusterId, node_type: NodeType, diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 1263db707..98849d807 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -9,7 +9,10 @@ mod tests; use codec::{Decode, Encode, HasCompact}; use ddc_primitives::{BucketId, ClusterId}; -use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger}; +use ddc_traits::{ + cluster::ClusterVisitor, + customer::{CustomerCharger, CustomerChargerError}, +}; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, @@ -544,32 +547,37 @@ pub mod pallet { content_owner: T::AccountId, billing_vault: T::AccountId, amount: u128, - ) -> DispatchResult { - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; + ) -> Result { + let actually_charged: BalanceOf; + let mut ledger = Self::ledger(&content_owner).ok_or(CustomerChargerError::NotOwner)?; let mut amount_to_deduct = amount.saturated_into::>(); - ensure!(ledger.total >= ledger.active, Error::::ArithmeticUnderflow); + ensure!(ledger.total >= ledger.active, CustomerChargerError::ArithmeticUnderflow); if ledger.active >= amount_to_deduct { + actually_charged = amount_to_deduct; ledger.active = ledger .active .checked_sub(&amount_to_deduct) - .ok_or(Error::::ArithmeticUnderflow)?; + .ok_or(CustomerChargerError::ArithmeticUnderflow)?; ledger.total = ledger .total .checked_sub(&amount_to_deduct) - .ok_or(Error::::ArithmeticUnderflow)?; + .ok_or(CustomerChargerError::ArithmeticUnderflow)?; Self::update_ledger(&content_owner, &ledger); } else { let diff = amount_to_deduct .checked_sub(&ledger.active) - .ok_or(Error::::ArithmeticUnderflow)?; + .ok_or(CustomerChargerError::ArithmeticUnderflow)?; + actually_charged = diff; ledger.total = ledger .total .checked_sub(&ledger.active) - .ok_or(Error::::ArithmeticUnderflow)?; + .ok_or(CustomerChargerError::ArithmeticUnderflow)?; amount_to_deduct = ledger.active; ledger.active = BalanceOf::::zero(); - let (ledger, _charged) = ledger.charge_unlocking(diff)?; + let (ledger, _charged) = ledger + .charge_unlocking(diff) + .map_err(|_| CustomerChargerError::UnlockFailed)?; Self::update_ledger(&content_owner, &ledger); }; @@ -578,10 +586,11 @@ pub mod pallet { &billing_vault, amount_to_deduct, ExistenceRequirement::KeepAlive, - )?; + ) + .map_err(|_| CustomerChargerError::TransferFailed)?; Self::deposit_event(Event::::Charged(content_owner, amount_to_deduct)); - Ok(()) + Ok(actually_charged.saturated_into::()) } } } diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 5113b1e69..0004eb3a5 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -1,7 +1,7 @@ //! Test utilities use crate::{self as pallet_ddc_customers, *}; -use ddc_primitives::{ClusterPricingParams, NodePubKey, NodeType}; +use ddc_primitives::{ClusterFeesParams, ClusterPricingParams, NodePubKey, NodeType}; use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; use frame_support::{ @@ -15,6 +15,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, + Perbill, }; /// The AccountId alias in this test module. @@ -139,6 +140,20 @@ impl ClusterVisitor for TestClusterVisitor { unit_per_get_request: 4, }) } + + fn get_fees_params(_cluster_id: &ClusterId) -> Result { + Ok(ClusterFeesParams { + treasury_share: Perbill::from_percent(1), + validators_share: Perbill::from_percent(10), + cluster_reserve_share: Perbill::from_percent(2), + }) + } + + fn get_reserve_account_id( + _cluster_id: &ClusterId, + ) -> Result { + Err(ClusterVisitorError::ClusterDoesNotExist) + } } pub struct ExtBuilder; diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml index ed77fa188..534342060 100644 --- a/pallets/ddc-payouts/Cargo.toml +++ b/pallets/ddc-payouts/Cargo.toml @@ -9,6 +9,7 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features = ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } +frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } @@ -20,6 +21,7 @@ sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://g sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] +pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -38,5 +40,6 @@ std = [ "sp-staking/std", "sp-std/std", "sp-core/std", + "frame-election-provider-support/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 8143622bb..2786dc21b 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -14,8 +14,17 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +#[cfg(test)] +pub(crate) mod mock; +#[cfg(test)] +mod tests; + use ddc_primitives::{ClusterId, DdcEra}; -use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger as CustomerChargerType}; +use ddc_traits::{ + cluster::ClusterVisitor as ClusterVisitorType, + customer::CustomerCharger as CustomerChargerType, pallet::PalletVisitor as PalletVisitorType, +}; +use frame_election_provider_support::SortedListProvider; use frame_support::{ pallet_prelude::*, parameter_types, @@ -25,7 +34,7 @@ use frame_support::{ }; use frame_system::pallet_prelude::*; pub use pallet::*; -use sp_runtime::Perbill; +use sp_runtime::{PerThing, Perbill}; use sp_std::prelude::*; type BatchIndex = u16; @@ -33,8 +42,8 @@ type BatchIndex = u16; /// Stores usage of customers #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct CustomerUsage { - pub transferred_bytes: u128, - pub stored_bytes: u128, + pub transferred_bytes: u64, + pub stored_bytes: u64, pub number_of_puts: u128, pub number_of_gets: u128, } @@ -42,8 +51,8 @@ pub struct CustomerUsage { /// Stores usage of node provider #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct NodeUsage { - pub transferred_bytes: u128, - pub stored_bytes: u128, + pub transferred_bytes: u64, + pub stored_bytes: u64, pub number_of_puts: u128, pub number_of_gets: u128, } @@ -51,10 +60,10 @@ pub struct NodeUsage { /// Stores reward in tokens(units) of node provider as per NodeUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct NodeReward { - pub transfer: u128, // for transferred_bytes - pub storage: u128, // for stored_bytes - pub puts: u128, // for number_of_puts - pub gets: u128, // for number_of_gets + pub transfer: u128, // tokens for transferred_bytes + pub storage: u128, // tokens for stored_bytes + pub puts: u128, // tokens for number_of_puts + pub gets: u128, // tokens for number_of_gets } #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] @@ -68,10 +77,10 @@ pub struct BillingReportDebt { /// Stores charge in tokens(units) of customer as per CustomerUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct CustomerCharge { - pub transfer: u128, // for transferred_bytes - pub storage: u128, // for stored_bytes - pub puts: u128, // for number_of_puts - pub gets: u128, // for number_of_gets + pub transfer: u128, // tokens for transferred_bytes + pub storage: u128, // tokens for stored_bytes + pub puts: u128, // tokens for number_of_puts + pub gets: u128, // tokens for number_of_gets } /// The balance type of this pallet. @@ -99,11 +108,11 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; #[pallet::constant] type PalletId: Get; - type Currency: LockableCurrency; - type CustomerCharger: CustomerChargerType; - type ClusterVisitor: ClusterVisitor; + type TreasuryVisitor: PalletVisitorType; + type ClusterVisitor: ClusterVisitorType; + type ValidatorList: SortedListProvider; } #[pallet::event] @@ -133,6 +142,21 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, }, + TreasuryFeesCollected { + cluster_id: ClusterId, + era: DdcEra, + amount: u128, + }, + ClusterReserveFeesCollected { + cluster_id: ClusterId, + era: DdcEra, + amount: u128, + }, + ValidatorFeesCollected { + cluster_id: ClusterId, + era: DdcEra, + amount: u128, + }, RewardingStarted { cluster_id: ClusterId, era: DdcEra, @@ -151,6 +175,9 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, }, + AuthorisedCaller { + authorised_caller: T::AccountId, + }, } #[pallet::error] @@ -178,7 +205,6 @@ pub mod pallet { Blake2_128Concat, DdcEra, BillingReport, - ValueQuery, >; #[pallet::storage] @@ -187,30 +213,23 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn debtor_customers)] - pub type DebtorCustomers = StorageDoubleMap< - _, - Blake2_128Concat, - ClusterId, - Blake2_128Concat, - T::AccountId, - u128, - ValueQuery, - >; + pub type DebtorCustomers = + StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(T))] pub struct BillingReport { - state: State, - vault: T::AccountId, - total_customer_charge: CustomerCharge, - total_distributed_reward: u128, - total_node_usage: NodeUsage, + pub state: State, + pub vault: T::AccountId, + pub total_customer_charge: CustomerCharge, + pub total_distributed_reward: u128, + pub total_node_usage: NodeUsage, // stage 1 - charging_max_batch_index: BatchIndex, - charging_processed_batches: BoundedBTreeSet, + pub charging_max_batch_index: BatchIndex, + pub charging_processed_batches: BoundedBTreeSet, // stage 2 - rewarding_max_batch_index: BatchIndex, - rewarding_processed_batches: BoundedBTreeSet, + pub rewarding_max_batch_index: BatchIndex, + pub rewarding_processed_batches: BoundedBTreeSet, } impl Default for BillingReport { @@ -235,8 +254,9 @@ pub mod pallet { NotInitialized, Initialized, ChargingCustomers, + CustomersChargedWithFees, CustomersCharged, - DeductingFees, + FeesDeducted, RewardingProviders, ProvidersRewarded, Finalized, @@ -251,7 +271,9 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; // requires Governance approval - AuthorisedCaller::::put(authorised_caller); + AuthorisedCaller::::put(authorised_caller.clone()); + + Self::deposit_event(Event::::AuthorisedCaller { authorised_caller }); Ok(()) } @@ -294,10 +316,7 @@ pub mod pallet { let caller = ensure_signed(origin)?; ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); - ensure!( - max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), - Error::::BatchIndexOverflow - ); + ensure!(max_batch_index < MaxBatchesCount::get(), Error::::BatchIndexOverflow); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -374,49 +393,52 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; let customer_id = payer.0.clone(); - match T::CustomerCharger::charge_content_owner( + let amount_actually_charged = match T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), total_customer_charge, ) { - Ok(_) => { - updated_billing_report.total_customer_charge.storage = - temp_total_customer_storage_charge; - updated_billing_report.total_customer_charge.transfer = - temp_total_customer_transfer_charge; - updated_billing_report.total_customer_charge.puts = - temp_total_customer_puts_charge; - updated_billing_report.total_customer_charge.gets = - temp_total_customer_gets_charge; - - Self::deposit_event(Event::::Charged { - cluster_id, - era, - customer_id, - amount: total_customer_charge, - }); - }, - Err(_e) => { - let mut customer_dept = - DebtorCustomers::::try_get(cluster_id, customer_id.clone()) - .unwrap_or_else(|_| Zero::zero()); - - customer_dept = customer_dept - .checked_add(total_customer_charge) - .ok_or(Error::::ArithmeticOverflow)?; - DebtorCustomers::::insert( - cluster_id, - customer_id.clone(), - customer_dept, - ); - - Self::deposit_event(Event::::ChargeFailed { - cluster_id, - era, - customer_id, - amount: total_customer_charge, - }); - }, + Ok(actually_charged) => actually_charged, + Err(_e) => 0, + }; + + if amount_actually_charged < total_customer_charge { + // debt + let mut customer_debt = + DebtorCustomers::::try_get(cluster_id, customer_id.clone()) + .unwrap_or_else(|_| Zero::zero()); + + customer_debt = (|| -> Option { + customer_debt + .checked_add(total_customer_charge)? + .checked_sub(amount_actually_charged) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + DebtorCustomers::::insert(cluster_id, customer_id.clone(), customer_debt); + + Self::deposit_event(Event::::ChargeFailed { + cluster_id, + era, + customer_id, + amount: total_customer_charge, + }); + } else { + updated_billing_report.total_customer_charge.storage = + temp_total_customer_storage_charge; + updated_billing_report.total_customer_charge.transfer = + temp_total_customer_transfer_charge; + updated_billing_report.total_customer_charge.puts = + temp_total_customer_puts_charge; + updated_billing_report.total_customer_charge.gets = + temp_total_customer_gets_charge; + + Self::deposit_event(Event::::Charged { + cluster_id, + era, + customer_id, + amount: total_customer_charge, + }); } } @@ -448,11 +470,74 @@ pub mod pallet { &billing_report.charging_max_batch_index, )?; - billing_report.state = State::CustomersCharged; - ActiveBillingReports::::insert(cluster_id, era, billing_report); - Self::deposit_event(Event::::ChargingFinished { cluster_id, era }); + // deduct fees + let fees = T::ClusterVisitor::get_fees_params(&cluster_id) + .map_err(|_| Error::::NotExpectedClusterState)?; + + let total_customer_charge = (|| -> Option { + billing_report + .total_customer_charge + .transfer + .checked_add(billing_report.total_customer_charge.storage)? + .checked_add(billing_report.total_customer_charge.puts)? + .checked_add(billing_report.total_customer_charge.gets) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + let treasury_fee = fees.treasury_share * total_customer_charge; + let validators_fee = fees.validators_share * total_customer_charge; + let cluster_reserve_fee = fees.cluster_reserve_share * total_customer_charge; + + charge_treasury_fees::( + treasury_fee, + &billing_report.vault, + &T::TreasuryVisitor::get_account_id(), + )?; + Self::deposit_event(Event::::TreasuryFeesCollected { + cluster_id, + era, + amount: treasury_fee, + }); + + charge_cluster_reserve_fees::( + cluster_reserve_fee, + &billing_report.vault, + &T::ClusterVisitor::get_reserve_account_id(&cluster_id) + .map_err(|_| Error::::NotExpectedClusterState)?, + )?; + Self::deposit_event(Event::::ClusterReserveFeesCollected { + cluster_id, + era, + amount: cluster_reserve_fee, + }); + + charge_validator_fees::(validators_fee, &billing_report.vault)?; + Self::deposit_event(Event::::ValidatorFeesCollected { + cluster_id, + era, + amount: validators_fee, + }); + + // 1 - (X + Y + Z) > 0, 0 < X + Y + Z < 1 + let total_left_from_one = + (fees.treasury_share + fees.validators_share + fees.cluster_reserve_share) + .left_from_one(); + + // X * Z < X, 0 < Z < 1 + billing_report.total_customer_charge.transfer = + total_left_from_one * billing_report.total_customer_charge.transfer; + billing_report.total_customer_charge.storage = + total_left_from_one * billing_report.total_customer_charge.storage; + billing_report.total_customer_charge.puts = + total_left_from_one * billing_report.total_customer_charge.puts; + billing_report.total_customer_charge.gets = + total_left_from_one * billing_report.total_customer_charge.gets; + + billing_report.state = State::CustomersChargedWithFees; + ActiveBillingReports::::insert(cluster_id, era, billing_report); + Ok(()) } @@ -467,15 +552,15 @@ pub mod pallet { let caller = ensure_signed(origin)?; ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); - ensure!( - max_batch_index > 0 && max_batch_index < MaxBatchesCount::get(), - Error::::BatchIndexOverflow - ); + ensure!(max_batch_index < MaxBatchesCount::get(), Error::::BatchIndexOverflow); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; - ensure!(billing_report.state == State::CustomersCharged, Error::::NotExpectedState); + ensure!( + billing_report.state == State::CustomersChargedWithFees, + Error::::NotExpectedState + ); billing_report.total_node_usage = total_node_usage; billing_report.rewarding_max_batch_index = max_batch_index; @@ -629,6 +714,55 @@ pub mod pallet { } } + fn charge_treasury_fees( + treasury_fee: u128, + vault: &T::AccountId, + treasury_vault: &T::AccountId, + ) -> DispatchResult { + let amount_to_deduct = treasury_fee.saturated_into::>(); + ::Currency::transfer( + vault, + treasury_vault, + amount_to_deduct, + ExistenceRequirement::KeepAlive, + ) + } + + fn charge_cluster_reserve_fees( + cluster_reserve_fee: u128, + vault: &T::AccountId, + reserve_vault: &T::AccountId, + ) -> DispatchResult { + let amount_to_deduct = cluster_reserve_fee.saturated_into::>(); + ::Currency::transfer( + vault, + reserve_vault, + amount_to_deduct, + ExistenceRequirement::KeepAlive, + ) + } + + fn charge_validator_fees( + validators_fee: u128, + vault: &T::AccountId, + ) -> DispatchResult { + let amount_to_deduct = validators_fee + .checked_div(T::ValidatorList::count().try_into().unwrap()) + .ok_or(Error::::ArithmeticOverflow)? + .saturated_into::>(); + + for validator_account_id in T::ValidatorList::iter() { + ::Currency::transfer( + vault, + &validator_account_id, + amount_to_deduct, + ExistenceRequirement::KeepAlive, + )?; + } + + Ok(()) + } + fn get_node_reward( node_usage: &NodeUsage, total_nodes_usage: &NodeUsage, @@ -665,16 +799,14 @@ pub mod pallet { .map_err(|_| Error::::NotExpectedClusterState)?; total.transfer = (|| -> Option { - usage - .transferred_bytes + (usage.transferred_bytes as u128) .checked_mul(pricing.unit_per_mb_streamed)? .checked_div(byte_unit::MEBIBYTE) })() .ok_or(Error::::ArithmeticOverflow)?; total.storage = (|| -> Option { - usage - .stored_bytes + (usage.stored_bytes as u128) .checked_mul(pricing.unit_per_mb_stored)? .checked_div(byte_unit::MEBIBYTE) })() @@ -700,9 +832,9 @@ pub mod pallet { // Check if the Vec contains all integers between 1 and rewarding_max_batch_index ensure!(!batches.is_empty(), Error::::BatchesMissed); - ensure!(*max_batch_index as usize == batches.len() - 1usize, Error::::BatchesMissed); + ensure!((*max_batch_index + 1) as usize == batches.len(), Error::::BatchesMissed); - for index in 0..*max_batch_index { + for index in 0..*max_batch_index + 1 { ensure!(batches.contains(&index), Error::::BatchesMissed); } @@ -710,7 +842,7 @@ pub mod pallet { } impl Pallet { - fn sub_account_id(cluster_id: ClusterId, era: DdcEra) -> T::AccountId { + pub fn sub_account_id(cluster_id: ClusterId, era: DdcEra) -> T::AccountId { let mut bytes = Vec::new(); bytes.extend_from_slice(&cluster_id[..]); bytes.extend_from_slice(&era.encode()); diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs new file mode 100644 index 000000000..31f3dfb11 --- /dev/null +++ b/pallets/ddc-payouts/src/mock.rs @@ -0,0 +1,304 @@ +//! Test utilities + +#![allow(dead_code)] + +use crate::{self as pallet_ddc_payouts, *}; +use ddc_primitives::{ClusterFeesParams, ClusterPricingParams, NodePubKey, NodeType}; +use ddc_traits::{ + cluster::{ClusterVisitor, ClusterVisitorError}, + customer::{CustomerCharger, CustomerChargerError}, + pallet::PalletVisitor, +}; +use frame_election_provider_support::SortedListProvider; + +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64, Everything}, + weights::constants::RocksDbWeight, + PalletId, +}; +use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; +use sp_core::H256; +use sp_io::TestExternalities; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; +use sp_std::prelude::*; + +/// The AccountId alias in this test module. +pub type AccountId = u64; +pub(crate) type AccountIndex = u64; +pub(crate) type BlockNumber = u64; +pub(crate) type Balance = u128; + +type UncheckedExtrinsic = MockUncheckedExtrinsic; +type Block = MockBlock; +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + DdcPayouts: pallet_ddc_payouts::{Pallet, Call, Storage, Event}, + } +); + +parameter_types! { + pub static ExistentialDeposit: Balance = 1; +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = RocksDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type MaxLocks = ConstU32<1024>; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +parameter_types! { + pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); +} + +impl crate::pallet::Config for Test { + type RuntimeEvent = RuntimeEvent; + type PalletId = PayoutsPalletId; + type Currency = Balances; + type CustomerCharger = TestCustomerCharger; + type ClusterVisitor = TestClusterVisitor; + type TreasuryVisitor = TestTreasuryVisitor; + type ValidatorList = TestValidatorVisitor; +} + +pub struct TestCustomerCharger; +impl CustomerCharger for TestCustomerCharger { + fn charge_content_owner( + content_owner: T::AccountId, + billing_vault: T::AccountId, + amount: u128, + ) -> Result { + ensure!(amount > 1_000_000, CustomerChargerError::TransferFailed); // any error will do + + let mut amount_to_charge = amount; + if amount_to_charge < 50_000_000 { + amount_to_charge = PARTIAL_CHARGE; + } + + let charge = amount_to_charge.saturated_into::>(); + + ::Currency::transfer( + &content_owner, + &billing_vault, + charge, + ExistenceRequirement::KeepAlive, + ) + .map_err(|_| CustomerChargerError::TransferFailed)?; + Ok(amount_to_charge) + } +} + +pub const RESERVE_ACCOUNT_ID: AccountId = 999; +pub const TREASURY_ACCOUNT_ID: AccountId = 888; +pub const VALIDATOR1_ACCOUNT_ID: AccountId = 111; +pub const VALIDATOR2_ACCOUNT_ID: AccountId = 222; +pub const VALIDATOR3_ACCOUNT_ID: AccountId = 333; +pub const PARTIAL_CHARGE: u128 = 100; + +pub const PRICING_PARAMS: ClusterPricingParams = ClusterPricingParams { + unit_per_mb_streamed: 2_000_000, + unit_per_mb_stored: 3_000_000, + unit_per_put_request: 4_000_000, + unit_per_get_request: 5_000_000, +}; + +pub const PRICING_FEES: ClusterFeesParams = ClusterFeesParams { + treasury_share: Perbill::from_percent(1), + validators_share: Perbill::from_percent(10), + cluster_reserve_share: Perbill::from_percent(2), +}; + +pub struct TestTreasuryVisitor; +impl PalletVisitor for TestTreasuryVisitor { + fn get_account_id() -> T::AccountId { + let reserve_account = TREASURY_ACCOUNT_ID.to_ne_bytes(); + T::AccountId::decode(&mut &reserve_account[..]).unwrap() + } +} + +fn create_account_id_from_u64(id: u64) -> T::AccountId { + let bytes = id.to_ne_bytes(); + T::AccountId::decode(&mut &bytes[..]).unwrap() +} + +pub struct TestValidatorVisitor(sp_std::marker::PhantomData); +impl SortedListProvider for TestValidatorVisitor { + type Score = u64; + type Error = (); + + /// Returns iterator over voter list, which can have `take` called on it. + fn iter() -> Box> { + Box::new( + vec![ + create_account_id_from_u64::(VALIDATOR1_ACCOUNT_ID), + create_account_id_from_u64::(VALIDATOR2_ACCOUNT_ID), + create_account_id_from_u64::(VALIDATOR3_ACCOUNT_ID), + ] + .into_iter(), + ) + } + fn iter_from( + _start: &T::AccountId, + ) -> Result>, Self::Error> { + unimplemented!() + } + fn count() -> u32 { + 3 + } + fn contains(_id: &T::AccountId) -> bool { + unimplemented!() + } + fn on_insert(_: T::AccountId, _weight: Self::Score) -> Result<(), Self::Error> { + // nothing to do on insert. + Ok(()) + } + fn get_score(_id: &T::AccountId) -> Result { + unimplemented!() + } + fn on_update(_: &T::AccountId, _weight: Self::Score) -> Result<(), Self::Error> { + // nothing to do on update. + Ok(()) + } + fn on_remove(_: &T::AccountId) -> Result<(), Self::Error> { + // nothing to do on remove. + Ok(()) + } + fn unsafe_regenerate( + _: impl IntoIterator, + _: Box Self::Score>, + ) -> u32 { + // nothing to do upon regenerate. + 0 + } + + fn try_state() -> Result<(), &'static str> { + unimplemented!() + } + + fn unsafe_clear() { + unimplemented!() + } + + #[cfg(feature = "runtime-benchmarks")] + fn score_update_worst_case(_who: &T::AccountId, _is_increase: bool) -> Self::Score { + unimplemented!() + } +} + +pub struct TestClusterVisitor; +impl ClusterVisitor for TestClusterVisitor { + fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { + true + } + fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { + Ok(()) + } + fn get_bond_size( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(10) + } + fn get_chill_delay( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(T::BlockNumber::from(10u32)) + } + fn get_unbonding_delay( + _cluster_id: &ClusterId, + _node_type: NodeType, + ) -> Result { + Ok(T::BlockNumber::from(10u32)) + } + + fn get_pricing_params( + _cluster_id: &ClusterId, + ) -> Result { + Ok(PRICING_PARAMS) + } + + fn get_fees_params(_cluster_id: &ClusterId) -> Result { + Ok(PRICING_FEES) + } + + fn get_reserve_account_id( + _cluster_id: &ClusterId, + ) -> Result { + let reserve_account = RESERVE_ACCOUNT_ID.to_ne_bytes(); + Ok(T::AccountId::decode(&mut &reserve_account[..]).unwrap()) + } +} + +pub(crate) type TestRuntimeCall = ::RuntimeCall; + +pub struct ExtBuilder; + +impl ExtBuilder { + fn build(self) -> TestExternalities { + sp_tracing::try_init_simple(); + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let _ = pallet_balances::GenesisConfig:: { + balances: vec![ + (1, 1000000000000000000000000), + (2, 10), // < PARTIAL_CHARGE + (3, 1000), // > PARTIAL_CHARGE + (4, 1000000000000000000000000), + ], + } + .assimilate_storage(&mut storage); + + TestExternalities::new(storage) + } + pub fn build_and_execute(self, test: impl FnOnce()) { + sp_tracing::try_init_simple(); + let mut ext = self.build(); + ext.execute_with(test); + } +} diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs new file mode 100644 index 000000000..d63d799e3 --- /dev/null +++ b/pallets/ddc-payouts/src/tests.rs @@ -0,0 +1,1590 @@ +//! Tests for the module. + +use super::{mock::*, *}; +use ddc_primitives::ClusterId; +use frame_support::{assert_noop, assert_ok, error::BadOrigin}; + +#[test] +fn set_authorised_caller_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let root_account = 1u64; + let dac_account = 2u64; + + assert_noop!( + DdcPayouts::set_authorised_caller(RuntimeOrigin::signed(root_account), dac_account), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + System::assert_last_event( + Event::AuthorisedCaller { authorised_caller: dac_account }.into(), + ); + + assert_eq!(DdcPayouts::authorised_caller().unwrap(), dac_account); + }) +} + +#[test] +fn begin_billing_report_fails_for_unauthorised() { + ExtBuilder.build_and_execute(|| { + let root_account = 1u64; + let dac_account = 2u64; + let cluster_id = ClusterId::from([1; 20]); + let era = 100; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account + 1), + cluster_id, + era, + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::begin_billing_report(RuntimeOrigin::signed(root_account), cluster_id, era,), + Error::::Unauthorised + ); + }) +} + +#[test] +fn begin_billing_report_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 2u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + System::assert_last_event(Event::BillingReportInitialized { cluster_id, era }.into()); + + let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::Initialized); + }) +} + +#[test] +fn begin_charging_customers_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let dac_account = 2u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 2; + + assert_noop!( + DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::begin_charging_customers( + RuntimeOrigin::root(), + cluster_id, + era, + max_batch_index, + ), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + ), + Error::::BillingReportDoesNotExist + ); + }) +} + +#[test] +fn begin_charging_customers_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 2u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 2; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + System::assert_last_event(Event::ChargingStarted { cluster_id, era }.into()); + + let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::ChargingCustomers); + assert_eq!(report.charging_max_batch_index, max_batch_index); + }) +} + +#[test] +fn send_charging_customers_batch_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let root_account = 1u64; + let dac_account = 2u64; + let user1 = 3u64; + let user2 = 4u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 2; + let batch_index = 1; + let payers1 = vec![(user1, CustomerUsage::default())]; + let payers2 = vec![(user2, CustomerUsage::default())]; + + assert_noop!( + DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(root_account), + cluster_id, + era, + batch_index, + payers1.clone(), + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::root(), + cluster_id, + era, + batch_index, + payers1.clone(), + ), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1.clone(), + ), + Error::::BillingReportDoesNotExist + ); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1.clone(), + )); + + assert_noop!( + DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1, + ), + Error::::BatchIndexAlreadyProcessed + ); + + assert_noop!( + DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers2, + ), + Error::::BatchIndexAlreadyProcessed + ); + }) +} + +fn calculate_charge(usage: CustomerUsage) -> u128 { + PRICING_PARAMS.unit_per_mb_streamed * (usage.transferred_bytes as u128) / byte_unit::MEBIBYTE + + (PRICING_PARAMS.unit_per_mb_stored * usage.stored_bytes as u128) / byte_unit::MEBIBYTE + + PRICING_PARAMS.unit_per_put_request * usage.number_of_puts + + PRICING_PARAMS.unit_per_get_request * usage.number_of_gets +} + +#[test] +fn send_charging_customers_batch_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 123u64; + let user1 = 1u64; + let user2_debtor = 2u64; + let user3_debtor = 3u64; + let user4 = 4u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 3; + let batch_index = 0; + let usage1 = CustomerUsage { + // should pass without debt + transferred_bytes: 23452345, + stored_bytes: 3345234523, + number_of_puts: 4456456345234523, + number_of_gets: 523423, + }; + let usage2 = CustomerUsage { + // should fail as not enough balance + transferred_bytes: 1, + stored_bytes: 2, + number_of_puts: 3, + number_of_gets: 4, + }; + let usage3 = CustomerUsage { + // should pass but with debt + transferred_bytes: 1, + stored_bytes: 2, + number_of_puts: 3, + number_of_gets: 4, + }; + let usage4 = CustomerUsage { + // should pass without debt + transferred_bytes: 467457, + stored_bytes: 45674567456, + number_of_puts: 3456345, + number_of_gets: 242334563456423, + }; + let payers1 = vec![(user2_debtor, usage2.clone()), (user4, usage4.clone())]; + let payers2 = vec![(user1, usage1.clone())]; + let payers3 = vec![(user3_debtor, usage3.clone())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + assert_eq!(System::events().len(), 3); + + // batch 1 + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1, + )); + + let usage4_charge = calculate_charge(usage4); + let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + assert_eq!(balance, usage4_charge); + + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let mut debt = calculate_charge(usage2); + assert_eq!(user2_debt, debt); + + System::assert_has_event( + Event::ChargeFailed { cluster_id, era, customer_id: user2_debtor, amount: debt }.into(), + ); + System::assert_last_event( + Event::Charged { cluster_id, era, customer_id: user4, amount: usage4_charge }.into(), + ); + + assert_eq!(System::events().len(), 5 + 3); // 3 for Currency::transfer + + // batch 2 + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 1, + payers2, + )); + + System::assert_last_event( + Event::Charged { + cluster_id, + era, + customer_id: user1, + amount: calculate_charge(usage1), + } + .into(), + ); + + let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::ChargingCustomers); + let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + assert_eq!(user1_debt, None); + + let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + // batch 3 + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 2, + payers3, + )); + + let user3_charge = calculate_charge(usage3); + balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + assert_eq!(balance, balance_before + PARTIAL_CHARGE); + + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + + debt = user3_charge - PARTIAL_CHARGE; + assert_eq!(user3_debt, debt); + + System::assert_last_event( + Event::ChargeFailed { + cluster_id, + era, + customer_id: user3_debtor, + amount: user3_charge, + } + .into(), + ); + }) +} + +#[test] +fn end_charging_customers_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let root_account = 100u64; + let dac_account = 123u64; + let user1 = 1u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 2; + let batch_index = 1; + let payers = vec![(user1, CustomerUsage::default())]; + + assert_noop!( + DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(root_account), + cluster_id, + era, + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::end_charging_customers(RuntimeOrigin::root(), cluster_id, era,), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::BillingReportDoesNotExist + ); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_noop!( + DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::BatchesMissed + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + assert_noop!( + DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::BatchesMissed + ); + }) +} + +#[test] +fn end_charging_customers_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 123u64; + let user1 = 1u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 0; + let batch_index = 0; + let usage1 = CustomerUsage { + transferred_bytes: 23452345, + stored_bytes: 3345234523, + number_of_puts: 4456456345234523, + number_of_gets: 523423, + }; + let payers = vec![(user1, usage1.clone())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let charge = calculate_charge(usage1); + System::assert_last_event( + Event::Charged { cluster_id, era, customer_id: user1, amount: charge }.into(), + ); + + let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + assert_eq!(balance, charge); + assert_eq!(System::events().len(), 4 + 3); // 3 for Currency::transfer + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); + + let treasury_fee = PRICING_FEES.treasury_share * charge; + let reserve_fee = PRICING_FEES.cluster_reserve_share * charge; + let validator_fee = PRICING_FEES.validators_share * charge; + + System::assert_has_event( + Event::TreasuryFeesCollected { cluster_id, era, amount: treasury_fee }.into(), + ); + + System::assert_has_event( + Event::ClusterReserveFeesCollected { cluster_id, era, amount: reserve_fee }.into(), + ); + + System::assert_has_event( + Event::ValidatorFeesCollected { cluster_id, era, amount: validator_fee }.into(), + ); + + let transfers = 3 + 3 + 3 * 3; // for Currency::transfer + assert_eq!(System::events().len(), 7 + 1 + 3 + transfers); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report_after.state, State::CustomersChargedWithFees); + + let total_left_from_one = (PRICING_FEES.treasury_share + + PRICING_FEES.validators_share + + PRICING_FEES.cluster_reserve_share) + .left_from_one(); + + balance = Balances::free_balance(TREASURY_ACCOUNT_ID); + assert_eq!(balance, PRICING_FEES.treasury_share * charge); + + balance = Balances::free_balance(RESERVE_ACCOUNT_ID); + assert_eq!(balance, PRICING_FEES.cluster_reserve_share * charge); + + balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); + assert_eq!(balance, PRICING_FEES.validators_share * charge / 3); + + balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); + assert_eq!(balance, PRICING_FEES.validators_share * charge / 3); + + balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); + assert_eq!(balance, PRICING_FEES.validators_share * charge / 3); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + }) +} + +#[test] +fn begin_rewarding_providers_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let root_account = 1u64; + let dac_account = 2u64; + let user1 = 3u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 2; + let batch_index = 1; + let payers = vec![(user1, CustomerUsage::default())]; + let node_usage = NodeUsage::default(); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(root_account), + cluster_id, + era, + max_batch_index, + node_usage.clone(), + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::root(), + cluster_id, + era, + max_batch_index, + node_usage.clone(), + ), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + node_usage.clone(), + ), + Error::::BillingReportDoesNotExist + ); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + node_usage.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + node_usage.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers.clone(), + )); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + node_usage.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 1, + payers, + )); + + assert_noop!( + DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + node_usage, + ), + Error::::NotExpectedState + ); + }) +} + +#[test] +fn begin_rewarding_providers_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 123u64; + let user1 = 1u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 0; + let batch_index = 0; + let total_node_usage = NodeUsage::default(); + let payers = vec![(user1, CustomerUsage::default())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::Initialized); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + total_node_usage, + )); + + System::assert_last_event(Event::RewardingStarted { cluster_id, era }.into()); + + report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::RewardingProviders); + }) +} + +#[test] +fn send_rewarding_providers_batch_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let root_account = 1u64; + let dac_account = 2u64; + let user1 = 3u64; + let user2 = 4u64; + let node1 = 33u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 1; + let batch_index = 0; + let payers1 = vec![(user1, CustomerUsage::default())]; + let payers2 = vec![(user2, CustomerUsage::default())]; + let payees = vec![(node1, NodeUsage::default())]; + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(root_account), + cluster_id, + era, + batch_index, + payees.clone(), + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::root(), + cluster_id, + era, + batch_index, + payees.clone(), + ), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees.clone(), + ), + Error::::BillingReportDoesNotExist + ); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1, + )); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 1, + payers2, + )); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees.clone(), + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees, + ), + Error::::NotExpectedState + ); + }) +} + +#[test] +fn send_rewarding_providers_batch_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 123u64; + let user1 = 1u64; + let node1 = 10u64; + let node2 = 11u64; + let node3 = 12u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 0; + let max_node_batch_index = 1; + let batch_index = 0; + let batch_node_index = 0; + let usage1 = CustomerUsage { + transferred_bytes: 23452345, + stored_bytes: 3345234523, + number_of_puts: 4456456345234523, + number_of_gets: 523423, + }; + + let node_usage1 = NodeUsage { + // CDN + transferred_bytes: usage1.transferred_bytes * 2 / 3, + stored_bytes: 0, + number_of_puts: usage1.number_of_puts * 2 / 3, + number_of_gets: usage1.number_of_gets * 2 / 3, + }; + + let node_usage2 = NodeUsage { + // Storage + transferred_bytes: 0, + stored_bytes: usage1.stored_bytes * 2, + number_of_puts: 0, + number_of_gets: 0, + }; + + let node_usage3 = NodeUsage { + // CDN + Storage + transferred_bytes: usage1.transferred_bytes * 2, + stored_bytes: usage1.stored_bytes * 3, + number_of_puts: usage1.number_of_puts * 2, + number_of_gets: usage1.number_of_gets * 2, + }; + + let total_nodes_usage = NodeUsage { + transferred_bytes: node_usage1.transferred_bytes + + node_usage2.transferred_bytes + + node_usage3.transferred_bytes, + stored_bytes: node_usage1.stored_bytes + + node_usage2.stored_bytes + + node_usage3.stored_bytes, + number_of_puts: node_usage1.number_of_puts + + node_usage2.number_of_puts + + node_usage3.number_of_puts, + number_of_gets: node_usage1.number_of_gets + + node_usage2.number_of_gets + + node_usage3.number_of_gets, + }; + + let payers = vec![(user1, usage1)]; + let payees1 = vec![(node1, node_usage1.clone()), (node2, node_usage2.clone())]; + let payees2 = vec![(node3, node_usage3.clone())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let total_left_from_one = (PRICING_FEES.treasury_share + + PRICING_FEES.validators_share + + PRICING_FEES.cluster_reserve_share) + .left_from_one(); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_node_batch_index, + total_nodes_usage.clone(), + )); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_node_index, + payees1, + )); + + let mut ratio = Perbill::from_rational( + node_usage1.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + let mut transfer_charge = ratio * report_after.total_customer_charge.transfer; + + ratio = Perbill::from_rational(node_usage1.stored_bytes, total_nodes_usage.stored_bytes); + let mut storage_charge = ratio * report_after.total_customer_charge.storage; + + ratio = + Perbill::from_rational(node_usage1.number_of_puts, total_nodes_usage.number_of_puts); + let mut puts_charge = ratio * report_after.total_customer_charge.puts; + + ratio = + Perbill::from_rational(node_usage1.number_of_gets, total_nodes_usage.number_of_gets); + let mut gets_charge = ratio * report_after.total_customer_charge.gets; + + let mut balance = Balances::free_balance(node1); + assert_eq!(balance, transfer_charge + storage_charge + puts_charge + gets_charge); + + ratio = Perbill::from_rational( + node_usage2.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + transfer_charge = ratio * report_after.total_customer_charge.transfer; + + ratio = Perbill::from_rational(node_usage2.stored_bytes, total_nodes_usage.stored_bytes); + storage_charge = ratio * report_after.total_customer_charge.storage; + + ratio = + Perbill::from_rational(node_usage2.number_of_puts, total_nodes_usage.number_of_puts); + puts_charge = ratio * report_after.total_customer_charge.puts; + + ratio = + Perbill::from_rational(node_usage2.number_of_gets, total_nodes_usage.number_of_gets); + gets_charge = ratio * report_after.total_customer_charge.gets; + + balance = Balances::free_balance(node2); + assert_eq!(balance, transfer_charge + storage_charge + puts_charge + gets_charge); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_node_index + 1, + payees2, + )); + + ratio = Perbill::from_rational( + node_usage3.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + transfer_charge = ratio * report_after.total_customer_charge.transfer; + + ratio = Perbill::from_rational(node_usage3.stored_bytes, total_nodes_usage.stored_bytes); + storage_charge = ratio * report_after.total_customer_charge.storage; + + ratio = + Perbill::from_rational(node_usage3.number_of_puts, total_nodes_usage.number_of_puts); + puts_charge = ratio * report_after.total_customer_charge.puts; + + ratio = + Perbill::from_rational(node_usage3.number_of_gets, total_nodes_usage.number_of_gets); + gets_charge = ratio * report_after.total_customer_charge.gets; + + balance = Balances::free_balance(node3); + assert_eq!(balance, transfer_charge + storage_charge + puts_charge + gets_charge); + + assert_ok!(DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + }) +} + +#[test] +fn end_rewarding_providers_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let root_account = 1u64; + let dac_account = 2u64; + let user1 = 3u64; + let user2 = 4u64; + let node1 = 33u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 1; + let batch_index = 0; + let payers1 = vec![(user1, CustomerUsage::default())]; + let payers2 = vec![(user2, CustomerUsage::default())]; + let payees = vec![(node1, NodeUsage::default())]; + let total_node_usage = NodeUsage::default(); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(root_account), + cluster_id, + era, + ), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::end_rewarding_providers(RuntimeOrigin::root(), cluster_id, era,), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::BillingReportDoesNotExist + ); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 1, + payers2, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + total_node_usage, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::BatchesMissed + ); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees, + )); + + assert_noop!( + DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + ), + Error::::BatchesMissed + ); + }) +} + +#[test] +fn end_rewarding_providers_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 2u64; + let user1 = 3u64; + let node1 = 33u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 0; + let batch_index = 0; + let total_node_usage = NodeUsage::default(); + let payers = vec![(user1, CustomerUsage::default())]; + let payees = vec![(node1, NodeUsage::default())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::Initialized); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + total_node_usage, + )); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees, + )); + + assert_ok!(DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + System::assert_last_event(Event::RewardingFinished { cluster_id, era }.into()); + + report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::ProvidersRewarded); + }) +} + +#[test] +fn end_billing_report_fails_uninitialised() { + ExtBuilder.build_and_execute(|| { + let root_account = 1u64; + let dac_account = 2u64; + let user1 = 3u64; + let user2 = 4u64; + let node1 = 33u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 1; + let batch_index = 0; + let payers1 = vec![(user1, CustomerUsage::default())]; + let payers2 = vec![(user2, CustomerUsage::default())]; + let payees = vec![(node1, NodeUsage::default())]; + let total_node_usage = NodeUsage::default(); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(root_account), cluster_id, era,), + Error::::Unauthorised + ); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::root(), cluster_id, era,), + BadOrigin + ); + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::BillingReportDoesNotExist + ); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers1, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 1, + payers2, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + total_node_usage, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees.clone(), + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index + 1, + payees, + )); + + assert_noop!( + DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + Error::::NotExpectedState + ); + }) +} + +#[test] +fn end_billing_report_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 2u64; + let user1 = 3u64; + let node1 = 33u64; + let cluster_id = ClusterId::from([12; 20]); + let era = 100; + let max_batch_index = 0; + let batch_index = 0; + let total_node_usage = NodeUsage::default(); + let payers = vec![(user1, CustomerUsage::default())]; + let payees = vec![(node1, NodeUsage::default())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report.state, State::Initialized); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + total_node_usage, + )); + + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payees, + )); + + assert_ok!(DdcPayouts::end_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + System::assert_last_event(Event::BillingReportFinalized { cluster_id, era }.into()); + + let report_end = DdcPayouts::active_billing_reports(cluster_id, era); + assert_eq!(report_end, None); + }) +} diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index a047f30c1..eaee9f844 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -3,7 +3,7 @@ #![allow(dead_code)] use crate::{self as pallet_ddc_staking, *}; -use ddc_primitives::{CDNNodePubKey, ClusterPricingParams, StorageNodePubKey}; +use ddc_primitives::{CDNNodePubKey, ClusterFeesParams, ClusterPricingParams, StorageNodePubKey}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, node::{NodeVisitor, NodeVisitorError}, @@ -20,6 +20,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, + Perbill, }; use sp_std::collections::btree_map::BTreeMap; @@ -142,6 +143,20 @@ impl ClusterVisitor for TestClusterVisitor { unit_per_get_request: 5, }) } + + fn get_fees_params(_cluster_id: &ClusterId) -> Result { + Ok(ClusterFeesParams { + treasury_share: Perbill::from_percent(1), + validators_share: Perbill::from_percent(10), + cluster_reserve_share: Perbill::from_percent(2), + }) + } + + fn get_reserve_account_id( + _cluster_id: &ClusterId, + ) -> Result { + Err(ClusterVisitorError::ClusterDoesNotExist) + } } pub struct TestNodeVisitor; diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 7ac05a660..78c25e2f7 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -5,7 +5,7 @@ use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_core::hash::H160; -use sp_runtime::{AccountId32, RuntimeDebug}; +use sp_runtime::{AccountId32, Perbill, RuntimeDebug}; pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; @@ -18,6 +18,14 @@ pub struct ClusterPricingParams { pub unit_per_put_request: u128, pub unit_per_get_request: u128, } + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterFeesParams { + pub treasury_share: Perbill, + pub validators_share: Perbill, + pub cluster_reserve_share: Perbill, +} + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 5b1d42076..e0e425c13 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -39,6 +39,7 @@ sp-version = { default-features = false, git = "https://github.com/paritytech/su # frame dependencies cere-dev-runtime-constants = { path = "./constants", default-features = false } cere-runtime-common = { path = "../common", default-features = false } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 2aeb530df..5aa907989 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -23,6 +23,7 @@ #![recursion_limit = "256"] use codec::{Decode, Encode, MaxEncodedLen}; +use ddc_traits::pallet::PalletVisitor; use frame_election_provider_support::{onchain, BalancingConfig, SequentialPhragmen, VoteWeight}; use frame_support::{ construct_runtime, @@ -72,8 +73,8 @@ use sp_runtime::{ curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, BlakeTwo256, Block as BlockT, ConvertInto, NumberFor, OpaqueKeys, - SaturatedConversion, StaticLookup, + self, AccountIdConversion, BlakeTwo256, Block as BlockT, ConvertInto, NumberFor, + OpaqueKeys, SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, @@ -1352,12 +1353,21 @@ parameter_types! { pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); } +pub struct TreasureWrapper; +impl PalletVisitor for TreasureWrapper { + fn get_account_id() -> T::AccountId { + TreasuryPalletId::get().into_account_truncating() + } +} + impl pallet_ddc_payouts::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletId = PayoutsPalletId; type Currency = Balances; type CustomerCharger = DdcCustomers; type ClusterVisitor = DdcClusters; + type TreasuryVisitor = TreasureWrapper; + type ValidatorList = pallet_staking::UseValidatorsMap; } construct_runtime!( diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index cdb3a5e21..e8cec5e50 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,4 +1,4 @@ -use ddc_primitives::{ClusterId, ClusterPricingParams, NodePubKey, NodeType}; +use ddc_primitives::{ClusterFeesParams, ClusterId, ClusterPricingParams, NodePubKey, NodeType}; use frame_system::Config; pub trait ClusterVisitor { @@ -15,6 +15,10 @@ pub trait ClusterVisitor { cluster_id: &ClusterId, ) -> Result; + fn get_fees_params(cluster_id: &ClusterId) -> Result; + + fn get_reserve_account_id(cluster_id: &ClusterId) -> Result; + fn get_chill_delay( cluster_id: &ClusterId, node_type: NodeType, diff --git a/traits/src/customer.rs b/traits/src/customer.rs index 73bbf784a..06cac510c 100644 --- a/traits/src/customer.rs +++ b/traits/src/customer.rs @@ -1,8 +1,14 @@ pub trait CustomerCharger { - // todo: WIP for decoupling payout and customers fn charge_content_owner( content_owner: T::AccountId, billing_vault: T::AccountId, amount: u128, - ) -> sp_runtime::DispatchResult; + ) -> Result; +} + +pub enum CustomerChargerError { + NotOwner, + ArithmeticUnderflow, + TransferFailed, + UnlockFailed, } diff --git a/traits/src/lib.rs b/traits/src/lib.rs index dc252fc3b..b82b351c0 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -2,4 +2,5 @@ pub mod cluster; pub mod customer; pub mod node; +pub mod pallet; pub mod staking; diff --git a/traits/src/pallet.rs b/traits/src/pallet.rs new file mode 100644 index 000000000..dec6f71b1 --- /dev/null +++ b/traits/src/pallet.rs @@ -0,0 +1,5 @@ +use frame_system::Config; + +pub trait PalletVisitor { + fn get_account_id() -> T::AccountId; +} From ad390bdc0303815837b724c43fe08542c0aa68e2 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:54:14 +0200 Subject: [PATCH 524/544] Payout type fix 0.9.30 (#166) enum coordination with DAC --- pallets/ddc-payouts/src/lib.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 2786dc21b..f5c2a1192 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -60,10 +60,10 @@ pub struct NodeUsage { /// Stores reward in tokens(units) of node provider as per NodeUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct NodeReward { - pub transfer: u128, // tokens for transferred_bytes - pub storage: u128, // tokens for stored_bytes - pub puts: u128, // tokens for number_of_puts - pub gets: u128, // tokens for number_of_gets + pub transfer: u128, // reward in tokens for NodeUsage::transferred_bytes + pub storage: u128, // reward in tokens for NodeUsage::stored_bytes + pub puts: u128, // reward in tokens for NodeUsage::number_of_puts + pub gets: u128, // reward in tokens for NodeUsage::number_of_gets } #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] @@ -77,10 +77,10 @@ pub struct BillingReportDebt { /// Stores charge in tokens(units) of customer as per CustomerUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] pub struct CustomerCharge { - pub transfer: u128, // tokens for transferred_bytes - pub storage: u128, // tokens for stored_bytes - pub puts: u128, // tokens for number_of_puts - pub gets: u128, // tokens for number_of_gets + pub transfer: u128, // charge in tokens for CustomerUsage::transferred_bytes + pub storage: u128, // charge in tokens for CustomerUsage::stored_bytes + pub puts: u128, // charge in tokens for CustomerUsage::number_of_puts + pub gets: u128, // charge in tokens for CustomerUsage::number_of_gets } /// The balance type of this pallet. @@ -249,17 +249,17 @@ pub mod pallet { } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Default)] + // don't remove or change numbers, if needed add a new state to the end with new number + // DAC uses the state value for integration! pub enum State { #[default] - NotInitialized, - Initialized, - ChargingCustomers, - CustomersChargedWithFees, - CustomersCharged, - FeesDeducted, - RewardingProviders, - ProvidersRewarded, - Finalized, + NotInitialized = 1, + Initialized = 2, + ChargingCustomers = 3, + CustomersChargedWithFees = 4, + RewardingProviders = 5, + ProvidersRewarded = 6, + Finalized = 7, } #[pallet::call] From 0b6b7453247fcabdac4271b9726d81c83554e7a9 Mon Sep 17 00:00:00 2001 From: rakanalh Date: Mon, 27 Nov 2023 19:37:22 +0300 Subject: [PATCH 525/544] Add deployment workflow to build docker image --- .github/workflows/dev.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index e83f7209f..a3c15fb0a 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -3,6 +3,7 @@ on: push: branches: - 'dev' + - 'deployment-0.9.30' workflow_dispatch: env: From 4c272c8b71abf75db8fa49d142db3d8f9a3396d3 Mon Sep 17 00:00:00 2001 From: rakanalh Date: Mon, 27 Nov 2023 19:41:36 +0300 Subject: [PATCH 526/544] Change the tag of the image --- .github/workflows/dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index a3c15fb0a..3c43d54af 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -69,7 +69,7 @@ jobs: tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ env.GITHUB_SHA }} - ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest + ${{ steps.login-ecr.outputs.registry }}/pos-network-node:deployment-0.9.30-latest - name: Copy wasm artifacts from the image run: | From eef0c94363a26fee1d63cfc0ca6f45f387ee1b52 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:19:02 +0200 Subject: [PATCH 527/544] Payout end state tests (#168) --- Cargo.lock | 2 + pallets/ddc-payouts/src/lib.rs | 164 ++++++++++++++------------ pallets/ddc-payouts/src/mock.rs | 27 ++++- pallets/ddc-payouts/src/tests.rs | 194 ++++++++++++++++++++++++++++--- traits/Cargo.toml | 2 + traits/src/cluster.rs | 4 + traits/src/customer.rs | 5 + 7 files changed, 306 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52d3cfc98..66d8d13da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1666,6 +1666,8 @@ version = "0.1.0" dependencies = [ "ddc-primitives", "frame-system", + "parity-scale-codec", + "scale-info", "sp-runtime", ] diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index f5c2a1192..ac1516e93 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -358,7 +358,7 @@ pub mod pallet { let mut updated_billing_report = billing_report; for payer in payers { - let customer_charge = get_customer_charge::(cluster_id, &payer.1)?; + let mut customer_charge = get_customer_charge::(cluster_id, &payer.1)?; let total_customer_charge = (|| -> Option { customer_charge .transfer @@ -368,30 +368,6 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - let temp_total_customer_storage_charge = updated_billing_report - .total_customer_charge - .storage - .checked_add(customer_charge.storage) - .ok_or(Error::::ArithmeticOverflow)?; - - let temp_total_customer_transfer_charge = updated_billing_report - .total_customer_charge - .transfer - .checked_add(customer_charge.transfer) - .ok_or(Error::::ArithmeticOverflow)?; - - let temp_total_customer_puts_charge = updated_billing_report - .total_customer_charge - .puts - .checked_add(customer_charge.puts) - .ok_or(Error::::ArithmeticOverflow)?; - - let temp_total_customer_gets_charge = updated_billing_report - .total_customer_charge - .gets - .checked_add(customer_charge.gets) - .ok_or(Error::::ArithmeticOverflow)?; - let customer_id = payer.0.clone(); let amount_actually_charged = match T::CustomerCharger::charge_content_owner( customer_id.clone(), @@ -423,16 +399,19 @@ pub mod pallet { customer_id, amount: total_customer_charge, }); - } else { - updated_billing_report.total_customer_charge.storage = - temp_total_customer_storage_charge; - updated_billing_report.total_customer_charge.transfer = - temp_total_customer_transfer_charge; - updated_billing_report.total_customer_charge.puts = - temp_total_customer_puts_charge; - updated_billing_report.total_customer_charge.gets = - temp_total_customer_gets_charge; + if amount_actually_charged > 0 { + // something was charged and should be added + // calculate ratio + let ratio = + Perbill::from_rational(amount_actually_charged, total_customer_charge); + + customer_charge.storage = ratio * customer_charge.storage; + customer_charge.transfer = ratio * customer_charge.transfer; + customer_charge.gets = ratio * customer_charge.gets; + customer_charge.puts = ratio * customer_charge.puts; + } + } else { Self::deposit_event(Event::::Charged { cluster_id, era, @@ -440,6 +419,30 @@ pub mod pallet { amount: total_customer_charge, }); } + + updated_billing_report.total_customer_charge.storage = updated_billing_report + .total_customer_charge + .storage + .checked_add(customer_charge.storage) + .ok_or(Error::::ArithmeticOverflow)?; + + updated_billing_report.total_customer_charge.transfer = updated_billing_report + .total_customer_charge + .transfer + .checked_add(customer_charge.transfer) + .ok_or(Error::::ArithmeticOverflow)?; + + updated_billing_report.total_customer_charge.puts = updated_billing_report + .total_customer_charge + .puts + .checked_add(customer_charge.puts) + .ok_or(Error::::ArithmeticOverflow)?; + + updated_billing_report.total_customer_charge.gets = updated_billing_report + .total_customer_charge + .gets + .checked_add(customer_charge.gets) + .ok_or(Error::::ArithmeticOverflow)?; } updated_billing_report @@ -490,50 +493,59 @@ pub mod pallet { let validators_fee = fees.validators_share * total_customer_charge; let cluster_reserve_fee = fees.cluster_reserve_share * total_customer_charge; - charge_treasury_fees::( - treasury_fee, - &billing_report.vault, - &T::TreasuryVisitor::get_account_id(), - )?; - Self::deposit_event(Event::::TreasuryFeesCollected { - cluster_id, - era, - amount: treasury_fee, - }); - - charge_cluster_reserve_fees::( - cluster_reserve_fee, - &billing_report.vault, - &T::ClusterVisitor::get_reserve_account_id(&cluster_id) - .map_err(|_| Error::::NotExpectedClusterState)?, - )?; - Self::deposit_event(Event::::ClusterReserveFeesCollected { - cluster_id, - era, - amount: cluster_reserve_fee, - }); - - charge_validator_fees::(validators_fee, &billing_report.vault)?; - Self::deposit_event(Event::::ValidatorFeesCollected { - cluster_id, - era, - amount: validators_fee, - }); + if treasury_fee > 0 { + charge_treasury_fees::( + treasury_fee, + &billing_report.vault, + &T::TreasuryVisitor::get_account_id(), + )?; + + Self::deposit_event(Event::::TreasuryFeesCollected { + cluster_id, + era, + amount: treasury_fee, + }); + } + + if cluster_reserve_fee > 0 { + charge_cluster_reserve_fees::( + cluster_reserve_fee, + &billing_report.vault, + &T::ClusterVisitor::get_reserve_account_id(&cluster_id) + .map_err(|_| Error::::NotExpectedClusterState)?, + )?; + Self::deposit_event(Event::::ClusterReserveFeesCollected { + cluster_id, + era, + amount: cluster_reserve_fee, + }); + } + + if validators_fee > 0 { + charge_validator_fees::(validators_fee, &billing_report.vault)?; + Self::deposit_event(Event::::ValidatorFeesCollected { + cluster_id, + era, + amount: validators_fee, + }); + } // 1 - (X + Y + Z) > 0, 0 < X + Y + Z < 1 let total_left_from_one = (fees.treasury_share + fees.validators_share + fees.cluster_reserve_share) .left_from_one(); - // X * Z < X, 0 < Z < 1 - billing_report.total_customer_charge.transfer = - total_left_from_one * billing_report.total_customer_charge.transfer; - billing_report.total_customer_charge.storage = - total_left_from_one * billing_report.total_customer_charge.storage; - billing_report.total_customer_charge.puts = - total_left_from_one * billing_report.total_customer_charge.puts; - billing_report.total_customer_charge.gets = - total_left_from_one * billing_report.total_customer_charge.gets; + if !total_left_from_one.is_zero() { + // X * Z < X, 0 < Z < 1 + billing_report.total_customer_charge.transfer = + total_left_from_one * billing_report.total_customer_charge.transfer; + billing_report.total_customer_charge.storage = + total_left_from_one * billing_report.total_customer_charge.storage; + billing_report.total_customer_charge.puts = + total_left_from_one * billing_report.total_customer_charge.puts; + billing_report.total_customer_charge.gets = + total_left_from_one * billing_report.total_customer_charge.gets; + } billing_report.state = State::CustomersChargedWithFees; ActiveBillingReports::::insert(cluster_id, era, billing_report); @@ -688,7 +700,7 @@ pub mod pallet { let caller = ensure_signed(origin)?; ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); - let billing_report = ActiveBillingReports::::try_get(cluster_id, era) + let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ProvidersRewarded, Error::::NotExpectedState); @@ -707,7 +719,11 @@ pub mod pallet { Error::::NotDistributedBalance ); - ActiveBillingReports::::remove(cluster_id, era); + billing_report.charging_processed_batches.clear(); + billing_report.rewarding_processed_batches.clear(); + billing_report.state = State::Finalized; + + ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::BillingReportFinalized { cluster_id, era }); Ok(()) diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 31f3dfb11..eaee8ffc6 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -117,7 +117,7 @@ impl CustomerCharger for TestCustomerCharger { let mut amount_to_charge = amount; if amount_to_charge < 50_000_000 { - amount_to_charge = PARTIAL_CHARGE; + amount_to_charge = PARTIAL_CHARGE; // for user 3 } let charge = amount_to_charge.saturated_into::>(); @@ -139,6 +139,9 @@ pub const VALIDATOR1_ACCOUNT_ID: AccountId = 111; pub const VALIDATOR2_ACCOUNT_ID: AccountId = 222; pub const VALIDATOR3_ACCOUNT_ID: AccountId = 333; pub const PARTIAL_CHARGE: u128 = 100; +pub const USER3_BALANCE: u128 = 1000; + +pub const FREE_CLUSTER_ID: ClusterId = ClusterId::zero(); pub const PRICING_PARAMS: ClusterPricingParams = ClusterPricingParams { unit_per_mb_streamed: 2_000_000, @@ -153,6 +156,12 @@ pub const PRICING_FEES: ClusterFeesParams = ClusterFeesParams { cluster_reserve_share: Perbill::from_percent(2), }; +pub const PRICING_FEES_ZERO: ClusterFeesParams = ClusterFeesParams { + treasury_share: Perbill::from_percent(0), + validators_share: Perbill::from_percent(0), + cluster_reserve_share: Perbill::from_percent(0), +}; + pub struct TestTreasuryVisitor; impl PalletVisitor for TestTreasuryVisitor { fn get_account_id() -> T::AccountId { @@ -230,6 +239,14 @@ impl SortedListProvider for TestValidator } } +pub fn get_fees(cluster_id: &ClusterId) -> Result { + if *cluster_id == FREE_CLUSTER_ID { + Ok(PRICING_FEES_ZERO) + } else { + Ok(PRICING_FEES) + } +} + pub struct TestClusterVisitor; impl ClusterVisitor for TestClusterVisitor { fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { @@ -263,8 +280,8 @@ impl ClusterVisitor for TestClusterVisitor { Ok(PRICING_PARAMS) } - fn get_fees_params(_cluster_id: &ClusterId) -> Result { - Ok(PRICING_FEES) + fn get_fees_params(cluster_id: &ClusterId) -> Result { + get_fees(cluster_id) } fn get_reserve_account_id( @@ -287,8 +304,8 @@ impl ExtBuilder { let _ = pallet_balances::GenesisConfig:: { balances: vec![ (1, 1000000000000000000000000), - (2, 10), // < PARTIAL_CHARGE - (3, 1000), // > PARTIAL_CHARGE + (2, 10), // < PARTIAL_CHARGE + (3, USER3_BALANCE), // > PARTIAL_CHARGE (4, 1000000000000000000000000), ], } diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index d63d799e3..b4195c077 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -257,11 +257,20 @@ fn send_charging_customers_batch_fails_uninitialised() { }) } +fn calculate_charge_parts(usage: CustomerUsage) -> CustomerCharge { + CustomerCharge { + transfer: PRICING_PARAMS.unit_per_mb_streamed * (usage.transferred_bytes as u128) / + byte_unit::MEBIBYTE, + storage: (PRICING_PARAMS.unit_per_mb_stored * usage.stored_bytes as u128) / + byte_unit::MEBIBYTE, + puts: PRICING_PARAMS.unit_per_put_request * usage.number_of_puts, + gets: PRICING_PARAMS.unit_per_get_request * usage.number_of_gets, + } +} + fn calculate_charge(usage: CustomerUsage) -> u128 { - PRICING_PARAMS.unit_per_mb_streamed * (usage.transferred_bytes as u128) / byte_unit::MEBIBYTE + - (PRICING_PARAMS.unit_per_mb_stored * usage.stored_bytes as u128) / byte_unit::MEBIBYTE + - PRICING_PARAMS.unit_per_put_request * usage.number_of_puts + - PRICING_PARAMS.unit_per_get_request * usage.number_of_gets + let charge = calculate_charge_parts(usage); + charge.transfer + charge.storage + charge.puts + charge.gets } #[test] @@ -293,7 +302,7 @@ fn send_charging_customers_batch_works() { number_of_gets: 4, }; let usage3 = CustomerUsage { - // should pass but with debt + // should pass but with debt (partial charge) transferred_bytes: 1, stored_bytes: 2, number_of_puts: 3, @@ -334,14 +343,22 @@ fn send_charging_customers_batch_works() { payers1, )); - let usage4_charge = calculate_charge(usage4); + let usage4_charge = calculate_charge(usage4.clone()); let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); assert_eq!(balance, usage4_charge); let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); - let mut debt = calculate_charge(usage2); + let mut debt = calculate_charge(usage2.clone()); assert_eq!(user2_debt, debt); + let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let charge2 = calculate_charge_parts(usage2); + let charge4 = calculate_charge_parts(usage4); + assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); + assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); + assert_eq!(charge2.storage + charge4.storage, report.total_customer_charge.storage); + assert_eq!(charge2.transfer + charge4.transfer, report.total_customer_charge.transfer); + System::assert_has_event( Event::ChargeFailed { cluster_id, era, customer_id: user2_debtor, amount: debt }.into(), ); @@ -352,6 +369,7 @@ fn send_charging_customers_batch_works() { assert_eq!(System::events().len(), 5 + 3); // 3 for Currency::transfer // batch 2 + let mut before_total_customer_charge = report.total_customer_charge.clone(); assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, @@ -365,18 +383,37 @@ fn send_charging_customers_batch_works() { cluster_id, era, customer_id: user1, - amount: calculate_charge(usage1), + amount: calculate_charge(usage1.clone()), } .into(), ); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let charge1 = calculate_charge_parts(usage1); + assert_eq!( + charge1.puts + before_total_customer_charge.puts, + report.total_customer_charge.puts + ); + assert_eq!( + charge1.gets + before_total_customer_charge.gets, + report.total_customer_charge.gets + ); + assert_eq!( + charge1.storage + before_total_customer_charge.storage, + report.total_customer_charge.storage + ); + assert_eq!( + charge1.transfer + before_total_customer_charge.transfer, + report.total_customer_charge.transfer + ); + assert_eq!(report.state, State::ChargingCustomers); let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); // batch 3 + before_total_customer_charge = report.total_customer_charge.clone(); assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, @@ -385,12 +422,31 @@ fn send_charging_customers_batch_works() { payers3, )); - let user3_charge = calculate_charge(usage3); + let user3_charge = calculate_charge(usage3.clone()); + let charge3 = calculate_charge_parts(usage3); + let ratio = Perbill::from_rational(PARTIAL_CHARGE, user3_charge); + report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!( + ratio * charge3.puts + before_total_customer_charge.puts, + report.total_customer_charge.puts + ); + assert_eq!( + ratio * charge3.gets + before_total_customer_charge.gets, + report.total_customer_charge.gets + ); + assert_eq!( + ratio * charge3.storage + before_total_customer_charge.storage, + report.total_customer_charge.storage + ); + assert_eq!( + ratio * charge3.transfer + before_total_customer_charge.transfer, + report.total_customer_charge.transfer + ); + balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); assert_eq!(balance, balance_before + PARTIAL_CHARGE); let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); - debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -598,6 +654,116 @@ fn end_charging_customers_works() { }) } +#[test] +fn end_charging_customers_works_zero_fees() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 123u64; + let user1 = 1u64; + let cluster_id = ClusterId::zero(); + let era = 100; + let max_batch_index = 0; + let batch_index = 0; + let usage1 = CustomerUsage { + transferred_bytes: 23452345, + stored_bytes: 3345234523, + number_of_puts: 4456456345234523, + number_of_gets: 523423, + }; + let payers = vec![(user1, usage1.clone())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers, + )); + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let charge = calculate_charge(usage1); + System::assert_last_event( + Event::Charged { cluster_id, era, customer_id: user1, amount: charge }.into(), + ); + + let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + assert_eq!(balance, charge); + assert_eq!(System::events().len(), 4 + 3); // 3 for Currency::transfer + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); + assert_eq!(System::events().len(), 7 + 1); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(report_after.state, State::CustomersChargedWithFees); + + let fees = get_fees(&cluster_id).unwrap(); + + let total_left_from_one = + (fees.treasury_share + fees.validators_share + fees.cluster_reserve_share) + .left_from_one(); + + assert_eq!(total_left_from_one, Perbill::one()); + + assert_eq!(fees.treasury_share, Perbill::zero()); + assert_eq!(fees.validators_share, Perbill::zero()); + assert_eq!(fees.cluster_reserve_share, Perbill::zero()); + + balance = Balances::free_balance(TREASURY_ACCOUNT_ID); + assert_eq!(balance, 0); + + balance = Balances::free_balance(RESERVE_ACCOUNT_ID); + assert_eq!(balance, 0); + + balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); + assert_eq!(balance, 0); + + balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); + assert_eq!(balance, 0); + + balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); + assert_eq!(balance, 0); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + }) +} + #[test] fn begin_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { @@ -1584,7 +1750,9 @@ fn end_billing_report_works() { System::assert_last_event(Event::BillingReportFinalized { cluster_id, era }.into()); - let report_end = DdcPayouts::active_billing_reports(cluster_id, era); - assert_eq!(report_end, None); + let report_end = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert!(report_end.rewarding_processed_batches.is_empty()); + assert!(report_end.charging_processed_batches.is_empty()); + assert_eq!(report_end.state, State::Finalized); }) } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 9b7fa403f..79d2bcad3 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] +codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { path = "../primitives", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index e8cec5e50..dcd1f259d 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,5 +1,8 @@ +use codec::{Decode, Encode}; use ddc_primitives::{ClusterFeesParams, ClusterId, ClusterPricingParams, NodePubKey, NodeType}; use frame_system::Config; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; pub trait ClusterVisitor { fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; @@ -30,6 +33,7 @@ pub trait ClusterVisitor { ) -> Result; } +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum ClusterVisitorError { ClusterDoesNotExist, ClusterGovParamsNotSet, diff --git a/traits/src/customer.rs b/traits/src/customer.rs index 06cac510c..2441fd46b 100644 --- a/traits/src/customer.rs +++ b/traits/src/customer.rs @@ -1,3 +1,7 @@ +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; + pub trait CustomerCharger { fn charge_content_owner( content_owner: T::AccountId, @@ -6,6 +10,7 @@ pub trait CustomerCharger { ) -> Result; } +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum CustomerChargerError { NotOwner, ArithmeticUnderflow, From 523a9d4317b81b4e50707edf52fa78278c8dba98 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:02:13 +0200 Subject: [PATCH 528/544] batch index events (#174) --- pallets/ddc-payouts/src/lib.rs | 4 ++++ pallets/ddc-payouts/src/tests.rs | 34 +++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index ac1516e93..cb4c0b841 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -129,12 +129,14 @@ pub mod pallet { Charged { cluster_id: ClusterId, era: DdcEra, + batch_index: BatchIndex, customer_id: T::AccountId, amount: u128, }, ChargeFailed { cluster_id: ClusterId, era: DdcEra, + batch_index: BatchIndex, customer_id: T::AccountId, amount: u128, }, @@ -396,6 +398,7 @@ pub mod pallet { Self::deposit_event(Event::::ChargeFailed { cluster_id, era, + batch_index, customer_id, amount: total_customer_charge, }); @@ -415,6 +418,7 @@ pub mod pallet { Self::deposit_event(Event::::Charged { cluster_id, era, + batch_index, customer_id, amount: total_customer_charge, }); diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index b4195c077..b4df284ae 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -286,7 +286,7 @@ fn send_charging_customers_batch_works() { let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 3; - let batch_index = 0; + let mut batch_index = 0; let usage1 = CustomerUsage { // should pass without debt transferred_bytes: 23452345, @@ -360,21 +360,36 @@ fn send_charging_customers_batch_works() { assert_eq!(charge2.transfer + charge4.transfer, report.total_customer_charge.transfer); System::assert_has_event( - Event::ChargeFailed { cluster_id, era, customer_id: user2_debtor, amount: debt }.into(), + Event::ChargeFailed { + cluster_id, + era, + customer_id: user2_debtor, + batch_index, + amount: debt, + } + .into(), ); System::assert_last_event( - Event::Charged { cluster_id, era, customer_id: user4, amount: usage4_charge }.into(), + Event::Charged { + cluster_id, + era, + customer_id: user4, + batch_index, + amount: usage4_charge, + } + .into(), ); assert_eq!(System::events().len(), 5 + 3); // 3 for Currency::transfer // batch 2 let mut before_total_customer_charge = report.total_customer_charge.clone(); + batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, era, - batch_index + 1, + batch_index, payers2, )); @@ -382,6 +397,7 @@ fn send_charging_customers_batch_works() { Event::Charged { cluster_id, era, + batch_index, customer_id: user1, amount: calculate_charge(usage1.clone()), } @@ -413,12 +429,13 @@ fn send_charging_customers_batch_works() { let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); // batch 3 + batch_index += 2; before_total_customer_charge = report.total_customer_charge.clone(); assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, era, - batch_index + 2, + batch_index, payers3, )); @@ -454,6 +471,7 @@ fn send_charging_customers_batch_works() { Event::ChargeFailed { cluster_id, era, + batch_index, customer_id: user3_debtor, amount: user3_charge, } @@ -578,7 +596,8 @@ fn end_charging_customers_works() { let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); let charge = calculate_charge(usage1); System::assert_last_event( - Event::Charged { cluster_id, era, customer_id: user1, amount: charge }.into(), + Event::Charged { cluster_id, era, batch_index, customer_id: user1, amount: charge } + .into(), ); let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); @@ -699,7 +718,8 @@ fn end_charging_customers_works_zero_fees() { let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); let charge = calculate_charge(usage1); System::assert_last_event( - Event::Charged { cluster_id, era, customer_id: user1, amount: charge }.into(), + Event::Charged { cluster_id, era, customer_id: user1, batch_index, amount: charge } + .into(), ); let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); From c20bff2543c68402bc2bd75a069c73ba7a66a164 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:08:59 +0200 Subject: [PATCH 529/544] payout and customers fixes (#178) --- pallets/ddc-customers/src/lib.rs | 68 +++++++---------- pallets/ddc-customers/src/mock.rs | 6 +- pallets/ddc-customers/src/tests.rs | 114 ++++++++++++++++++++++++++--- pallets/ddc-payouts/src/lib.rs | 35 ++++++--- pallets/ddc-payouts/src/mock.rs | 10 +-- pallets/ddc-payouts/src/tests.rs | 25 ++++++- traits/src/customer.rs | 4 +- 7 files changed, 188 insertions(+), 74 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 98849d807..cdd8decb0 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -9,10 +9,7 @@ mod tests; use codec::{Decode, Encode, HasCompact}; use ddc_primitives::{BucketId, ClusterId}; -use ddc_traits::{ - cluster::ClusterVisitor, - customer::{CustomerCharger, CustomerChargerError}, -}; +use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger}; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, @@ -21,7 +18,7 @@ use frame_support::{ use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, Zero}, - RuntimeDebug, SaturatedConversion, + DispatchError, RuntimeDebug, SaturatedConversion, }; use sp_std::prelude::*; @@ -129,8 +126,6 @@ impl< .ok_or(Error::::ArithmeticOverflow)?; if temp <= value { unlocking_balance = temp; - self.active = - self.active.checked_sub(&last.value).ok_or(Error::::ArithmeticUnderflow)?; self.unlocking.pop(); } else { let diff = @@ -138,8 +133,6 @@ impl< unlocking_balance = unlocking_balance.checked_add(&diff).ok_or(Error::::ArithmeticOverflow)?; - self.active = - self.active.checked_sub(&diff).ok_or(Error::::ArithmeticUnderflow)?; last.value = last.value.checked_sub(&diff).ok_or(Error::::ArithmeticUnderflow)?; } @@ -429,7 +422,7 @@ pub mod pallet { .map_err(|_| Error::::NoMoreChunks)?; }; - Self::update_ledger(&owner, &ledger); + >::insert(&owner, &ledger); Self::deposit_event(Event::::InitialDepositUnlock(ledger.owner, value)); } @@ -466,7 +459,7 @@ pub mod pallet { log::debug!("Updating ledger"); // This was the consequence of a partial deposit unlock. just update the ledger and // move on. - Self::update_ledger(&owner, &ledger); + >::insert(&owner, &ledger); }; log::debug!("Current total: {:?}", ledger.total); @@ -506,11 +499,9 @@ pub mod pallet { owner: &T::AccountId, ledger: &AccountsLedger, T>, ) -> DispatchResult { - let account_id = Self::account_id(); - ::Currency::transfer( owner, - &account_id, + &Self::account_id(), ledger.total, ExistenceRequirement::KeepAlive, )?; @@ -519,14 +510,6 @@ pub mod pallet { Ok(()) } - /// Update the ledger for a owner. - fn update_ledger( - owner: &T::AccountId, - ledger: &AccountsLedger, T>, - ) { - >::insert(owner, ledger); - } - /// Remove all associated data of a owner account from the accounts system. /// /// Assumes storage is upgraded before calling. @@ -547,47 +530,48 @@ pub mod pallet { content_owner: T::AccountId, billing_vault: T::AccountId, amount: u128, - ) -> Result { + ) -> Result { let actually_charged: BalanceOf; - let mut ledger = Self::ledger(&content_owner).ok_or(CustomerChargerError::NotOwner)?; - let mut amount_to_deduct = amount.saturated_into::>(); + let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; + let amount_to_deduct = amount.saturated_into::>(); - ensure!(ledger.total >= ledger.active, CustomerChargerError::ArithmeticUnderflow); if ledger.active >= amount_to_deduct { actually_charged = amount_to_deduct; ledger.active = ledger .active .checked_sub(&amount_to_deduct) - .ok_or(CustomerChargerError::ArithmeticUnderflow)?; + .ok_or(Error::::ArithmeticUnderflow)?; ledger.total = ledger .total .checked_sub(&amount_to_deduct) - .ok_or(CustomerChargerError::ArithmeticUnderflow)?; - Self::update_ledger(&content_owner, &ledger); + .ok_or(Error::::ArithmeticUnderflow)?; + + >::insert(&content_owner, &ledger); } else { let diff = amount_to_deduct .checked_sub(&ledger.active) - .ok_or(CustomerChargerError::ArithmeticUnderflow)?; - actually_charged = diff; + .ok_or(Error::::ArithmeticUnderflow)?; + + actually_charged = ledger.active; ledger.total = ledger .total .checked_sub(&ledger.active) - .ok_or(CustomerChargerError::ArithmeticUnderflow)?; - amount_to_deduct = ledger.active; + .ok_or(Error::::ArithmeticUnderflow)?; ledger.active = BalanceOf::::zero(); - let (ledger, _charged) = ledger - .charge_unlocking(diff) - .map_err(|_| CustomerChargerError::UnlockFailed)?; - Self::update_ledger(&content_owner, &ledger); - }; + + let (ledger, charged) = ledger.charge_unlocking(diff)?; + + actually_charged.checked_add(&charged).ok_or(Error::::ArithmeticUnderflow)?; + + >::insert(&content_owner, &ledger); + } ::Currency::transfer( &Self::account_id(), &billing_vault, - amount_to_deduct, - ExistenceRequirement::KeepAlive, - ) - .map_err(|_| CustomerChargerError::TransferFailed)?; + actually_charged, + ExistenceRequirement::AllowDeath, + )?; Self::deposit_event(Event::::Charged(content_owner, amount_to_deduct)); Ok(actually_charged.saturated_into::()) diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 0004eb3a5..ae482c7ee 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -163,8 +163,10 @@ impl ExtBuilder { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); - let _ = pallet_balances::GenesisConfig:: { balances: vec![(1, 100), (2, 100)] } - .assimilate_storage(&mut storage); + let _ = pallet_balances::GenesisConfig:: { + balances: vec![(1, 100), (2, 100), (3, 1000)], + } + .assimilate_storage(&mut storage); TestExternalities::new(storage) } diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 869115e3b..8e2ebd945 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -79,26 +79,27 @@ fn deposit_and_deposit_extra_works() { BalancesError::::KeepAlive ); + let amount1 = 10_u128; // Deposited - assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 10_u128)); + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_1), amount1)); // Check storage assert_eq!( DdcCustomers::ledger(&account_1), Some(AccountsLedger { - owner: 1, - total: 10_u128, - active: 10_u128, + owner: account_1, + total: amount1, + active: amount1, unlocking: Default::default(), }) ); // Checking that event was emitted - System::assert_last_event(Event::Deposited(account_1, 10).into()); + System::assert_last_event(Event::Deposited(account_1, amount1).into()); // Deposit should fail when called the second time assert_noop!( - DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 10_u128), + DdcCustomers::deposit(RuntimeOrigin::signed(account_1), amount1), Error::::AlreadyPaired ); @@ -109,21 +110,110 @@ fn deposit_and_deposit_extra_works() { ); // Deposited extra - assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_1), 20_u128)); + let amount2 = 20_u128; + assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_1), amount2)); // Check storage assert_eq!( DdcCustomers::ledger(&account_1), Some(AccountsLedger { - owner: 1, - total: 30_u128, - active: 30_u128, + owner: account_1, + total: amount1 + amount2, + active: amount1 + amount2, unlocking: Default::default(), }) ); // Checking that event was emitted - System::assert_last_event(Event::Deposited(account_1, 20).into()); + System::assert_last_event(Event::Deposited(account_1, amount2).into()); + }) +} + +#[test] +fn charge_content_owner_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let account_3 = 3; + let vault = 4; + let deposit = 100_u128; + + let balance_before_deposit = Balances::free_balance(account_3); + // Deposited + assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_3), deposit)); + let balance_after_deposit = Balances::free_balance(account_3); + assert_eq!(balance_before_deposit - deposit, balance_after_deposit); + + let pallet_balance = Balances::free_balance(DdcCustomers::account_id()); + assert_eq!(deposit, pallet_balance); + + // Check storage + assert_eq!( + DdcCustomers::ledger(&account_3), + Some(AccountsLedger { + owner: account_3, + total: deposit, + active: deposit, + unlocking: Default::default(), + }) + ); + + // Checking that event was emitted + System::assert_last_event(Event::Deposited(account_3, deposit).into()); + + // successful transfer + let charge1 = 10; + let charged = DdcCustomers::charge_content_owner(account_3, vault, charge1).unwrap(); + assert_eq!(charge1, charged); + + let vault_balance = Balances::free_balance(vault); + assert_eq!(charged, vault_balance); + + let account_balance = Balances::free_balance(account_3); + assert_eq!(balance_after_deposit, account_balance); + + let pallet_balance_after_charge = Balances::free_balance(DdcCustomers::account_id()); + assert_eq!(pallet_balance - charged, pallet_balance_after_charge); + + // Check storage + assert_eq!( + DdcCustomers::ledger(&account_3), + Some(AccountsLedger { + owner: account_3, + total: deposit - charge1, + active: deposit - charge1, + unlocking: Default::default(), + }) + ); + + // failed transfer + let charge2 = 100u128; + let charge_result = DdcCustomers::charge_content_owner(account_3, vault, charge2).unwrap(); + assert_eq!( + DdcCustomers::ledger(&account_3), + Some(AccountsLedger { + owner: account_3, + total: 0, + active: 0, + unlocking: Default::default(), + }) + ); + + assert_eq!(0, Balances::free_balance(DdcCustomers::account_id())); + assert_eq!(charge_result, deposit - charge1); + + assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_3), deposit)); + assert_eq!( + DdcCustomers::ledger(&account_3), + Some(AccountsLedger { + owner: account_3, + total: deposit, + active: deposit, + unlocking: Default::default(), + }) + ); + + assert_eq!(deposit, Balances::free_balance(DdcCustomers::account_id())); }) } @@ -188,7 +278,7 @@ fn unlock_and_withdraw_deposit_works() { }) ); - // Unlock remaining chuncks & withdraw + // Unlock remaining chunks & withdraw assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(account_1), 3_u128)); System::set_block_number(52); assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index cb4c0b841..036c521c8 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -140,6 +140,13 @@ pub mod pallet { customer_id: T::AccountId, amount: u128, }, + Indebted { + cluster_id: ClusterId, + era: DdcEra, + batch_index: BatchIndex, + customer_id: T::AccountId, + amount: u128, + }, ChargingFinished { cluster_id: ClusterId, era: DdcEra, @@ -386,15 +393,23 @@ pub mod pallet { DebtorCustomers::::try_get(cluster_id, customer_id.clone()) .unwrap_or_else(|_| Zero::zero()); - customer_debt = (|| -> Option { - customer_debt - .checked_add(total_customer_charge)? - .checked_sub(amount_actually_charged) - })() - .ok_or(Error::::ArithmeticOverflow)?; + let debt = total_customer_charge + .checked_sub(amount_actually_charged) + .ok_or(Error::::ArithmeticOverflow)?; + + customer_debt = + customer_debt.checked_add(debt).ok_or(Error::::ArithmeticOverflow)?; DebtorCustomers::::insert(cluster_id, customer_id.clone(), customer_debt); + Self::deposit_event(Event::::Indebted { + cluster_id, + era, + batch_index, + customer_id: customer_id.clone(), + amount: debt, + }); + Self::deposit_event(Event::::ChargeFailed { cluster_id, era, @@ -639,7 +654,7 @@ pub mod pallet { &updated_billing_report.vault, &node_provider_id, reward, - ExistenceRequirement::KeepAlive, + ExistenceRequirement::AllowDeath, )?; updated_billing_report @@ -744,7 +759,7 @@ pub mod pallet { vault, treasury_vault, amount_to_deduct, - ExistenceRequirement::KeepAlive, + ExistenceRequirement::AllowDeath, ) } @@ -758,7 +773,7 @@ pub mod pallet { vault, reserve_vault, amount_to_deduct, - ExistenceRequirement::KeepAlive, + ExistenceRequirement::AllowDeath, ) } @@ -776,7 +791,7 @@ pub mod pallet { vault, &validator_account_id, amount_to_deduct, - ExistenceRequirement::KeepAlive, + ExistenceRequirement::AllowDeath, )?; } diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index eaee8ffc6..c181e7431 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -6,7 +6,7 @@ use crate::{self as pallet_ddc_payouts, *}; use ddc_primitives::{ClusterFeesParams, ClusterPricingParams, NodePubKey, NodeType}; use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, - customer::{CustomerCharger, CustomerChargerError}, + customer::CustomerCharger, pallet::PalletVisitor, }; use frame_election_provider_support::SortedListProvider; @@ -23,6 +23,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, + DispatchError, }; use sp_std::prelude::*; @@ -112,8 +113,8 @@ impl CustomerCharger for TestCustomerCharger { content_owner: T::AccountId, billing_vault: T::AccountId, amount: u128, - ) -> Result { - ensure!(amount > 1_000_000, CustomerChargerError::TransferFailed); // any error will do + ) -> Result { + ensure!(amount > 1_000_000, DispatchError::BadOrigin); // any error will do let mut amount_to_charge = amount; if amount_to_charge < 50_000_000 { @@ -127,8 +128,7 @@ impl CustomerCharger for TestCustomerCharger { &billing_vault, charge, ExistenceRequirement::KeepAlive, - ) - .map_err(|_| CustomerChargerError::TransferFailed)?; + )?; Ok(amount_to_charge) } } diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index b4df284ae..40480bf88 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -369,6 +369,17 @@ fn send_charging_customers_batch_works() { } .into(), ); + + System::assert_has_event( + Event::Indebted { + cluster_id, + era, + customer_id: user2_debtor, + batch_index, + amount: debt, + } + .into(), + ); System::assert_last_event( Event::Charged { cluster_id, @@ -380,7 +391,7 @@ fn send_charging_customers_batch_works() { .into(), ); - assert_eq!(System::events().len(), 5 + 3); // 3 for Currency::transfer + assert_eq!(System::events().len(), 5 + 3 + 1); // 3 for Currency::transfer // batch 2 let mut before_total_customer_charge = report.total_customer_charge.clone(); @@ -428,6 +439,7 @@ fn send_charging_customers_batch_works() { assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + // batch 3 batch_index += 2; before_total_customer_charge = report.total_customer_charge.clone(); @@ -467,6 +479,17 @@ fn send_charging_customers_batch_works() { debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); + System::assert_has_event( + Event::Indebted { + cluster_id, + era, + customer_id: user3_debtor, + batch_index, + amount: user3_debt, + } + .into(), + ); + System::assert_last_event( Event::ChargeFailed { cluster_id, diff --git a/traits/src/customer.rs b/traits/src/customer.rs index 2441fd46b..2fd624af1 100644 --- a/traits/src/customer.rs +++ b/traits/src/customer.rs @@ -1,13 +1,13 @@ use codec::{Decode, Encode}; use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; +use sp_runtime::{DispatchError, RuntimeDebug}; pub trait CustomerCharger { fn charge_content_owner( content_owner: T::AccountId, billing_vault: T::AccountId, amount: u128, - ) -> Result; + ) -> Result; } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] From 09724a7721b3367868c87222ae71757b0bc66429 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:07:45 +0200 Subject: [PATCH 530/544] Dac customer trasnfer fix (#181) --- pallets/ddc-customers/Cargo.toml | 2 +- pallets/ddc-customers/src/lib.rs | 142 ++++++++++++++--------------- pallets/ddc-customers/src/mock.rs | 2 +- pallets/ddc-customers/src/tests.rs | 22 ++--- pallets/ddc-payouts/src/mock.rs | 10 +- pallets/ddc-payouts/src/tests.rs | 108 +++++++++++----------- 6 files changed, 138 insertions(+), 148 deletions(-) diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 28fc87408..b7191864e 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -11,6 +11,7 @@ frame-support = { default-features = false, git = "https://github.com/paritytech frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -18,7 +19,6 @@ sp-std = { default-features = false, git = "https://github.com/paritytech/substr pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index cdd8decb0..90e5c3939 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -15,15 +15,15 @@ use frame_support::{ traits::{Currency, DefensiveSaturating, ExistenceRequirement}, BoundedVec, PalletId, }; +pub use pallet::*; use scale_info::TypeInfo; +use sp_io::hashing::blake2_128; use sp_runtime::{ - traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, Zero}, + traits::{AccountIdConversion, CheckedAdd, CheckedSub, Saturating, Zero}, DispatchError, RuntimeDebug, SaturatedConversion, }; use sp_std::prelude::*; -pub use pallet::*; - /// The balance type of this pallet. pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -36,10 +36,10 @@ parameter_types! { /// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] -pub struct UnlockChunk { +pub struct UnlockChunk { /// Amount of funds to be unlocked. #[codec(compact)] - value: Balance, + value: BalanceOf, /// Block number at which point it'll be unlocked. #[codec(compact)] block: T::BlockNumber, @@ -60,32 +60,27 @@ pub struct BucketsDetails { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] -pub struct AccountsLedger { +pub struct AccountsLedger { /// The owner account whose balance is actually locked and can be used for CDN usage. - pub owner: AccountId, + pub owner: T::AccountId, /// The total amount of the owner's balance that we are currently accounting for. /// It's just `active` plus all the `unlocking` balances. #[codec(compact)] - pub total: Balance, + pub total: BalanceOf, /// The total amount of the owner's balance that will be accessible for CDN payments in any /// forthcoming rounds. #[codec(compact)] - pub active: Balance, + pub active: BalanceOf, /// Any balance that is becoming free, which may eventually be transferred out of the owner /// (assuming that the content owner has to pay for network usage). It is assumed that this /// will be treated as a first in, first out queue where the new (higher value) eras get pushed /// on the back. - pub unlocking: BoundedVec, MaxUnlockingChunks>, + pub unlocking: BoundedVec, MaxUnlockingChunks>, } -impl< - AccountId, - Balance: HasCompact + Copy + Saturating + AtLeast32BitUnsigned + Zero, - T: Config, - > AccountsLedger -{ +impl AccountsLedger { /// Initializes the default object using the given owner. - pub fn default_from(owner: AccountId) -> Self { + pub fn default_from(owner: T::AccountId) -> Self { Self { owner, total: Zero::zero(), active: Zero::zero(), unlocking: Default::default() } } @@ -113,37 +108,6 @@ impl< Self { owner: self.owner, total, active: self.active, unlocking } } - - /// Charge funds that were scheduled for unlocking. - /// - /// Returns the updated ledger, and the amount actually charged. - fn charge_unlocking(mut self, value: Balance) -> Result<(Self, Balance), Error> { - let mut unlocking_balance = Balance::zero(); - - while let Some(last) = self.unlocking.last_mut() { - let temp = unlocking_balance - .checked_add(&last.value) - .ok_or(Error::::ArithmeticOverflow)?; - if temp <= value { - unlocking_balance = temp; - self.unlocking.pop(); - } else { - let diff = - value.checked_sub(&unlocking_balance).ok_or(Error::::ArithmeticUnderflow)?; - - unlocking_balance = - unlocking_balance.checked_add(&diff).ok_or(Error::::ArithmeticOverflow)?; - last.value = - last.value.checked_sub(&diff).ok_or(Error::::ArithmeticUnderflow)?; - } - - if unlocking_balance >= value { - break - } - } - - Ok((self, unlocking_balance)) - } } #[frame_support::pallet] @@ -173,12 +137,7 @@ pub mod pallet { /// Map from all (unlocked) "owner" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] - pub type Ledger = StorageMap< - _, - Blake2_128Concat, - T::AccountId, - AccountsLedger, T>, - >; + pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, AccountsLedger>; #[pallet::type_value] pub fn DefaultBucketCount() -> BucketId { @@ -255,13 +214,7 @@ pub mod pallet { #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { - fn build(&self) { - let account_id = >::account_id(); - let min = ::Currency::minimum_balance(); - if ::Currency::free_balance(&account_id) < min { - let _ = ::Currency::make_free_balance_be(&account_id, min); - } - } + fn build(&self) {} } #[pallet::call] @@ -473,13 +426,11 @@ pub mod pallet { let value = old_total.checked_sub(&ledger.total).ok_or(Error::::ArithmeticUnderflow)?; - let account_id = Self::account_id(); - ::Currency::transfer( - &account_id, + &Self::sub_account_id(&owner), &owner, value, - ExistenceRequirement::KeepAlive, + ExistenceRequirement::AllowDeath, )?; Self::deposit_event(Event::::Withdrawn(owner, value)); } @@ -492,18 +443,26 @@ pub mod pallet { pub fn account_id() -> T::AccountId { T::PalletId::get().into_account_truncating() } + + pub fn sub_account_id(account_id: &T::AccountId) -> T::AccountId { + let hash = blake2_128(&account_id.encode()); + + // hash is 28 bytes + T::PalletId::get().into_sub_account_truncating(hash) + } + /// Update the ledger for a owner. /// /// This will also deposit the funds to pallet. fn update_ledger_and_deposit( owner: &T::AccountId, - ledger: &AccountsLedger, T>, + ledger: &AccountsLedger, ) -> DispatchResult { ::Currency::transfer( owner, - &Self::account_id(), + &Self::sub_account_id(owner), ledger.total, - ExistenceRequirement::KeepAlive, + ExistenceRequirement::AllowDeath, )?; >::insert(owner, ledger); @@ -523,6 +482,42 @@ pub mod pallet { Ok(()) } + + /// Charge funds that were scheduled for unlocking. + /// + /// Returns the updated ledger, and the amount actually charged. + fn charge_unlocking( + mut ledger: AccountsLedger, + value: BalanceOf, + ) -> Result<(AccountsLedger, BalanceOf), Error> { + let mut unlocking_balance = BalanceOf::::zero(); + + while let Some(last) = ledger.unlocking.last_mut() { + let temp = unlocking_balance + .checked_add(&last.value) + .ok_or(Error::::ArithmeticOverflow)?; + if temp <= value { + unlocking_balance = temp; + ledger.unlocking.pop(); + } else { + let diff = value + .checked_sub(&unlocking_balance) + .ok_or(Error::::ArithmeticUnderflow)?; + + unlocking_balance = unlocking_balance + .checked_add(&diff) + .ok_or(Error::::ArithmeticOverflow)?; + last.value = + last.value.checked_sub(&diff).ok_or(Error::::ArithmeticUnderflow)?; + } + + if unlocking_balance >= value { + break + } + } + + Ok((ledger, unlocking_balance)) + } } impl CustomerCharger for Pallet { @@ -545,8 +540,6 @@ pub mod pallet { .total .checked_sub(&amount_to_deduct) .ok_or(Error::::ArithmeticUnderflow)?; - - >::insert(&content_owner, &ledger); } else { let diff = amount_to_deduct .checked_sub(&ledger.active) @@ -559,19 +552,20 @@ pub mod pallet { .ok_or(Error::::ArithmeticUnderflow)?; ledger.active = BalanceOf::::zero(); - let (ledger, charged) = ledger.charge_unlocking(diff)?; + let (_ledger, charged) = Self::charge_unlocking(ledger, diff)?; + ledger = _ledger; actually_charged.checked_add(&charged).ok_or(Error::::ArithmeticUnderflow)?; - - >::insert(&content_owner, &ledger); } ::Currency::transfer( - &Self::account_id(), + &Self::sub_account_id(&content_owner), &billing_vault, actually_charged, ExistenceRequirement::AllowDeath, )?; + + >::insert(&content_owner, &ledger); // update state after successful transfer Self::deposit_event(Event::::Charged(content_owner, amount_to_deduct)); Ok(actually_charged.saturated_into::()) diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index ae482c7ee..5912347eb 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -19,7 +19,7 @@ use sp_runtime::{ }; /// The AccountId alias in this test module. -pub(crate) type AccountId = u64; +pub(crate) type AccountId = u128; pub(crate) type AccountIndex = u64; pub(crate) type BlockNumber = u64; pub(crate) type Balance = u128; diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 8e2ebd945..4c9f4f6db 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -134,8 +134,8 @@ fn charge_content_owner_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let account_3 = 3; - let vault = 4; + let account_3: u128 = 3; + let vault: u128 = 4; let deposit = 100_u128; let balance_before_deposit = Balances::free_balance(account_3); @@ -144,7 +144,7 @@ fn charge_content_owner_works() { let balance_after_deposit = Balances::free_balance(account_3); assert_eq!(balance_before_deposit - deposit, balance_after_deposit); - let pallet_balance = Balances::free_balance(DdcCustomers::account_id()); + let pallet_balance = Balances::free_balance(DdcCustomers::sub_account_id(&account_3)); assert_eq!(deposit, pallet_balance); // Check storage @@ -172,7 +172,8 @@ fn charge_content_owner_works() { let account_balance = Balances::free_balance(account_3); assert_eq!(balance_after_deposit, account_balance); - let pallet_balance_after_charge = Balances::free_balance(DdcCustomers::account_id()); + let pallet_balance_after_charge = + Balances::free_balance(DdcCustomers::sub_account_id(&account_3)); assert_eq!(pallet_balance - charged, pallet_balance_after_charge); // Check storage @@ -199,7 +200,7 @@ fn charge_content_owner_works() { }) ); - assert_eq!(0, Balances::free_balance(DdcCustomers::account_id())); + assert_eq!(0, Balances::free_balance(DdcCustomers::sub_account_id(&account_3))); assert_eq!(charge_result, deposit - charge1); assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_3), deposit)); @@ -213,7 +214,7 @@ fn charge_content_owner_works() { }) ); - assert_eq!(deposit, Balances::free_balance(DdcCustomers::account_id())); + assert_eq!(deposit, Balances::free_balance(DdcCustomers::sub_account_id(&account_3))); }) } @@ -234,12 +235,7 @@ fn unlock_and_withdraw_deposit_works() { assert_ok!(DdcCustomers::unlock_deposit(RuntimeOrigin::signed(account_1), 1_u128)); System::set_block_number(2); - let mut unlocking_chunks: BoundedVec, MaxUnlockingChunks> = - Default::default(); - match unlocking_chunks.try_push(UnlockChunk { value: 1, block: 11 }) { - Ok(_) => (), - Err(_) => println!("No more chunks"), - }; + let unlocking_chunks = vec![UnlockChunk { value: 1, block: 11 }]; // Check storage assert_eq!( DdcCustomers::ledger(&1), @@ -247,7 +243,7 @@ fn unlock_and_withdraw_deposit_works() { owner: account_1, total: 35_u128, active: 34_u128, - unlocking: unlocking_chunks.clone(), + unlocking: BoundedVec::try_from(unlocking_chunks).unwrap(), }) ); diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index c181e7431..25e6b443c 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -28,7 +28,7 @@ use sp_runtime::{ use sp_std::prelude::*; /// The AccountId alias in this test module. -pub type AccountId = u64; +pub type AccountId = u128; pub(crate) type AccountIndex = u64; pub(crate) type BlockNumber = u64; pub(crate) type Balance = u128; @@ -170,7 +170,7 @@ impl PalletVisitor for TestTreasuryVisitor { } } -fn create_account_id_from_u64(id: u64) -> T::AccountId { +fn create_account_id_from_u128(id: u128) -> T::AccountId { let bytes = id.to_ne_bytes(); T::AccountId::decode(&mut &bytes[..]).unwrap() } @@ -184,9 +184,9 @@ impl SortedListProvider for TestValidator fn iter() -> Box> { Box::new( vec![ - create_account_id_from_u64::(VALIDATOR1_ACCOUNT_ID), - create_account_id_from_u64::(VALIDATOR2_ACCOUNT_ID), - create_account_id_from_u64::(VALIDATOR3_ACCOUNT_ID), + create_account_id_from_u128::(VALIDATOR1_ACCOUNT_ID), + create_account_id_from_u128::(VALIDATOR2_ACCOUNT_ID), + create_account_id_from_u128::(VALIDATOR3_ACCOUNT_ID), ] .into_iter(), ) diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 40480bf88..1e2ea13f2 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -9,8 +9,8 @@ fn set_authorised_caller_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let root_account = 1u64; - let dac_account = 2u64; + let root_account = 1u128; + let dac_account = 2u128; assert_noop!( DdcPayouts::set_authorised_caller(RuntimeOrigin::signed(root_account), dac_account), @@ -30,8 +30,8 @@ fn set_authorised_caller_works() { #[test] fn begin_billing_report_fails_for_unauthorised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u64; - let dac_account = 2u64; + let root_account = 1u128; + let dac_account = 2u128; let cluster_id = ClusterId::from([1; 20]); let era = 100; @@ -58,7 +58,7 @@ fn begin_billing_report_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 2u64; + let dac_account = 2u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; @@ -80,7 +80,7 @@ fn begin_billing_report_works() { #[test] fn begin_charging_customers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let dac_account = 2u64; + let dac_account = 2u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -124,7 +124,7 @@ fn begin_charging_customers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 2u64; + let dac_account = 2u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -155,10 +155,10 @@ fn begin_charging_customers_works() { #[test] fn send_charging_customers_batch_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u64; - let dac_account = 2u64; - let user1 = 3u64; - let user2 = 4u64; + let root_account = 1u128; + let dac_account = 2u128; + let user1 = 3u128; + let user2 = 4u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -278,11 +278,11 @@ fn send_charging_customers_batch_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u64; - let user1 = 1u64; - let user2_debtor = 2u64; - let user3_debtor = 3u64; - let user4 = 4u64; + let dac_account = 123u128; + let user1 = 1u128; + let user2_debtor = 2u128; + let user3_debtor = 3u128; + let user4 = 4u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 3; @@ -506,9 +506,9 @@ fn send_charging_customers_batch_works() { #[test] fn end_charging_customers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 100u64; - let dac_account = 123u64; - let user1 = 1u64; + let root_account = 100u128; + let dac_account = 123u128; + let user1 = 1u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -579,8 +579,8 @@ fn end_charging_customers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u64; - let user1 = 1u64; + let dac_account = 123u128; + let user1 = 1u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -701,8 +701,8 @@ fn end_charging_customers_works_zero_fees() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u64; - let user1 = 1u64; + let dac_account = 123u128; + let user1 = 1u128; let cluster_id = ClusterId::zero(); let era = 100; let max_batch_index = 0; @@ -810,9 +810,9 @@ fn end_charging_customers_works_zero_fees() { #[test] fn begin_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u64; - let dac_account = 2u64; - let user1 = 3u64; + let root_account = 1u128; + let dac_account = 2u128; + let user1 = 3u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -935,8 +935,8 @@ fn begin_rewarding_providers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u64; - let user1 = 1u64; + let dac_account = 123u128; + let user1 = 1u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -994,11 +994,11 @@ fn begin_rewarding_providers_works() { #[test] fn send_rewarding_providers_batch_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u64; - let dac_account = 2u64; - let user1 = 3u64; - let user2 = 4u64; - let node1 = 33u64; + let root_account = 1u128; + let dac_account = 2u128; + let user1 = 3u128; + let user2 = 4u128; + let node1 = 33u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 1; @@ -1139,11 +1139,11 @@ fn send_rewarding_providers_batch_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u64; - let user1 = 1u64; - let node1 = 10u64; - let node2 = 11u64; - let node3 = 12u64; + let dac_account = 123u128; + let user1 = 1u128; + let node1 = 10u128; + let node2 = 11u128; + let node3 = 12u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -1348,11 +1348,11 @@ fn send_rewarding_providers_batch_works() { #[test] fn end_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u64; - let dac_account = 2u64; - let user1 = 3u64; - let user2 = 4u64; - let node1 = 33u64; + let root_account = 1u128; + let dac_account = 2u128; + let user1 = 3u128; + let user2 = 4u128; + let node1 = 33u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 1; @@ -1508,9 +1508,9 @@ fn end_rewarding_providers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 2u64; - let user1 = 3u64; - let node1 = 33u64; + let dac_account = 2u128; + let user1 = 3u128; + let node1 = 33u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -1583,11 +1583,11 @@ fn end_rewarding_providers_works() { #[test] fn end_billing_report_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u64; - let dac_account = 2u64; - let user1 = 3u64; - let user2 = 4u64; - let node1 = 33u64; + let root_account = 1u128; + let dac_account = 2u128; + let user1 = 3u128; + let user2 = 4u128; + let node1 = 33u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 1; @@ -1720,9 +1720,9 @@ fn end_billing_report_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 2u64; - let user1 = 3u64; - let node1 = 33u64; + let dac_account = 2u128; + let user1 = 3u128; + let node1 = 33u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; From 8155a21555921d85182e199ab81e40139ce3c767 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:35:01 +0200 Subject: [PATCH 531/544] charge_content_owner fail (#183) --- pallets/ddc-payouts/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 036c521c8..af50c033b 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -378,6 +378,12 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; let customer_id = payer.0.clone(); + let amount_actually_charged = T::CustomerCharger::charge_content_owner( + customer_id.clone(), + updated_billing_report.vault.clone(), + total_customer_charge, + )?; + /* let amount_actually_charged = match T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), @@ -385,7 +391,7 @@ pub mod pallet { ) { Ok(actually_charged) => actually_charged, Err(_e) => 0, - }; + }; */ if amount_actually_charged < total_customer_charge { // debt From d36ae2c19da032dcd1c96de30f4a3de73a3760c4 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Tue, 5 Dec 2023 01:32:21 +0200 Subject: [PATCH 532/544] Fees batches fixes (#186) --- pallets/ddc-clusters/src/cluster.rs | 8 +- pallets/ddc-clusters/src/tests.rs | 26 +-- pallets/ddc-customers/src/mock.rs | 8 +- pallets/ddc-payouts/src/lib.rs | 86 +++++----- pallets/ddc-payouts/src/mock.rs | 41 +++-- pallets/ddc-payouts/src/tests.rs | 255 ++++++++++++++++++++-------- pallets/ddc-staking/src/mock.rs | 8 +- primitives/src/lib.rs | 8 +- 8 files changed, 294 insertions(+), 146 deletions(-) diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 4be19d73f..ff55e49bf 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -3,7 +3,7 @@ use codec::{Decode, Encode}; use ddc_primitives::ClusterId; use frame_support::{pallet_prelude::*, parameter_types}; use scale_info::TypeInfo; -use sp_runtime::Perbill; +use sp_runtime::Perquintill; parameter_types! { pub MaxClusterParamsLen: u16 = 2048; @@ -32,9 +32,9 @@ pub struct ClusterParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(Balance, BlockNumber, T))] pub struct ClusterGovParams { - pub treasury_share: Perbill, - pub validators_share: Perbill, - pub cluster_reserve_share: Perbill, + pub treasury_share: Perquintill, + pub validators_share: Perquintill, + pub cluster_reserve_share: Perquintill, pub cdn_bond_size: Balance, pub cdn_chill_delay: BlockNumber, pub cdn_unbonding_delay: BlockNumber, diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index 922ad7a7a..9e87b2e49 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -6,7 +6,7 @@ use frame_support::{assert_noop, assert_ok, error::BadOrigin}; use frame_system::Config; use hex_literal::hex; use pallet_ddc_nodes::{CDNNodeParams, NodeParams}; -use sp_runtime::{traits::Hash, AccountId32, Perbill}; +use sp_runtime::{traits::Hash, AccountId32, Perquintill}; #[test] fn create_cluster_works() { @@ -14,9 +14,9 @@ fn create_cluster_works() { System::set_block_number(1); let cluster_gov_params = ClusterGovParams { - treasury_share: Perbill::from_float(0.05), - validators_share: Perbill::from_float(0.01), - cluster_reserve_share: Perbill::from_float(0.02), + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), cdn_bond_size: 100, cdn_chill_delay: 50, cdn_unbonding_delay: 50, @@ -98,9 +98,9 @@ fn add_and_delete_node_works() { AccountId::from([2; 32]), ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, ClusterGovParams { - treasury_share: Perbill::from_float(0.05), - validators_share: Perbill::from_float(0.01), - cluster_reserve_share: Perbill::from_float(0.02), + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), cdn_bond_size: 100, cdn_chill_delay: 50, cdn_unbonding_delay: 50, @@ -309,9 +309,9 @@ fn set_cluster_params_works() { AccountId::from([2; 32]), ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, ClusterGovParams { - treasury_share: Perbill::from_float(0.05), - validators_share: Perbill::from_float(0.01), - cluster_reserve_share: Perbill::from_float(0.02), + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), cdn_bond_size: 100, cdn_chill_delay: 50, cdn_unbonding_delay: 50, @@ -354,9 +354,9 @@ fn set_cluster_gov_params_works() { System::set_block_number(1); let cluster_gov_params = ClusterGovParams { - treasury_share: Perbill::from_float(0.05), - validators_share: Perbill::from_float(0.01), - cluster_reserve_share: Perbill::from_float(0.02), + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), cdn_bond_size: 100, cdn_chill_delay: 50, cdn_unbonding_delay: 50, diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 5912347eb..43db67e76 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -15,7 +15,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, - Perbill, + Perquintill, }; /// The AccountId alias in this test module. @@ -143,9 +143,9 @@ impl ClusterVisitor for TestClusterVisitor { fn get_fees_params(_cluster_id: &ClusterId) -> Result { Ok(ClusterFeesParams { - treasury_share: Perbill::from_percent(1), - validators_share: Perbill::from_percent(10), - cluster_reserve_share: Perbill::from_percent(2), + treasury_share: Perquintill::from_percent(1), + validators_share: Perquintill::from_percent(10), + cluster_reserve_share: Perquintill::from_percent(2), }) } diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index af50c033b..d17052f6c 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -34,7 +34,7 @@ use frame_support::{ }; use frame_system::pallet_prelude::*; pub use pallet::*; -use sp_runtime::{PerThing, Perbill}; +use sp_runtime::{PerThing, Perquintill}; use sp_std::prelude::*; type BatchIndex = u16; @@ -89,6 +89,7 @@ pub type BalanceOf = parameter_types! { pub MaxBatchesCount: u16 = 1000; + pub MaxDust: u16 = 20000; } #[frame_support::pallet] @@ -378,12 +379,12 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; let customer_id = payer.0.clone(); - let amount_actually_charged = T::CustomerCharger::charge_content_owner( + /*let amount_actually_charged = T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), total_customer_charge, - )?; - /* + )?;*/ + let amount_actually_charged = match T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), @@ -391,7 +392,7 @@ pub mod pallet { ) { Ok(actually_charged) => actually_charged, Err(_e) => 0, - }; */ + }; if amount_actually_charged < total_customer_charge { // debt @@ -427,8 +428,10 @@ pub mod pallet { if amount_actually_charged > 0 { // something was charged and should be added // calculate ratio - let ratio = - Perbill::from_rational(amount_actually_charged, total_customer_charge); + let ratio = Perquintill::from_rational( + amount_actually_charged, + total_customer_charge, + ); customer_charge.storage = ratio * customer_charge.storage; customer_charge.transfer = ratio * customer_charge.transfer; @@ -654,19 +657,21 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; let node_provider_id = payee.0; - let reward: BalanceOf = amount_to_reward.saturated_into::>(); - - ::Currency::transfer( - &updated_billing_report.vault, - &node_provider_id, - reward, - ExistenceRequirement::AllowDeath, - )?; - - updated_billing_report - .total_distributed_reward - .checked_add(amount_to_reward) - .ok_or(Error::::ArithmeticOverflow)?; + if amount_to_reward > 0 { + let reward: BalanceOf = amount_to_reward.saturated_into::>(); + + ::Currency::transfer( + &updated_billing_report.vault, + &node_provider_id, + reward, + ExistenceRequirement::AllowDeath, + )?; + + updated_billing_report.total_distributed_reward = updated_billing_report + .total_distributed_reward + .checked_add(amount_to_reward) + .ok_or(Error::::ArithmeticOverflow)?; + } Self::deposit_event(Event::::Rewarded { cluster_id, @@ -708,6 +713,22 @@ pub mod pallet { &billing_report.rewarding_max_batch_index, )?; + let expected_amount_to_reward = (|| -> Option { + billing_report + .total_customer_charge + .transfer + .checked_add(billing_report.total_customer_charge.storage)? + .checked_add(billing_report.total_customer_charge.puts)? + .checked_add(billing_report.total_customer_charge.gets) + })() + .ok_or(Error::::ArithmeticOverflow)?; + + ensure!( + expected_amount_to_reward - billing_report.total_distributed_reward <= + MaxDust::get().into(), + Error::::NotDistributedBalance + ); + billing_report.state = State::ProvidersRewarded; ActiveBillingReports::::insert(cluster_id, era, billing_report); @@ -729,20 +750,6 @@ pub mod pallet { .map_err(|_| Error::::BillingReportDoesNotExist)?; ensure!(billing_report.state == State::ProvidersRewarded, Error::::NotExpectedState); - let expected_amount_to_reward = (|| -> Option { - billing_report - .total_customer_charge - .transfer - .checked_add(billing_report.total_customer_charge.storage)? - .checked_add(billing_report.total_customer_charge.puts)? - .checked_add(billing_report.total_customer_charge.gets) - })() - .ok_or(Error::::ArithmeticOverflow)?; - - ensure!( - expected_amount_to_reward == billing_report.total_distributed_reward, - Error::::NotDistributedBalance - ); billing_report.charging_processed_batches.clear(); billing_report.rewarding_processed_batches.clear(); @@ -811,20 +818,23 @@ pub mod pallet { ) -> Option { let mut node_reward = NodeReward::default(); - let mut ratio = Perbill::from_rational( + let mut ratio = Perquintill::from_rational( node_usage.transferred_bytes, total_nodes_usage.transferred_bytes, ); + // ratio multiplied by X will be > 0, < X no overflow node_reward.transfer = ratio * total_customer_charge.transfer; - ratio = Perbill::from_rational(node_usage.stored_bytes, total_nodes_usage.stored_bytes); + ratio = Perquintill::from_rational(node_usage.stored_bytes, total_nodes_usage.stored_bytes); node_reward.storage = ratio * total_customer_charge.storage; - ratio = Perbill::from_rational(node_usage.number_of_puts, total_nodes_usage.number_of_puts); + ratio = + Perquintill::from_rational(node_usage.number_of_puts, total_nodes_usage.number_of_puts); node_reward.puts = ratio * total_customer_charge.puts; - ratio = Perbill::from_rational(node_usage.number_of_gets, total_nodes_usage.number_of_gets); + ratio = + Perquintill::from_rational(node_usage.number_of_gets, total_nodes_usage.number_of_gets); node_reward.gets = ratio * total_customer_charge.gets; Some(node_reward) diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 25e6b443c..74abd95f2 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -23,7 +23,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, - DispatchError, + DispatchError, Perquintill, }; use sp_std::prelude::*; @@ -117,7 +117,10 @@ impl CustomerCharger for TestCustomerCharger { ensure!(amount > 1_000_000, DispatchError::BadOrigin); // any error will do let mut amount_to_charge = amount; - if amount_to_charge < 50_000_000 { + let temp = ACCOUNT_ID_5.to_ne_bytes(); + let account_5 = T::AccountId::decode(&mut &temp[..]).unwrap(); + + if amount_to_charge < 50_000_000 && content_owner != account_5 { amount_to_charge = PARTIAL_CHARGE; // for user 3 } @@ -133,6 +136,7 @@ impl CustomerCharger for TestCustomerCharger { } } +pub const ACCOUNT_ID_5: AccountId = 5; pub const RESERVE_ACCOUNT_ID: AccountId = 999; pub const TREASURY_ACCOUNT_ID: AccountId = 888; pub const VALIDATOR1_ACCOUNT_ID: AccountId = 111; @@ -142,6 +146,7 @@ pub const PARTIAL_CHARGE: u128 = 100; pub const USER3_BALANCE: u128 = 1000; pub const FREE_CLUSTER_ID: ClusterId = ClusterId::zero(); +pub const ONE_CLUSTER_ID: ClusterId = ClusterId::repeat_byte(5u8); pub const PRICING_PARAMS: ClusterPricingParams = ClusterPricingParams { unit_per_mb_streamed: 2_000_000, @@ -150,16 +155,23 @@ pub const PRICING_PARAMS: ClusterPricingParams = ClusterPricingParams { unit_per_get_request: 5_000_000, }; +pub const PRICING_PARAMS_ONE: ClusterPricingParams = ClusterPricingParams { + unit_per_mb_streamed: 10_000_000_000, + unit_per_mb_stored: 10_000_000_000, + unit_per_put_request: 10_000_000_000, + unit_per_get_request: 10_000_000_000, +}; + pub const PRICING_FEES: ClusterFeesParams = ClusterFeesParams { - treasury_share: Perbill::from_percent(1), - validators_share: Perbill::from_percent(10), - cluster_reserve_share: Perbill::from_percent(2), + treasury_share: Perquintill::from_percent(1), + validators_share: Perquintill::from_percent(10), + cluster_reserve_share: Perquintill::from_percent(2), }; pub const PRICING_FEES_ZERO: ClusterFeesParams = ClusterFeesParams { - treasury_share: Perbill::from_percent(0), - validators_share: Perbill::from_percent(0), - cluster_reserve_share: Perbill::from_percent(0), + treasury_share: Perquintill::from_percent(0), + validators_share: Perquintill::from_percent(0), + cluster_reserve_share: Perquintill::from_percent(0), }; pub struct TestTreasuryVisitor; @@ -240,7 +252,7 @@ impl SortedListProvider for TestValidator } pub fn get_fees(cluster_id: &ClusterId) -> Result { - if *cluster_id == FREE_CLUSTER_ID { + if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { Ok(PRICING_FEES_ZERO) } else { Ok(PRICING_FEES) @@ -275,9 +287,13 @@ impl ClusterVisitor for TestClusterVisitor { } fn get_pricing_params( - _cluster_id: &ClusterId, + cluster_id: &ClusterId, ) -> Result { - Ok(PRICING_PARAMS) + if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { + Ok(PRICING_PARAMS_ONE) + } else { + Ok(PRICING_PARAMS) + } } fn get_fees_params(cluster_id: &ClusterId) -> Result { @@ -303,10 +319,11 @@ impl ExtBuilder { let _ = pallet_balances::GenesisConfig:: { balances: vec![ - (1, 1000000000000000000000000), + (1, 10000000000000000000000000000), (2, 10), // < PARTIAL_CHARGE (3, USER3_BALANCE), // > PARTIAL_CHARGE (4, 1000000000000000000000000), + (5, 1000000000000000000000000), ], } .assimilate_storage(&mut storage); diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 1e2ea13f2..6bab56cce 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -3,7 +3,7 @@ use super::{mock::*, *}; use ddc_primitives::ClusterId; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; - +use sp_runtime::Perquintill; #[test] fn set_authorised_caller_works() { ExtBuilder.build_and_execute(|| { @@ -257,24 +257,30 @@ fn send_charging_customers_batch_fails_uninitialised() { }) } -fn calculate_charge_parts(usage: CustomerUsage) -> CustomerCharge { +fn calculate_charge_parts(cluster_id: ClusterId, usage: CustomerUsage) -> CustomerCharge { + let pricing_params = if cluster_id == FREE_CLUSTER_ID || cluster_id == ONE_CLUSTER_ID { + PRICING_PARAMS_ONE + } else { + PRICING_PARAMS + }; + CustomerCharge { - transfer: PRICING_PARAMS.unit_per_mb_streamed * (usage.transferred_bytes as u128) / + transfer: pricing_params.unit_per_mb_streamed * (usage.transferred_bytes as u128) / byte_unit::MEBIBYTE, - storage: (PRICING_PARAMS.unit_per_mb_stored * usage.stored_bytes as u128) / + storage: (pricing_params.unit_per_mb_stored * usage.stored_bytes as u128) / byte_unit::MEBIBYTE, - puts: PRICING_PARAMS.unit_per_put_request * usage.number_of_puts, - gets: PRICING_PARAMS.unit_per_get_request * usage.number_of_gets, + puts: pricing_params.unit_per_put_request * usage.number_of_puts, + gets: pricing_params.unit_per_get_request * usage.number_of_gets, } } -fn calculate_charge(usage: CustomerUsage) -> u128 { - let charge = calculate_charge_parts(usage); +fn calculate_charge(cluster_id: ClusterId, usage: CustomerUsage) -> u128 { + let charge = calculate_charge_parts(cluster_id, usage); charge.transfer + charge.storage + charge.puts + charge.gets } #[test] -fn send_charging_customers_batch_works() { +fn send_charging_customers_batch_works1() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); @@ -343,17 +349,17 @@ fn send_charging_customers_batch_works() { payers1, )); - let usage4_charge = calculate_charge(usage4.clone()); + let usage4_charge = calculate_charge(cluster_id, usage4.clone()); let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); assert_eq!(balance, usage4_charge); let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); - let mut debt = calculate_charge(usage2.clone()); + let mut debt = calculate_charge(cluster_id, usage2.clone()); assert_eq!(user2_debt, debt); let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let charge2 = calculate_charge_parts(usage2); - let charge4 = calculate_charge_parts(usage4); + let charge2 = calculate_charge_parts(cluster_id, usage2); + let charge4 = calculate_charge_parts(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); assert_eq!(charge2.storage + charge4.storage, report.total_customer_charge.storage); @@ -410,13 +416,13 @@ fn send_charging_customers_batch_works() { era, batch_index, customer_id: user1, - amount: calculate_charge(usage1.clone()), + amount: calculate_charge(cluster_id, usage1.clone()), } .into(), ); report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let charge1 = calculate_charge_parts(usage1); + let charge1 = calculate_charge_parts(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -441,7 +447,7 @@ fn send_charging_customers_batch_works() { let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); // batch 3 - batch_index += 2; + batch_index += 1; before_total_customer_charge = report.total_customer_charge.clone(); assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), @@ -451,9 +457,9 @@ fn send_charging_customers_batch_works() { payers3, )); - let user3_charge = calculate_charge(usage3.clone()); - let charge3 = calculate_charge_parts(usage3); - let ratio = Perbill::from_rational(PARTIAL_CHARGE, user3_charge); + let user3_charge = calculate_charge(cluster_id, usage3.clone()); + let charge3 = calculate_charge_parts(cluster_id, usage3); + let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, @@ -503,6 +509,77 @@ fn send_charging_customers_batch_works() { }) } +#[test] +fn send_charging_customers_batch_works2() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let dac_account = 123u128; + let user5 = 5u128; + let cluster_id = ONE_CLUSTER_ID; + let era = 100; + let max_batch_index = 0; + let batch_index = 0; + let usage5 = CustomerUsage { + // should pass without debt + transferred_bytes: 1024, + stored_bytes: 1024, + number_of_puts: 1, + number_of_gets: 1, + }; + let payers5 = vec![(user5, usage5.clone())]; + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + max_batch_index, + )); + assert_eq!(System::events().len(), 3); + + // batch 1 + let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let before_total_customer_charge = report.total_customer_charge.clone(); + let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_index, + payers5, + )); + + let usage5_charge = calculate_charge(cluster_id, usage5.clone()); + let charge5 = calculate_charge_parts(cluster_id, usage5); + let balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + assert_eq!(balance, usage5_charge + balance_before); + assert_eq!( + charge5.puts + before_total_customer_charge.puts, + report.total_customer_charge.puts + ); + assert_eq!( + charge5.gets + before_total_customer_charge.gets, + report.total_customer_charge.gets + ); + assert_eq!( + charge5.storage + before_total_customer_charge.storage, + report.total_customer_charge.storage + ); + assert_eq!( + charge5.transfer + before_total_customer_charge.transfer, + report.total_customer_charge.transfer + ); + }) +} + #[test] fn end_charging_customers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { @@ -617,7 +694,7 @@ fn end_charging_customers_works() { )); let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let charge = calculate_charge(usage1); + let charge = calculate_charge(cluster_id, usage1); System::assert_last_event( Event::Charged { cluster_id, era, batch_index, customer_id: user1, amount: charge } .into(), @@ -710,8 +787,8 @@ fn end_charging_customers_works_zero_fees() { let usage1 = CustomerUsage { transferred_bytes: 23452345, stored_bytes: 3345234523, - number_of_puts: 4456456345234523, - number_of_gets: 523423, + number_of_puts: 1, + number_of_gets: 1, }; let payers = vec![(user1, usage1.clone())]; @@ -739,7 +816,7 @@ fn end_charging_customers_works_zero_fees() { )); let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let charge = calculate_charge(usage1); + let charge = calculate_charge(cluster_id, usage1); System::assert_last_event( Event::Charged { cluster_id, era, customer_id: user1, batch_index, amount: charge } .into(), @@ -767,11 +844,11 @@ fn end_charging_customers_works_zero_fees() { (fees.treasury_share + fees.validators_share + fees.cluster_reserve_share) .left_from_one(); - assert_eq!(total_left_from_one, Perbill::one()); + assert_eq!(total_left_from_one, Perquintill::one()); - assert_eq!(fees.treasury_share, Perbill::zero()); - assert_eq!(fees.validators_share, Perbill::zero()); - assert_eq!(fees.cluster_reserve_share, Perbill::zero()); + assert_eq!(fees.treasury_share, Perquintill::zero()); + assert_eq!(fees.validators_share, Perquintill::zero()); + assert_eq!(fees.cluster_reserve_share, Perquintill::zero()); balance = Balances::free_balance(TREASURY_ACCOUNT_ID); assert_eq!(balance, 0); @@ -1269,46 +1346,59 @@ fn send_rewarding_providers_batch_works() { payees1, )); - let mut ratio = Perbill::from_rational( + let ratio1_transfer = Perquintill::from_rational( node_usage1.transferred_bytes, total_nodes_usage.transferred_bytes, ); - let mut transfer_charge = ratio * report_after.total_customer_charge.transfer; + let mut transfer_charge = ratio1_transfer * report_after.total_customer_charge.transfer; - ratio = Perbill::from_rational(node_usage1.stored_bytes, total_nodes_usage.stored_bytes); - let mut storage_charge = ratio * report_after.total_customer_charge.storage; + let ratio1_storage = + Perquintill::from_rational(node_usage1.stored_bytes, total_nodes_usage.stored_bytes); + let mut storage_charge = ratio1_storage * report_after.total_customer_charge.storage; - ratio = - Perbill::from_rational(node_usage1.number_of_puts, total_nodes_usage.number_of_puts); - let mut puts_charge = ratio * report_after.total_customer_charge.puts; + let ratio1_puts = Perquintill::from_rational( + node_usage1.number_of_puts, + total_nodes_usage.number_of_puts, + ); + let mut puts_charge = ratio1_puts * report_after.total_customer_charge.puts; - ratio = - Perbill::from_rational(node_usage1.number_of_gets, total_nodes_usage.number_of_gets); - let mut gets_charge = ratio * report_after.total_customer_charge.gets; + let ratio1_gets = Perquintill::from_rational( + node_usage1.number_of_gets, + total_nodes_usage.number_of_gets, + ); + let mut gets_charge = ratio1_gets * report_after.total_customer_charge.gets; - let mut balance = Balances::free_balance(node1); - assert_eq!(balance, transfer_charge + storage_charge + puts_charge + gets_charge); + let balance_node1 = Balances::free_balance(node1); + assert_eq!(balance_node1, transfer_charge + storage_charge + puts_charge + gets_charge); + let mut report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - ratio = Perbill::from_rational( + let ratio2_transfer = Perquintill::from_rational( node_usage2.transferred_bytes, total_nodes_usage.transferred_bytes, ); - transfer_charge = ratio * report_after.total_customer_charge.transfer; + transfer_charge = ratio2_transfer * report_after.total_customer_charge.transfer; - ratio = Perbill::from_rational(node_usage2.stored_bytes, total_nodes_usage.stored_bytes); - storage_charge = ratio * report_after.total_customer_charge.storage; + let ratio2_storage = + Perquintill::from_rational(node_usage2.stored_bytes, total_nodes_usage.stored_bytes); + storage_charge = ratio2_storage * report_after.total_customer_charge.storage; - ratio = - Perbill::from_rational(node_usage2.number_of_puts, total_nodes_usage.number_of_puts); - puts_charge = ratio * report_after.total_customer_charge.puts; + let ratio2_puts = Perquintill::from_rational( + node_usage2.number_of_puts, + total_nodes_usage.number_of_puts, + ); + puts_charge = ratio2_puts * report_after.total_customer_charge.puts; - ratio = - Perbill::from_rational(node_usage2.number_of_gets, total_nodes_usage.number_of_gets); - gets_charge = ratio * report_after.total_customer_charge.gets; + let ratio2_gets = Perquintill::from_rational( + node_usage2.number_of_gets, + total_nodes_usage.number_of_gets, + ); + gets_charge = ratio2_gets * report_after.total_customer_charge.gets; - balance = Balances::free_balance(node2); - assert_eq!(balance, transfer_charge + storage_charge + puts_charge + gets_charge); + let balance_node2 = Balances::free_balance(node2); + assert_eq!(balance_node2, transfer_charge + storage_charge + puts_charge + gets_charge); + assert_eq!(report_reward.total_distributed_reward, balance_node1 + balance_node2); + // batch 2 assert_ok!(DdcPayouts::send_rewarding_providers_batch( RuntimeOrigin::signed(dac_account), cluster_id, @@ -1317,25 +1407,42 @@ fn send_rewarding_providers_batch_works() { payees2, )); - ratio = Perbill::from_rational( + let ratio3_transfer = Perquintill::from_rational( node_usage3.transferred_bytes, total_nodes_usage.transferred_bytes, ); - transfer_charge = ratio * report_after.total_customer_charge.transfer; + transfer_charge = ratio3_transfer * report_after.total_customer_charge.transfer; - ratio = Perbill::from_rational(node_usage3.stored_bytes, total_nodes_usage.stored_bytes); - storage_charge = ratio * report_after.total_customer_charge.storage; + let ratio3_storage = + Perquintill::from_rational(node_usage3.stored_bytes, total_nodes_usage.stored_bytes); + storage_charge = ratio3_storage * report_after.total_customer_charge.storage; - ratio = - Perbill::from_rational(node_usage3.number_of_puts, total_nodes_usage.number_of_puts); - puts_charge = ratio * report_after.total_customer_charge.puts; + let ratio3_puts = Perquintill::from_rational( + node_usage3.number_of_puts, + total_nodes_usage.number_of_puts, + ); + puts_charge = ratio3_puts * report_after.total_customer_charge.puts; - ratio = - Perbill::from_rational(node_usage3.number_of_gets, total_nodes_usage.number_of_gets); - gets_charge = ratio * report_after.total_customer_charge.gets; + let ratio3_gets = Perquintill::from_rational( + node_usage3.number_of_gets, + total_nodes_usage.number_of_gets, + ); + gets_charge = ratio3_gets * report_after.total_customer_charge.gets; - balance = Balances::free_balance(node3); - assert_eq!(balance, transfer_charge + storage_charge + puts_charge + gets_charge); + report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let balance_node3 = Balances::free_balance(node3); + assert_eq!(balance_node3, transfer_charge + storage_charge + puts_charge + gets_charge); + assert_eq!( + report_reward.total_distributed_reward, + balance_node1 + balance_node2 + balance_node3 + ); + + let expected_amount_to_reward = report_reward.total_customer_charge.transfer + + report_reward.total_customer_charge.storage + + report_reward.total_customer_charge.puts + + report_reward.total_customer_charge.gets; + + assert!(expected_amount_to_reward - report_reward.total_distributed_reward <= 20000); assert_ok!(DdcPayouts::end_rewarding_providers( RuntimeOrigin::signed(dac_account), @@ -1509,15 +1616,29 @@ fn end_rewarding_providers_works() { System::set_block_number(1); let dac_account = 2u128; - let user1 = 3u128; + let user1 = 1u128; let node1 = 33u128; let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; let batch_index = 0; - let total_node_usage = NodeUsage::default(); - let payers = vec![(user1, CustomerUsage::default())]; - let payees = vec![(node1, NodeUsage::default())]; + let usage1 = CustomerUsage { + transferred_bytes: 23452345, + stored_bytes: 3345234523, + number_of_puts: 4456456345234523, + number_of_gets: 523423, + }; + + let node_usage1 = NodeUsage { + // CDN + Storage + transferred_bytes: usage1.transferred_bytes * 2 / 3, + stored_bytes: usage1.stored_bytes * 2 / 3, + number_of_puts: usage1.number_of_puts * 2 / 3, + number_of_gets: usage1.number_of_gets * 2 / 3, + }; + let total_node_usage = node_usage1.clone(); + let payers = vec![(user1, usage1)]; + let payees = vec![(node1, node_usage1)]; assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index eaee9f844..9085b5ed5 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -20,7 +20,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, - Perbill, + Perquintill, }; use sp_std::collections::btree_map::BTreeMap; @@ -146,9 +146,9 @@ impl ClusterVisitor for TestClusterVisitor { fn get_fees_params(_cluster_id: &ClusterId) -> Result { Ok(ClusterFeesParams { - treasury_share: Perbill::from_percent(1), - validators_share: Perbill::from_percent(10), - cluster_reserve_share: Perbill::from_percent(2), + treasury_share: Perquintill::from_percent(1), + validators_share: Perquintill::from_percent(10), + cluster_reserve_share: Perquintill::from_percent(2), }) } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 78c25e2f7..54b1c0c9e 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -5,7 +5,7 @@ use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_core::hash::H160; -use sp_runtime::{AccountId32, Perbill, RuntimeDebug}; +use sp_runtime::{AccountId32, Perquintill, RuntimeDebug}; pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; @@ -21,9 +21,9 @@ pub struct ClusterPricingParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterFeesParams { - pub treasury_share: Perbill, - pub validators_share: Perbill, - pub cluster_reserve_share: Perbill, + pub treasury_share: Perquintill, + pub validators_share: Perquintill, + pub cluster_reserve_share: Perquintill, } #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] From 974077a6a308b3289f592a7703844eb4787a03f8 Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Mon, 11 Dec 2023 09:19:33 +0100 Subject: [PATCH 533/544] Backporting the `dev` branch to substrate `0.9.30` (#192) Backporting the following PRs from the `dev` branch: - [#184](https://github.com/Cerebellum-Network/blockchain-node/pull/184) - [#169](https://github.com/Cerebellum-Network/blockchain-node/pull/169) - [#175](https://github.com/Cerebellum-Network/blockchain-node/pull/175) - [#177](https://github.com/Cerebellum-Network/blockchain-node/pull/177) - [#159](https://github.com/Cerebellum-Network/blockchain-node/pull/159) - [#162](https://github.com/Cerebellum-Network/blockchain-node/pull/162) - [#153](https://github.com/Cerebellum-Network/blockchain-node/pull/153) - [#163](https://github.com/Cerebellum-Network/blockchain-node/pull/163) - [#143](https://github.com/Cerebellum-Network/blockchain-node/pull/143) - [#150](https://github.com/Cerebellum-Network/blockchain-node/pull/150) - [#149](https://github.com/Cerebellum-Network/blockchain-node/pull/149) --------- Co-authored-by: Raid5594 <52794079+Raid5594@users.noreply.github.com> Co-authored-by: Alisher A. Khassanov --- .maintain/frame-weight-template.hbs | 24 +- Cargo.lock | 464 ++++++++++------ node/service/src/chain_spec.rs | 1 + pallets/ddc-clusters/Cargo.toml | 12 + pallets/ddc-clusters/src/benchmarking.rs | 119 +++++ pallets/ddc-clusters/src/cluster.rs | 34 +- pallets/ddc-clusters/src/lib.rs | 304 ++++++++--- pallets/ddc-clusters/src/mock.rs | 66 ++- .../ddc-clusters/src/node_provider_auth.rs | 74 ++- pallets/ddc-clusters/src/testing_utils.rs | 133 +++++ pallets/ddc-clusters/src/tests.rs | 356 +++++++++---- pallets/ddc-clusters/src/weights.rs | 155 ++++++ pallets/ddc-customers/Cargo.toml | 26 +- pallets/ddc-customers/src/benchmarking.rs | 153 ++++++ pallets/ddc-customers/src/lib.rs | 135 +++-- pallets/ddc-customers/src/mock.rs | 89 +++- pallets/ddc-customers/src/tests.rs | 4 +- pallets/ddc-customers/src/weights.rs | 132 +++++ pallets/ddc-nodes/Cargo.toml | 9 + pallets/ddc-nodes/src/benchmarking.rs | 61 +++ pallets/ddc-nodes/src/cdn_node.rs | 12 +- pallets/ddc-nodes/src/lib.rs | 49 +- pallets/ddc-nodes/src/mock.rs | 21 +- pallets/ddc-nodes/src/node.rs | 14 +- pallets/ddc-nodes/src/storage_node.rs | 13 +- pallets/ddc-nodes/src/testing_utils.rs | 31 ++ pallets/ddc-nodes/src/tests.rs | 400 +++++++++++++- pallets/ddc-nodes/src/weights.rs | 83 +++ pallets/ddc-payouts/Cargo.toml | 9 +- pallets/ddc-payouts/src/benchmarking.rs | 500 ++++++++++++++++++ pallets/ddc-payouts/src/lib.rs | 46 +- pallets/ddc-payouts/src/mock.rs | 44 +- pallets/ddc-payouts/src/weights.rs | 210 ++++++++ pallets/ddc-staking/Cargo.toml | 2 + pallets/ddc-staking/src/benchmarking.rs | 27 +- pallets/ddc-staking/src/lib.rs | 189 +++++-- pallets/ddc-staking/src/mock.rs | 154 +++++- pallets/ddc-staking/src/testing_utils.rs | 90 +++- pallets/ddc-staking/src/tests.rs | 359 ++++++++++++- pallets/ddc-staking/src/weights.rs | 142 +++-- primitives/src/lib.rs | 63 ++- runtime/cere-dev/Cargo.toml | 4 + runtime/cere-dev/src/lib.rs | 16 + traits/Cargo.toml | 1 + traits/src/cluster.rs | 41 +- traits/src/customer.rs | 14 +- traits/src/node.rs | 12 +- traits/src/staking.rs | 16 +- 48 files changed, 4295 insertions(+), 618 deletions(-) create mode 100644 pallets/ddc-clusters/src/benchmarking.rs create mode 100644 pallets/ddc-clusters/src/testing_utils.rs create mode 100644 pallets/ddc-clusters/src/weights.rs create mode 100644 pallets/ddc-customers/src/benchmarking.rs create mode 100644 pallets/ddc-customers/src/weights.rs create mode 100644 pallets/ddc-nodes/src/benchmarking.rs create mode 100644 pallets/ddc-nodes/src/testing_utils.rs create mode 100644 pallets/ddc-nodes/src/weights.rs create mode 100644 pallets/ddc-payouts/src/benchmarking.rs create mode 100644 pallets/ddc-payouts/src/weights.rs diff --git a/.maintain/frame-weight-template.hbs b/.maintain/frame-weight-template.hbs index e2248b4e2..ad0077736 100644 --- a/.maintain/frame-weight-template.hbs +++ b/.maintain/frame-weight-template.hbs @@ -47,22 +47,22 @@ impl WeightInfo for SubstrateWeight { {{~#each benchmark.components as |c| ~}} {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} ) -> Weight { - Weight::from_ref_time({{underscore benchmark.base_weight}} as u64) + Weight::from_ref_time({{underscore benchmark.base_weight}}_u64) {{#each benchmark.component_weight as |cw|}} // Standard Error: {{underscore cw.error}} - .saturating_add(Weight::from_ref_time({{underscore cw.slope}} as u64).saturating_mul({{cw.name}} as u64)) + .saturating_add(Weight::from_ref_time({{underscore cw.slope}}_u64).saturating_mul({{cw.name}} as u64)) {{/each}} {{#if (ne benchmark.base_reads "0")}} - .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as u64)) + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64)) {{/if}} {{#each benchmark.component_reads as |cr|}} - .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as u64).saturating_mul({{cr.name}} as u64))) + .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}} as u64))) {{/each}} {{#if (ne benchmark.base_writes "0")}} - .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as u64)) + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64)) {{/if}} {{#each benchmark.component_writes as |cw|}} - .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as u64).saturating_mul({{cw.name}} as u64))) + .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}} as u64))) {{/each}} } {{/each}} @@ -82,22 +82,22 @@ impl WeightInfo for () { {{~#each benchmark.components as |c| ~}} {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} ) -> Weight { - Weight::from_ref_time({{underscore benchmark.base_weight}} as u64) + Weight::from_ref_time({{underscore benchmark.base_weight}}_u64) {{#each benchmark.component_weight as |cw|}} // Standard Error: {{underscore cw.error}} - .saturating_add(Weight::from_ref_time({{underscore cw.slope}} as u64).saturating_mul({{cw.name}} as u64)) + .saturating_add(Weight::from_ref_time({{underscore cw.slope}}_u64).saturating_mul({{cw.name}} as u64)) {{/each}} {{#if (ne benchmark.base_reads "0")}} - .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as u64)) + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64)) {{/if}} {{#each benchmark.component_reads as |cr|}} - .saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as u64).saturating_mul({{cr.name}} as u64))) + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}} as u64))) {{/each}} {{#if (ne benchmark.base_writes "0")}} - .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as u64)) + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64)) {{/if}} {{#each benchmark.component_writes as |cw|}} - .saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as u64).saturating_mul({{cw.name}} as u64))) + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}} as u64))) {{/each}} } {{/each}} diff --git a/Cargo.lock b/Cargo.lock index 66d8d13da..e75b40eaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ - "gimli 0.28.0", + "gimli 0.28.1", ] [[package]] @@ -211,12 +211,12 @@ dependencies = [ [[package]] name = "async-channel" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37875bd9915b7d67c2f117ea2c30a0989874d0b2cb694fe25403c85763c0c9e" +checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" dependencies = [ "concurrent-queue", - "event-listener 3.1.0", + "event-listener 4.0.0", "event-listener-strategy", "futures-core", "pin-project-lite 0.2.13", @@ -224,30 +224,30 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0" +checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" dependencies = [ - "async-lock 2.8.0", + "async-lock 3.2.0", "async-task", "concurrent-queue", "fastrand 2.0.1", - "futures-lite 1.13.0", + "futures-lite 2.1.0", "slab", ] [[package]] name = "async-global-executor" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" +checksum = "9b4353121d5644cdf2beb5726ab752e79a8db1ebb52031770ec47db31d245526" dependencies = [ - "async-channel 1.9.0", + "async-channel 2.1.1", "async-executor", - "async-io 1.13.0", - "async-lock 2.8.0", + "async-io 2.2.1", + "async-lock 3.2.0", "blocking", - "futures-lite 1.13.0", + "futures-lite 2.1.0", "once_cell", ] @@ -273,22 +273,21 @@ dependencies = [ [[package]] name = "async-io" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed9d5715c2d329bf1b4da8d60455b99b187f27ba726df2883799af9af60997" +checksum = "d6d3b15875ba253d1110c740755e246537483f152fa334f91abd7fe84c88b3ff" dependencies = [ - "async-lock 3.1.0", + "async-lock 3.2.0", "cfg-if", "concurrent-queue", "futures-io", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "parking", - "polling 3.3.0", - "rustix 0.38.21", + "polling 3.3.1", + "rustix 0.38.27", "slab", "tracing", - "waker-fn", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -302,11 +301,11 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb2ab2aa8a746e221ab826c73f48bc6ba41be6763f0855cb249eb6d154cf1d7" +checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c" dependencies = [ - "event-listener 3.1.0", + "event-listener 4.0.0", "event-listener-strategy", "pin-project-lite 0.2.13", ] @@ -324,7 +323,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.21", + "rustix 0.38.27", "windows-sys 0.48.0", ] @@ -334,13 +333,13 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" dependencies = [ - "async-io 2.2.0", + "async-io 2.2.1", "async-lock 2.8.0", "atomic-waker", "cfg-if", "futures-core", "futures-io", - "rustix 0.38.21", + "rustix 0.38.27", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -660,12 +659,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ - "async-channel 2.1.0", - "async-lock 3.1.0", + "async-channel 2.1.1", + "async-lock 3.2.0", "async-task", "fastrand 2.0.1", "futures-io", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "piper", "tracing", ] @@ -756,9 +755,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12024c4645c97566567129c204f65d5815a8c9aecf30fcbe682b2fe034996d36" +checksum = "e34637b3140142bdf929fb439e8aa4ebad7651ebf7b1080b3930aa16ac1459ff" dependencies = [ "serde", ] @@ -778,10 +777,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.84" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ + "jobserver", "libc", ] @@ -1184,7 +1184,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1283,9 +1283,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" dependencies = [ "crossbeam-utils", ] @@ -1310,9 +1310,9 @@ checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -1320,9 +1320,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "core2" @@ -1625,15 +1625,15 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "data-encoding-macro" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c904b33cc60130e1aeea4956ab803d08a3f4a0ca82d64ed757afac3891f2bb99" +checksum = "20c01c06f5f429efdf2bae21eb67c28b3df3cf85b7dd2d8ef09c0838dac5d33e" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -1641,9 +1641,9 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdf3fce3ce863539ec1d7fd1b6dcc3c645663376b43ed376bbf887733e4f772" +checksum = "0047d07f2c89b17dd631c80450d69841a6b5d7fb17278cbc43d7e4cfcf2576f3" dependencies = [ "data-encoding", "syn 1.0.109", @@ -1665,6 +1665,7 @@ name = "ddc-traits" version = "0.1.0" dependencies = [ "ddc-primitives", + "frame-support", "frame-system", "parity-scale-codec", "scale-info", @@ -1972,12 +1973,12 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2007,13 +2008,24 @@ dependencies = [ "pin-project-lite 0.2.13", ] +[[package]] +name = "event-listener" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "770d968249b5d99410d61f5bf89057f3199a077a04d087092f58e7d10692baae" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite 0.2.13", +] + [[package]] name = "event-listener-strategy" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96b852f1345da36d551b9473fa1e2b1eb5c5195585c6c018118bc92a8d91160" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ - "event-listener 3.1.0", + "event-listener 4.0.0", "pin-project-lite 0.2.13", ] @@ -2074,9 +2086,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.3" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f69037fe1b785e84986b4f2cbcf647381876a00671d25ceef715d7812dd7e1dd" +checksum = "27573eac26f4dd11e2b1916c3fe1baa56407c83c71a773a8ba17ec0bca03b6b7" [[package]] name = "file-per-thread-logger" @@ -2090,14 +2102,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.22" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", - "windows-sys 0.48.0", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", ] [[package]] @@ -2161,9 +2173,9 @@ dependencies = [ [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -2247,7 +2259,7 @@ name = "frame-election-provider-solution-type" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -2350,7 +2362,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -2520,11 +2532,14 @@ dependencies = [ [[package]] name = "futures-lite" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" +checksum = "aeee267a1883f7ebef3700f262d2d54de95dfaf38189015a74fdc4e0c7ad8143" dependencies = [ + "fastrand 2.0.1", "futures-core", + "futures-io", + "parking", "pin-project-lite 0.2.13", ] @@ -2671,9 +2686,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "glob" @@ -2683,15 +2698,15 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" dependencies = [ "aho-corasick", "bstr", - "fnv", "log", - "regex", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -2719,9 +2734,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" dependencies = [ "bytes", "fnv", @@ -2729,7 +2744,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.1.0", "slab", "tokio", "tokio-util", @@ -2776,9 +2791,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -2985,9 +3000,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -3068,7 +3083,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.3", ] [[package]] @@ -3146,7 +3161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.21", + "rustix 0.38.27", "windows-sys 0.48.0", ] @@ -3171,11 +3186,20 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jobserver" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -3272,7 +3296,7 @@ version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd67957d4280217247588ac86614ead007b301ca2fa9f19c19f880a536f029e3" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -4076,9 +4100,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "lock_api" @@ -4189,7 +4213,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.21", + "rustix 0.38.27", ] [[package]] @@ -4265,9 +4289,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -4326,7 +4350,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro-error", "proc-macro2", "quote", @@ -4622,9 +4646,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" @@ -4931,6 +4955,7 @@ version = "4.8.1" dependencies = [ "ddc-primitives", "ddc-traits", + "frame-benchmarking", "frame-support", "frame-system", "hex", @@ -4942,6 +4967,7 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -4956,12 +4982,14 @@ version = "0.1.0" dependencies = [ "ddc-primitives", "ddc-traits", + "frame-benchmarking", "frame-support", "frame-system", "log", "pallet-balances", "pallet-timestamp", "parity-scale-codec", + "rand_chacha 0.2.2", "scale-info", "sp-core", "sp-io", @@ -5001,6 +5029,7 @@ version = "4.8.1" dependencies = [ "ddc-primitives", "ddc-traits", + "frame-benchmarking", "frame-support", "frame-system", "pallet-balances", @@ -5048,9 +5077,11 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "lazy_static", "pallet-balances", "pallet-timestamp", "parity-scale-codec", + "parking_lot 0.12.1", "scale-info", "sp-core", "sp-io", @@ -5520,7 +5551,7 @@ name = "pallet-staking-reward-curve" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -5688,9 +5719,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.5" +version = "3.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" +checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" dependencies = [ "arrayvec 0.7.4", "bitvec", @@ -5703,11 +5734,11 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.5" +version = "3.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" +checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 2.0.1", "proc-macro2", "quote", "syn 1.0.109", @@ -5812,7 +5843,7 @@ dependencies = [ "libc", "redox_syscall 0.4.1", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -5847,9 +5878,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" @@ -6002,16 +6033,16 @@ dependencies = [ [[package]] name = "polling" -version = "3.3.0" +version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" +checksum = "cf63fa624ab313c11656b4cda960bfc46c410187ad493c41f6ba2d8c1e991c9e" dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite 0.2.13", - "rustix 0.38.21", + "rustix 0.38.27", "tracing", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -6098,6 +6129,16 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +dependencies = [ + "toml_datetime", + "toml_edit", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -6124,9 +6165,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -6466,15 +6507,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -6626,9 +6658,9 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.5" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", "getrandom 0.2.11", @@ -6741,7 +6773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", - "errno 0.3.6", + "errno 0.3.8", "io-lifetimes 1.0.11", "libc", "linux-raw-sys 0.3.8", @@ -6750,15 +6782,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.21" +version = "0.38.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "bfeae074e687625746172d639330f1de242a178bf3189b51e35a7a21573513ac" dependencies = [ "bitflags 2.4.1", - "errno 0.3.6", + "errno 0.3.8", "libc", - "linux-raw-sys 0.4.11", - "windows-sys 0.48.0", + "linux-raw-sys 0.4.12", + "windows-sys 0.52.0", ] [[package]] @@ -6943,7 +6975,7 @@ name = "sc-chain-spec-derive" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -7823,7 +7855,7 @@ name = "sc-tracing-proc-macro" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -7901,7 +7933,7 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -7946,7 +7978,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.5", + "ring 0.17.7", "untrusted 0.9.0", ] @@ -8048,18 +8080,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -8224,9 +8256,9 @@ checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "snap" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" +checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" [[package]] name = "snow" @@ -8239,7 +8271,7 @@ dependencies = [ "chacha20poly1305", "curve25519-dalek 4.1.1", "rand_core 0.6.4", - "ring 0.17.5", + "ring 0.17.7", "rustc_version 0.4.0", "sha2 0.10.8", "subtle", @@ -8305,7 +8337,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "blake2", - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -8750,7 +8782,7 @@ version = "5.0.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ "Inflector", - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -9190,7 +9222,7 @@ name = "substrate-test-utils-derive" version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -9295,15 +9327,15 @@ dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall 0.4.1", - "rustix 0.38.21", + "rustix 0.38.27", "windows-sys 0.48.0", ] [[package]] name = "termcolor" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" dependencies = [ "winapi-util", ] @@ -9480,6 +9512,23 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.1.0", + "toml_datetime", + "winnow", +] + [[package]] name = "tower-service" version = "0.3.2" @@ -9639,9 +9688,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "try-runtime-cli" @@ -9722,9 +9771,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-ident" @@ -9789,20 +9838,20 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna 0.4.0", + "idna 0.5.0", "percent-encoding", ] [[package]] name = "utf8-width" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" [[package]] name = "valuable" @@ -9873,9 +9922,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -9883,9 +9932,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -9898,9 +9947,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" dependencies = [ "cfg-if", "js-sys", @@ -9910,9 +9959,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -9920,9 +9969,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -9933,9 +9982,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-gc-api" @@ -10186,9 +10235,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", @@ -10200,7 +10249,7 @@ version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring 0.17.5", + "ring 0.17.7", "untrusted 0.9.0", ] @@ -10222,7 +10271,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.21", + "rustix 0.38.27", ] [[package]] @@ -10281,7 +10330,7 @@ version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -10318,7 +10367,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -10336,6 +10394,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -10348,6 +10421,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.34.0" @@ -10372,6 +10451,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.34.0" @@ -10396,6 +10481,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.34.0" @@ -10420,6 +10511,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.34.0" @@ -10444,6 +10541,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -10456,6 +10559,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.34.0" @@ -10480,6 +10589,21 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "winnow" +version = "0.5.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" @@ -10526,9 +10650,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 1559b913a..726fa96d8 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -235,6 +235,7 @@ pub fn cere_dev_genesis( transaction_payment: Default::default(), ddc_customers: Default::default(), nomination_pools: Default::default(), + ddc_clusters: Default::default(), } } diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index ac1c569aa..98abf9897 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } hex = { version = "0.4", default-features = false } @@ -14,6 +15,7 @@ hex-literal = "^0.3.1" pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true } sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -23,6 +25,7 @@ pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -30,9 +33,11 @@ substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", br default = ["std"] std = [ "codec/std", + "serde", "ddc-primitives/std", "frame-support/std", "frame-system/std", + "frame-benchmarking/std", "pallet-contracts/std", "pallet-ddc-nodes/std", "scale-info/std", @@ -40,3 +45,10 @@ std = [ "sp-runtime/std", "sp-std/std", ] +runtime-benchmarks = [ + "ddc-primitives/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] diff --git a/pallets/ddc-clusters/src/benchmarking.rs b/pallets/ddc-clusters/src/benchmarking.rs new file mode 100644 index 000000000..9ce6b28d9 --- /dev/null +++ b/pallets/ddc-clusters/src/benchmarking.rs @@ -0,0 +1,119 @@ +//! DdcStaking pallet benchmarking. + +use ddc_primitives::{ClusterGovParams, ClusterId, ClusterParams, NodePubKey}; +pub use frame_benchmarking::{ + account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, + BenchmarkError, +}; +use frame_system::RawOrigin; +use pallet_contracts::chain_extension::UncheckedFrom; +use sp_runtime::{AccountId32, Perquintill}; +use sp_std::prelude::*; +use testing_utils::*; + +use super::*; +use crate::{cluster::ClusterProps, Pallet as DdcClusters}; + +const USER_SEED: u32 = 999666; +const USER_SEED_2: u32 = 999555; + +benchmarks! { + where_clause { where + T::AccountId: UncheckedFrom + AsRef<[u8]> } + + create_cluster { + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + cdn_bond_size: 100u32.into(), + cdn_chill_delay: 50u32.into(), + cdn_unbonding_delay: 50u32.into(), + storage_bond_size: 100u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + }: _(RawOrigin::Root, cluster_id, user.clone(), user, cluster_params, cluster_gov_params) + verify { + assert!(Clusters::::contains_key(cluster_id)); + } + + add_node { + let bytes = [0u8; 32]; + let node_pub_key = NodePubKey::CDNPubKey(AccountId32::from(bytes)); + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); + }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) + verify { + assert!(ClustersNodes::::contains_key(cluster_id, node_pub_key)); + } + + remove_node { + let bytes = [0u8; 32]; + let node_pub_key = NodePubKey::CDNPubKey(AccountId32::from(bytes)); + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); + let _ = DdcClusters::::add_node( + RawOrigin::Signed(user.clone()).into(), + cluster_id, + node_pub_key.clone() + ); + }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) + verify { + assert!(!ClustersNodes::::contains_key(cluster_id, node_pub_key)); + } + + set_cluster_params { + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + let user_2 = account::("user", USER_SEED_2, 0u32); + let _ = config_cluster::(user.clone(), cluster_id); + let new_cluster_params = ClusterParams { node_provider_auth_contract: Some(user_2.clone()) }; + }: _(RawOrigin::Signed(user.clone()), cluster_id, new_cluster_params) + verify { + assert_eq!(Clusters::::try_get(cluster_id).unwrap().props, ClusterProps { node_provider_auth_contract: Some(user_2) }); + } + + set_cluster_gov_params { + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + let _ = config_cluster::(user, cluster_id); + let new_cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + cdn_bond_size: 10u32.into(), + cdn_chill_delay: 5u32.into(), + cdn_unbonding_delay: 5u32.into(), + storage_bond_size: 10u32.into(), + storage_chill_delay: 5u32.into(), + storage_unbonding_delay: 5u32.into(), + unit_per_mb_stored: 1, + unit_per_mb_streamed: 1, + unit_per_put_request: 1, + unit_per_get_request: 1, + }; + }: _(RawOrigin::Root, cluster_id, new_cluster_gov_params.clone()) + verify { + assert_eq!(ClustersGovParams::::try_get(cluster_id).unwrap(), new_cluster_gov_params); + } + + impl_benchmark_test_suite!( + DdcClusters, + crate::mock::ExtBuilder.build(), + crate::mock::Test, + ); +} diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index ff55e49bf..5fc7821c8 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -1,14 +1,16 @@ use crate::pallet::Error; use codec::{Decode, Encode}; -use ddc_primitives::ClusterId; +use ddc_primitives::{ClusterId, ClusterParams}; use frame_support::{pallet_prelude::*, parameter_types}; use scale_info::TypeInfo; -use sp_runtime::Perquintill; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; parameter_types! { pub MaxClusterParamsLen: u16 = 2048; } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct Cluster { pub cluster_id: ClusterId, @@ -17,34 +19,10 @@ pub struct Cluster { pub props: ClusterProps, } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterProps { - pub node_provider_auth_contract: AccountId, -} - -// ClusterParams includes Governance non-sensetive parameters only -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct ClusterParams { - pub node_provider_auth_contract: AccountId, -} - -// ClusterGovParams includes Governance sensetive parameters -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -#[scale_info(skip_type_params(Balance, BlockNumber, T))] -pub struct ClusterGovParams { - pub treasury_share: Perquintill, - pub validators_share: Perquintill, - pub cluster_reserve_share: Perquintill, - pub cdn_bond_size: Balance, - pub cdn_chill_delay: BlockNumber, - pub cdn_unbonding_delay: BlockNumber, - pub storage_bond_size: Balance, - pub storage_chill_delay: BlockNumber, - pub storage_unbonding_delay: BlockNumber, - pub unit_per_mb_stored: u128, - pub unit_per_mb_streamed: u128, - pub unit_per_put_request: u128, - pub unit_per_get_request: u128, + pub node_provider_auth_contract: Option, } impl Cluster { diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 99b8e1448..a9c501854 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -15,21 +15,33 @@ #![recursion_limit = "256"] #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 +pub mod weights; +use crate::weights::WeightInfo; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; +#[cfg(any(feature = "runtime-benchmarks", test))] +pub mod testing_utils; + #[cfg(test)] pub(crate) mod mock; #[cfg(test)] mod tests; use crate::{ - cluster::{Cluster, ClusterGovParams, ClusterParams}, + cluster::Cluster, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; -use ddc_primitives::{ClusterFeesParams, ClusterId, ClusterPricingParams, NodePubKey, NodeType}; +use ddc_primitives::{ + ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams, + ClusterPricingParams, NodePubKey, NodeType, +}; use ddc_traits::{ - cluster::{ClusterVisitor, ClusterVisitorError}, - staking::{StakingVisitor, StakingVisitorError}, + cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError}, + staking::{StakerCreator, StakingVisitor, StakingVisitorError}, }; use frame_support::{ + assert_ok, pallet_prelude::*, traits::{Currency, LockableCurrency}, }; @@ -39,7 +51,7 @@ use pallet_ddc_nodes::{NodeRepository, NodeTrait}; use sp_runtime::SaturatedConversion; use sp_std::prelude::*; -mod cluster; +pub mod cluster; mod node_provider_auth; /// The balance type of this pallet. @@ -49,6 +61,7 @@ pub type BalanceOf = #[frame_support::pallet] pub mod pallet { use super::*; + use ddc_traits::cluster::{ClusterManager, ClusterManagerError}; use pallet_contracts::chain_extension::UncheckedFrom; #[pallet::pallet] @@ -61,7 +74,9 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type NodeRepository: NodeRepository; // todo: get rid of tight coupling with nodes-pallet type StakingVisitor: StakingVisitor; + type StakerCreator: StakerCreator>; type Currency: LockableCurrency; + type WeightInfo: WeightInfo; } #[pallet::event] @@ -80,16 +95,18 @@ pub mod pallet { ClusterDoesNotExist, ClusterParamsExceedsLimit, AttemptToAddNonExistentNode, + AttemptToAddAlreadyAssignedNode, AttemptToRemoveNonExistentNode, - NodeIsAlreadyAssigned, - NodeIsNotAssigned, + AttemptToRemoveNotAssignedNode, OnlyClusterManager, NodeIsNotAuthorized, - NodeHasNoStake, + NodeHasNoActivatedStake, NodeStakeIsInvalid, /// Cluster candidate should not plan to chill. NodeChillingIsProhibited, NodeAuthContractCallFailed, + NodeAuthContractDeployFailed, + NodeAuthNodeAuthorizationNotSuccessful, } #[pallet::storage] @@ -114,12 +131,66 @@ pub mod pallet { OptionQuery, >; + #[pallet::genesis_config] + pub struct GenesisConfig { + pub clusters: Vec>, + #[allow(clippy::type_complexity)] + pub clusters_gov_params: Vec<(ClusterId, ClusterGovParams, T::BlockNumber>)>, + pub clusters_nodes: Vec<(ClusterId, Vec)>, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { + clusters: Default::default(), + clusters_gov_params: Default::default(), + clusters_nodes: Default::default(), + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig + where + T::AccountId: UncheckedFrom + AsRef<[u8]>, + { + fn build(&self) { + for cluster in &self.clusters { + assert_ok!(Pallet::::create_cluster( + frame_system::Origin::::Root.into(), + cluster.cluster_id, + cluster.manager_id.clone(), + cluster.reserve_id.clone(), + ClusterParams:: { + node_provider_auth_contract: cluster + .props + .node_provider_auth_contract + .clone(), + }, + self.clusters_gov_params + .iter() + .find(|(id, _)| id == &cluster.cluster_id) + .unwrap() + .1 + .clone(), + )); + + for (cluster_id, nodes) in &self.clusters_nodes { + for node_pub_key in nodes { + >::insert(cluster_id, node_pub_key, true); + } + } + } + } + } + #[pallet::call] impl Pallet where T::AccountId: UncheckedFrom + AsRef<[u8]>, { - #[pallet::weight(10_000)] + #[pallet::weight(::WeightInfo::create_cluster())] pub fn create_cluster( origin: OriginFor, cluster_id: ClusterId, @@ -129,19 +200,16 @@ pub mod pallet { cluster_gov_params: ClusterGovParams, T::BlockNumber>, ) -> DispatchResult { ensure_root(origin)?; // requires Governance approval - let cluster = - Cluster::new(cluster_id, cluster_manager_id, cluster_reserve_id, cluster_params) - .map_err(Into::>::into)?; - ensure!(!Clusters::::contains_key(cluster_id), Error::::ClusterAlreadyExists); - - Clusters::::insert(cluster_id, cluster); - ClustersGovParams::::insert(cluster_id, cluster_gov_params); - Self::deposit_event(Event::::ClusterCreated { cluster_id }); - - Ok(()) + Self::do_create_cluster( + cluster_id, + cluster_manager_id, + cluster_reserve_id, + cluster_params, + cluster_gov_params, + ) } - #[pallet::weight(10_000)] + #[pallet::weight(::WeightInfo::add_node())] pub fn add_node( origin: OriginFor, cluster_id: ClusterId, @@ -150,47 +218,47 @@ pub mod pallet { let caller_id = ensure_signed(origin)?; let cluster = Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; - ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - // Node with this node with this public key exists. - let mut node = T::NodeRepository::get(node_pub_key.clone()) - .map_err(|_| Error::::AttemptToAddNonExistentNode)?; - ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAlreadyAssigned); + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); // Sufficient funds are locked at the DDC Staking module. - let has_stake = T::StakingVisitor::node_has_stake(&node_pub_key, &cluster_id) - .map_err(Into::>::into)?; - ensure!(has_stake, Error::::NodeHasNoStake); + let has_activated_stake = + T::StakingVisitor::has_activated_stake(&node_pub_key, &cluster_id) + .map_err(Into::>::into)?; + ensure!(has_activated_stake, Error::::NodeHasNoActivatedStake); // Candidate is not planning to pause operations any time soon. - let is_chilling = T::StakingVisitor::node_is_chilling(&node_pub_key) + let has_chilling_attempt = T::StakingVisitor::has_chilling_attempt(&node_pub_key) .map_err(Into::>::into)?; - ensure!(!is_chilling, Error::::NodeChillingIsProhibited); + ensure!(!has_chilling_attempt, Error::::NodeChillingIsProhibited); + + // Node with this node with this public key exists. + let node = T::NodeRepository::get(node_pub_key.clone()) + .map_err(|_| Error::::AttemptToAddNonExistentNode)?; // Cluster extension smart contract allows joining. - let auth_contract = NodeProviderAuthContract::::new( - cluster.props.node_provider_auth_contract, - caller_id, - ); - let is_authorized = auth_contract - .is_authorized( - node.get_provider_id().to_owned(), - node.get_pub_key(), - node.get_type(), - ) - .map_err(Into::>::into)?; - ensure!(is_authorized, Error::::NodeIsNotAuthorized); + if let Some(address) = cluster.props.node_provider_auth_contract { + let auth_contract = NodeProviderAuthContract::::new(address, caller_id); + + let is_authorized = auth_contract + .is_authorized( + node.get_provider_id().to_owned(), + node.get_pub_key(), + node.get_type(), + ) + .map_err(Into::>::into)?; + ensure!(is_authorized, Error::::NodeIsNotAuthorized); + }; // Add node to the cluster. - node.set_cluster_id(Some(cluster_id)); - T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; - ClustersNodes::::insert(cluster_id, node_pub_key.clone(), true); + >::add_node(&cluster_id, &node_pub_key) + .map_err(Into::>::into)?; Self::deposit_event(Event::::ClusterNodeAdded { cluster_id, node_pub_key }); Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(::WeightInfo::remove_node())] pub fn remove_node( origin: OriginFor, cluster_id: ClusterId, @@ -199,21 +267,19 @@ pub mod pallet { let caller_id = ensure_signed(origin)?; let cluster = Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - let mut node = T::NodeRepository::get(node_pub_key.clone()) - .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; - ensure!(node.get_cluster_id() == &Some(cluster_id), Error::::NodeIsNotAssigned); - node.set_cluster_id(None); - T::NodeRepository::update(node) - .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; - ClustersNodes::::remove(cluster_id, node_pub_key.clone()); + + // Remove node from the cluster. + >::remove_node(&cluster_id, &node_pub_key) + .map_err(Into::>::into)?; Self::deposit_event(Event::::ClusterNodeRemoved { cluster_id, node_pub_key }); Ok(()) } // Sets Governance non-sensetive parameters only - #[pallet::weight(10_000)] + #[pallet::weight(::WeightInfo::set_cluster_params())] pub fn set_cluster_params( origin: OriginFor, cluster_id: ClusterId, @@ -231,7 +297,7 @@ pub mod pallet { } // Requires Governance approval - #[pallet::weight(10_000)] + #[pallet::weight(::WeightInfo::set_cluster_gov_params())] pub fn set_cluster_gov_params( origin: OriginFor, cluster_id: ClusterId, @@ -247,11 +313,28 @@ pub mod pallet { } } - impl ClusterVisitor for Pallet { - fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool { - ClustersNodes::::get(cluster_id, node_pub_key).is_some() + impl Pallet { + fn do_create_cluster( + cluster_id: ClusterId, + cluster_manager_id: T::AccountId, + cluster_reserve_id: T::AccountId, + cluster_params: ClusterParams, + cluster_gov_params: ClusterGovParams, T::BlockNumber>, + ) -> DispatchResult { + let cluster = + Cluster::new(cluster_id, cluster_manager_id, cluster_reserve_id, cluster_params) + .map_err(Into::>::into)?; + ensure!(!Clusters::::contains_key(cluster_id), Error::::ClusterAlreadyExists); + + Clusters::::insert(cluster_id, cluster); + ClustersGovParams::::insert(cluster_id, cluster_gov_params); + Self::deposit_event(Event::::ClusterCreated { cluster_id }); + + Ok(()) } + } + impl ClusterVisitor for Pallet { fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { Clusters::::get(cluster_id) .map(|_| ()) @@ -328,12 +411,96 @@ pub mod pallet { NodeType::CDN => Ok(cluster_gov_params.cdn_unbonding_delay), } } + + fn get_bonding_params( + cluster_id: &ClusterId, + ) -> Result, ClusterVisitorError> { + let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) + .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; + Ok(ClusterBondingParams { + cdn_bond_size: cluster_gov_params.cdn_bond_size.saturated_into::(), + cdn_chill_delay: cluster_gov_params.cdn_chill_delay, + cdn_unbonding_delay: cluster_gov_params.cdn_unbonding_delay, + storage_bond_size: cluster_gov_params.storage_bond_size.saturated_into::(), + storage_chill_delay: cluster_gov_params.storage_chill_delay, + storage_unbonding_delay: cluster_gov_params.storage_unbonding_delay, + }) + } + } + + impl ClusterManager for Pallet { + fn contains_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool { + ClustersNodes::::get(cluster_id, node_pub_key).is_some() + } + + fn add_node( + cluster_id: &ClusterId, + node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError> { + let mut node = T::NodeRepository::get(node_pub_key.clone()) + .map_err(|_| ClusterManagerError::AttemptToAddNonExistentNode)?; + + ensure!( + node.get_cluster_id().is_none(), + ClusterManagerError::AttemptToAddAlreadyAssignedNode + ); + + node.set_cluster_id(Some(*cluster_id)); + T::NodeRepository::update(node) + .map_err(|_| ClusterManagerError::AttemptToAddNonExistentNode)?; + + ClustersNodes::::insert(cluster_id, node_pub_key.clone(), true); + + Ok(()) + } + + fn remove_node( + cluster_id: &ClusterId, + node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError> { + let mut node = T::NodeRepository::get(node_pub_key.clone()) + .map_err(|_| ClusterManagerError::AttemptToRemoveNonExistentNode)?; + + ensure!( + node.get_cluster_id() == &Some(*cluster_id), + ClusterManagerError::AttemptToRemoveNotAssignedNode + ); + + node.set_cluster_id(None); + T::NodeRepository::update(node) + .map_err(|_| ClusterManagerError::AttemptToRemoveNonExistentNode)?; + + ClustersNodes::::remove(cluster_id, node_pub_key.clone()); + + Ok(()) + } + } + + impl ClusterCreator> for Pallet + where + T::AccountId: UncheckedFrom + AsRef<[u8]>, + { + fn create_new_cluster( + cluster_id: ClusterId, + cluster_manager_id: T::AccountId, + cluster_reserve_id: T::AccountId, + cluster_params: ClusterParams, + cluster_gov_params: ClusterGovParams, T::BlockNumber>, + ) -> DispatchResult { + Self::do_create_cluster( + cluster_id, + cluster_manager_id, + cluster_reserve_id, + cluster_params, + cluster_gov_params, + ) + } } impl From for Error { fn from(error: StakingVisitorError) -> Self { match error { - StakingVisitorError::NodeStakeDoesNotExist => Error::::NodeHasNoStake, + StakingVisitorError::NodeStakeDoesNotExist => Error::::NodeHasNoActivatedStake, StakingVisitorError::NodeStakeIsInBadState => Error::::NodeStakeIsInvalid, } } @@ -344,6 +511,25 @@ pub mod pallet { match error { NodeProviderAuthContractError::ContractCallFailed => Error::::NodeAuthContractCallFailed, + NodeProviderAuthContractError::ContractDeployFailed => + Error::::NodeAuthContractDeployFailed, + NodeProviderAuthContractError::NodeAuthorizationNotSuccessful => + Error::::NodeAuthNodeAuthorizationNotSuccessful, + } + } + } + + impl From for Error { + fn from(error: ClusterManagerError) -> Self { + match error { + ClusterManagerError::AttemptToRemoveNotAssignedNode => + Error::::AttemptToRemoveNotAssignedNode, + ClusterManagerError::AttemptToRemoveNonExistentNode => + Error::::AttemptToRemoveNonExistentNode, + ClusterManagerError::AttemptToAddNonExistentNode => + Error::::AttemptToAddNonExistentNode, + ClusterManagerError::AttemptToAddAlreadyAssignedNode => + Error::::AttemptToAddAlreadyAssignedNode, } } } diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs index b6c2e4fd2..d9beb473d 100644 --- a/pallets/ddc-clusters/src/mock.rs +++ b/pallets/ddc-clusters/src/mock.rs @@ -4,7 +4,7 @@ use crate::{self as pallet_ddc_clusters, *}; use ddc_primitives::{ClusterId, NodePubKey}; -use ddc_traits::staking::{StakingVisitor, StakingVisitorError}; +use ddc_traits::staking::{StakerCreator, StakingVisitor, StakingVisitorError}; use frame_support::{ construct_runtime, parameter_types, traits::{ConstU32, ConstU64, Everything, Nothing}, @@ -19,7 +19,7 @@ use sp_runtime::{ traits::{ BlakeTwo256, Convert, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify, }, - MultiSignature, + MultiSignature, Perquintill, }; /// The AccountId alias in this test module. @@ -181,6 +181,8 @@ impl pallet_timestamp::Config for Test { impl pallet_ddc_nodes::Config for Test { type RuntimeEvent = RuntimeEvent; + type StakingVisitor = TestStakingVisitor; + type WeightInfo = (); } impl crate::pallet::Config for Test { @@ -188,27 +190,46 @@ impl crate::pallet::Config for Test { type Currency = Balances; type NodeRepository = DdcNodes; type StakingVisitor = TestStakingVisitor; + type StakerCreator = TestStaker; + type WeightInfo = (); } pub(crate) type DdcStakingCall = crate::Call; pub(crate) type TestRuntimeCall = ::RuntimeCall; pub struct TestStakingVisitor; +pub struct TestStaker; + impl StakingVisitor for TestStakingVisitor { - fn node_has_stake( + fn has_activated_stake( _node_pub_key: &NodePubKey, _cluster_id: &ClusterId, ) -> Result { Ok(true) } - fn node_is_chilling(_node_pub_key: &NodePubKey) -> Result { + fn has_stake(_node_pub_key: &NodePubKey) -> bool { + true + } + fn has_chilling_attempt(_node_pub_key: &NodePubKey) -> Result { Ok(false) } } +impl StakerCreator> for TestStaker { + fn bond_stake_and_participate( + _stash: T::AccountId, + _controller: T::AccountId, + _node: NodePubKey, + _value: BalanceOf, + _cluster_id: ClusterId, + ) -> sp_runtime::DispatchResult { + Ok(()) + } +} + pub struct ExtBuilder; impl ExtBuilder { - fn build(self) -> TestExternalities { + pub fn build(self) -> TestExternalities { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); @@ -222,6 +243,41 @@ impl ExtBuilder { } .assimilate_storage(&mut storage); + let cluster_gov_params = ClusterGovParams { + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([0; 32])); + + // For testing purposes only + pallet_ddc_clusters::GenesisConfig::::default().build(); + + if let Ok(cluster) = Cluster::new( + ClusterId::from([0; 20]), + AccountId::from([0; 32]), + AccountId::from([0; 32]), + ClusterParams { node_provider_auth_contract: Some(AccountId::from([0; 32])) }, + ) { + let _ = pallet_ddc_clusters::GenesisConfig:: { + clusters: vec![cluster], + clusters_gov_params: vec![(ClusterId::from([0; 20]), cluster_gov_params)], + clusters_nodes: vec![(ClusterId::from([0; 20]), vec![node_pub_key])], + } + .assimilate_storage(&mut storage); + } + TestExternalities::new(storage) } pub fn build_and_execute(self, test: impl FnOnce()) { diff --git a/pallets/ddc-clusters/src/node_provider_auth.rs b/pallets/ddc-clusters/src/node_provider_auth.rs index e3f038818..d73e45628 100644 --- a/pallets/ddc-clusters/src/node_provider_auth.rs +++ b/pallets/ddc-clusters/src/node_provider_auth.rs @@ -2,8 +2,10 @@ use crate::Config; use codec::Encode; use ddc_primitives::{NodePubKey, NodeType}; use frame_support::weights::Weight; +use hex_literal::hex; use pallet_contracts::chain_extension::UncheckedFrom; -use sp_std::prelude::Vec; +use sp_runtime::traits::Hash; +use sp_std::{prelude::Vec, vec}; /// ink! 4.x selector for the "is_authorized" message, equals to the first four bytes of the /// blake2("is_authorized"). See also: https://use.ink/basics/selectors#selector-calculation/, @@ -15,7 +17,7 @@ const INK_SELECTOR_IS_AUTHORIZED: [u8; 4] = [0x96, 0xb0, 0x45, 0x3e]; const EXTENSION_CALL_GAS_LIMIT: Weight = Weight::from_ref_time(5_000_000_000_000); pub struct NodeProviderAuthContract { - contract_id: T::AccountId, + pub contract_id: T::AccountId, caller_id: T::AccountId, } @@ -59,6 +61,72 @@ where Ok(is_authorized) } + pub fn deploy_contract( + &self, + caller_id: T::AccountId, + ) -> Result { + pub const CTOR_SELECTOR: [u8; 4] = hex!("9bae9d5e"); + + fn encode_constructor() -> Vec { + let mut call_data = CTOR_SELECTOR.to_vec(); + let x = 0_u128; + for _ in 0..9 { + x.encode_to(&mut call_data); + } + call_data + } + + // Load the contract code. + let wasm = &include_bytes!("./test_data/node_provider_auth_white_list.wasm")[..]; + let _wasm_hash = ::Hashing::hash(wasm); + let contract_args = encode_constructor(); + + // Deploy the contract. + let contract_id = pallet_contracts::Pallet::::bare_instantiate( + caller_id.clone(), + Default::default(), + EXTENSION_CALL_GAS_LIMIT, + None, + wasm.into(), + contract_args, + vec![], + false, + ) + .result + .map_err(|_| NodeProviderAuthContractError::ContractDeployFailed)? + .account_id; + + Ok(Self::new(contract_id, caller_id)) + } + + pub fn authorize_node( + &self, + node_pub_key: NodePubKey, + ) -> Result { + pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("7a04093d"); + + let call_data = { + // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool + let args: ([u8; 4], Vec) = + (ADD_DDC_NODE_SELECTOR, node_pub_key.encode()[1..].to_vec()); + args.encode() + }; + + let _ = pallet_contracts::Pallet::::bare_call( + self.caller_id.clone(), + self.contract_id.clone(), + Default::default(), + EXTENSION_CALL_GAS_LIMIT, + None, + call_data, + false, + ) + .result + .map_err(|_| NodeProviderAuthContractError::NodeAuthorizationNotSuccessful)?; + + Ok(true) + } + pub fn new(contract_id: T::AccountId, caller_id: T::AccountId) -> Self { Self { contract_id, caller_id } } @@ -66,4 +134,6 @@ where pub enum NodeProviderAuthContractError { ContractCallFailed, + ContractDeployFailed, + NodeAuthorizationNotSuccessful, } diff --git a/pallets/ddc-clusters/src/testing_utils.rs b/pallets/ddc-clusters/src/testing_utils.rs new file mode 100644 index 000000000..b32e9ecca --- /dev/null +++ b/pallets/ddc-clusters/src/testing_utils.rs @@ -0,0 +1,133 @@ +//! DdcStaking pallet benchmarking. + +use ddc_primitives::{ + CDNNodeParams, ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, +}; +pub use frame_benchmarking::{ + account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, + BenchmarkError, +}; +use frame_system::RawOrigin; +use pallet_contracts::chain_extension::UncheckedFrom; +use pallet_ddc_nodes::Node; +use sp_runtime::Perquintill; +use sp_std::prelude::*; + +use crate::{Pallet as DdcClusters, *}; + +pub fn config_cluster(user: T::AccountId, cluster_id: ClusterId) +where + T::AccountId: UncheckedFrom + AsRef<[u8]>, +{ + let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + cdn_bond_size: 100u32.into(), + cdn_chill_delay: 50u32.into(), + cdn_unbonding_delay: 50u32.into(), + storage_bond_size: 100u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + let _ = DdcClusters::::create_cluster( + RawOrigin::Root.into(), + cluster_id, + user.clone(), + user, + cluster_params, + cluster_gov_params, + ); +} + +pub fn config_cluster_and_node( + user: T::AccountId, + node_pub_key: NodePubKey, + cluster_id: ClusterId, +) -> Result<(), Box> +where + T::AccountId: UncheckedFrom + AsRef<[u8]>, +{ + let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + cdn_bond_size: 100u32.into(), + cdn_chill_delay: 50u32.into(), + cdn_unbonding_delay: 50u32.into(), + storage_bond_size: 100u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + let _ = DdcClusters::::create_cluster( + RawOrigin::Root.into(), + cluster_id, + user.clone(), + user.clone(), + cluster_params, + cluster_gov_params, + ); + + if let Ok(new_node) = + Node::::new(node_pub_key.clone(), user.clone(), NodeParams::CDNParams(cdn_node_params)) + { + let _ = T::NodeRepository::create(new_node); + } + + T::StakerCreator::bond_stake_and_participate( + user.clone(), + user.clone(), + node_pub_key.clone(), + 10_000u32.into(), + cluster_id, + ) + .unwrap(); + + let mut auth_contract = NodeProviderAuthContract::::new(user.clone(), user.clone()); + auth_contract = auth_contract.deploy_contract(user.clone())?; + auth_contract.authorize_node(node_pub_key)?; + + let updated_cluster_params = + ClusterParams { node_provider_auth_contract: Some(auth_contract.contract_id) }; + + // Register auth contract + let _ = DdcClusters::::set_cluster_params( + RawOrigin::Signed(user).into(), + cluster_id, + updated_cluster_params, + ); + + Ok(()) +} + +impl From for Box { + fn from(error: NodeProviderAuthContractError) -> Self { + match error { + NodeProviderAuthContractError::ContractCallFailed => + Box::new(BenchmarkError::Stop("NodeAuthContractCallFailed")), + NodeProviderAuthContractError::ContractDeployFailed => + Box::new(BenchmarkError::Stop("NodeAuthContractDeployFailed")), + NodeProviderAuthContractError::NodeAuthorizationNotSuccessful => + Box::new(BenchmarkError::Stop("NodeAuthNodeAuthorizationNotSuccessful")), + } + } +} diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index 9e87b2e49..b94627f47 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -1,18 +1,26 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_primitives::{ + CDNNodeParams, ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, + ClusterPricingParams, NodeParams, NodePubKey, +}; +use ddc_traits::cluster::ClusterManager; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; use frame_system::Config; use hex_literal::hex; -use pallet_ddc_nodes::{CDNNodeParams, NodeParams}; -use sp_runtime::{traits::Hash, AccountId32, Perquintill}; +use sp_runtime::{traits::Hash, Perquintill}; #[test] fn create_cluster_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); + let cluster_id = ClusterId::from([1; 20]); + let cluster_manager_id = AccountId::from([1; 32]); + let cluster_reserve_id = AccountId::from([2; 32]); + let auth_contract = AccountId::from([3; 32]); + let cluster_gov_params = ClusterGovParams { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), @@ -33,10 +41,10 @@ fn create_cluster_works() { assert_noop!( DdcClusters::create_cluster( RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - AccountId::from([1; 32]), - AccountId::from([2; 32]), - ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_id, + cluster_manager_id.clone(), + cluster_reserve_id.clone(), + ClusterParams { node_provider_auth_contract: Some(auth_contract.clone()) }, cluster_gov_params.clone() ), BadOrigin @@ -45,10 +53,10 @@ fn create_cluster_works() { // Creating 1 cluster should work fine assert_ok!(DdcClusters::create_cluster( RuntimeOrigin::root(), - ClusterId::from([1; 20]), - AccountId::from([1; 32]), - AccountId::from([2; 32]), - ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_id, + cluster_manager_id.clone(), + cluster_reserve_id.clone(), + ClusterParams { node_provider_auth_contract: Some(auth_contract.clone()) }, cluster_gov_params.clone() )); @@ -56,20 +64,20 @@ fn create_cluster_works() { assert_noop!( DdcClusters::create_cluster( RuntimeOrigin::root(), - ClusterId::from([1; 20]), - AccountId::from([1; 32]), - AccountId::from([2; 32]), - ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_id, + cluster_manager_id, + cluster_reserve_id, + ClusterParams { node_provider_auth_contract: Some(auth_contract) }, cluster_gov_params ), Error::::ClusterAlreadyExists ); + // Checking storage + assert!(Clusters::::contains_key(cluster_id)); // Checking that event was emitted assert_eq!(System::events().len(), 1); - System::assert_last_event( - Event::ClusterCreated { cluster_id: ClusterId::from([1; 20]) }.into(), - ) + System::assert_last_event(Event::ClusterCreated { cluster_id }.into()) }) } @@ -78,14 +86,19 @@ fn add_and_delete_node_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); + let cluster_id = ClusterId::from([1; 20]); + let cluster_manager_id = AccountId::from([1; 32]); + let cluster_reserve_id = AccountId::from([2; 32]); + let node_pub_key = AccountId::from([3; 32]); + let contract_id = deploy_contract(); // Cluster doesn't exist assert_noop!( DdcClusters::add_node( - RuntimeOrigin::signed(AccountId::from([2; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), ), Error::::ClusterDoesNotExist ); @@ -93,10 +106,10 @@ fn add_and_delete_node_works() { // Creating 1 cluster should work fine assert_ok!(DdcClusters::create_cluster( RuntimeOrigin::root(), - ClusterId::from([1; 20]), - AccountId::from([1; 32]), - AccountId::from([2; 32]), - ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_id, + cluster_manager_id.clone(), + cluster_reserve_id.clone(), + ClusterParams { node_provider_auth_contract: Some(cluster_manager_id.clone()) }, ClusterGovParams { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), @@ -117,9 +130,9 @@ fn add_and_delete_node_works() { // Not Cluster Manager assert_noop!( DdcClusters::add_node( - RuntimeOrigin::signed(AccountId::from([2; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_reserve_id), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), ), Error::::OnlyClusterManager ); @@ -127,17 +140,13 @@ fn add_and_delete_node_works() { // Node doesn't exist assert_noop!( DdcClusters::add_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), ), Error::::AttemptToAddNonExistentNode ); - // Create node - let bytes = [4u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { host: vec![1u8, 255], http_port: 35000u16, @@ -147,66 +156,71 @@ fn add_and_delete_node_works() { // Node created assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - NodePubKey::CDNPubKey(node_pub_key), + RuntimeOrigin::signed(cluster_manager_id.clone()), + NodePubKey::CDNPubKey(node_pub_key.clone()), NodeParams::CDNParams(cdn_node_params) )); // Node doesn't exist assert_noop!( DdcClusters::add_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), ), Error::::NodeAuthContractCallFailed ); // Set the correct address for auth contract assert_ok!(DdcClusters::set_cluster_params( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - cluster::ClusterParams { node_provider_auth_contract: contract_id }, + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + ClusterParams { node_provider_auth_contract: Some(contract_id) }, )); - // Node doesn't exist + // Node added succesfully assert_ok!(DdcClusters::add_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), + )); + + assert!(>::contains_node( + &cluster_id, + &NodePubKey::CDNPubKey(node_pub_key.clone()) )); // Node already assigned assert_noop!( DdcClusters::add_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), ), - Error::::NodeIsAlreadyAssigned + Error::::AttemptToAddAlreadyAssignedNode ); // Checking that event was emitted System::assert_last_event( Event::ClusterNodeAdded { - cluster_id: ClusterId::from([1; 20]), - node_pub_key: NodePubKey::CDNPubKey(AccountId::from([4; 32])), + cluster_id, + node_pub_key: NodePubKey::CDNPubKey(node_pub_key.clone()), } .into(), ); // Remove node assert_ok!(DdcClusters::remove_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key.clone()), )); // Checking that event was emitted System::assert_last_event( Event::ClusterNodeRemoved { - cluster_id: ClusterId::from([1; 20]), - node_pub_key: NodePubKey::CDNPubKey(AccountId::from([4; 32])), + cluster_id, + node_pub_key: NodePubKey::CDNPubKey(node_pub_key.clone()), } .into(), ); @@ -214,11 +228,11 @@ fn add_and_delete_node_works() { // Remove node should fail assert_noop!( DdcClusters::remove_node( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - NodePubKey::CDNPubKey(AccountId::from([4; 32])), + RuntimeOrigin::signed(cluster_manager_id), + cluster_id, + NodePubKey::CDNPubKey(node_pub_key), ), - Error::::NodeIsNotAssigned + Error::::AttemptToRemoveNotAssignedNode ); pub const CTOR_SELECTOR: [u8; 4] = hex!("9bae9d5e"); @@ -233,8 +247,10 @@ fn add_and_delete_node_works() { } fn deploy_contract() -> AccountId { + let cluster_manager_id = AccountId::from([1; 32]); + let node_pub_key = AccountId::from([3; 32]); // Admin account who deploys the contract. - let alice = AccountId::from([1; 32]); + let alice = cluster_manager_id; let _ = Balances::deposit_creating(&alice, 1_000_000_000_000); // Load the contract code. @@ -261,7 +277,7 @@ fn add_and_delete_node_works() { let contract_id = Contracts::contract_address(&alice, &wasm_hash, &[]); pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("7a04093d"); - let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([4; 32])); + let node_pub_key = NodePubKey::CDNPubKey(node_pub_key); let call_data = { // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool @@ -291,12 +307,18 @@ fn set_cluster_params_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); + let cluster_id = ClusterId::from([1; 20]); + let cluster_manager_id = AccountId::from([1; 32]); + let cluster_reserve_id = AccountId::from([2; 32]); + let auth_contract_1 = AccountId::from([3; 32]); + let auth_contract_2 = AccountId::from([4; 32]); + // Cluster doesn't exist assert_noop!( DdcClusters::set_cluster_params( - RuntimeOrigin::signed(AccountId::from([2; 32])), - ClusterId::from([2; 20]), - ClusterParams { node_provider_auth_contract: AccountId::from([2; 32]) }, + RuntimeOrigin::signed(cluster_manager_id.clone()), + cluster_id, + ClusterParams { node_provider_auth_contract: Some(auth_contract_1.clone()) }, ), Error::::ClusterDoesNotExist ); @@ -304,10 +326,10 @@ fn set_cluster_params_works() { // Creating 1 cluster should work fine assert_ok!(DdcClusters::create_cluster( RuntimeOrigin::root(), - ClusterId::from([1; 20]), - AccountId::from([1; 32]), - AccountId::from([2; 32]), - ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_id, + cluster_manager_id.clone(), + cluster_reserve_id.clone(), + ClusterParams { node_provider_auth_contract: Some(auth_contract_1) }, ClusterGovParams { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), @@ -327,24 +349,22 @@ fn set_cluster_params_works() { assert_noop!( DdcClusters::set_cluster_params( - RuntimeOrigin::signed(AccountId::from([2; 32])), - ClusterId::from([1; 20]), - ClusterParams { node_provider_auth_contract: AccountId::from([2; 32]) }, + RuntimeOrigin::signed(cluster_reserve_id), + cluster_id, + ClusterParams { node_provider_auth_contract: Some(auth_contract_2.clone()) }, ), Error::::OnlyClusterManager ); assert_ok!(DdcClusters::set_cluster_params( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), - ClusterParams { node_provider_auth_contract: AccountId::from([2; 32]) }, + RuntimeOrigin::signed(cluster_manager_id), + cluster_id, + ClusterParams { node_provider_auth_contract: Some(auth_contract_2) }, )); // Checking that event was emitted assert_eq!(System::events().len(), 2); - System::assert_last_event( - Event::ClusterParamsSet { cluster_id: ClusterId::from([1; 20]) }.into(), - ) + System::assert_last_event(Event::ClusterParamsSet { cluster_id }.into()) }) } @@ -353,6 +373,11 @@ fn set_cluster_gov_params_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); + let cluster_id = ClusterId::from([1; 20]); + let cluster_manager_id = AccountId::from([1; 32]); + let cluster_reserve_id = AccountId::from([2; 32]); + let auth_contract = AccountId::from([3; 32]); + let cluster_gov_params = ClusterGovParams { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), @@ -373,7 +398,7 @@ fn set_cluster_gov_params_works() { assert_noop!( DdcClusters::set_cluster_gov_params( RuntimeOrigin::root(), - ClusterId::from([2; 20]), + cluster_id, cluster_gov_params.clone() ), Error::::ClusterDoesNotExist @@ -381,17 +406,17 @@ fn set_cluster_gov_params_works() { assert_ok!(DdcClusters::create_cluster( RuntimeOrigin::root(), - ClusterId::from([1; 20]), - AccountId::from([1; 32]), - AccountId::from([2; 32]), - ClusterParams { node_provider_auth_contract: AccountId::from([1; 32]) }, + cluster_id, + cluster_manager_id.clone(), + cluster_reserve_id, + ClusterParams { node_provider_auth_contract: Some(auth_contract) }, cluster_gov_params.clone() )); assert_noop!( DdcClusters::set_cluster_gov_params( - RuntimeOrigin::signed(AccountId::from([1; 32])), - ClusterId::from([1; 20]), + RuntimeOrigin::signed(cluster_manager_id), + cluster_id, cluster_gov_params.clone() ), BadOrigin @@ -399,14 +424,163 @@ fn set_cluster_gov_params_works() { assert_ok!(DdcClusters::set_cluster_gov_params( RuntimeOrigin::root(), - ClusterId::from([1; 20]), + cluster_id, cluster_gov_params )); // Checking that event was emitted assert_eq!(System::events().len(), 2); - System::assert_last_event( - Event::ClusterGovParamsSet { cluster_id: ClusterId::from([1; 20]) }.into(), - ) + System::assert_last_event(Event::ClusterGovParamsSet { cluster_id }.into()) + }) +} + +#[test] +fn cluster_visitor_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + let cluster_manager_id = AccountId::from([1; 32]); + let cluster_reserve_id = AccountId::from([2; 32]); + let auth_contract = AccountId::from([3; 32]); + + let cluster_gov_params = ClusterGovParams { + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + // Creating 1 cluster should work fine + assert_ok!(DdcClusters::create_cluster( + RuntimeOrigin::root(), + cluster_id, + cluster_manager_id, + cluster_reserve_id.clone(), + ClusterParams { node_provider_auth_contract: Some(auth_contract) }, + cluster_gov_params + )); + + assert_ok!(>::ensure_cluster(&cluster_id)); + + assert_eq!( + >::get_bond_size(&cluster_id, NodeType::CDN) + .unwrap(), + 100u128 + ); + assert_eq!( + >::get_bond_size(&cluster_id, NodeType::Storage) + .unwrap(), + 100u128 + ); + + assert_eq!( + >::get_pricing_params(&cluster_id).unwrap(), + ClusterPricingParams { + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + } + ); + + assert_eq!( + >::get_fees_params(&cluster_id).unwrap(), + ClusterFeesParams { + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02) + } + ); + + assert_eq!( + >::get_reserve_account_id(&cluster_id).unwrap(), + cluster_reserve_id + ); + + assert_eq!( + >::get_chill_delay(&cluster_id, NodeType::CDN) + .unwrap(), + 50 + ); + assert_eq!( + >::get_chill_delay(&cluster_id, NodeType::Storage) + .unwrap(), + 50 + ); + + assert_eq!( + >::get_unbonding_delay(&cluster_id, NodeType::CDN) + .unwrap(), + 50 + ); + assert_eq!( + >::get_unbonding_delay( + &cluster_id, + NodeType::Storage + ) + .unwrap(), + 50 + ); + + assert_eq!( + >::get_bonding_params(&cluster_id).unwrap(), + ClusterBondingParams::<::BlockNumber> { + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + } + ); + }) +} + +#[test] +fn cluster_creator_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + let cluster_manager_id = AccountId::from([1; 32]); + let cluster_reserve_id = AccountId::from([2; 32]); + let auth_contract = AccountId::from([3; 32]); + + let cluster_gov_params = ClusterGovParams { + treasury_share: Perquintill::from_float(0.05), + validators_share: Perquintill::from_float(0.01), + cluster_reserve_share: Perquintill::from_float(0.02), + cdn_bond_size: 100, + cdn_chill_delay: 50, + cdn_unbonding_delay: 50, + storage_bond_size: 100, + storage_chill_delay: 50, + storage_unbonding_delay: 50, + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + assert_ok!(>>::create_new_cluster( + cluster_id, + cluster_manager_id, + cluster_reserve_id, + ClusterParams { node_provider_auth_contract: Some(auth_contract) }, + cluster_gov_params + )); + + assert!(Clusters::::contains_key(cluster_id)); + assert!(ClustersGovParams::::contains_key(cluster_id)); }) } diff --git a/pallets/ddc-clusters/src/weights.rs b/pallets/ddc-clusters/src/weights.rs new file mode 100644 index 000000000..96e4b735f --- /dev/null +++ b/pallets/ddc-clusters/src/weights.rs @@ -0,0 +1,155 @@ + +//! Autogenerated weights for `pallet_ddc_clusters` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Raids-MacBook-Pro-2.local`, CPU: `` +//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/cere +// benchmark +// pallet +// --chain +// dev +// --pallet +// pallet_ddc_clusters +// --extrinsic +// * +// --steps +// 20 +// --repeat +// 50 +// --output +// pallets/ddc-clusters/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_ddc_clusters. +pub trait WeightInfo { + fn create_cluster() -> Weight; + fn add_node() -> Weight; + fn remove_node() -> Weight; + fn set_cluster_params() -> Weight; + fn set_cluster_gov_params() -> Weight; +} + +/// Weight functions for `pallet_ddc_clusters`. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: DdcClusters Clusters (r:1 w:1) + // Storage: DdcClusters ClustersGovParams (r:0 w:1) + fn create_cluster() -> Weight { + // Minimum execution time: 14_000 nanoseconds. + Weight::from_ref_time(15_000_000u64) + .saturating_add(T::DbWeight::get().reads(1u64)) + .saturating_add(T::DbWeight::get().writes(2u64)) + } + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:0) + // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Bonded (r:1 w:0) + // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: System Account (r:1 w:0) + // Storage: Contracts ContractInfoOf (r:1 w:1) + // Storage: Contracts CodeStorage (r:1 w:0) + // Storage: Timestamp Now (r:1 w:0) + // Storage: System EventTopics (r:2 w:2) + // Storage: DdcClusters ClustersNodes (r:0 w:1) + // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) + // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) + fn add_node() -> Weight { + // Minimum execution time: 307_000 nanoseconds. + Weight::from_ref_time(354_000_000u64) + .saturating_add(T::DbWeight::get().reads(15u64)) + .saturating_add(T::DbWeight::get().writes(5u64)) + } + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcClusters ClustersNodes (r:0 w:1) + fn remove_node() -> Weight { + // Minimum execution time: 23_000 nanoseconds. + Weight::from_ref_time(24_000_000u64) + .saturating_add(T::DbWeight::get().reads(2u64)) + .saturating_add(T::DbWeight::get().writes(2u64)) + } + // Storage: DdcClusters Clusters (r:1 w:1) + fn set_cluster_params() -> Weight { + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000u64) + .saturating_add(T::DbWeight::get().reads(1u64)) + .saturating_add(T::DbWeight::get().writes(1u64)) + } + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:0 w:1) + fn set_cluster_gov_params() -> Weight { + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000u64) + .saturating_add(T::DbWeight::get().reads(1u64)) + .saturating_add(T::DbWeight::get().writes(1u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: DdcClusters Clusters (r:1 w:1) + // Storage: DdcClusters ClustersGovParams (r:0 w:1) + fn create_cluster() -> Weight { + // Minimum execution time: 14_000 nanoseconds. + Weight::from_ref_time(15_000_000u64) + .saturating_add(RocksDbWeight::get().reads(1u64)) + .saturating_add(RocksDbWeight::get().writes(2u64)) + } + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:0) + // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Bonded (r:1 w:0) + // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: System Account (r:1 w:0) + // Storage: Contracts ContractInfoOf (r:1 w:1) + // Storage: Contracts CodeStorage (r:1 w:0) + // Storage: Timestamp Now (r:1 w:0) + // Storage: System EventTopics (r:2 w:2) + // Storage: DdcClusters ClustersNodes (r:0 w:1) + // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) + // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) + fn add_node() -> Weight { + // Minimum execution time: 307_000 nanoseconds. + Weight::from_ref_time(354_000_000u64) + .saturating_add(RocksDbWeight::get().reads(15u64)) + .saturating_add(RocksDbWeight::get().writes(5u64)) + } + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcClusters ClustersNodes (r:0 w:1) + fn remove_node() -> Weight { + // Minimum execution time: 23_000 nanoseconds. + Weight::from_ref_time(24_000_000u64) + .saturating_add(RocksDbWeight::get().reads(2u64)) + .saturating_add(RocksDbWeight::get().writes(2u64)) + } + // Storage: DdcClusters Clusters (r:1 w:1) + fn set_cluster_params() -> Weight { + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000u64) + .saturating_add(RocksDbWeight::get().reads(1u64)) + .saturating_add(RocksDbWeight::get().writes(1u64)) + } + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:0 w:1) + fn set_cluster_gov_params() -> Weight { + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000u64) + .saturating_add(RocksDbWeight::get().reads(1u64)) + .saturating_add(RocksDbWeight::get().writes(1u64)) + } +} \ No newline at end of file diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index b7191864e..93f1c2ddd 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -4,21 +4,29 @@ version = "0.1.0" edition = "2021" [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } -ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +# 3rd Party +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +log = { version = "0.4.17", default-features = false } +rand_chacha = { version = "0.2", default-features = false, optional = true } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } + +# Cere +ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } + [dev-dependencies] +frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -29,7 +37,15 @@ std = [ "ddc-primitives/std", "frame-support/std", "frame-system/std", + "frame-benchmarking?/std", "scale-info/std", "sp-runtime/std", "sp-std/std", ] +runtime-benchmarks = [ + "ddc-primitives/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] diff --git a/pallets/ddc-customers/src/benchmarking.rs b/pallets/ddc-customers/src/benchmarking.rs new file mode 100644 index 000000000..84d16daec --- /dev/null +++ b/pallets/ddc-customers/src/benchmarking.rs @@ -0,0 +1,153 @@ +//! DdcStaking pallet benchmarking. +#![cfg(feature = "runtime-benchmarks")] + +use super::*; +use crate::Pallet as DdcCustomers; +use ddc_primitives::{ClusterGovParams, ClusterId, ClusterParams}; +use frame_benchmarking::{account, benchmarks, whitelist_account}; +use frame_support::traits::Currency; +use sp_runtime::Perquintill; +use sp_std::prelude::*; + +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +use frame_system::{Pallet as System, RawOrigin}; + +const USER_SEED: u32 = 999666; + +benchmarks! { + create_bucket { + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + cdn_bond_size: 100u32.into(), + cdn_chill_delay: 50u32.into(), + cdn_unbonding_delay: 50u32.into(), + storage_bond_size: 100u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + + let _ = ::ClusterCreator::create_new_cluster( + ClusterId::from([1; 20]), + user.clone(), + user.clone(), + ClusterParams { node_provider_auth_contract: Some(user.clone()) }, + cluster_gov_params + ); + + whitelist_account!(user); + }: _(RawOrigin::Signed(user), cluster_id) + verify { + assert_eq!(Pallet::::buckets_count(), 1); + } + + deposit { + let user = account::("user", USER_SEED, 0u32); + let balance = ::Currency::minimum_balance() * 100u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let amount = ::Currency::minimum_balance() * 50u32.into(); + + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), amount) + verify { + assert!(Ledger::::contains_key(user)); + } + + deposit_extra { + let user = account::("user", USER_SEED, 0u32); + let balance = ::Currency::minimum_balance() * 200u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let amount = ::Currency::minimum_balance() * 50u32.into(); + + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), amount) + verify { + assert!(Ledger::::contains_key(user)); + } + + unlock_deposit { + let user = account::("user", USER_SEED, 0u32); + let balance = ::Currency::minimum_balance() * 200u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let amount = ::Currency::minimum_balance() * 50u32.into(); + + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + + whitelist_account!(user); + }: unlock_deposit(RawOrigin::Signed(user.clone()), amount) + verify { + assert!(Ledger::::contains_key(user)); + } + + // Worst case scenario, 31/32 chunks unlocked after the unlocking duration + withdraw_unlocked_deposit_update { + + System::::set_block_number(1u32.into()); + + let user = account::("user", USER_SEED, 0u32); + let balance = ::Currency::minimum_balance() * 2000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let amount = ::Currency::minimum_balance() * 32u32.into(); + + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + + for _k in 1 .. 32 { + let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); + } + + System::::set_block_number(5256001u32.into()); + + whitelist_account!(user); + }: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) + verify { + let ledger = Ledger::::try_get(user).unwrap(); + assert_eq!(ledger.active, amount / 32u32.into()); + } + + // Worst case scenario, everything is removed after the unlocking duration + withdraw_unlocked_deposit_kill { + + System::::set_block_number(1u32.into()); + + let user = account::("user", USER_SEED, 0u32); + let user2 = account::("user", USER_SEED, 1u32); + let balance = ::Currency::minimum_balance() * 2000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = ::Currency::make_free_balance_be(&user2, balance); + let amount = ::Currency::minimum_balance() * 32u32.into(); + + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + // To keep the balance of pallet positive + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user2).into(), amount); + + + for _k in 1 .. 33 { + let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); + } + + System::::set_block_number(5256001u32.into()); + + whitelist_account!(user); + }: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) + verify { + assert!(!Ledger::::contains_key(user)); + } + + impl_benchmark_test_suite!( + DdcCustomers, + crate::mock::ExtBuilder.build(), + crate::mock::Test, + ); +} diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 90e5c3939..3c3d72d69 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -1,6 +1,12 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +pub mod weights; +use crate::weights::WeightInfo; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; + #[cfg(test)] pub(crate) mod mock; #[cfg(test)] @@ -9,7 +15,10 @@ mod tests; use codec::{Decode, Encode, HasCompact}; use ddc_primitives::{BucketId, ClusterId}; -use ddc_traits::{cluster::ClusterVisitor, customer::CustomerCharger}; +use ddc_traits::{ + cluster::{ClusterCreator, ClusterVisitor}, + customer::{CustomerCharger, CustomerDepositor}, +}; use frame_support::{ parameter_types, traits::{Currency, DefensiveSaturating, ExistenceRequirement}, @@ -132,6 +141,8 @@ pub mod pallet { #[pallet::constant] type UnlockingDelay: Get<::BlockNumber>; type ClusterVisitor: ClusterVisitor; + type ClusterCreator: ClusterCreator>; + type WeightInfo: WeightInfo; } /// Map from all (unlocked) "owner" accounts to the info regarding the staking. @@ -200,6 +211,8 @@ pub mod pallet { ArithmeticOverflow, // Arithmetic underflow ArithmeticUnderflow, + // Transferring balance to pallet's vault has failed + TransferFailed, } #[pallet::genesis_config] @@ -222,7 +235,7 @@ pub mod pallet { /// Create new bucket with specified cluster id /// /// Anyone can create a bucket - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::create_bucket())] pub fn create_bucket(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = @@ -249,34 +262,13 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the owner account. /// /// Emits `Deposited`. - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::deposit())] pub fn deposit( origin: OriginFor, #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let owner = ensure_signed(origin)?; - - if >::contains_key(&owner) { - Err(Error::::AlreadyPaired)? - } - - // Reject a deposit which is considered to be _dust_. - if value < ::Currency::minimum_balance() { - Err(Error::::InsufficientDeposit)? - } - - frame_system::Pallet::::inc_consumers(&owner).map_err(|_| Error::::BadState)?; - - let owner_balance = ::Currency::free_balance(&owner); - let value = value.min(owner_balance); - let item = AccountsLedger { - owner: owner.clone(), - total: value, - active: value, - unlocking: Default::default(), - }; - Self::update_ledger_and_deposit(&owner, &item)?; - Self::deposit_event(Event::::Deposited(owner, value)); + >::deposit(owner, value.saturated_into())?; Ok(()) } @@ -286,32 +278,13 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the owner. /// /// Emits `Deposited`. - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::deposit_extra())] pub fn deposit_extra( origin: OriginFor, #[pallet::compact] max_additional: BalanceOf, ) -> DispatchResult { let owner = ensure_signed(origin)?; - - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; - - let owner_balance = ::Currency::free_balance(&owner); - let extra = owner_balance.min(max_additional); - ledger.total = - ledger.total.checked_add(&extra).ok_or(Error::::ArithmeticOverflow)?; - ledger.active = - ledger.active.checked_add(&extra).ok_or(Error::::ArithmeticOverflow)?; - - // Last check: the new active amount of ledger must be more than ED. - ensure!( - ledger.active >= ::Currency::minimum_balance(), - Error::::InsufficientDeposit - ); - - Self::update_ledger_and_deposit(&owner, &ledger)?; - - Self::deposit_event(Event::::Deposited(owner, extra)); - + >::deposit_extra(owner, max_additional.saturated_into())?; Ok(()) } @@ -331,7 +304,7 @@ pub mod pallet { /// Emits `InitialDepositUnlock`. /// /// See also [`Call::withdraw_unlocked_deposit`]. - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::unlock_deposit())] pub fn unlock_deposit( origin: OriginFor, #[pallet::compact] value: BalanceOf, @@ -392,15 +365,15 @@ pub mod pallet { /// Emits `Withdrawn`. /// /// See also [`Call::unlock_deposit`]. - #[pallet::weight(10_000)] - pub fn withdraw_unlocked_deposit(origin: OriginFor) -> DispatchResult { + #[pallet::weight(T::WeightInfo::withdraw_unlocked_deposit_kill())] + pub fn withdraw_unlocked_deposit(origin: OriginFor) -> DispatchResultWithPostInfo { let owner = ensure_signed(origin)?; let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; let (owner, old_total) = (ledger.owner.clone(), ledger.total); let current_block = >::block_number(); ledger = ledger.consolidate_unlocked(current_block); - if ledger.unlocking.is_empty() && + let post_info_weight = if ledger.unlocking.is_empty() && ledger.active < ::Currency::minimum_balance() { log::debug!("Killing owner"); @@ -408,11 +381,15 @@ pub mod pallet { // active portion to fall below existential deposit + will have no more unlocking // chunks left. We can now safely remove all accounts-related information. Self::kill_owner(&owner)?; + // This is worst case scenario, so we use the full weight and return None + None } else { log::debug!("Updating ledger"); // This was the consequence of a partial deposit unlock. just update the ledger and // move on. >::insert(&owner, &ledger); + // This is only an update, so we use less overall weight. + Some(::WeightInfo::withdraw_unlocked_deposit_update()) }; log::debug!("Current total: {:?}", ledger.total); @@ -435,7 +412,7 @@ pub mod pallet { Self::deposit_event(Event::::Withdrawn(owner, value)); } - Ok(()) + Ok(post_info_weight.into()) } } @@ -571,4 +548,60 @@ pub mod pallet { Ok(actually_charged.saturated_into::()) } } + + impl CustomerDepositor for Pallet { + fn deposit(owner: T::AccountId, amount: u128) -> Result<(), DispatchError> { + let value = amount.saturated_into::>(); + + if >::contains_key(&owner) { + Err(Error::::AlreadyPaired)? + } + + // Reject a deposit which is considered to be _dust_. + if value < ::Currency::minimum_balance() { + Err(Error::::InsufficientDeposit)? + } + + frame_system::Pallet::::inc_consumers(&owner).map_err(|_| Error::::BadState)?; + + let owner_balance = ::Currency::free_balance(&owner); + let value = value.min(owner_balance); + let item = AccountsLedger { + owner: owner.clone(), + total: value, + active: value, + unlocking: Default::default(), + }; + + Self::update_ledger_and_deposit(&owner, &item) + .map_err(|_| Error::::TransferFailed)?; + Self::deposit_event(Event::::Deposited(owner, value)); + + Ok(()) + } + + fn deposit_extra(owner: T::AccountId, amount: u128) -> Result<(), DispatchError> { + let max_additional = amount.saturated_into::>(); + let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + + let owner_balance = ::Currency::free_balance(&owner); + let extra = owner_balance.min(max_additional); + ledger.total = + ledger.total.checked_add(&extra).ok_or(Error::::ArithmeticOverflow)?; + ledger.active = + ledger.active.checked_add(&extra).ok_or(Error::::ArithmeticOverflow)?; + + // Last check: the new active amount of ledger must be more than ED. + ensure!( + ledger.active >= ::Currency::minimum_balance(), + Error::::InsufficientDeposit + ); + + Self::update_ledger_and_deposit(&owner, &ledger) + .map_err(|_| Error::::TransferFailed)?; + Self::deposit_event(Event::::Deposited(owner, extra)); + + Ok(()) + } + } } diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 43db67e76..11af9b667 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -1,8 +1,13 @@ //! Test utilities use crate::{self as pallet_ddc_customers, *}; -use ddc_primitives::{ClusterFeesParams, ClusterPricingParams, NodePubKey, NodeType}; -use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; +use ddc_primitives::{ + ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams, + ClusterPricingParams, NodePubKey, NodeType, +}; +use ddc_traits::cluster::{ + ClusterCreator, ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError, +}; use frame_support::{ construct_runtime, parameter_types, @@ -15,7 +20,7 @@ use sp_io::TestExternalities; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, - Perquintill, + DispatchResult, Perquintill, }; /// The AccountId alias in this test module. @@ -101,13 +106,12 @@ impl crate::pallet::Config for Test { type PalletId = DdcCustomersPalletId; type RuntimeEvent = RuntimeEvent; type ClusterVisitor = TestClusterVisitor; + type ClusterCreator = TestClusterCreator; + type WeightInfo = (); } pub struct TestClusterVisitor; impl ClusterVisitor for TestClusterVisitor { - fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { - true - } fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { Ok(()) } @@ -154,12 +158,83 @@ impl ClusterVisitor for TestClusterVisitor { ) -> Result { Err(ClusterVisitorError::ClusterDoesNotExist) } + + fn get_bonding_params( + cluster_id: &ClusterId, + ) -> Result, ClusterVisitorError> { + Ok(ClusterBondingParams { + cdn_bond_size: >::get_bond_size( + cluster_id, + NodeType::CDN, + ) + .unwrap_or_default(), + cdn_chill_delay: >::get_chill_delay( + cluster_id, + NodeType::CDN, + ) + .unwrap_or_default(), + cdn_unbonding_delay: >::get_unbonding_delay( + cluster_id, + NodeType::CDN, + ) + .unwrap_or_default(), + storage_bond_size: >::get_bond_size( + cluster_id, + NodeType::Storage, + ) + .unwrap_or_default(), + storage_chill_delay: >::get_chill_delay( + cluster_id, + NodeType::Storage, + ) + .unwrap_or_default(), + storage_unbonding_delay: + >::get_unbonding_delay( + cluster_id, + NodeType::Storage, + ) + .unwrap_or_default(), + }) + } +} + +pub struct TestClusterManager; +impl ClusterManager for TestClusterManager { + fn contains_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { + true + } + fn add_node( + _cluster_id: &ClusterId, + _node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError> { + Ok(()) + } + + fn remove_node( + _cluster_id: &ClusterId, + _node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError> { + Ok(()) + } +} + +pub struct TestClusterCreator; +impl ClusterCreator for TestClusterCreator { + fn create_new_cluster( + _cluster_id: ClusterId, + _cluster_manager_id: T::AccountId, + _cluster_reserve_id: T::AccountId, + _cluster_params: ClusterParams, + _cluster_gov_params: ClusterGovParams, + ) -> DispatchResult { + Ok(()) + } } pub struct ExtBuilder; impl ExtBuilder { - fn build(self) -> TestExternalities { + pub fn build(self) -> TestExternalities { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 4c9f4f6db..a90d43482 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -2,9 +2,7 @@ use super::{mock::*, *}; use ddc_primitives::ClusterId; - use frame_support::{assert_noop, assert_ok}; -use pallet_balances::Error as BalancesError; #[test] fn create_bucket_works() { @@ -76,7 +74,7 @@ fn deposit_and_deposit_extra_works() { // Deposit all tokens fails (should not kill account) assert_noop!( DdcCustomers::deposit(RuntimeOrigin::signed(account_1), 100_u128), - BalancesError::::KeepAlive + Error::::TransferFailed ); let amount1 = 10_u128; diff --git a/pallets/ddc-customers/src/weights.rs b/pallets/ddc-customers/src/weights.rs new file mode 100644 index 000000000..66ae43d01 --- /dev/null +++ b/pallets/ddc-customers/src/weights.rs @@ -0,0 +1,132 @@ + +//! Autogenerated weights for `pallet_ddc_customers` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Raids-MacBook-Pro-2.local`, CPU: `` +//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/cere +// benchmark +// pallet +// --chain +// dev +// --pallet +// pallet_ddc_customers +// --extrinsic +// * +// --steps +// 200 +// --repeat +// 1000 +// --output +// pallets/ddc-customers/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_ddc_nodes. +pub trait WeightInfo { + fn create_bucket() -> Weight; + fn deposit() -> Weight; + fn deposit_extra() -> Weight; + fn unlock_deposit() -> Weight; + fn withdraw_unlocked_deposit_update() -> Weight; + fn withdraw_unlocked_deposit_kill() -> Weight; +} + +/// Weight functions for `pallet_ddc_customers`. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: DdcCustomers BucketsCount (r:1 w:1) + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcCustomers Buckets (r:0 w:1) + fn create_bucket() -> Weight { + Weight::from_ref_time(18_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn deposit() -> Weight { + Weight::from_ref_time(26_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn deposit_extra() -> Weight { + Weight::from_ref_time(28_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + fn unlock_deposit() -> Weight { + Weight::from_ref_time(16_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + fn withdraw_unlocked_deposit_update() -> Weight { + Weight::from_ref_time(14_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn withdraw_unlocked_deposit_kill() -> Weight { + Weight::from_ref_time(31_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: DdcCustomers BucketsCount (r:1 w:1) + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: DdcCustomers Buckets (r:0 w:1) + fn create_bucket() -> Weight { + Weight::from_ref_time(18_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn deposit() -> Weight { + Weight::from_ref_time(26_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn deposit_extra() -> Weight { + Weight::from_ref_time(28_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + fn unlock_deposit() -> Weight { + Weight::from_ref_time(16_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + fn withdraw_unlocked_deposit_update() -> Weight { + Weight::from_ref_time(14_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn withdraw_unlocked_deposit_kill() -> Weight { + Weight::from_ref_time(31_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } +} \ No newline at end of file diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 589bcc7e9..3d189469f 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } @@ -26,6 +27,7 @@ default = ["std"] std = [ "codec/std", "ddc-primitives/std", + "frame-benchmarking/std", "frame-support/std", "frame-system/std", "scale-info/std", @@ -33,3 +35,10 @@ std = [ "sp-std/std", "sp-core/std", ] +runtime-benchmarks = [ + "ddc-primitives/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] diff --git a/pallets/ddc-nodes/src/benchmarking.rs b/pallets/ddc-nodes/src/benchmarking.rs new file mode 100644 index 000000000..448cde563 --- /dev/null +++ b/pallets/ddc-nodes/src/benchmarking.rs @@ -0,0 +1,61 @@ +//! DdcStaking pallet benchmarking. + +use super::*; +use crate::{cdn_node::CDNNodeProps, Pallet as DdcNodes}; +use ddc_primitives::CDNNodePubKey; +use testing_utils::*; + +use sp_std::prelude::*; + +pub use frame_benchmarking::{ + account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, +}; +use frame_system::RawOrigin; + +const USER_SEED: u32 = 999666; + +benchmarks! { + create_node { + let (user, node, cdn_node_params, _) = create_user_and_config::("user", USER_SEED); + + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node, cdn_node_params) + verify { + assert!(CDNNodes::::contains_key(CDNNodePubKey::new([0; 32]))); + } + + delete_node { + let (user, node, cdn_node_params, _) = create_user_and_config::("user", USER_SEED); + + DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; + + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node) + verify { + assert!(!CDNNodes::::contains_key(CDNNodePubKey::new([0; 32]))); + } + + set_node_params { + let (user, node, cdn_node_params, cdn_node_params_new) = create_user_and_config::("user", USER_SEED); + + DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; + + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node, cdn_node_params_new) + verify { + assert_eq!(CDNNodes::::try_get( + CDNNodePubKey::new([0; 32])).unwrap().props, + CDNNodeProps { + host: vec![2u8, 255].try_into().unwrap(), + http_port: 45000u16, + grpc_port: 55000u16, + p2p_port: 65000u16, + }); + } + + impl_benchmark_test_suite!( + DdcNodes, + crate::mock::ExtBuilder.build(), + crate::mock::Test, + ); +} diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index eafe6cd27..43c3721f4 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,6 +1,6 @@ -use crate::node::{NodeError, NodeParams, NodeProps, NodeTrait}; +use crate::node::{NodeError, NodeProps, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, NodeType}; +use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -28,14 +28,6 @@ pub struct CDNNodeProps { pub p2p_port: u16, } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNodeParams { - pub host: Vec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, -} - impl CDNNode { pub fn new( node_pub_key: NodePubKey, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f18d724b7..f3c7f1f93 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -19,8 +19,20 @@ pub(crate) mod mock; #[cfg(test)] mod tests; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, StorageNodePubKey}; -use ddc_traits::node::{NodeVisitor, NodeVisitorError}; +pub mod weights; +use crate::weights::WeightInfo; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; +#[cfg(any(feature = "runtime-benchmarks", test))] +pub mod testing_utils; + +use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, StorageNodePubKey}; +use ddc_traits::{ + node::{NodeCreator, NodeVisitor, NodeVisitorError}, + staking::StakingVisitor, +}; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_std::prelude::*; @@ -31,8 +43,8 @@ mod node; mod storage_node; pub use crate::{ - cdn_node::{CDNNode, CDNNodeParams}, - node::{Node, NodeError, NodeParams, NodeTrait}, + cdn_node::CDNNode, + node::{Node, NodeError, NodeTrait}, storage_node::StorageNode, }; @@ -48,6 +60,8 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type StakingVisitor: StakingVisitor; + type WeightInfo: WeightInfo; } #[pallet::event] @@ -68,6 +82,7 @@ pub mod pallet { OnlyNodeProvider, NodeIsAssignedToCluster, HostLenExceedsLimit, + NodeHasDanglingStake, } #[pallet::storage] @@ -81,7 +96,7 @@ pub mod pallet { #[pallet::call] impl Pallet { - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::create_node())] pub fn create_node( origin: OriginFor, node_pub_key: NodePubKey, @@ -95,18 +110,20 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::delete_node())] pub fn delete_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { let caller_id = ensure_signed(origin)?; let node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); + let has_stake = T::StakingVisitor::has_stake(&node_pub_key); + ensure!(!has_stake, Error::::NodeHasDanglingStake); Self::delete(node_pub_key.clone()).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeDeleted { node_pub_key }); Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::set_node_params())] pub fn set_node_params( origin: OriginFor, node_pub_key: NodePubKey, @@ -129,6 +146,7 @@ pub mod pallet { fn delete(node_pub_key: NodePubKey) -> Result<(), NodeRepositoryError>; } + #[derive(Debug, PartialEq)] pub enum NodeRepositoryError { StorageNodeAlreadyExists, CDNNodeAlreadyExists, @@ -220,5 +238,22 @@ pub mod pallet { Self::get(node_pub_key.clone()).map_err(|_| NodeVisitorError::NodeDoesNotExist)?; Ok(*node.get_cluster_id()) } + + fn exists(node_pub_key: &NodePubKey) -> bool { + Self::get(node_pub_key.clone()).is_ok() + } + } + + impl NodeCreator for Pallet { + fn create_node( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> DispatchResult { + let node = Node::::new(node_pub_key, provider_id, node_params) + .map_err(Into::>::into)?; + Self::create(node).map_err(Into::>::into)?; + Ok(()) + } } } diff --git a/pallets/ddc-nodes/src/mock.rs b/pallets/ddc-nodes/src/mock.rs index 18377ac58..ca74d8af7 100644 --- a/pallets/ddc-nodes/src/mock.rs +++ b/pallets/ddc-nodes/src/mock.rs @@ -3,6 +3,7 @@ #![allow(dead_code)] use crate::{self as pallet_ddc_nodes, *}; +use ddc_traits::staking::{StakingVisitor, StakingVisitorError}; use frame_support::{ construct_runtime, parameter_types, traits::{ConstU32, ConstU64, Everything}, @@ -90,6 +91,24 @@ impl pallet_timestamp::Config for Test { impl crate::pallet::Config for Test { type RuntimeEvent = RuntimeEvent; + type StakingVisitor = TestStakingVisitor; + type WeightInfo = (); +} + +pub struct TestStakingVisitor; +impl StakingVisitor for TestStakingVisitor { + fn has_activated_stake( + _node_pub_key: &NodePubKey, + _cluster_id: &ClusterId, + ) -> Result { + Ok(false) + } + fn has_stake(_node_pub_key: &NodePubKey) -> bool { + false + } + fn has_chilling_attempt(_node_pub_key: &NodePubKey) -> Result { + Ok(false) + } } pub(crate) type TestRuntimeCall = ::RuntimeCall; @@ -97,7 +116,7 @@ pub(crate) type TestRuntimeCall = ::RuntimeCall; pub struct ExtBuilder; impl ExtBuilder { - fn build(self) -> TestExternalities { + pub fn build(self) -> TestExternalities { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 042d13be3..f0a5be5d5 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,13 +1,13 @@ #![allow(clippy::needless_lifetimes)] // ToDo use crate::{ - cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps}, + cdn_node::{CDNNode, CDNNodeProps}, pallet::Error, - storage_node::{StorageNode, StorageNodeParams, StorageNodeProps}, + storage_node::{StorageNode, StorageNodeProps}, ClusterId, }; use codec::{Decode, Encode}; -use ddc_primitives::{NodePubKey, NodeType}; +use ddc_primitives::{NodeParams, NodePubKey, NodeType}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -17,13 +17,6 @@ pub enum Node { CDN(CDNNode), } -// Params fields are always coming from extrinsic input -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum NodeParams { - StorageParams(StorageNodeParams), - CDNParams(CDNNodeParams), -} - // Props fields may include internal protocol properties #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeProps { @@ -108,6 +101,7 @@ impl NodeTrait for Node { } } +#[derive(Debug, PartialEq)] pub enum NodeError { InvalidStorageNodePubKey, InvalidCDNNodePubKey, diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 902739771..0749c044e 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,10 +1,9 @@ -use crate::node::{NodeError, NodeParams, NodeProps, NodeTrait}; +use crate::node::{NodeError, NodeProps, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{ClusterId, NodePubKey, NodeType, StorageNodePubKey}; +use ddc_primitives::{ClusterId, NodeParams, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; -use sp_std::prelude::Vec; parameter_types! { pub MaxStorageNodeParamsLen: u16 = 2048; @@ -28,14 +27,6 @@ pub struct StorageNodeProps { pub p2p_port: u16, } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct StorageNodeParams { - pub host: Vec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, -} - impl StorageNode { pub fn new( node_pub_key: NodePubKey, diff --git a/pallets/ddc-nodes/src/testing_utils.rs b/pallets/ddc-nodes/src/testing_utils.rs new file mode 100644 index 000000000..8db4dfd35 --- /dev/null +++ b/pallets/ddc-nodes/src/testing_utils.rs @@ -0,0 +1,31 @@ +//! Testing utils for ddc-staking. + +use crate::{Config, NodePubKey}; +use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams}; +use frame_benchmarking::account; +use sp_std::vec; + +const SEED: u32 = 0; + +/// Grab a funded user. +pub fn create_user_and_config( + string: &'static str, + n: u32, +) -> (T::AccountId, NodePubKey, NodeParams, NodeParams) { + let user = account(string, n, SEED); + let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let cdn_node_params = NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }); + + let cdn_node_params_new = NodeParams::CDNParams(CDNNodeParams { + host: vec![2u8, 255], + http_port: 45000u16, + grpc_port: 55000u16, + p2p_port: 65000u16, + }); + (user, node, cdn_node_params, cdn_node_params_new) +} diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index 1c5a80137..ea2c6d8af 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -1,13 +1,12 @@ //! Tests for the module. use super::{mock::*, *}; -use crate::{cdn_node::CDNNodeParams, storage_node::StorageNodeParams}; -use ddc_primitives::NodePubKey; +use ddc_primitives::{CDNNodeParams, NodePubKey, StorageNodeParams}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::AccountId32; #[test] -fn create_node_works() { +fn create_cdn_node_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); let bytes = [0u8; 32]; @@ -34,6 +33,31 @@ fn create_node_works() { Error::::InvalidNodeParams ); + // Pub key invalid + assert_noop!( + CDNNode::::new( + NodePubKey::StoragePubKey(node_pub_key.clone()), + 1u64, + NodeParams::CDNParams(cdn_node_params.clone()) + ), + NodeError::InvalidCDNNodePubKey + ); + + // Host length exceeds limit + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8; 256], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::HostLenExceedsLimit + ); + // Node created assert_ok!(DdcNodes::create_node( RuntimeOrigin::signed(1), @@ -41,6 +65,17 @@ fn create_node_works() { NodeParams::CDNParams(cdn_node_params.clone()) )); + // Check storage + assert!(CDNNodes::::contains_key(node_pub_key.clone())); + assert!(DdcNodes::exists(&NodePubKey::CDNPubKey(node_pub_key.clone()))); + if let Ok(cluster_id) = + DdcNodes::get_cluster_id(&NodePubKey::CDNPubKey(node_pub_key.clone())) + { + assert_eq!(cluster_id, None); + } + let cdn_node = DdcNodes::cdn_nodes(&node_pub_key).unwrap(); + assert_eq!(cdn_node.pub_key, node_pub_key); + // Node already exists assert_noop!( DdcNodes::create_node( @@ -60,7 +95,162 @@ fn create_node_works() { } #[test] -fn set_node_params_works() { +fn create_cdn_node_with_node_creator() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node created + assert_ok!(>::create_node( + NodePubKey::CDNPubKey(node_pub_key.clone()), + 1u64, + NodeParams::CDNParams(cdn_node_params) + )); + + // Check storage + assert!(CDNNodes::::contains_key(node_pub_key.clone())); + assert!(DdcNodes::exists(&NodePubKey::CDNPubKey(node_pub_key.clone()))); + if let Ok(cluster_id) = + DdcNodes::get_cluster_id(&NodePubKey::CDNPubKey(node_pub_key.clone())) + { + assert_eq!(cluster_id, None); + } + let cdn_node = DdcNodes::cdn_nodes(&node_pub_key).unwrap(); + assert_eq!(cdn_node.pub_key, node_pub_key); + }) +} + +#[test] +fn create_storage_node_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let storage_node_params = StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node params are not valid + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::InvalidNodeParams + ); + + // Pub key invalid + assert_noop!( + StorageNode::::new( + NodePubKey::CDNPubKey(node_pub_key.clone()), + 1u64, + NodeParams::StorageParams(storage_node_params.clone()) + ), + NodeError::InvalidStorageNodePubKey + ); + + // Host length exceeds limit + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(StorageNodeParams { + host: vec![1u8; 256], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::HostLenExceedsLimit + ); + + // Node created + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params.clone()) + )); + + // Check storage + assert!(StorageNodes::::contains_key(node_pub_key.clone())); + assert!(DdcNodes::exists(&NodePubKey::StoragePubKey(node_pub_key.clone()))); + if let Ok(cluster_id) = + DdcNodes::get_cluster_id(&NodePubKey::StoragePubKey(node_pub_key.clone())) + { + assert_eq!(cluster_id, None); + } + let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + assert_eq!(storage_node.pub_key, node_pub_key); + + // Node already exists + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params) + ), + Error::::NodeAlreadyExists + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 1); + System::assert_last_event( + Event::NodeCreated { node_pub_key: NodePubKey::StoragePubKey(node_pub_key) }.into(), + ) + }) +} + +#[test] +fn create_storage_node_with_node_creator() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let storage_node_params = StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node created + assert_ok!(>::create_node( + NodePubKey::StoragePubKey(node_pub_key.clone()), + 1u64, + NodeParams::StorageParams(storage_node_params) + )); + + // Check storage + assert!(StorageNodes::::contains_key(node_pub_key.clone())); + assert!(DdcNodes::exists(&NodePubKey::StoragePubKey(node_pub_key.clone()))); + if let Ok(cluster_id) = + DdcNodes::get_cluster_id(&NodePubKey::StoragePubKey(node_pub_key.clone())) + { + assert_eq!(cluster_id, None); + } + let cdn_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + assert_eq!(cdn_node.pub_key, node_pub_key); + }) +} + +#[test] +fn set_cdn_node_params_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); let bytes = [0u8; 32]; @@ -117,11 +307,55 @@ fn set_node_params_works() { DdcNodes::set_node_params( RuntimeOrigin::signed(2), NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) + NodeParams::CDNParams(cdn_node_params.clone()) ), Error::::OnlyNodeProvider ); + // CDN host length exceeds limit + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8; 256], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::HostLenExceedsLimit + ); + + let bytes_2 = [1u8; 32]; + let node_pub_key_2 = AccountId32::from(bytes_2); + let node = Node::::new( + NodePubKey::CDNPubKey(node_pub_key_2), + 2u64, + NodeParams::CDNParams(cdn_node_params), + ) + .unwrap(); + + // Update should fail if node doesn't exist + assert_noop!( + >::update(node), + NodeRepositoryError::CDNNodeDoesNotExist + ); + + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::CDNPubKey(node_pub_key.clone()), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8; 256], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::HostLenExceedsLimit + ); + // Checking that event was emitted assert_eq!(System::events().len(), 2); System::assert_last_event( @@ -131,7 +365,109 @@ fn set_node_params_works() { } #[test] -fn set_delete_node_works() { +fn set_storage_node_params_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let storage_node_params = StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + let cdn_node_params = CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node doesn't exist + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params.clone()) + ), + Error::::NodeDoesNotExist + ); + + // Node created + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params.clone()) + )); + + // Set node params + assert_ok!(DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params.clone()) + )); + + // Node params are not valid + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::CDNParams(cdn_node_params) + ), + Error::::InvalidNodeParams + ); + + // Only node provider can set params + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(2), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params.clone()) + ), + Error::::OnlyNodeProvider + ); + + let bytes_2 = [1u8; 32]; + let node_pub_key_2 = AccountId32::from(bytes_2); + let node = Node::::new( + NodePubKey::StoragePubKey(node_pub_key_2), + 2u64, + NodeParams::StorageParams(storage_node_params), + ) + .unwrap(); + + // Update should fail if node doesn't exist + assert_noop!( + >::update(node), + NodeRepositoryError::StorageNodeDoesNotExist + ); + + // Storage host length exceeds limit + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(StorageNodeParams { + host: vec![1u8; 256], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::HostLenExceedsLimit + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event( + Event::NodeParamsChanged { node_pub_key: NodePubKey::StoragePubKey(node_pub_key) } + .into(), + ) + }) +} + +#[test] +fn delete_cdn_node_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); let bytes = [0u8; 32]; @@ -181,3 +517,55 @@ fn set_delete_node_works() { ) }) } + +#[test] +fn delete_storage_node_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + let bytes = [0u8; 32]; + let node_pub_key = AccountId32::from(bytes); + let storage_node_params = StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + + // Node doesn't exist + assert_noop!( + DdcNodes::delete_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()) + ), + Error::::NodeDoesNotExist + ); + + // Create node + assert_ok!(DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params) + )); + + // Only node provider can delete + assert_noop!( + DdcNodes::delete_node( + RuntimeOrigin::signed(2), + NodePubKey::StoragePubKey(node_pub_key.clone()) + ), + Error::::OnlyNodeProvider + ); + + // Delete node + assert_ok!(DdcNodes::delete_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + )); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event( + Event::NodeDeleted { node_pub_key: NodePubKey::StoragePubKey(node_pub_key) }.into(), + ) + }) +} diff --git a/pallets/ddc-nodes/src/weights.rs b/pallets/ddc-nodes/src/weights.rs new file mode 100644 index 000000000..868380f40 --- /dev/null +++ b/pallets/ddc-nodes/src/weights.rs @@ -0,0 +1,83 @@ + +//! Autogenerated weights for `pallet_ddc_nodes` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Raids-MBP-2`, CPU: `` +//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/cere +// benchmark +// pallet +// --chain +// dev +// --pallet +// pallet_ddc_nodes +// --extrinsic +// * +// --steps +// 200 +// --repeat +// 1000 +// --output +// pallets/ddc-nodes/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_ddc_nodes. +pub trait WeightInfo { + fn create_node() -> Weight; + fn delete_node() -> Weight; + fn set_node_params() -> Weight; +} + +/// Weights for pallet_ddc_nodes. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: DdcNodes CDNNodes (r:1 w:1) + fn create_node() -> Weight { + Weight::from_ref_time(12_000_000u64) + .saturating_add(T::DbWeight::get().reads(1u64)) + .saturating_add(T::DbWeight::get().writes(1u64)) + } + // Storage: DdcNodes CDNNodes (r:1 w:1) + fn delete_node() -> Weight { + Weight::from_ref_time(14_000_000u64) + .saturating_add(T::DbWeight::get().reads(1u64)) + .saturating_add(T::DbWeight::get().writes(1u64)) + } + // Storage: DdcNodes CDNNodes (r:1 w:1) + fn set_node_params() -> Weight { + Weight::from_ref_time(15_000_000u64) + .saturating_add(T::DbWeight::get().reads(1u64)) + .saturating_add(T::DbWeight::get().writes(1u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: DdcNodes CDNNodes (r:1 w:1) + fn create_node() -> Weight { + Weight::from_ref_time(12_000_000u64) + .saturating_add(RocksDbWeight::get().reads(1u64)) + .saturating_add(RocksDbWeight::get().writes(1u64)) + } + // Storage: DdcNodes CDNNodes (r:1 w:1) + fn delete_node() -> Weight { + Weight::from_ref_time(14_000_000u64) + .saturating_add(RocksDbWeight::get().reads(1u64)) + .saturating_add(RocksDbWeight::get().writes(1u64)) + } + // Storage: DdcNodes CDNNodes (r:1 w:1) + fn set_node_params() -> Weight { + Weight::from_ref_time(15_000_000u64) + .saturating_add(RocksDbWeight::get().reads(1u64)) + .saturating_add(RocksDbWeight::get().writes(1u64)) + } +} \ No newline at end of file diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml index 534342060..82b5f34c7 100644 --- a/pallets/ddc-payouts/Cargo.toml +++ b/pallets/ddc-payouts/Cargo.toml @@ -42,4 +42,11 @@ std = [ "sp-core/std", "frame-election-provider-support/std", ] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] + +runtime-benchmarks = [ + "ddc-primitives/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] diff --git a/pallets/ddc-payouts/src/benchmarking.rs b/pallets/ddc-payouts/src/benchmarking.rs new file mode 100644 index 000000000..80c6528cb --- /dev/null +++ b/pallets/ddc-payouts/src/benchmarking.rs @@ -0,0 +1,500 @@ +//! DdcPayouts pallet benchmarking. + +use ddc_primitives::{ClusterGovParams, ClusterId, ClusterParams}; +pub use frame_benchmarking::{account, benchmarks, whitelist_account}; +use frame_system::RawOrigin; +use sp_runtime::Perquintill; +use sp_std::prelude::*; + +use super::*; +use crate::Pallet as DdcPayouts; + +const CERE: u128 = 10000000000; + +fn create_dac_account() -> T::AccountId { + let dac_account = create_account::("dac_account", 0, 0); + authorize_account::(dac_account.clone()); + dac_account +} + +fn create_account(name: &'static str, idx: u32, seed: u32) -> T::AccountId { + account::(name, idx, seed) +} + +fn authorize_account(account: T::AccountId) { + AuthorisedCaller::::put(account); +} + +fn endow_account(account: &T::AccountId, amount: u128) { + let balance = amount.saturated_into::>(); + let _ = T::Currency::make_free_balance_be(account, balance); +} + +fn endow_customer(customer: &T::AccountId, amount: u128) { + endow_account::(customer, amount); + T::CustomerDepositor::deposit( + customer.clone(), + // we need to keep min existensial deposit + amount - T::Currency::minimum_balance().saturated_into::(), + ) + .expect("Customer deposit failed"); +} + +fn create_cluster( + cluster_id: ClusterId, + cluster_manager_id: T::AccountId, + cluster_reserve_id: T::AccountId, + cluster_params: ClusterParams, + cluster_gov_params: ClusterGovParams, T::BlockNumber>, +) { + T::ClusterCreator::create_new_cluster( + cluster_id, + cluster_manager_id, + cluster_reserve_id, + cluster_params, + cluster_gov_params, + ) + .expect("Cluster is not created"); +} + +fn create_default_cluster(cluster_id: ClusterId) { + let cluster_manager = create_account::("cm", 0, 0); + let cluster_reserve = create_account::("cr", 0, 0); + let cluster_params = ClusterParams { node_provider_auth_contract: Default::default() }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::from_percent(5), + validators_share: Perquintill::from_percent(10), + cluster_reserve_share: Perquintill::from_percent(15), + unit_per_mb_stored: CERE, + unit_per_mb_streamed: CERE, + unit_per_put_request: CERE, + unit_per_get_request: CERE, + ..Default::default() + }; + + create_cluster::( + cluster_id, + cluster_manager, + cluster_reserve, + cluster_params, + cluster_gov_params, + ); +} + +struct BillingReportParams { + cluster_id: ClusterId, + era: DdcEra, + state: State, + total_customer_charge: CustomerCharge, + total_distributed_reward: u128, + total_node_usage: NodeUsage, + charging_max_batch_index: BatchIndex, + charging_processed_batches: BoundedBTreeSet, + rewarding_max_batch_index: BatchIndex, + rewarding_processed_batches: BoundedBTreeSet, +} + +fn create_billing_report(params: BillingReportParams) { + let vault = DdcPayouts::::sub_account_id(params.cluster_id, params.era); + let billing_report = BillingReport:: { + vault, + state: params.state, + total_customer_charge: params.total_customer_charge, + total_distributed_reward: params.total_distributed_reward, + total_node_usage: params.total_node_usage, + charging_max_batch_index: params.charging_max_batch_index, + charging_processed_batches: params.charging_processed_batches, + rewarding_max_batch_index: params.rewarding_max_batch_index, + rewarding_processed_batches: params.rewarding_processed_batches, + }; + + ActiveBillingReports::::insert(params.cluster_id, params.era, billing_report); +} + +benchmarks! { + + set_authorised_caller { + let dac_account = create_account::("dac_account", 0, 0); + + }: _(RawOrigin::Root, dac_account.clone()) + verify { + assert_eq!(AuthorisedCaller::::get(), Some(dac_account)); + } + + begin_billing_report { + + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + + create_default_cluster::(cluster_id); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era) + verify { + assert!(ActiveBillingReports::::contains_key(cluster_id, era)); + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::Initialized); + } + + begin_charging_customers { + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::Initialized; + let total_customer_charge = CustomerCharge::default(); + let total_distributed_reward : u128= 0; + let total_node_usage = NodeUsage::default(); + let charging_max_batch_index = BatchIndex::default(); + let charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + let rewarding_max_batch_index = BatchIndex::default(); + let rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge, + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + let max_batch_index: BatchIndex = 10; + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, max_batch_index) + verify { + assert!(ActiveBillingReports::::contains_key(cluster_id, era)); + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::ChargingCustomers); + assert_eq!(billing_report.charging_max_batch_index, max_batch_index); + } + + send_charging_customers_batch { + let b in 1 .. MaxBatchSize::get() as u32; + + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::ChargingCustomers; + let total_customer_charge = CustomerCharge::default(); + let total_distributed_reward : u128 = 0; + let total_node_usage = NodeUsage::default(); + let charging_max_batch_index = 0; + let charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + let rewarding_max_batch_index = BatchIndex::default(); + let rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge, + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let batch_index: BatchIndex = 0; + let payers: Vec<(T::AccountId, CustomerUsage)> = (0..b).map(|i| { + let customer = create_account::("customer", i, i); + + if b % 2 == 0 { + // no customer debt path + endow_customer::(&customer, 1_000_000 * CERE); + } else { + // customer debt path + endow_customer::(&customer, 10 * CERE); + } + + let customer_usage = CustomerUsage { + transferred_bytes: 200000000, // 200 mb + stored_bytes: 100000000, // 100 mb + number_of_gets: 10, // 10 gets + number_of_puts: 5, // 5 puts + }; + + (customer, customer_usage) + }).collect(); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, batch_index, payers) + verify { + assert!(ActiveBillingReports::::contains_key(cluster_id, era)); + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::ChargingCustomers); + assert!(billing_report.charging_processed_batches.contains(&batch_index)); + } + + end_charging_customers { + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::ChargingCustomers; + let total_customer_charge = CustomerCharge { + transfer: 200 * CERE, // price for 200 mb + storage: 100 * CERE, // price for 100 mb + gets: 10 * CERE, // price for 10 gets + puts: 5 * CERE, // price for 5 puts + }; + let total_distributed_reward : u128 = 0; + let total_node_usage = NodeUsage::default(); + let charging_max_batch_index = 0; + let mut charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + charging_processed_batches.try_insert(0).unwrap(); + let rewarding_max_batch_index = BatchIndex::default(); + let rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge: total_customer_charge.clone(), + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let vault = DdcPayouts::::sub_account_id(cluster_id, era); + let total_customer_charge_amount = total_customer_charge.transfer + total_customer_charge.storage + total_customer_charge.gets + total_customer_charge.puts; + endow_account::(&vault, total_customer_charge_amount); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era) + verify { + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::CustomersChargedWithFees); + assert!(billing_report.charging_processed_batches.contains(&charging_max_batch_index)); + } + + begin_rewarding_providers { + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::CustomersChargedWithFees; + let total_customer_charge = CustomerCharge { + transfer: 200 * CERE, // price for 200 mb + storage: 100 * CERE, // price for 100 mb + gets: 10 * CERE, // price for 10 gets + puts: 5 * CERE, // price for 5 puts + }; + let total_distributed_reward : u128 = 0; + let total_node_usage = NodeUsage::default(); + let charging_max_batch_index = 0; + let mut charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + charging_processed_batches.try_insert(0).unwrap(); + let rewarding_max_batch_index = BatchIndex::default(); + let rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge, + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let max_batch_index: BatchIndex = 10; + let total_node_usage = NodeUsage { + transferred_bytes: 200000000, // 200 mb + stored_bytes: 100000000, // 100 mb + number_of_gets: 10, // 10 gets + number_of_puts: 5, // 5 puts + }; + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, max_batch_index, total_node_usage) + verify { + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::RewardingProviders); + assert_eq!(billing_report.rewarding_max_batch_index, max_batch_index); + } + + send_rewarding_providers_batch { + let b in 1 .. MaxBatchSize::get() as u32; + + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::RewardingProviders; + let total_customer_charge = CustomerCharge { + transfer: (200 * CERE).saturating_mul(b.into()), // price for 200 mb per customer + storage: (100 * CERE).saturating_mul(b.into()), // price for 100 mb per customer + gets: (10 * CERE).saturating_mul(b.into()), // price for 10 gets per customer + puts: (5 * CERE).saturating_mul(b.into()), // price for 5 puts per customer + }; + let total_distributed_reward : u128 = 0; + let total_node_usage = NodeUsage { + transferred_bytes: 200000000u64.saturating_mul(b.into()), // 200 mb per provider + stored_bytes: 100000000u64.saturating_mul(b.into()), // 100 mb per provider + number_of_gets: 10u128.saturating_mul(b.into()), // 10 gets per provider + number_of_puts: 5u128.saturating_mul(b.into()), // 5 puts per provider + }; + let charging_max_batch_index = 0; + let mut charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + charging_processed_batches.try_insert(0).unwrap(); + let rewarding_max_batch_index = 0; + let rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge: total_customer_charge.clone(), + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let vault = DdcPayouts::::sub_account_id(cluster_id, era); + let total_customer_charge_amount = total_customer_charge.transfer + total_customer_charge.storage + total_customer_charge.gets + total_customer_charge.puts; + endow_account::(&vault, total_customer_charge_amount + T::Currency::minimum_balance().saturated_into::()); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + let batch_index: BatchIndex = 0; + let payees: Vec<(T::AccountId, NodeUsage)> = (0..b).map(|i| { + let provider = create_account::("provider", i, i); + endow_account::(&provider, T::Currency::minimum_balance().saturated_into()); + let node_usage = NodeUsage { + transferred_bytes: 200000000, // 200 mb + stored_bytes: 100000000, // 100 mb + number_of_gets: 10, // 10 gets + number_of_puts: 5, // 5 puts + }; + (provider, node_usage) + }).collect(); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, batch_index, payees) + verify { + assert!(ActiveBillingReports::::contains_key(cluster_id, era)); + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::RewardingProviders); + assert!(billing_report.rewarding_processed_batches.contains(&batch_index)); + } + + end_rewarding_providers { + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::RewardingProviders; + let total_customer_charge = CustomerCharge { + transfer: 200 * CERE, // price for 200 mb + storage: 100 * CERE, // price for 100 mb + gets: 10 * CERE, // price for 10 gets + puts: 5 * CERE, // price for 5 puts + }; + let total_distributed_reward : u128 = total_customer_charge.transfer + total_customer_charge.storage + total_customer_charge.gets + total_customer_charge.puts; + let total_node_usage = NodeUsage { + transferred_bytes: 200000000, // 200 mb + stored_bytes: 100000000, // 100 mb + number_of_gets: 10, // 10 gets + number_of_puts: 5, // 5 puts + }; + let charging_max_batch_index = 0; + let mut charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + charging_processed_batches.try_insert(0).unwrap(); + let rewarding_max_batch_index = 0; + let mut rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + rewarding_processed_batches.try_insert(0).unwrap(); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge, + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era) + verify { + assert!(ActiveBillingReports::::contains_key(cluster_id, era)); + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::ProvidersRewarded); + } + + end_billing_report { + let cluster_id = ClusterId::from([1; 20]); + let era : DdcEra = 1; + let state = State::ProvidersRewarded; + let total_customer_charge = CustomerCharge { + transfer: 200 * CERE, // price for 200 mb + storage: 100 * CERE, // price for 100 mb + gets: 10 * CERE, // price for 10 gets + puts: 5 * CERE, // price for 5 puts + }; + let total_distributed_reward : u128 = total_customer_charge.transfer + total_customer_charge.storage + total_customer_charge.gets + total_customer_charge.puts; + let total_node_usage = NodeUsage { + transferred_bytes: 200000000, // 200 mb + stored_bytes: 100000000, // 100 mb + number_of_gets: 10, // 10 gets + number_of_puts: 5, // 5 puts + }; + let charging_max_batch_index = 0; + let mut charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + charging_processed_batches.try_insert(0).unwrap(); + let rewarding_max_batch_index = 0; + let mut rewarding_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); + rewarding_processed_batches.try_insert(0).unwrap(); + + create_default_cluster::(cluster_id); + create_billing_report::(BillingReportParams { + cluster_id, + era, + state, + total_customer_charge, + total_distributed_reward, + total_node_usage, + charging_max_batch_index, + charging_processed_batches, + rewarding_max_batch_index, + rewarding_processed_batches, + }); + + let dac_account = create_dac_account::(); + whitelist_account!(dac_account); + + }: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era) + verify { + assert!(ActiveBillingReports::::contains_key(cluster_id, era)); + let billing_report = ActiveBillingReports::::get(cluster_id, era).unwrap(); + assert_eq!(billing_report.state, State::Finalized); + } + +} diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index d17052f6c..d61d22059 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -14,6 +14,12 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "256"] +pub mod weights; +use crate::weights::WeightInfo; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; + #[cfg(test)] pub(crate) mod mock; #[cfg(test)] @@ -21,8 +27,11 @@ mod tests; use ddc_primitives::{ClusterId, DdcEra}; use ddc_traits::{ - cluster::ClusterVisitor as ClusterVisitorType, - customer::CustomerCharger as CustomerChargerType, pallet::PalletVisitor as PalletVisitorType, + cluster::{ClusterCreator as ClusterCreatorType, ClusterVisitor as ClusterVisitorType}, + customer::{ + CustomerCharger as CustomerChargerType, CustomerDepositor as CustomerDepositorType, + }, + pallet::PalletVisitor as PalletVisitorType, }; use frame_election_provider_support::SortedListProvider; use frame_support::{ @@ -90,6 +99,7 @@ pub type BalanceOf = parameter_types! { pub MaxBatchesCount: u16 = 1000; pub MaxDust: u16 = 20000; + pub MaxBatchSize: u16 = 1000; } #[frame_support::pallet] @@ -111,9 +121,12 @@ pub mod pallet { type PalletId: Get; type Currency: LockableCurrency; type CustomerCharger: CustomerChargerType; + type CustomerDepositor: CustomerDepositorType; type TreasuryVisitor: PalletVisitorType; type ClusterVisitor: ClusterVisitorType; type ValidatorList: SortedListProvider; + type ClusterCreator: ClusterCreatorType>; + type WeightInfo: WeightInfo; } #[pallet::event] @@ -204,6 +217,7 @@ pub mod pallet { BoundedVecOverflow, ArithmeticOverflow, NotExpectedClusterState, + BatchSizeIsOutOfBounds, } #[pallet::storage] @@ -274,7 +288,7 @@ pub mod pallet { #[pallet::call] impl Pallet { - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::set_authorised_caller())] pub fn set_authorised_caller( origin: OriginFor, authorised_caller: T::AccountId, @@ -288,7 +302,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::begin_billing_report())] pub fn begin_billing_report( origin: OriginFor, cluster_id: ClusterId, @@ -316,7 +330,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::begin_charging_customers())] pub fn begin_charging_customers( origin: OriginFor, cluster_id: ClusterId, @@ -342,7 +356,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::send_charging_customers_batch(payers.len().saturated_into()))] pub fn send_charging_customers_batch( origin: OriginFor, cluster_id: ClusterId, @@ -353,6 +367,11 @@ pub mod pallet { let caller = ensure_signed(origin)?; ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!( + !payers.is_empty() && payers.len() <= MaxBatchSize::get() as usize, + Error::::BatchSizeIsOutOfBounds + ); + let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -483,7 +502,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::end_charging_customers())] pub fn end_charging_customers( origin: OriginFor, cluster_id: ClusterId, @@ -581,7 +600,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::begin_rewarding_providers())] pub fn begin_rewarding_providers( origin: OriginFor, cluster_id: ClusterId, @@ -612,7 +631,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::send_rewarding_providers_batch(payees.len().saturated_into()))] pub fn send_rewarding_providers_batch( origin: OriginFor, cluster_id: ClusterId, @@ -623,6 +642,11 @@ pub mod pallet { let caller = ensure_signed(origin)?; ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!( + !payees.is_empty() && payees.len() <= MaxBatchSize::get() as usize, + Error::::BatchSizeIsOutOfBounds + ); + let billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -691,7 +715,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::end_rewarding_providers())] pub fn end_rewarding_providers( origin: OriginFor, cluster_id: ClusterId, @@ -737,7 +761,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(10_000)] + #[pallet::weight(T::WeightInfo::end_billing_report())] pub fn end_billing_report( origin: OriginFor, cluster_id: ClusterId, diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 74abd95f2..b0f184a9b 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -3,10 +3,13 @@ #![allow(dead_code)] use crate::{self as pallet_ddc_payouts, *}; -use ddc_primitives::{ClusterFeesParams, ClusterPricingParams, NodePubKey, NodeType}; +use ddc_primitives::{ + ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams, + NodeType, +}; use ddc_traits::{ - cluster::{ClusterVisitor, ClusterVisitorError}, - customer::CustomerCharger, + cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError}, + customer::{CustomerCharger, CustomerDepositor}, pallet::PalletVisitor, }; use frame_election_provider_support::SortedListProvider; @@ -102,9 +105,12 @@ impl crate::pallet::Config for Test { type PalletId = PayoutsPalletId; type Currency = Balances; type CustomerCharger = TestCustomerCharger; + type CustomerDepositor = TestCustomerDepositor; type ClusterVisitor = TestClusterVisitor; type TreasuryVisitor = TestTreasuryVisitor; type ValidatorList = TestValidatorVisitor; + type ClusterCreator = TestClusterCreator; + type WeightInfo = (); } pub struct TestCustomerCharger; @@ -137,6 +143,29 @@ impl CustomerCharger for TestCustomerCharger { } pub const ACCOUNT_ID_5: AccountId = 5; +pub struct TestClusterCreator; +impl ClusterCreator for TestClusterCreator { + fn create_new_cluster( + _cluster_id: ClusterId, + _cluster_manager_id: T::AccountId, + _cluster_reserve_id: T::AccountId, + _cluster_params: ClusterParams, + _cluster_gov_params: ClusterGovParams, + ) -> DispatchResult { + Ok(()) + } +} + +pub struct TestCustomerDepositor; +impl CustomerDepositor for TestCustomerDepositor { + fn deposit(_customer: T::AccountId, _amount: u128) -> Result<(), DispatchError> { + Ok(()) + } + fn deposit_extra(_customer: T::AccountId, _amount: u128) -> Result<(), DispatchError> { + Ok(()) + } +} + pub const RESERVE_ACCOUNT_ID: AccountId = 999; pub const TREASURY_ACCOUNT_ID: AccountId = 888; pub const VALIDATOR1_ACCOUNT_ID: AccountId = 111; @@ -261,9 +290,6 @@ pub fn get_fees(cluster_id: &ClusterId) -> Result ClusterVisitor for TestClusterVisitor { - fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { - true - } fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { Ok(()) } @@ -306,6 +332,12 @@ impl ClusterVisitor for TestClusterVisitor { let reserve_account = RESERVE_ACCOUNT_ID.to_ne_bytes(); Ok(T::AccountId::decode(&mut &reserve_account[..]).unwrap()) } + + fn get_bonding_params( + _cluster_id: &ClusterId, + ) -> Result, ClusterVisitorError> { + unimplemented!() + } } pub(crate) type TestRuntimeCall = ::RuntimeCall; diff --git a/pallets/ddc-payouts/src/weights.rs b/pallets/ddc-payouts/src/weights.rs new file mode 100644 index 000000000..e4764f492 --- /dev/null +++ b/pallets/ddc-payouts/src/weights.rs @@ -0,0 +1,210 @@ +//! Autogenerated weights for pallet_ddc_payouts +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/debug/cere +// benchmark +// pallet +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-payouts +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template-clippy.hbs +// --output=pallets/ddc-payouts/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_ddc_payouts. +pub trait WeightInfo { + fn set_authorised_caller() -> Weight; + fn begin_billing_report() -> Weight; + fn begin_charging_customers() -> Weight; + fn send_charging_customers_batch(b: u32, ) -> Weight; + fn end_charging_customers() -> Weight; + fn begin_rewarding_providers() -> Weight; + fn send_rewarding_providers_batch(b: u32, ) -> Weight; + fn end_rewarding_providers() -> Weight; + fn end_billing_report() -> Weight; +} + +/// Weights for pallet_ddc_payouts using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) + fn set_authorised_caller() -> Weight { + Weight::from_ref_time(251_000_000_u64) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn begin_billing_report() -> Weight { + Weight::from_ref_time(466_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn begin_charging_customers() -> Weight { + Weight::from_ref_time(440_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:2 w:2) + // Storage: DdcPayouts DebtorCustomers (r:1 w:1) + /// The range of component `b` is `[1, 1000]`. + fn send_charging_customers_batch(b: u32, ) -> Weight { + Weight::from_ref_time(1_267_000_000_u64) + // Standard Error: 3_691_054 + .saturating_add(Weight::from_ref_time(557_422_673_u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(b as u64))) + .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(b as u64))) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) + // Storage: System Account (r:3 w:3) + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: Staking CounterForValidators (r:1 w:0) + // Storage: Staking Validators (r:2 w:0) + fn end_charging_customers() -> Weight { + Weight::from_ref_time(1_978_000_000_u64) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn begin_rewarding_providers() -> Weight { + Weight::from_ref_time(446_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + // Storage: System Account (r:2 w:2) + /// The range of component `b` is `[1, 1000]`. + fn send_rewarding_providers_batch(b: u32, ) -> Weight { + Weight::from_ref_time(758_000_000_u64) + // Standard Error: 148_210 + .saturating_add(Weight::from_ref_time(336_218_526_u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b as u64))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(b as u64))) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn end_rewarding_providers() -> Weight { + Weight::from_ref_time(458_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn end_billing_report() -> Weight { + Weight::from_ref_time(449_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) + fn set_authorised_caller() -> Weight { + Weight::from_ref_time(251_000_000_u64) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn begin_billing_report() -> Weight { + Weight::from_ref_time(466_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn begin_charging_customers() -> Weight { + Weight::from_ref_time(440_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) + // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:2 w:2) + // Storage: DdcPayouts DebtorCustomers (r:1 w:1) + /// The range of component `b` is `[1, 1000]`. + fn send_charging_customers_batch(b: u32, ) -> Weight { + Weight::from_ref_time(1_267_000_000_u64) + // Standard Error: 3_691_054 + .saturating_add(Weight::from_ref_time(557_422_673_u64).saturating_mul(b as u64)) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(b as u64))) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + .saturating_add(RocksDbWeight::get().writes((2_u64).saturating_mul(b as u64))) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) + // Storage: System Account (r:3 w:3) + // Storage: DdcClusters Clusters (r:1 w:0) + // Storage: Staking CounterForValidators (r:1 w:0) + // Storage: Staking Validators (r:2 w:0) + fn end_charging_customers() -> Weight { + Weight::from_ref_time(1_978_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(10_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn begin_rewarding_providers() -> Weight { + Weight::from_ref_time(446_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + // Storage: System Account (r:2 w:2) + /// The range of component `b` is `[1, 1000]`. + fn send_rewarding_providers_batch(b: u32, ) -> Weight { + Weight::from_ref_time(758_000_000_u64) + // Standard Error: 148_210 + .saturating_add(Weight::from_ref_time(336_218_526_u64).saturating_mul(b as u64)) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(b as u64))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(b as u64))) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn end_rewarding_providers() -> Weight { + Weight::from_ref_time(458_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) + // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) + fn end_billing_report() -> Weight { + Weight::from_ref_time(449_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index 67dddf18a..ac2bfaebc 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -16,8 +16,10 @@ sp-runtime = { default-features = false, git = "https://github.com/paritytech/su sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] +lazy_static = "1.4.0" pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +parking_lot = "0.12.1" sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 6353e4a5d..37eb110a1 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -2,7 +2,7 @@ use super::*; use crate::Pallet as DdcStaking; -use ddc_primitives::{CDNNodePubKey, NodeType}; +use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams, NodeType, StorageNodePubKey}; use testing_utils::*; use frame_support::traits::Currency; @@ -23,6 +23,16 @@ benchmarks! { let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let _ = T::NodeCreator::create_node( + node.clone(), + stash.clone(), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + )?; let amount = T::Currency::minimum_balance() * 10u32.into(); whitelist_account!(stash); }: _(RawOrigin::Signed(stash.clone()), controller_lookup, node.clone(), amount) @@ -65,7 +75,8 @@ benchmarks! { } store { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(100u128), node_pub_key)?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -74,7 +85,8 @@ benchmarks! { } serve { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; + let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128), node_pub_key)?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -86,7 +98,8 @@ benchmarks! { // clean up any existing state. clear_storages_and_cdns::(); - let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; + let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128), node_pub_key)?; DdcStaking::::serve(RawOrigin::Signed(cdn_controller.clone()).into(), ClusterId::from([1; 20]))?; assert!(CDNs::::contains_key(&cdn_stash)); frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); @@ -117,4 +130,10 @@ benchmarks! { verify { assert!(Nodes::::contains_key(&new_node)); } + + impl_benchmark_test_suite!( + DdcStaking, + crate::mock::ExtBuilder::default().build(), + crate::mock::Test, + ); } diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index c7efa74c7..d7bbad30e 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -31,9 +31,9 @@ use crate::weights::WeightInfo; use codec::{Decode, Encode, HasCompact}; pub use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use ddc_traits::{ - cluster::{ClusterVisitor, ClusterVisitorError}, - node::NodeVisitor, - staking::{StakingVisitor, StakingVisitorError}, + cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError}, + node::{NodeCreator, NodeVisitor}, + staking::{StakerCreator, StakingVisitor, StakingVisitorError}, }; use frame_support::{ @@ -141,6 +141,8 @@ impl< #[frame_support::pallet] pub mod pallet { + use ddc_traits::{cluster::ClusterManager, node::NodeVisitorError}; + use super::*; #[pallet::pallet] @@ -159,7 +161,13 @@ pub mod pallet { type ClusterVisitor: ClusterVisitor; + type ClusterCreator: ClusterCreator>; + + type ClusterManager: ClusterManager; + type NodeVisitor: NodeVisitor; + + type NodeCreator: NodeCreator; } /// Map from all locked "stash" accounts to the controller account. @@ -195,6 +203,16 @@ pub mod pallet { #[pallet::getter(fn providers)] pub type Providers = StorageMap<_, Twox64Concat, T::AccountId, NodePubKey>; + /// Map of Storage node provider stash accounts that aim to leave a cluster + #[pallet::storage] + #[pallet::getter(fn leaving_storages)] + pub type LeavingStorages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; + + // Map of CDN node provider stash accounts that aim to leave a cluster + #[pallet::storage] + #[pallet::getter(fn leaving_cdns)] + pub type LeavingCDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; + #[pallet::genesis_config] pub struct GenesisConfig { #[allow(clippy::type_complexity)] @@ -273,6 +291,12 @@ pub mod pallet { /// An account that started participating as either a storage network or CDN participant. /// \[stash\] Activated(T::AccountId), + /// An account that started unbonding tokens below the minimum value set for the cluster + /// his CDN or Storage node is assigned to \[stash\] + LeaveSoon(T::AccountId), + /// An account that unbonded tokens below the minimum value set for the cluster his + /// CDN or Storage node was assigned to \[stash\] + Left(T::AccountId), } #[pallet::error] @@ -302,6 +326,8 @@ pub mod pallet { NotNodeController, /// No stake found associated with the provided node. NodeHasNoStake, + /// No cluster found + NoCluster, /// No cluster governance params found for cluster NoClusterGovParams, /// Conditions for fast chill are not met, try the regular `chill` from @@ -314,6 +340,11 @@ pub mod pallet { ArithmeticOverflow, /// Arithmetic underflow occurred ArithmeticUnderflow, + /// Attempt to associate stake with non-existing node + NodeIsNotFound, + /// Action is prohibited for a node provider stash account that is in the process of + /// leaving a cluster + NodeIsLeaving, } #[pallet::call] @@ -355,6 +386,9 @@ pub mod pallet { Err(Error::::AlreadyPaired)? } + // Checks that the node is registered in the network + ensure!(T::NodeVisitor::exists(&node), Error::::NodeIsNotFound); + frame_system::Pallet::::inc_consumers(&stash).map_err(|_| Error::::BadState)?; Nodes::::insert(&node, &stash); @@ -404,6 +438,7 @@ pub mod pallet { ) -> DispatchResult { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, @@ -432,6 +467,8 @@ pub mod pallet { .map_err(Into::>::into)?; bond_size.saturated_into::>() } else { + // If node is not assigned to a cluster or node is chilling, allow to unbond + // any available amount. Zero::zero() }; @@ -439,36 +476,50 @@ pub mod pallet { // cluster. If a user runs into this error, they should chill first. ensure!(ledger.active >= min_active_bond, Error::::InsufficientBond); - let unbonding_delay_in_blocks = if let Some(cluster_id) = Self::cdns(&ledger.stash) - { - T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(Into::>::into)? - } else if let Some(cluster_id) = Self::storages(&ledger.stash) { - T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::Storage) - .map_err(Into::>::into)? - } else { - let node_pub_key = - >::get(&ledger.stash).ok_or(Error::::BadState)?; + let node_pub_key = + >::get(&ledger.stash).ok_or(Error::::BadState)?; + + let unbonding_delay = if T::NodeVisitor::exists(&node_pub_key) { + let node_cluster_id = T::NodeVisitor::get_cluster_id(&node_pub_key) + .map_err(Into::>::into)?; + + if let Some(cluster_id) = node_cluster_id { + let bonding_params = T::ClusterVisitor::get_bonding_params(&cluster_id) + .map_err(Into::>::into)?; + + let min_bond_size = match node_pub_key { + NodePubKey::CDNPubKey(_) => bonding_params.cdn_bond_size, + NodePubKey::StoragePubKey(_) => bonding_params.storage_bond_size, + }; + + // If provider is trying to unbond after chilling and aims to leave the + // cluster eventually, we keep its stake till the end of unbonding period. + if ledger.active < min_bond_size.saturated_into::>() { + match node_pub_key { + NodePubKey::CDNPubKey(_) => + LeavingCDNs::::insert(ledger.stash.clone(), cluster_id), + NodePubKey::StoragePubKey(_) => + LeavingStorages::::insert(ledger.stash.clone(), cluster_id), + }; + + Self::deposit_event(Event::::LeaveSoon(ledger.stash.clone())); + }; - if let Ok(Some(cluster_id)) = T::NodeVisitor::get_cluster_id(&node_pub_key) { match node_pub_key { - NodePubKey::CDNPubKey(_) => - T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(Into::>::into)?, - NodePubKey::StoragePubKey(_) => T::ClusterVisitor::get_unbonding_delay( - &cluster_id, - NodeType::Storage, - ) - .map_err(Into::>::into)?, + NodePubKey::CDNPubKey(_) => bonding_params.cdn_unbonding_delay, + NodePubKey::StoragePubKey(_) => bonding_params.storage_unbonding_delay, } } else { // If node is not a member of any cluster, allow immediate unbonding. T::BlockNumber::from(0u32) } + } else { + // If node was deleted, allow immediate unbonding. + T::BlockNumber::from(0u32) }; // block number + configuration -> no overflow - let block = >::block_number() + unbonding_delay_in_blocks; + let block = >::block_number() + unbonding_delay; if let Some(chunk) = ledger.unlocking.last_mut().filter(|chunk| chunk.block == block) { @@ -505,6 +556,7 @@ pub mod pallet { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); + let node_pub_key = >::get(stash.clone()).ok_or(Error::::BadState)?; ledger = ledger.consolidate_unlocked(>::block_number()); @@ -526,7 +578,22 @@ pub mod pallet { // Already checked that this won't overflow by entry condition. let value = old_total.checked_sub(&ledger.total).ok_or(Error::::ArithmeticUnderflow)?; - Self::deposit_event(Event::::Withdrawn(stash, value)); + Self::deposit_event(Event::::Withdrawn(stash.clone(), value)); + + // If provider aimed to leave the cluster and the unbonding period ends, remove + // the node from the cluster + if let Some(cluster_id) = + >::get(&stash).or_else(|| >::get(&stash)) + { + // Cluster manager could remove the node from cluster by this moment already, so + // it is ok to ignore result. + let _ = T::ClusterManager::remove_node(&cluster_id, &node_pub_key); + + >::remove(&stash); + >::remove(&stash); + + Self::deposit_event(Event::::Left(stash)); + } } Ok(()) @@ -573,6 +640,10 @@ pub mod pallet { // Cancel previous "chill" attempts Self::reset_chilling(&controller); return Ok(()) + } else { + // Can't participate in new CDN network if provider hasn't left the previous cluster + // yet + ensure!(!LeavingCDNs::::contains_key(stash), Error::::NodeIsLeaving); } Self::do_add_cdn(stash, cluster_id); @@ -621,6 +692,10 @@ pub mod pallet { // Cancel previous "chill" attempts Self::reset_chilling(&controller); return Ok(()) + } else { + // Can't participate in new Storage network if provider hasn't left the previous + // cluster yet + ensure!(!LeavingStorages::::contains_key(stash), Error::::NodeIsLeaving); } Self::do_add_storage(stash, cluster_id); @@ -661,7 +736,7 @@ pub mod pallet { .map_err(Into::>::into)?; (cluster, chill_delay) } else { - return Ok(()) // already chilled + return Ok(()) // node is already chilling or leaving the cluster }; if delay == T::BlockNumber::from(0u32) { @@ -741,6 +816,11 @@ pub mod pallet { ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); + // Ensure that provider is not about leaving the cluster as it may cause the removal + // of an unexpected node after unbonding. + ensure!(!>::contains_key(&stash), Error::::NodeIsLeaving); + ensure!(!>::contains_key(&stash), Error::::NodeIsLeaving); + >::insert(new_node.clone(), stash.clone()); >::insert(stash, new_node); @@ -763,7 +843,7 @@ pub mod pallet { .or_else(|| >::get(&stash)) .ok_or(Error::::NodeHasNoStake)?; - let is_cluster_node = T::ClusterVisitor::cluster_has_node(&cluster_id, &node_pub_key); + let is_cluster_node = T::ClusterManager::contains_node(&cluster_id, &node_pub_key); ensure!(!is_cluster_node, Error::::FastChillProhibited); // block number + 1 => no overflow @@ -879,8 +959,39 @@ pub mod pallet { } } + impl StakerCreator> for Pallet { + fn bond_stake_and_participate( + stash: T::AccountId, + controller: T::AccountId, + node: NodePubKey, + value: BalanceOf, + cluster_id: ClusterId, + ) -> DispatchResult { + Nodes::::insert(&node, &stash); + Providers::::insert(&stash, &node); + >::insert(&stash, &controller); + let stash_balance = T::Currency::free_balance(&stash); + let value = value.min(stash_balance); + Self::deposit_event(Event::::Bonded(stash.clone(), value)); + let item = StakingLedger { + stash: stash.clone(), + total: value, + active: value, + chilling: Default::default(), + unlocking: Default::default(), + }; + Self::update_ledger(&controller, &item); + match node { + NodePubKey::StoragePubKey(_node) => Self::do_add_storage(&stash, cluster_id), + NodePubKey::CDNPubKey(_node) => Self::do_add_cdn(&stash, cluster_id), + } + + Ok(()) + } + } + impl StakingVisitor for Pallet { - fn node_has_stake( + fn has_activated_stake( node_pub_key: &NodePubKey, cluster_id: &ClusterId, ) -> Result { @@ -889,34 +1000,46 @@ pub mod pallet { let maybe_cdn_in_cluster = CDNs::::get(&stash); let maybe_storage_in_cluster = Storages::::get(&stash); - let has_stake: bool = maybe_cdn_in_cluster + let has_activated_stake: bool = maybe_cdn_in_cluster .or(maybe_storage_in_cluster) .is_some_and(|staking_cluster| staking_cluster == *cluster_id); - Ok(has_stake) + Ok(has_activated_stake) } - fn node_is_chilling(node_pub_key: &NodePubKey) -> Result { + fn has_stake(node_pub_key: &NodePubKey) -> bool { + >::get(node_pub_key).is_some() + } + + fn has_chilling_attempt(node_pub_key: &NodePubKey) -> Result { let stash = >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; let controller = >::get(&stash).ok_or(StakingVisitorError::NodeStakeIsInBadState)?; - let is_chilling = >::get(&controller) + let is_chilling_attempt = >::get(&controller) .ok_or(StakingVisitorError::NodeStakeIsInBadState)? .chilling .is_some(); - Ok(is_chilling) + Ok(is_chilling_attempt) } } impl From for Error { fn from(error: ClusterVisitorError) -> Self { match error { - ClusterVisitorError::ClusterDoesNotExist => Error::::NodeHasNoStake, + ClusterVisitorError::ClusterDoesNotExist => Error::::NoCluster, ClusterVisitorError::ClusterGovParamsNotSet => Error::::NoClusterGovParams, } } } + + impl From for Error { + fn from(error: NodeVisitorError) -> Self { + match error { + NodeVisitorError::NodeDoesNotExist => Error::::NodeIsNotFound, + } + } + } } diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 9085b5ed5..c1aa469f5 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -3,18 +3,25 @@ #![allow(dead_code)] use crate::{self as pallet_ddc_staking, *}; -use ddc_primitives::{CDNNodePubKey, ClusterFeesParams, ClusterPricingParams, StorageNodePubKey}; +use ddc_primitives::{ + CDNNodePubKey, ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, + ClusterPricingParams, NodeParams, NodePubKey, StorageNodePubKey, +}; use ddc_traits::{ - cluster::{ClusterVisitor, ClusterVisitorError}, + cluster::{ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError}, node::{NodeVisitor, NodeVisitorError}, }; use frame_support::{ construct_runtime, + dispatch::DispatchResult, traits::{ConstU32, ConstU64, Everything, GenesisBuild}, weights::constants::RocksDbWeight, }; + use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; +use lazy_static::lazy_static; +use parking_lot::{ReentrantMutex, ReentrantMutexGuard}; use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ @@ -23,6 +30,7 @@ use sp_runtime::{ Perquintill, }; use sp_std::collections::btree_map::BTreeMap; +use std::cell::RefCell; /// The AccountId alias in this test module. pub(crate) type AccountId = u64; @@ -101,16 +109,41 @@ impl crate::pallet::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type ClusterVisitor = TestClusterVisitor; - type NodeVisitor = TestNodeVisitor; + type ClusterManager = TestClusterManager; + type NodeVisitor = MockNodeVisitor; + type NodeCreator = TestNodeCreator; + type ClusterCreator = TestClusterCreator; } pub(crate) type DdcStakingCall = crate::Call; pub(crate) type TestRuntimeCall = ::RuntimeCall; +pub struct TestNodeCreator; +pub struct TestClusterCreator; pub struct TestClusterVisitor; -impl ClusterVisitor for TestClusterVisitor { - fn cluster_has_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { - true + +impl NodeCreator for TestNodeCreator { + fn create_node( + _node_pub_key: NodePubKey, + _provider_id: T::AccountId, + _node_params: NodeParams, + ) -> DispatchResult { + Ok(()) } +} + +impl ClusterCreator for TestClusterCreator { + fn create_new_cluster( + _cluster_id: ClusterId, + _cluster_manager_id: T::AccountId, + _cluster_reserve_id: T::AccountId, + _cluster_params: ClusterParams, + _cluster_gov_params: ClusterGovParams, + ) -> DispatchResult { + Ok(()) + } +} + +impl ClusterVisitor for TestClusterVisitor { fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { Ok(()) } @@ -157,12 +190,113 @@ impl ClusterVisitor for TestClusterVisitor { ) -> Result { Err(ClusterVisitorError::ClusterDoesNotExist) } + + fn get_bonding_params( + cluster_id: &ClusterId, + ) -> Result, ClusterVisitorError> { + Ok(ClusterBondingParams { + cdn_bond_size: >::get_bond_size( + cluster_id, + NodeType::CDN, + ) + .unwrap_or_default(), + cdn_chill_delay: >::get_chill_delay( + cluster_id, + NodeType::CDN, + ) + .unwrap_or_default(), + cdn_unbonding_delay: >::get_unbonding_delay( + cluster_id, + NodeType::CDN, + ) + .unwrap_or_default(), + storage_bond_size: >::get_bond_size( + cluster_id, + NodeType::Storage, + ) + .unwrap_or_default(), + storage_chill_delay: >::get_chill_delay( + cluster_id, + NodeType::Storage, + ) + .unwrap_or_default(), + storage_unbonding_delay: + >::get_unbonding_delay( + cluster_id, + NodeType::Storage, + ) + .unwrap_or_default(), + }) + } } -pub struct TestNodeVisitor; -impl NodeVisitor for TestNodeVisitor { +pub struct TestClusterManager; +impl ClusterManager for TestClusterManager { + fn contains_node(_cluster_id: &ClusterId, _node_pub_key: &NodePubKey) -> bool { + true + } + + fn add_node( + _cluster_id: &ClusterId, + _node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError> { + Ok(()) + } + + fn remove_node( + _cluster_id: &ClusterId, + _node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError> { + Ok(()) + } +} + +lazy_static! { + // We have to use the ReentrantMutex as every test's thread that needs to perform some configuration on the mock acquires the lock at least 2 times: + // the first time when the mock configuration happens, and + // the second time when the pallet calls the MockNodeVisitor during execution + static ref MOCK_NODE: ReentrantMutex> = + ReentrantMutex::new(RefCell::new(MockNode::default())); +} + +pub struct MockNode { + pub cluster_id: Option, + pub exists: bool, +} + +impl Default for MockNode { + fn default() -> Self { + Self { cluster_id: None, exists: true } + } +} + +pub struct MockNodeVisitor; + +impl MockNodeVisitor { + // Every test's thread must hold the lock till the end of its test + pub fn set_and_hold_lock(mock: MockNode) -> ReentrantMutexGuard<'static, RefCell> { + let lock = MOCK_NODE.lock(); + *lock.borrow_mut() = mock; + lock + } + + // Every test's thread must release the lock that it previously acquired in the end of its + // test + pub fn reset_and_release_lock(lock: ReentrantMutexGuard<'static, RefCell>) { + *lock.borrow_mut() = MockNode::default(); + } +} + +impl NodeVisitor for MockNodeVisitor { fn get_cluster_id(_node_pub_key: &NodePubKey) -> Result, NodeVisitorError> { - Ok(None) + let lock = MOCK_NODE.lock(); + let mock_ref = lock.borrow(); + Ok(mock_ref.cluster_id) + } + fn exists(_node_pub_key: &NodePubKey) -> bool { + let lock = MOCK_NODE.lock(); + let mock_ref = lock.borrow(); + mock_ref.exists } } @@ -219,7 +353,7 @@ impl ExtBuilder { self.storages.push((stash, controller, stake, cluster)); self } - fn build(self) -> TestExternalities { + pub fn build(self) -> TestExternalities { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 58e6b656b..7dec075cc 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -1,12 +1,16 @@ //! Testing utils for ddc-staking. use crate::{Pallet as DdcStaking, *}; -use ddc_primitives::CDNNodePubKey; +use ddc_primitives::{ + CDNNodeParams, CDNNodePubKey, ClusterGovParams, ClusterId, ClusterParams, NodeParams, + StorageNodeParams, +}; + use frame_benchmarking::account; use frame_system::RawOrigin; use frame_support::traits::Currency; -use sp_runtime::traits::StaticLookup; +use sp_runtime::{traits::StaticLookup, Perquintill}; use sp_std::prelude::*; const SEED: u32 = 0; @@ -36,9 +40,10 @@ pub fn create_funded_user( pub fn create_funded_user_with_balance( string: &'static str, n: u32, - balance: BalanceOf, + balance_factor: u128, ) -> T::AccountId { let user = account(string, n, SEED); + let balance = T::Currency::minimum_balance() * balance_factor.saturated_into::>(); let _ = T::Currency::make_free_balance_be(&user, balance); user } @@ -53,6 +58,17 @@ pub fn create_stash_controller_node( let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + + T::NodeCreator::create_node( + node.clone(), + stash.clone(), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }), + )?; let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); DdcStaking::::bond( RawOrigin::Signed(stash.clone()).into(), @@ -66,19 +82,73 @@ pub fn create_stash_controller_node( /// Create a stash and controller pair with fixed balance. pub fn create_stash_controller_node_with_balance( n: u32, - balance: crate::BalanceOf, + balance_factor: u128, + node_pub_key: NodePubKey, ) -> Result<(T::AccountId, T::AccountId, NodePubKey), &'static str> { - let stash = create_funded_user_with_balance::("stash", n, balance); - let controller = create_funded_user_with_balance::("controller", n, balance); + let stash = create_funded_user_with_balance::("stash", n, balance_factor); + let controller = create_funded_user_with_balance::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + + let node_pub = node_pub_key.clone(); + match node_pub_key { + NodePubKey::CDNPubKey(node_pub_key) => { + T::NodeCreator::create_node( + ddc_primitives::NodePubKey::CDNPubKey(node_pub_key), + stash.clone(), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }), + )?; + }, + NodePubKey::StoragePubKey(node_pub_key) => { + T::NodeCreator::create_node( + NodePubKey::StoragePubKey(node_pub_key), + stash.clone(), + NodeParams::StorageParams(StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }), + )?; + }, + } + + let cluster_id = ClusterId::from([1; 20]); + let cluster_params = ClusterParams { node_provider_auth_contract: Some(stash.clone()) }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + cdn_bond_size: 10u32.into(), + cdn_chill_delay: 50u32.into(), + cdn_unbonding_delay: 50u32.into(), + storage_bond_size: 10u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + T::ClusterCreator::create_new_cluster( + cluster_id, + stash.clone(), + stash.clone(), + cluster_params, + cluster_gov_params, + )?; DdcStaking::::bond( RawOrigin::Signed(stash.clone()).into(), controller_lookup, - node.clone(), - balance, + node_pub.clone(), + T::Currency::minimum_balance() * balance_factor.saturated_into::>(), )?; - Ok((stash, controller, node)) + + Ok((stash, controller, node_pub)) } diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index d0756f3d4..358b736ce 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,7 +1,7 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::CDNNodePubKey; +use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; @@ -9,6 +9,21 @@ use pallet_balances::Error as BalancesError; pub const BLOCK_TIME: u64 = 1000; pub const INIT_TIMESTAMP: u64 = 30_000; +#[test] +fn test_default_staking_ledger() { + // Verifies initial conditions of mock + ExtBuilder::default().build_and_execute(|| { + let default_staking_ledger = StakingLedger::< + ::AccountId, + BalanceOf, + Test, + >::default_from(1); + // Account 11 is stashed and locked, and account 10 is the controller + assert_eq!(default_staking_ledger.stash, 1); + assert_eq!(default_staking_ledger.total, Zero::zero()); + }); +} + #[test] fn basic_setup_works() { // Verifies initial conditions of mock @@ -58,6 +73,10 @@ fn change_controller_works() { // Change controller. assert_ok!(DdcStaking::set_controller(RuntimeOrigin::signed(11), 3)); + assert_noop!( + DdcStaking::set_controller(RuntimeOrigin::signed(11), 3), + Error::::AlreadyPaired + ); assert_eq!(DdcStaking::bonded(&11), Some(3)); // 10 is no longer in control. @@ -89,6 +108,20 @@ fn not_enough_inital_bond_flow() { Error::::InsufficientBond ); + // Add new Storage participant, account 1 controlled by 2 with node 3. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(1), + 2, + NodePubKey::StoragePubKey(StorageNodePubKey::new([3; 32])), + 100 + )); + + // Not enough tokens bonded to store + assert_noop!( + DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), + Error::::InsufficientBond + ); + // Can not bond extra assert_noop!( DdcStaking::bond( @@ -121,6 +154,67 @@ fn not_enough_inital_bond_flow() { }) } +#[test] +fn unbonding_edge_cases_work() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + + // Add new CDN participant, account 3 controlled by 4 with node 5. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 100 + )); + + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + + assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(4), 1)); + while System::block_number() < 33 { + assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(4), 1)); + System::assert_last_event(Event::Unbonded(3, 1).into()); + System::set_block_number(System::block_number() + 1); + } + + assert_noop!(DdcStaking::unbond(RuntimeOrigin::signed(4), 1), Error::::NoMoreChunks); + }) +} + +#[test] +fn serve_or_store_should_be_prohibited() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + + // Add new CDN participant, account 3 controlled by 4 with node 5. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 100 + )); + + // Add new Storage participant, account 1 controlled by 2 with node 3. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(1), + 2, + NodePubKey::StoragePubKey(StorageNodePubKey::new([3; 32])), + 100 + )); + + // Not enough tokens bonded to serve + assert_noop!( + DdcStaking::serve(RuntimeOrigin::signed(2), ClusterId::from([1; 20])), + Error::::ServingProhibited + ); + + // Not enough tokens bonded to store + assert_noop!( + DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), + Error::::StoringProhibited + ); + }) +} + #[test] fn set_node_works() { ExtBuilder::default().build_and_execute(|| { @@ -160,6 +254,45 @@ fn set_node_works() { }) } +#[test] +fn cancel_previous_chill_works() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + // Add new CDN participant, account 3 controlled by 4 with node 5. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(3), + 4, + NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + 100 + )); + + // Add new Storage participant, account 1 controlled by 2 with node 3. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(1), + 2, + NodePubKey::StoragePubKey(StorageNodePubKey::new([3; 32])), + 100 + )); + + // Not enough tokens bonded to serve + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), cluster_id)); + + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(2), ClusterId::from([1; 20]))); + + // Schedule CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); + // Not enough tokens bonded to serve + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), cluster_id)); + + // Schedule CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(2))); + // Not enough tokens bonded to serve + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(2), cluster_id)); + }) +} + #[test] fn staking_should_work() { ExtBuilder::default().build_and_execute(|| { @@ -290,3 +423,227 @@ fn staking_should_work() { assert_eq!(DdcStaking::cdns(3), None); }); } + +#[test] +fn cdn_full_unbonding_works() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + + let provider_stash: u64 = 1; + let provider_controller: u64 = 2; + let cluster_id = ClusterId::from([1; 20]); + let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([1; 32])); + + let lock = MockNodeVisitor::set_and_hold_lock(MockNode { + cluster_id: Some(cluster_id), + exists: true, + }); + + let cdn_bond_size = 10_u128; + let cdn_chill_delay = 10_u64; + let cdn_unbond_delay = 10_u64; + + // Put some money in account that we'll use. + let _ = Balances::make_free_balance_be(&provider_controller, 2000); + let _ = Balances::make_free_balance_be(&provider_stash, 2000); + + // Add new CDN participant, account 1 controlled by 2 with node 1. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(provider_stash), + provider_controller, + node_pub_key.clone(), + cdn_bond_size, // min bond size + )); + System::assert_last_event(Event::Bonded(provider_stash, cdn_bond_size).into()); + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(provider_controller), cluster_id)); + System::assert_last_event(Event::Activated(provider_stash).into()); + + assert_eq!(DdcStaking::cdns(provider_stash), Some(cluster_id)); + assert_eq!(DdcStaking::nodes(node_pub_key), Some(provider_stash)); + + // Set block timestamp. + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + + // Schedule CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); + let chilling = System::block_number() + cdn_chill_delay; + System::assert_last_event(Event::ChillSoon(provider_stash, cluster_id, chilling).into()); + + // Set the block number that allows us to chill. + while System::block_number() < chilling { + System::set_block_number(System::block_number() + 1); + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + } + + // Actual CDN participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); + System::assert_last_event(Event::Chilled(provider_stash).into()); + + // Account is no longer a CDN participant. + assert_eq!(DdcStaking::cdns(provider_stash), None); + + // Start unbonding all tokens + assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(provider_controller), cdn_bond_size)); + System::assert_has_event(Event::LeaveSoon(provider_stash).into()); + assert_eq!(DdcStaking::leaving_cdns(provider_stash), Some(cluster_id)); + System::assert_last_event(Event::Unbonded(provider_stash, cdn_bond_size).into()); + + let unbonding = System::block_number() + cdn_unbond_delay; + // Set the block number that allows us to chill. + while System::block_number() < unbonding { + System::set_block_number(System::block_number() + 1); + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + } + + assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(provider_controller))); + System::assert_has_event(Event::Withdrawn(provider_stash, cdn_bond_size).into()); + assert_eq!(DdcStaking::leaving_cdns(provider_stash), None); + System::assert_last_event(Event::Left(provider_stash).into()); + + MockNodeVisitor::reset_and_release_lock(lock); + }); +} + +#[test] +fn storage_full_unbonding_works() { + ExtBuilder::default().build_and_execute(|| { + System::set_block_number(1); + + let provider_stash: u64 = 3; + let provider_controller: u64 = 4; + let cluster_id = ClusterId::from([1; 20]); + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([2; 32])); + + let lock = MockNodeVisitor::set_and_hold_lock(MockNode { + cluster_id: Some(cluster_id), + exists: true, + }); + + let storage_bond_size = 10_u128; + let storage_chill_delay = 10_u64; + let storage_unbond_delay = 10_u64; + + // Put some money in account that we'll use. + let _ = Balances::make_free_balance_be(&provider_controller, 2000); + let _ = Balances::make_free_balance_be(&provider_stash, 2000); + + // Add new Storage participant, account 1 controlled by 2 with node 1. + assert_ok!(DdcStaking::bond( + RuntimeOrigin::signed(provider_stash), + provider_controller, + node_pub_key.clone(), + storage_bond_size, // min bond size + )); + System::assert_last_event(Event::Bonded(provider_stash, storage_bond_size).into()); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(provider_controller), cluster_id)); + System::assert_last_event(Event::Activated(provider_stash).into()); + + assert_eq!(DdcStaking::storages(provider_stash), Some(cluster_id)); + assert_eq!(DdcStaking::nodes(node_pub_key), Some(provider_stash)); + + // Set block timestamp. + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + + // Schedule Storage participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); + let chilling = System::block_number() + storage_chill_delay; + System::assert_last_event(Event::ChillSoon(provider_stash, cluster_id, chilling).into()); + + // Set the block number that allows us to chill. + while System::block_number() < chilling { + System::set_block_number(System::block_number() + 1); + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + } + + // Actual Storage participant removal. + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); + System::assert_last_event(Event::Chilled(provider_stash).into()); + + // Account is no longer a Storage participant. + assert_eq!(DdcStaking::storages(provider_stash), None); + + // Start unbonding all tokens + assert_ok!(DdcStaking::unbond( + RuntimeOrigin::signed(provider_controller), + storage_bond_size + )); + System::assert_has_event(Event::LeaveSoon(provider_stash).into()); + assert_eq!(DdcStaking::leaving_storages(provider_stash), Some(cluster_id)); + System::assert_last_event(Event::Unbonded(provider_stash, storage_bond_size).into()); + + let unbonding = System::block_number() + storage_unbond_delay; + // Set the block number that allows us to chill. + while System::block_number() < unbonding { + System::set_block_number(System::block_number() + 1); + Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); + } + + assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(provider_controller))); + System::assert_has_event(Event::Withdrawn(provider_stash, storage_bond_size).into()); + assert_eq!(DdcStaking::leaving_storages(provider_stash), None); + System::assert_last_event(Event::Left(provider_stash).into()); + + MockNodeVisitor::reset_and_release_lock(lock); + }); +} + +#[test] +fn staking_creator_works() { + // Verifies initial conditions of mock + ExtBuilder::default().build_and_execute(|| { + let stash: u64 = 1; + let controller: u64 = 2; + let cluster_id = ClusterId::from([1; 20]); + let value = 5; + let cdn_node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([2; 32])); + let storage_node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([2; 32])); + + assert_ok!( + >>::bond_stake_and_participate( + stash, + controller, + cdn_node_pub_key, + value, + cluster_id, + ) + ); + + assert_ok!( + >>::bond_stake_and_participate( + stash, + controller, + storage_node_pub_key, + value, + cluster_id, + ) + ); + }); +} + +#[test] +fn staking_visitor_works() { + // Verifies initial conditions of mock + ExtBuilder::default().build_and_execute(|| { + let cluster_id = ClusterId::from([1; 20]); + let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])); + + // Add new CDN participant, account 3 controlled by 4 with node 5. + assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, node_pub_key.clone(), 100)); + + assert!(>::has_stake(&node_pub_key,)); + + if let Ok(result) = + >::has_chilling_attempt(&node_pub_key) + { + assert!(!result); + } + + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + + if let Ok(result) = + >::has_activated_stake(&node_pub_key, &cluster_id) + { + assert!(result); + } + }); +} diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index efca88632..5437d12a2 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -44,72 +44,95 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(37_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000_u64) - .saturating_add(T::DbWeight::get().reads(6_u64)) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000_u64) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 33_000 nanoseconds. + Weight::from_ref_time(34_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - Weight::from_ref_time(26_112_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000_u64) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) fn serve() -> Weight { - Weight::from_ref_time(19_892_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000_u64) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000_u64) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_000_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } - // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:2) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000_u64) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 13_000 nanoseconds. + Weight::from_ref_time(14_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } @@ -118,71 +141,94 @@ impl WeightInfo for () { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(37_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000_u64) - .saturating_add(RocksDbWeight::get().reads(6_u64)) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 33_000 nanoseconds. + Weight::from_ref_time(34_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - Weight::from_ref_time(26_112_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) fn serve() -> Weight { - Weight::from_ref_time(19_892_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000_u64) - .saturating_add(RocksDbWeight::get().reads(5_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000_u64) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_000_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } - // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:2) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000_u64) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 13_000 nanoseconds. + Weight::from_ref_time(14_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 54b1c0c9e..456c33299 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -1,16 +1,44 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::{Decode, Encode}; -use scale_info::TypeInfo; +use scale_info::{prelude::vec::Vec, TypeInfo}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_core::hash::H160; use sp_runtime::{AccountId32, Perquintill, RuntimeDebug}; + pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; pub type StorageNodePubKey = AccountId32; pub type CDNNodePubKey = AccountId32; + +// ClusterParams includes Governance non-sensetive parameters only +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterParams { + pub node_provider_auth_contract: Option, +} + +// ClusterGovParams includes Governance sensitive parameters +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Default)] +#[scale_info(skip_type_params(Balance, BlockNumber, T))] +pub struct ClusterGovParams { + pub treasury_share: Perquintill, + pub validators_share: Perquintill, + pub cluster_reserve_share: Perquintill, + pub cdn_bond_size: Balance, + pub cdn_chill_delay: BlockNumber, + pub cdn_unbonding_delay: BlockNumber, + pub storage_bond_size: Balance, + pub storage_chill_delay: BlockNumber, + pub storage_unbonding_delay: BlockNumber, + pub unit_per_mb_stored: u128, + pub unit_per_mb_streamed: u128, + pub unit_per_put_request: u128, + pub unit_per_get_request: u128, +} + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterPricingParams { pub unit_per_mb_stored: u128, @@ -26,6 +54,16 @@ pub struct ClusterFeesParams { pub cluster_reserve_share: Perquintill, } +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterBondingParams { + pub cdn_bond_size: u128, + pub cdn_chill_delay: BlockNumber, + pub cdn_unbonding_delay: BlockNumber, + pub storage_bond_size: u128, + pub storage_chill_delay: BlockNumber, + pub storage_unbonding_delay: BlockNumber, +} + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { @@ -58,3 +96,26 @@ impl TryFrom for NodeType { } } } + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct CDNNodeParams { + pub host: Vec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct StorageNodeParams { + pub host: Vec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, +} + +// Params fields are always coming from extrinsic input +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodeParams { + StorageParams(StorageNodeParams), + CDNParams(CDNNodeParams), +} diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index e0e425c13..87821e239 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -217,7 +217,11 @@ runtime-benchmarks = [ "pallet-session-benchmarking/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-staking/runtime-benchmarks", + "pallet-ddc-customers/runtime-benchmarks", + "pallet-ddc-clusters/runtime-benchmarks", + "pallet-ddc-nodes/runtime-benchmarks", "pallet-ddc-staking/runtime-benchmarks", + "pallet-ddc-payouts/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-tips/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 5aa907989..9b70d24a7 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1322,7 +1322,10 @@ impl pallet_ddc_staking::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; + type ClusterManager = pallet_ddc_clusters::Pallet; type NodeVisitor = pallet_ddc_nodes::Pallet; + type NodeCreator = pallet_ddc_nodes::Pallet; } parameter_types! { @@ -1336,17 +1339,23 @@ impl pallet_ddc_customers::Config for Runtime { type PalletId = DdcCustomersPalletId; type RuntimeEvent = RuntimeEvent; type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; + type WeightInfo = pallet_ddc_customers::weights::SubstrateWeight; } impl pallet_ddc_nodes::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type StakingVisitor = pallet_ddc_staking::Pallet; + type WeightInfo = pallet_ddc_nodes::weights::SubstrateWeight; } impl pallet_ddc_clusters::Config for Runtime { type RuntimeEvent = RuntimeEvent; type NodeRepository = pallet_ddc_nodes::Pallet; type StakingVisitor = pallet_ddc_staking::Pallet; + type StakerCreator = pallet_ddc_staking::Pallet; type Currency = Balances; + type WeightInfo = pallet_ddc_clusters::weights::SubstrateWeight; } parameter_types! { @@ -1365,9 +1374,12 @@ impl pallet_ddc_payouts::Config for Runtime { type PalletId = PayoutsPalletId; type Currency = Balances; type CustomerCharger = DdcCustomers; + type CustomerDepositor = DdcCustomers; type ClusterVisitor = DdcClusters; type TreasuryVisitor = TreasureWrapper; type ValidatorList = pallet_staking::UseValidatorsMap; + type ClusterCreator = DdcClusters; + type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; } construct_runtime!( @@ -1533,7 +1545,11 @@ mod benches { [pallet_scheduler, Scheduler] [pallet_session, SessionBench::] [pallet_staking, Staking] + [pallet_ddc_customers, DdcCustomers] + [pallet_ddc_clusters, DdcClusters] [pallet_ddc_staking, DdcStaking] + [pallet_ddc_nodes, DdcNodes] + [pallet_ddc_payouts, DdcPayouts] [frame_system, SystemBench::] [pallet_timestamp, Timestamp] [pallet_tips, Tips] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 79d2bcad3..9f1e81c34 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { path = "../primitives", default-features = false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } diff --git a/traits/src/cluster.rs b/traits/src/cluster.rs index dcd1f259d..d980c1ae4 100644 --- a/traits/src/cluster.rs +++ b/traits/src/cluster.rs @@ -1,12 +1,14 @@ use codec::{Decode, Encode}; -use ddc_primitives::{ClusterFeesParams, ClusterId, ClusterPricingParams, NodePubKey, NodeType}; +use ddc_primitives::{ + ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams, + ClusterPricingParams, NodePubKey, NodeType, +}; +use frame_support::dispatch::DispatchResult; use frame_system::Config; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; pub trait ClusterVisitor { - fn cluster_has_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; - fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError>; fn get_bond_size( @@ -31,6 +33,20 @@ pub trait ClusterVisitor { cluster_id: &ClusterId, node_type: NodeType, ) -> Result; + + fn get_bonding_params( + cluster_id: &ClusterId, + ) -> Result, ClusterVisitorError>; +} + +pub trait ClusterCreator { + fn create_new_cluster( + cluster_id: ClusterId, + cluster_manager_id: T::AccountId, + cluster_reserve_id: T::AccountId, + cluster_params: ClusterParams, + cluster_gov_params: ClusterGovParams, + ) -> DispatchResult; } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -38,3 +54,22 @@ pub enum ClusterVisitorError { ClusterDoesNotExist, ClusterGovParamsNotSet, } + +pub trait ClusterManager { + fn contains_node(cluster_id: &ClusterId, node_pub_key: &NodePubKey) -> bool; + fn add_node( + cluster_id: &ClusterId, + node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError>; + fn remove_node( + cluster_id: &ClusterId, + node_pub_key: &NodePubKey, + ) -> Result<(), ClusterManagerError>; +} + +pub enum ClusterManagerError { + AttemptToAddNonExistentNode, + AttemptToAddAlreadyAssignedNode, + AttemptToRemoveNotAssignedNode, + AttemptToRemoveNonExistentNode, +} diff --git a/traits/src/customer.rs b/traits/src/customer.rs index 2fd624af1..746a20f6d 100644 --- a/traits/src/customer.rs +++ b/traits/src/customer.rs @@ -1,6 +1,5 @@ -use codec::{Decode, Encode}; -use scale_info::TypeInfo; -use sp_runtime::{DispatchError, RuntimeDebug}; +use core::u128; +use sp_runtime::DispatchError; pub trait CustomerCharger { fn charge_content_owner( @@ -10,10 +9,7 @@ pub trait CustomerCharger { ) -> Result; } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum CustomerChargerError { - NotOwner, - ArithmeticUnderflow, - TransferFailed, - UnlockFailed, +pub trait CustomerDepositor { + fn deposit(customer: T::AccountId, amount: u128) -> Result<(), DispatchError>; + fn deposit_extra(customer: T::AccountId, amount: u128) -> Result<(), DispatchError>; } diff --git a/traits/src/node.rs b/traits/src/node.rs index af22b5a8b..ed60e0f1a 100644 --- a/traits/src/node.rs +++ b/traits/src/node.rs @@ -1,8 +1,18 @@ -use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_primitives::{ClusterId, NodeParams, NodePubKey}; +use frame_support::dispatch::DispatchResult; use frame_system::Config; pub trait NodeVisitor { fn get_cluster_id(node_pub_key: &NodePubKey) -> Result, NodeVisitorError>; + fn exists(node_pub_key: &NodePubKey) -> bool; +} + +pub trait NodeCreator { + fn create_node( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> DispatchResult; } pub enum NodeVisitorError { diff --git a/traits/src/staking.rs b/traits/src/staking.rs index 5ec1e8bcf..06697856f 100644 --- a/traits/src/staking.rs +++ b/traits/src/staking.rs @@ -2,12 +2,24 @@ use ddc_primitives::{ClusterId, NodePubKey}; use frame_system::Config; pub trait StakingVisitor { - fn node_has_stake( + fn has_activated_stake( node_pub_key: &NodePubKey, cluster_id: &ClusterId, ) -> Result; - fn node_is_chilling(node_pub_key: &NodePubKey) -> Result; + fn has_stake(node_pub_key: &NodePubKey) -> bool; + + fn has_chilling_attempt(node_pub_key: &NodePubKey) -> Result; +} + +pub trait StakerCreator { + fn bond_stake_and_participate( + stash: T::AccountId, + controller: T::AccountId, + node: NodePubKey, + value: Balance, + cluster_id: ClusterId, + ) -> sp_runtime::DispatchResult; } pub enum StakingVisitorError { From 2885ae9579a78fff02d48fd56b7d049e9b452cf6 Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Mon, 11 Dec 2023 13:06:50 +0100 Subject: [PATCH 534/544] Backporting #191, #176 from `dev` branch to substrate `0.9.30` (#193) Backporting the following PRs from the dev branch: - [#191](https://github.com/Cerebellum-Network/blockchain-node/pull/191) - [#176](https://github.com/Cerebellum-Network/blockchain-node/pull/176) --------- Co-authored-by: Alisher A. Khassanov --- Cargo.lock | 1 + docs/genesis-state.md | 39 +++++ dprint.json | 14 +- node/service/chain-specs/example.json | 232 ++++++++++++++++++++++++++ node/service/src/chain_spec.rs | 1 + pallets/ddc-customers/src/lib.rs | 44 ++++- pallets/ddc-customers/src/mock.rs | 2 +- pallets/ddc-nodes/Cargo.toml | 2 + pallets/ddc-nodes/src/cdn_node.rs | 4 + pallets/ddc-nodes/src/lib.rs | 25 +++ pallets/ddc-nodes/src/storage_node.rs | 4 + scripts/pre-commit.sh | 7 + 12 files changed, 359 insertions(+), 16 deletions(-) create mode 100644 docs/genesis-state.md create mode 100644 node/service/chain-specs/example.json diff --git a/Cargo.lock b/Cargo.lock index e75b40eaa..e6b76c111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5036,6 +5036,7 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/docs/genesis-state.md b/docs/genesis-state.md new file mode 100644 index 000000000..587683b62 --- /dev/null +++ b/docs/genesis-state.md @@ -0,0 +1,39 @@ +# State preset + +Sometimes we use the blockchain as a part of a test environment. +Those tests typically want a certain state of the blockchain. +One option is to make a script which sends a number of transactions to put the blockchain into the desired state. +But those scripts may become large and execution may take significant time. +Another option is to make a chain specification, a JSON file with the desired genesis state of the blockchain. +And launch the chain with the desired state from the first block. + +## Build a chain spec + +Chain specification is a JSON file which contains network parameters with the the initial runtime and a genesis state of the database for each runtime module. +There are two forms of chain specification - a human-readable _plain_ form where each runtime module is represented by it's name. +And a _raw_ form with key-value pairs which will be written to the database. + +1. Create a plain form chain spec. + + ```console + ./target/release/cere build-spec --chain=dev --disable-default-bootnode > plain.json + ``` + +1. Set genesis state for each module. + There is an example in `node/service/example.json`, you can copy everything except the `code` field value from it to the `plain.json`. + +1. Create a raw form chain spec. + + ```console + ./target/release/cere build-spec --chain=plain.json --disable-default-bootnode --raw > raw.json + ``` + +## Launch the chain + +```console +./target/release/cere --chain=raw.json --tmp --alice --unsafe-rpc-external --unsafe-ws-external --rpc-cors=all +``` + +## See also + +[docs.substrate.io: Create a custom chain specification](https://docs.substrate.io/tutorials/build-a-blockchain/add-trusted-nodes/#create-a-custom-chain-specification) diff --git a/dprint.json b/dprint.json index 82c59d3ee..46b8be32b 100644 --- a/dprint.json +++ b/dprint.json @@ -1,11 +1,5 @@ { - "includes": [ - "**/*.{toml}" - ], - "excludes": [ - "**/target" - ], - "plugins": [ - "https://plugins.dprint.dev/toml-0.5.3.wasm" - ] - } \ No newline at end of file + "includes": ["**/*.{toml}"], + "excludes": ["**/target"], + "plugins": ["https://plugins.dprint.dev/toml-0.5.3.wasm"] +} diff --git a/node/service/chain-specs/example.json b/node/service/chain-specs/example.json new file mode 100644 index 000000000..7e3b5c97c --- /dev/null +++ b/node/service/chain-specs/example.json @@ -0,0 +1,232 @@ +{ + "name": "Development", + "id": "cere_dev", + "chainType": "Development", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": "cere", + "properties": { + "ss58Format": 54, + "tokenDecimals": 10, + "tokenSymbol": "CERE" + }, + "forkBlocks": null, + "badBlocks": null, + "lightSyncState": null, + "codeSubstitutes": {}, + "genesis": { + "runtime": { + "system": { + "code": "0x00" + }, + "babe": { + "authorities": [], + "epochConfig": { + "c": [ + 1, + 4 + ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" + } + }, + "indices": { + "indices": [] + }, + "balances": { + "balances": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 10000000000000 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 10000000000000 + ], + [ + "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", + 10000000000000 + ], + [ + "5HpG9w8EBLe5XCrbczpwq5TSXvedjrBGCwqxK1iQ7qUsSWFc", + 10000000000000 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 10000000000000 + ] + ] + }, + "transactionPayment": { + "multiplier": "10000000000" + }, + "staking": { + "validatorCount": 1, + "minimumValidatorCount": 1, + "invulnerables": [ + "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY" + ], + "forceEra": "NotForcing", + "slashRewardFraction": 100000000, + "canceledPayout": 0, + "stakers": [ + [ + "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1000000000000, + "Validator" + ] + ], + "minNominatorBond": 0, + "minValidatorBond": 0, + "maxValidatorCount": null, + "maxNominatorCount": null + }, + "session": { + "keys": [ + [ + "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", + "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY", + { + "grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu", + "babe": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "im_online": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "authority_discovery": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" + } + ] + ] + }, + "democracy": { + "phantom": null + }, + "council": { + "phantom": null, + "members": [] + }, + "technicalCommittee": { + "phantom": null, + "members": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" + ] + }, + "elections": { + "members": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 10000000000 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 10000000000 + ] + ] + }, + "technicalMembership": { + "members": [], + "phantom": null + }, + "grandpa": { + "authorities": [] + }, + "treasury": null, + "sudo": { + "key": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" + }, + "imOnline": { + "keys": [] + }, + "authorityDiscovery": { + "keys": [] + }, + "society": { + "pot": 0, + "members": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" + ], + "maxMembers": 999 + }, + "vesting": { + "vesting": [] + }, + "nominationPools": { + "minJoinBond": 0, + "minCreateBond": 0, + "maxPools": 16, + "maxMembersPerPool": 32, + "maxMembers": 512 + }, + "ddcStaking": { + "cdns": [], + "storages": [] + }, + "ddcCustomers": { + "buckets": [ + [ + "0x0000000000000000000000000000000000000001", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 10000000000 + ] + ] + }, + "ddcNodes": { + "storageNodes": [ + { + "pub_key": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + "provider_id": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "cluster_id": "0x0000000000000000000000000000000000000001", + "props": { + "host": [], + "http_port": 8080, + "grpc_port": 8081, + "p2p_port": 8082 + } + } + ], + "cdnNodes": [] + }, + "ddcClusters": { + "clusters": [ + { + "cluster_id": "0x0000000000000000000000000000000000000001", + "manager_id": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "reserve_id": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "props": { + "node_provider_auth_contract": null + } + } + ], + "clustersGovParams": [ + [ + "0x0000000000000000000000000000000000000001", + { + "treasury_share": 0, + "validators_share": 0, + "cluster_reserve_share": 0, + "cdn_bond_size": 0, + "cdn_chill_delay": 0, + "cdn_unbonding_delay": 0, + "storage_bond_size": 0, + "storage_chill_delay": 0, + "storage_unbonding_delay": 0, + "unit_per_mb_stored": 0, + "unit_per_mb_streamed": 0, + "unit_per_put_request": 0, + "unit_per_get_request": 0 + } + ] + ], + "clustersNodes": [ + [ + "0x0000000000000000000000000000000000000001", + [ + { + "StoragePubKey": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" + } + ] + ] + ] + } + } + } +} \ No newline at end of file diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 726fa96d8..cceef05ee 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -236,6 +236,7 @@ pub fn cere_dev_genesis( ddc_customers: Default::default(), nomination_pools: Default::default(), ddc_clusters: Default::default(), + ddc_nodes: Default::default(), } } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 3c3d72d69..edbe62214 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -216,18 +216,52 @@ pub mod pallet { } #[pallet::genesis_config] - pub struct GenesisConfig; + pub struct GenesisConfig { + pub buckets: Vec<(ClusterId, T::AccountId, BalanceOf)>, + } #[cfg(feature = "std")] - impl Default for GenesisConfig { + impl Default for GenesisConfig { fn default() -> Self { - Self + GenesisConfig { buckets: Default::default() } } } #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) {} + impl GenesisBuild for GenesisConfig { + fn build(&self) { + let account_id = >::account_id(); + let min = ::Currency::minimum_balance(); + if ::Currency::free_balance(&account_id) < min { + let _ = ::Currency::make_free_balance_be(&account_id, min); + } + + for &(ref cluster_id, ref owner_id, ref deposit) in &self.buckets { + let cur_bucket_id = >::get() + .checked_add(1) + .ok_or(Error::::ArithmeticOverflow) + .unwrap(); + >::set(cur_bucket_id); + + let bucket = Bucket { + bucket_id: cur_bucket_id, + owner_id: owner_id.clone(), + cluster_id: *cluster_id, + }; + >::insert(cur_bucket_id, bucket); + + let ledger = AccountsLedger:: { + owner: owner_id.clone(), + total: *deposit, + active: *deposit, + unlocking: Default::default(), + }; + >::insert(&ledger.owner, &ledger); + + ::Currency::deposit_into_existing(&account_id, *deposit) + .unwrap(); + } + } } #[pallet::call] diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index 11af9b667..eb25c239c 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -41,7 +41,7 @@ construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - DdcCustomers: pallet_ddc_customers::{Pallet, Call, Storage, Config, Event}, + DdcCustomers: pallet_ddc_customers::{Pallet, Call, Storage, Config, Event}, } ); diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 3d189469f..ee7857e14 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -11,6 +11,7 @@ frame-benchmarking = { default-features = false, git = "https://github.com/parit frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true } sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -34,6 +35,7 @@ std = [ "sp-runtime/std", "sp-std/std", "sp-core/std", + "serde", ] runtime-benchmarks = [ "ddc-primitives/runtime-benchmarks", diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 43c3721f4..b7f5cf146 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -3,6 +3,8 @@ use codec::{Decode, Encode}; use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; @@ -11,6 +13,7 @@ parameter_types! { pub MaxHostLen: u8 = 255; } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(T))] pub struct CDNNode { @@ -20,6 +23,7 @@ pub struct CDNNode { pub props: CDNNodeProps, } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct CDNNodeProps { pub host: BoundedVec, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index f3c7f1f93..3d89e92b7 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -94,6 +94,31 @@ pub mod pallet { #[pallet::getter(fn cdn_nodes)] pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; + #[pallet::genesis_config] + pub struct GenesisConfig { + pub storage_nodes: Vec>, + pub cdn_nodes: Vec>, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { storage_nodes: Default::default(), cdn_nodes: Default::default() } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + for storage_node in &self.storage_nodes { + >::insert(storage_node.pub_key.clone(), storage_node); + } + for cdn_node in &self.cdn_nodes { + >::insert(cdn_node.pub_key.clone(), cdn_node); + } + } + } + #[pallet::call] impl Pallet { #[pallet::weight(T::WeightInfo::create_node())] diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 0749c044e..14f937c3b 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -3,6 +3,8 @@ use codec::{Decode, Encode}; use ddc_primitives::{ClusterId, NodeParams, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; use sp_runtime::RuntimeDebug; parameter_types! { @@ -10,6 +12,7 @@ parameter_types! { pub MaxHostLen: u8 = 255; } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(T))] pub struct StorageNode { @@ -19,6 +22,7 @@ pub struct StorageNode { pub props: StorageNodeProps, } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeProps { pub host: BoundedVec, diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 4106624b8..a01d1ba34 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -1,8 +1,15 @@ #!/bin/sh # Prevent committing badly formatted code + cargo fmt -- --check if [ $? -ne 0 ]; then echo "Run \`cargo fmt\` to fix formatting issues before committing." exit 1 fi + +dprint check +if [ $? -ne 0 ]; then + echo "Run \`dprint fmt\` to fix formatting issues before committing." + exit 1 +fi From e24b417b1e868bc3d57010e35860358a90b1e5a6 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:02:53 +0200 Subject: [PATCH 535/544] Payout provider share tests (#195) --- node/service/src/chain_spec.rs | 1 + pallets/ddc-customers/src/lib.rs | 24 ++- pallets/ddc-customers/src/mock.rs | 10 +- pallets/ddc-customers/src/tests.rs | 17 +- pallets/ddc-payouts/src/lib.rs | 70 ++++++- pallets/ddc-payouts/src/mock.rs | 58 ++++-- pallets/ddc-payouts/src/tests.rs | 318 +++++++++++++++++++++++++---- 7 files changed, 423 insertions(+), 75 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index cceef05ee..4aaf48b3f 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -237,6 +237,7 @@ pub fn cere_dev_genesis( nomination_pools: Default::default(), ddc_clusters: Default::default(), ddc_nodes: Default::default(), + ddc_payouts: Default::default(), } } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index edbe62214..191af3ecc 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -217,13 +217,14 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { + pub feeder_account: Option, pub buckets: Vec<(ClusterId, T::AccountId, BalanceOf)>, } #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { buckets: Default::default() } + GenesisConfig { feeder_account: None, buckets: Default::default() } } } @@ -232,8 +233,19 @@ pub mod pallet { fn build(&self) { let account_id = >::account_id(); let min = ::Currency::minimum_balance(); - if ::Currency::free_balance(&account_id) < min { - let _ = ::Currency::make_free_balance_be(&account_id, min); + + let balance = ::Currency::free_balance(&account_id); + if balance < min { + if let Some(vault) = &self.feeder_account { + let _ = ::Currency::transfer( + vault, + &account_id, + min - balance, + ExistenceRequirement::AllowDeath, + ); + } else { + let _ = ::Currency::make_free_balance_be(&account_id, min); + } } for &(ref cluster_id, ref owner_id, ref deposit) in &self.buckets { @@ -438,7 +450,7 @@ pub mod pallet { old_total.checked_sub(&ledger.total).ok_or(Error::::ArithmeticUnderflow)?; ::Currency::transfer( - &Self::sub_account_id(&owner), + &Self::account_id(), &owner, value, ExistenceRequirement::AllowDeath, @@ -471,7 +483,7 @@ pub mod pallet { ) -> DispatchResult { ::Currency::transfer( owner, - &Self::sub_account_id(owner), + &Self::account_id(), ledger.total, ExistenceRequirement::AllowDeath, )?; @@ -570,7 +582,7 @@ pub mod pallet { } ::Currency::transfer( - &Self::sub_account_id(&content_owner), + &Self::account_id(), &billing_vault, actually_charged, ExistenceRequirement::AllowDeath, diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index eb25c239c..d9e847eb0 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -11,7 +11,7 @@ use ddc_traits::cluster::{ use frame_support::{ construct_runtime, parameter_types, - traits::{ConstU32, ConstU64, Everything}, + traits::{ConstU32, ConstU64, Everything, GenesisBuild}, weights::constants::RocksDbWeight, }; use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; @@ -238,11 +238,17 @@ impl ExtBuilder { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); - let _ = pallet_balances::GenesisConfig:: { + let _balance_genesis = pallet_balances::GenesisConfig:: { balances: vec![(1, 100), (2, 100), (3, 1000)], } .assimilate_storage(&mut storage); + let _customer_genesis = pallet_ddc_customers::GenesisConfig:: { + feeder_account: None, + buckets: Default::default(), + } + .assimilate_storage(&mut storage); + TestExternalities::new(storage) } pub fn build_and_execute(self, test: impl FnOnce()) { diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index a90d43482..c378a3961 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -142,8 +142,8 @@ fn charge_content_owner_works() { let balance_after_deposit = Balances::free_balance(account_3); assert_eq!(balance_before_deposit - deposit, balance_after_deposit); - let pallet_balance = Balances::free_balance(DdcCustomers::sub_account_id(&account_3)); - assert_eq!(deposit, pallet_balance); + let pallet_balance = Balances::free_balance(DdcCustomers::account_id()); + assert_eq!(deposit, pallet_balance - Balances::minimum_balance()); // Check storage assert_eq!( @@ -170,8 +170,7 @@ fn charge_content_owner_works() { let account_balance = Balances::free_balance(account_3); assert_eq!(balance_after_deposit, account_balance); - let pallet_balance_after_charge = - Balances::free_balance(DdcCustomers::sub_account_id(&account_3)); + let pallet_balance_after_charge = Balances::free_balance(DdcCustomers::account_id()); assert_eq!(pallet_balance - charged, pallet_balance_after_charge); // Check storage @@ -198,7 +197,10 @@ fn charge_content_owner_works() { }) ); - assert_eq!(0, Balances::free_balance(DdcCustomers::sub_account_id(&account_3))); + assert_eq!( + 0, + Balances::free_balance(DdcCustomers::account_id()) - Balances::minimum_balance() + ); assert_eq!(charge_result, deposit - charge1); assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_3), deposit)); @@ -212,7 +214,10 @@ fn charge_content_owner_works() { }) ); - assert_eq!(deposit, Balances::free_balance(DdcCustomers::sub_account_id(&account_3))); + assert_eq!( + deposit, + Balances::free_balance(DdcCustomers::account_id()) - Balances::minimum_balance() + ); }) } diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index d61d22059..42ed6080f 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -240,6 +240,11 @@ pub mod pallet { pub type DebtorCustomers = StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; + #[pallet::storage] + #[pallet::getter(fn owing_providers)] + pub type OwingProviders = + StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] #[scale_info(skip_type_params(T))] pub struct BillingReport { @@ -316,13 +321,11 @@ pub mod pallet { Error::::NotExpectedState ); - let mut billing_report = BillingReport:: { - vault: Self::sub_account_id(cluster_id, era), + let billing_report = BillingReport:: { + vault: Self::account_id(), state: State::Initialized, ..Default::default() }; - billing_report.vault = Self::sub_account_id(cluster_id, era); - billing_report.state = State::Initialized; ActiveBillingReports::::insert(cluster_id, era, billing_report); Self::deposit_event(Event::::BillingReportInitialized { cluster_id, era }); @@ -398,12 +401,6 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; let customer_id = payer.0.clone(); - /*let amount_actually_charged = T::CustomerCharger::charge_content_owner( - customer_id.clone(), - updated_billing_report.vault.clone(), - total_customer_charge, - )?;*/ - let amount_actually_charged = match T::CustomerCharger::charge_content_owner( customer_id.clone(), updated_billing_report.vault.clone(), @@ -682,7 +679,21 @@ pub mod pallet { let node_provider_id = payee.0; if amount_to_reward > 0 { - let reward: BalanceOf = amount_to_reward.saturated_into::>(); + let mut reward: BalanceOf = + amount_to_reward.saturated_into::>(); + + let balance = ::Currency::free_balance( + &updated_billing_report.vault, + ) - ::Currency::minimum_balance(); + + if reward > balance { + ensure!( + reward - balance <= MaxDust::get().into(), + Error::::NotDistributedBalance + ); + + reward = balance; + } ::Currency::transfer( &updated_billing_report.vault, @@ -916,7 +927,44 @@ pub mod pallet { Ok(()) } + #[pallet::genesis_config] + pub struct GenesisConfig { + pub feeder_account: Option, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { feeder_account: None } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + let account_id = >::account_id(); + let min = ::Currency::minimum_balance(); + let balance = ::Currency::free_balance(&account_id); + if balance < min { + if let Some(vault) = &self.feeder_account { + let _ = ::Currency::transfer( + vault, + &account_id, + min - balance, + ExistenceRequirement::AllowDeath, + ); + } else { + let _ = ::Currency::make_free_balance_be(&account_id, min); + } + } + } + } + impl Pallet { + pub fn account_id() -> T::AccountId { + T::PalletId::get().into_account_truncating() + } + pub fn sub_account_id(cluster_id: ClusterId, era: DdcEra) -> T::AccountId { let mut bytes = Vec::new(); bytes.extend_from_slice(&cluster_id[..]); diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index b0f184a9b..00eba7232 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -49,10 +49,12 @@ construct_runtime!( { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - DdcPayouts: pallet_ddc_payouts::{Pallet, Call, Storage, Event}, + DdcPayouts: pallet_ddc_payouts::{Pallet, Call, Storage, Config, Event}, } ); +pub static MAX_DUST: u16 = 20000; + parameter_types! { pub static ExistentialDeposit: Balance = 1; } @@ -120,13 +122,28 @@ impl CustomerCharger for TestCustomerCharger { billing_vault: T::AccountId, amount: u128, ) -> Result { - ensure!(amount > 1_000_000, DispatchError::BadOrigin); // any error will do - let mut amount_to_charge = amount; - let temp = ACCOUNT_ID_5.to_ne_bytes(); + let mut temp = ACCOUNT_ID_1.to_ne_bytes(); + let account_1 = T::AccountId::decode(&mut &temp[..]).unwrap(); + temp = ACCOUNT_ID_2.to_ne_bytes(); + let account_2 = T::AccountId::decode(&mut &temp[..]).unwrap(); + temp = ACCOUNT_ID_3.to_ne_bytes(); + let account_3 = T::AccountId::decode(&mut &temp[..]).unwrap(); + temp = ACCOUNT_ID_4.to_ne_bytes(); + let account_4 = T::AccountId::decode(&mut &temp[..]).unwrap(); + temp = ACCOUNT_ID_5.to_ne_bytes(); let account_5 = T::AccountId::decode(&mut &temp[..]).unwrap(); - if amount_to_charge < 50_000_000 && content_owner != account_5 { + if content_owner == account_1 || + content_owner == account_2 || + content_owner == account_3 || + content_owner == account_4 || + content_owner == account_5 + { + ensure!(amount > 1_000_000, DispatchError::BadOrigin); // any error will do + } + + if amount_to_charge < 50_000_000 && content_owner == account_3 { amount_to_charge = PARTIAL_CHARGE; // for user 3 } @@ -142,6 +159,10 @@ impl CustomerCharger for TestCustomerCharger { } } +pub const ACCOUNT_ID_1: AccountId = 1; +pub const ACCOUNT_ID_2: AccountId = 2; +pub const ACCOUNT_ID_3: AccountId = 3; +pub const ACCOUNT_ID_4: AccountId = 4; pub const ACCOUNT_ID_5: AccountId = 5; pub struct TestClusterCreator; impl ClusterCreator for TestClusterCreator { @@ -280,11 +301,19 @@ impl SortedListProvider for TestValidator } } -pub fn get_fees(cluster_id: &ClusterId) -> Result { +pub fn get_fees(cluster_id: &ClusterId) -> ClusterFeesParams { if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { - Ok(PRICING_FEES_ZERO) + PRICING_FEES_ZERO } else { - Ok(PRICING_FEES) + PRICING_FEES + } +} + +pub fn get_pricing(cluster_id: &ClusterId) -> ClusterPricingParams { + if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { + PRICING_PARAMS_ONE + } else { + PRICING_PARAMS } } @@ -315,15 +344,11 @@ impl ClusterVisitor for TestClusterVisitor { fn get_pricing_params( cluster_id: &ClusterId, ) -> Result { - if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { - Ok(PRICING_PARAMS_ONE) - } else { - Ok(PRICING_PARAMS) - } + Ok(get_pricing(cluster_id)) } fn get_fees_params(cluster_id: &ClusterId) -> Result { - get_fees(cluster_id) + Ok(get_fees(cluster_id)) } fn get_reserve_account_id( @@ -349,7 +374,7 @@ impl ExtBuilder { sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); - let _ = pallet_balances::GenesisConfig:: { + let _balance_genesis = pallet_balances::GenesisConfig:: { balances: vec![ (1, 10000000000000000000000000000), (2, 10), // < PARTIAL_CHARGE @@ -360,6 +385,9 @@ impl ExtBuilder { } .assimilate_storage(&mut storage); + let _payout_genesis = pallet_ddc_payouts::GenesisConfig:: { feeder_account: None } + .assimilate_storage(&mut storage); + TestExternalities::new(storage) } pub fn build_and_execute(self, test: impl FnOnce()) { diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 6bab56cce..f4d1732af 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -258,11 +258,7 @@ fn send_charging_customers_batch_fails_uninitialised() { } fn calculate_charge_parts(cluster_id: ClusterId, usage: CustomerUsage) -> CustomerCharge { - let pricing_params = if cluster_id == FREE_CLUSTER_ID || cluster_id == ONE_CLUSTER_ID { - PRICING_PARAMS_ONE - } else { - PRICING_PARAMS - }; + let pricing_params = get_pricing(&cluster_id); CustomerCharge { transfer: pricing_params.unit_per_mb_streamed * (usage.transferred_bytes as u128) / @@ -350,8 +346,8 @@ fn send_charging_customers_batch_works1() { )); let usage4_charge = calculate_charge(cluster_id, usage4.clone()); - let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); - assert_eq!(balance, usage4_charge); + let mut balance = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance - Balances::minimum_balance(), usage4_charge); let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); let mut debt = calculate_charge(cluster_id, usage2.clone()); @@ -397,7 +393,7 @@ fn send_charging_customers_batch_works1() { .into(), ); - assert_eq!(System::events().len(), 5 + 3 + 1); // 3 for Currency::transfer + assert_eq!(System::events().len(), 5 + 1 + 1); // 1 for Currency::transfer // batch 2 let mut before_total_customer_charge = report.total_customer_charge.clone(); @@ -444,7 +440,7 @@ fn send_charging_customers_batch_works1() { let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); assert_eq!(user1_debt, None); - let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + let balance_before = Balances::free_balance(DdcPayouts::account_id()); // batch 3 batch_index += 1; @@ -478,7 +474,7 @@ fn send_charging_customers_batch_works1() { report.total_customer_charge.transfer ); - balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); @@ -547,7 +543,7 @@ fn send_charging_customers_batch_works2() { // batch 1 let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); let before_total_customer_charge = report.total_customer_charge.clone(); - let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + let balance_before = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, @@ -558,7 +554,7 @@ fn send_charging_customers_batch_works2() { let usage5_charge = calculate_charge(cluster_id, usage5.clone()); let charge5 = calculate_charge_parts(cluster_id, usage5); - let balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); + let balance = Balances::free_balance(DdcPayouts::account_id()); report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); assert_eq!(balance, usage5_charge + balance_before); assert_eq!( @@ -700,9 +696,9 @@ fn end_charging_customers_works() { .into(), ); - let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); - assert_eq!(balance, charge); - assert_eq!(System::events().len(), 4 + 3); // 3 for Currency::transfer + let mut balance = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance - Balances::minimum_balance(), charge); + assert_eq!(System::events().len(), 4 + 1); // 1 for Currency::transfer assert_ok!(DdcPayouts::end_charging_customers( RuntimeOrigin::signed(dac_account), @@ -712,9 +708,9 @@ fn end_charging_customers_works() { System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); - let treasury_fee = PRICING_FEES.treasury_share * charge; - let reserve_fee = PRICING_FEES.cluster_reserve_share * charge; - let validator_fee = PRICING_FEES.validators_share * charge; + let treasury_fee = get_fees(&cluster_id).treasury_share * charge; + let reserve_fee = get_fees(&cluster_id).cluster_reserve_share * charge; + let validator_fee = get_fees(&cluster_id).validators_share * charge; System::assert_has_event( Event::TreasuryFeesCollected { cluster_id, era, amount: treasury_fee }.into(), @@ -729,30 +725,30 @@ fn end_charging_customers_works() { ); let transfers = 3 + 3 + 3 * 3; // for Currency::transfer - assert_eq!(System::events().len(), 7 + 1 + 3 + transfers); + assert_eq!(System::events().len(), 5 + 1 + 3 + transfers); let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); - let total_left_from_one = (PRICING_FEES.treasury_share + - PRICING_FEES.validators_share + - PRICING_FEES.cluster_reserve_share) + let total_left_from_one = (get_fees(&cluster_id).treasury_share + + get_fees(&cluster_id).validators_share + + get_fees(&cluster_id).cluster_reserve_share) .left_from_one(); balance = Balances::free_balance(TREASURY_ACCOUNT_ID); - assert_eq!(balance, PRICING_FEES.treasury_share * charge); + assert_eq!(balance, get_fees(&cluster_id).treasury_share * charge); balance = Balances::free_balance(RESERVE_ACCOUNT_ID); - assert_eq!(balance, PRICING_FEES.cluster_reserve_share * charge); + assert_eq!(balance, get_fees(&cluster_id).cluster_reserve_share * charge); balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); - assert_eq!(balance, PRICING_FEES.validators_share * charge / 3); + assert_eq!(balance, get_fees(&cluster_id).validators_share * charge / 3); balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); - assert_eq!(balance, PRICING_FEES.validators_share * charge / 3); + assert_eq!(balance, get_fees(&cluster_id).validators_share * charge / 3); balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); - assert_eq!(balance, PRICING_FEES.validators_share * charge / 3); + assert_eq!(balance, get_fees(&cluster_id).validators_share * charge / 3); assert_eq!( report_after.total_customer_charge.transfer, @@ -822,9 +818,9 @@ fn end_charging_customers_works_zero_fees() { .into(), ); - let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); - assert_eq!(balance, charge); - assert_eq!(System::events().len(), 4 + 3); // 3 for Currency::transfer + let mut balance = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance - Balances::minimum_balance(), charge); + assert_eq!(System::events().len(), 4 + 1); // 1 for Currency::transfer assert_ok!(DdcPayouts::end_charging_customers( RuntimeOrigin::signed(dac_account), @@ -833,12 +829,12 @@ fn end_charging_customers_works_zero_fees() { )); System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); - assert_eq!(System::events().len(), 7 + 1); + assert_eq!(System::events().len(), 5 + 1); let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); - let fees = get_fees(&cluster_id).unwrap(); + let fees = get_fees(&cluster_id); let total_left_from_one = (fees.treasury_share + fees.validators_share + fees.cluster_reserve_share) @@ -1308,9 +1304,9 @@ fn send_rewarding_providers_batch_works() { )); let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let total_left_from_one = (PRICING_FEES.treasury_share + - PRICING_FEES.validators_share + - PRICING_FEES.cluster_reserve_share) + let total_left_from_one = (get_fees(&cluster_id).treasury_share + + get_fees(&cluster_id).validators_share + + get_fees(&cluster_id).cluster_reserve_share) .left_from_one(); assert_eq!( @@ -1452,6 +1448,258 @@ fn send_rewarding_providers_batch_works() { }) } +#[test] +fn send_rewarding_providers_batch_works100nodes() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let num_nodes = 100; + let num_users = 5; + let dac_account = 123u128; + let bank = 1u128; + let cluster_id = ONE_CLUSTER_ID; + let era = 100; + let user_batch_size = 10; + let node_batch_size = 10; + let mut batch_user_index = 0; + let mut batch_node_index = 0; + let usage1 = CustomerUsage { + transferred_bytes: 1024, + stored_bytes: 1024, + number_of_puts: 1, + number_of_gets: 1, + }; + + let node_usage1 = NodeUsage { + // CDN + transferred_bytes: Perquintill::from_float(0.75) * usage1.transferred_bytes, + stored_bytes: 0, + number_of_puts: Perquintill::from_float(0.75) * usage1.number_of_puts, + number_of_gets: Perquintill::from_float(0.75) * usage1.number_of_gets, + }; + + let node_usage2 = NodeUsage { + // Storage + transferred_bytes: 0, + stored_bytes: usage1.stored_bytes * 2, + number_of_puts: 0, + number_of_gets: 0, + }; + + let node_usage3 = NodeUsage { + // CDN + Storage + transferred_bytes: usage1.transferred_bytes * 2, + stored_bytes: usage1.stored_bytes * 3, + number_of_puts: usage1.number_of_puts * 2, + number_of_gets: usage1.number_of_gets * 2, + }; + + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut total_nodes_usage = NodeUsage::default(); + for i in 10..10 + num_nodes { + let node_usage = match i % 3 { + 0 => node_usage1.clone(), + 1 => node_usage2.clone(), + 2 => node_usage3.clone(), + _ => unreachable!(), + }; + total_nodes_usage.transferred_bytes += node_usage.transferred_bytes; + total_nodes_usage.stored_bytes += node_usage.stored_bytes; + total_nodes_usage.number_of_puts += node_usage.number_of_puts; + total_nodes_usage.number_of_gets += node_usage.number_of_gets; + + node_batch.push((i, node_usage)); + if node_batch.len() == node_batch_size { + payees.push(node_batch.clone()); + node_batch.clear(); + } + } + if !node_batch.is_empty() { + payees.push(node_batch.clone()); + } + + let mut total_charge = 0u128; + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(u128, CustomerUsage)> = Vec::new(); + for user_id in 1000..1000 + num_users { + let ratio = match user_id % 5 { + 0 => Perquintill::one(), + 1 => Perquintill::from_float(0.5), + 2 => Perquintill::from_float(2f64), + 3 => Perquintill::from_float(0.25), + 4 => Perquintill::from_float(0.001), + _ => unreachable!(), + }; + + let mut user_usage = usage1.clone(); + user_usage.transferred_bytes = ratio * user_usage.transferred_bytes; + user_usage.stored_bytes = ratio * user_usage.stored_bytes; + user_usage.number_of_puts = ratio * user_usage.number_of_puts; + user_usage.number_of_gets = ratio * user_usage.number_of_gets; + + let expected_charge = calculate_charge(cluster_id, user_usage.clone()); + Balances::transfer( + RuntimeOrigin::signed(bank), + user_id, + (expected_charge * 2).max(Balances::minimum_balance()), + ) + .unwrap(); + total_charge += expected_charge; + + user_batch.push((user_id, user_usage)); + if user_batch.len() == user_batch_size { + payers.push(user_batch.clone()); + user_batch.clear(); + } + } + if !user_batch.is_empty() { + payers.push(user_batch.clone()); + } + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payers.len() - 1) as u16, + )); + + for batch in payers.iter() { + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_user_index, + batch.to_vec(), + )); + + for (customer_id, usage) in batch.iter() { + let charge = calculate_charge(cluster_id, usage.clone()); + + System::assert_has_event( + Event::Charged { + cluster_id, + era, + customer_id: *customer_id, + batch_index: batch_user_index, + amount: charge, + } + .into(), + ); + } + batch_user_index += 1; + } + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let balance1 = Balances::free_balance(report_before.vault); + let balance2 = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance1, balance2); + assert_eq!(report_before.vault, DdcPayouts::account_id()); + assert_eq!(balance1 - Balances::minimum_balance(), total_charge); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let total_left_from_one = (get_fees(&cluster_id).treasury_share + + get_fees(&cluster_id).validators_share + + get_fees(&cluster_id).cluster_reserve_share) + .left_from_one(); + + let total_charge = report_after.total_customer_charge.transfer + + report_before.total_customer_charge.storage + + report_before.total_customer_charge.puts + + report_before.total_customer_charge.gets; + let balance_after = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(total_charge, balance_after - Balances::minimum_balance()); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payees.len() - 1) as u16, + total_nodes_usage.clone(), + )); + + for batch in payees.iter() { + let before_batch = Balances::free_balance(DdcPayouts::account_id()); + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_node_index, + batch.to_vec(), + )); + + let mut batch_charge = 0; + for (node1, node_usage1) in batch.iter() { + let ratio1_transfer = Perquintill::from_rational( + node_usage1.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + let transfer_charge = ratio1_transfer * report_after.total_customer_charge.transfer; + + let ratio1_storage = Perquintill::from_rational( + node_usage1.stored_bytes, + total_nodes_usage.stored_bytes, + ); + let storage_charge = ratio1_storage * report_after.total_customer_charge.storage; + + let ratio1_puts = Perquintill::from_rational( + node_usage1.number_of_puts, + total_nodes_usage.number_of_puts, + ); + let puts_charge = ratio1_puts * report_after.total_customer_charge.puts; + + let ratio1_gets = Perquintill::from_rational( + node_usage1.number_of_gets, + total_nodes_usage.number_of_gets, + ); + let gets_charge = ratio1_gets * report_after.total_customer_charge.gets; + + let balance_node1 = Balances::free_balance(node1); + assert!( + (transfer_charge + storage_charge + puts_charge + gets_charge) - balance_node1 < + MAX_DUST.into() + ); + + batch_charge += transfer_charge + storage_charge + puts_charge + gets_charge; + } + let after_batch = Balances::free_balance(DdcPayouts::account_id()); + assert!(batch_charge + after_batch - before_batch < MAX_DUST.into()); + + batch_node_index += 1; + } + assert!(Balances::free_balance(DdcPayouts::account_id()) < MAX_DUST.into()); + }) +} + #[test] fn end_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { From 276c4df51482f9ca7cefa572c8f2ea70e6f9ef52 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:27:46 +0200 Subject: [PATCH 536/544] Payout dust (#196) --- pallets/ddc-payouts/src/lib.rs | 59 +++++-- pallets/ddc-payouts/src/mock.rs | 2 +- pallets/ddc-payouts/src/tests.rs | 267 ++++++++++++++++++++++++++++++- 3 files changed, 309 insertions(+), 19 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 42ed6080f..4b309dd0d 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -190,6 +190,19 @@ pub mod pallet { node_provider_id: T::AccountId, amount: u128, }, + NotDistributedReward { + cluster_id: ClusterId, + era: DdcEra, + node_provider_id: T::AccountId, + expected_reward: u128, + distributed_reward: BalanceOf, + }, + NotDistributedOverallReward { + cluster_id: ClusterId, + era: DdcEra, + expected_reward: u128, + total_distributed_reward: u128, + }, RewardingFinished { cluster_id: ClusterId, era: DdcEra, @@ -212,7 +225,6 @@ pub mod pallet { BatchIndexAlreadyProcessed, BatchIndexIsOutOfRange, BatchesMissed, - NotDistributedBalance, BatchIndexOverflow, BoundedVecOverflow, ArithmeticOverflow, @@ -682,17 +694,22 @@ pub mod pallet { let mut reward: BalanceOf = amount_to_reward.saturated_into::>(); - let balance = ::Currency::free_balance( + let vault_balance = ::Currency::free_balance( &updated_billing_report.vault, ) - ::Currency::minimum_balance(); - if reward > balance { - ensure!( - reward - balance <= MaxDust::get().into(), - Error::::NotDistributedBalance - ); - - reward = balance; + if reward > vault_balance { + if reward - vault_balance > MaxDust::get().into() { + Self::deposit_event(Event::::NotDistributedReward { + cluster_id, + era, + node_provider_id: node_provider_id.clone(), + expected_reward: amount_to_reward, + distributed_reward: vault_balance, + }); + } + + reward = vault_balance; } ::Currency::transfer( @@ -758,11 +775,16 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - ensure!( - expected_amount_to_reward - billing_report.total_distributed_reward <= - MaxDust::get().into(), - Error::::NotDistributedBalance - ); + if expected_amount_to_reward - billing_report.total_distributed_reward > + MaxDust::get().into() + { + Self::deposit_event(Event::::NotDistributedOverallReward { + cluster_id, + era, + expected_reward: expected_amount_to_reward, + total_distributed_reward: billing_report.total_distributed_reward, + }); + } billing_report.state = State::ProvidersRewarded; ActiveBillingReports::::insert(cluster_id, era, billing_report); @@ -854,14 +876,17 @@ pub mod pallet { let mut node_reward = NodeReward::default(); let mut ratio = Perquintill::from_rational( - node_usage.transferred_bytes, - total_nodes_usage.transferred_bytes, + node_usage.transferred_bytes as u128, + total_nodes_usage.transferred_bytes as u128, ); // ratio multiplied by X will be > 0, < X no overflow node_reward.transfer = ratio * total_customer_charge.transfer; - ratio = Perquintill::from_rational(node_usage.stored_bytes, total_nodes_usage.stored_bytes); + ratio = Perquintill::from_rational( + node_usage.stored_bytes as u128, + total_nodes_usage.stored_bytes as u128, + ); node_reward.storage = ratio * total_customer_charge.storage; ratio = diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 00eba7232..23fd03310 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -53,7 +53,7 @@ construct_runtime!( } ); -pub static MAX_DUST: u16 = 20000; +pub static MAX_DUST: u16 = 100; parameter_types! { pub static ExistentialDeposit: Balance = 1; diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index f4d1732af..4a1a9047e 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -1449,7 +1449,7 @@ fn send_rewarding_providers_batch_works() { } #[test] -fn send_rewarding_providers_batch_works100nodes() { +fn send_rewarding_providers_batch_100nodes_small_usage_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); @@ -1700,6 +1700,271 @@ fn send_rewarding_providers_batch_works100nodes() { }) } +#[test] +fn send_rewarding_providers_batch_100nodes_large_usage_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let num_nodes = 100; + let num_users = 5; + let dac_account = 123u128; + let bank = 1u128; + let cluster_id = ONE_CLUSTER_ID; + let era = 100; + let user_batch_size = 10; + let node_batch_size = 10; + let mut batch_user_index = 0; + let mut batch_node_index = 0; + let usage1 = CustomerUsage { + transferred_bytes: 1024, + stored_bytes: 1024, + number_of_puts: 1, + number_of_gets: 1, + }; + + let node_usage1 = NodeUsage { + // CDN + transferred_bytes: Perquintill::from_float(0.75) * usage1.transferred_bytes, + stored_bytes: 0, + number_of_puts: Perquintill::from_float(0.75) * usage1.number_of_puts, + number_of_gets: Perquintill::from_float(0.75) * usage1.number_of_gets, + }; + + let node_usage2 = NodeUsage { + // Storage + transferred_bytes: 0, + stored_bytes: usage1.stored_bytes * 2, + number_of_puts: 0, + number_of_gets: 0, + }; + + let node_usage3 = NodeUsage { + // CDN + Storage + transferred_bytes: usage1.transferred_bytes * 2, + stored_bytes: usage1.stored_bytes * 3, + number_of_puts: usage1.number_of_puts * 2, + number_of_gets: usage1.number_of_gets * 2, + }; + + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut total_nodes_usage = NodeUsage::default(); + for i in 10..10 + num_nodes { + let ratio = match i % 5 { + 0 => Perquintill::from_float(1_000_000.0), + 1 => Perquintill::from_float(10_000_000.0), + 2 => Perquintill::from_float(100_000_000.0), + 3 => Perquintill::from_float(1_000_000_000.0), + 4 => Perquintill::from_float(10_000_000_000.0), + _ => unreachable!(), + }; + let mut node_usage = match i % 3 { + 0 => node_usage1.clone(), + 1 => node_usage2.clone(), + 2 => node_usage3.clone(), + _ => unreachable!(), + }; + node_usage.transferred_bytes = ratio * node_usage.transferred_bytes; + node_usage.stored_bytes = ratio * node_usage.stored_bytes; + node_usage.number_of_puts = ratio * node_usage.number_of_puts; + node_usage.number_of_gets = ratio * node_usage.number_of_gets; + + total_nodes_usage.transferred_bytes += node_usage.transferred_bytes; + total_nodes_usage.stored_bytes += node_usage.stored_bytes; + total_nodes_usage.number_of_puts += node_usage.number_of_puts; + total_nodes_usage.number_of_gets += node_usage.number_of_gets; + + node_batch.push((i, node_usage)); + if node_batch.len() == node_batch_size { + payees.push(node_batch.clone()); + node_batch.clear(); + } + } + if !node_batch.is_empty() { + payees.push(node_batch.clone()); + } + + let mut total_charge = 0u128; + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(u128, CustomerUsage)> = Vec::new(); + for user_id in 1000..1000 + num_users { + let ratio = match user_id % 5 { + 0 => Perquintill::from_float(1_000_000.0), + 1 => Perquintill::from_float(10_000_000.0), + 2 => Perquintill::from_float(100_000_000.0), + 3 => Perquintill::from_float(1_000_000_000.0), + 4 => Perquintill::from_float(10_000_000_000.0), + _ => unreachable!(), + }; + + let mut user_usage = usage1.clone(); + user_usage.transferred_bytes = ratio * user_usage.transferred_bytes; + user_usage.stored_bytes = ratio * user_usage.stored_bytes; + user_usage.number_of_puts = ratio * user_usage.number_of_puts; + user_usage.number_of_gets = ratio * user_usage.number_of_gets; + + let expected_charge = calculate_charge(cluster_id, user_usage.clone()); + Balances::transfer( + RuntimeOrigin::signed(bank), + user_id, + (expected_charge * 2).max(Balances::minimum_balance()), + ) + .unwrap(); + total_charge += expected_charge; + + user_batch.push((user_id, user_usage)); + if user_batch.len() == user_batch_size { + payers.push(user_batch.clone()); + user_batch.clear(); + } + } + if !user_batch.is_empty() { + payers.push(user_batch.clone()); + } + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payers.len() - 1) as u16, + )); + + for batch in payers.iter() { + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_user_index, + batch.to_vec(), + )); + + for (customer_id, usage) in batch.iter() { + let charge = calculate_charge(cluster_id, usage.clone()); + + System::assert_has_event( + Event::Charged { + cluster_id, + era, + customer_id: *customer_id, + batch_index: batch_user_index, + amount: charge, + } + .into(), + ); + } + batch_user_index += 1; + } + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let balance1 = Balances::free_balance(report_before.vault); + let balance2 = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance1, balance2); + assert_eq!(report_before.vault, DdcPayouts::account_id()); + assert_eq!(balance1 - Balances::minimum_balance(), total_charge); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let total_left_from_one = (get_fees(&cluster_id).treasury_share + + get_fees(&cluster_id).validators_share + + get_fees(&cluster_id).cluster_reserve_share) + .left_from_one(); + + let total_charge = report_after.total_customer_charge.transfer + + report_before.total_customer_charge.storage + + report_before.total_customer_charge.puts + + report_before.total_customer_charge.gets; + let balance_after = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(total_charge, balance_after - Balances::minimum_balance()); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payees.len() - 1) as u16, + total_nodes_usage.clone(), + )); + + for batch in payees.iter() { + let before_batch = Balances::free_balance(DdcPayouts::account_id()); + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_node_index, + batch.to_vec(), + )); + + let mut batch_charge = 0; + for (node1, node_usage1) in batch.iter() { + let ratio1_transfer = Perquintill::from_rational( + node_usage1.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + let transfer_charge = ratio1_transfer * report_after.total_customer_charge.transfer; + + let ratio1_storage = Perquintill::from_rational( + node_usage1.stored_bytes, + total_nodes_usage.stored_bytes, + ); + let storage_charge = ratio1_storage * report_after.total_customer_charge.storage; + + let ratio1_puts = Perquintill::from_rational( + node_usage1.number_of_puts, + total_nodes_usage.number_of_puts, + ); + let puts_charge = ratio1_puts * report_after.total_customer_charge.puts; + + let ratio1_gets = Perquintill::from_rational( + node_usage1.number_of_gets, + total_nodes_usage.number_of_gets, + ); + let gets_charge = ratio1_gets * report_after.total_customer_charge.gets; + + let balance_node1 = Balances::free_balance(node1); + assert!( + (transfer_charge + storage_charge + puts_charge + gets_charge) - balance_node1 < + MAX_DUST.into() + ); + + batch_charge += transfer_charge + storage_charge + puts_charge + gets_charge; + } + let after_batch = Balances::free_balance(DdcPayouts::account_id()); + assert!(batch_charge + after_batch - before_batch < MAX_DUST.into()); + + batch_node_index += 1; + } + assert!(Balances::free_balance(DdcPayouts::account_id()) < MAX_DUST.into()); + }) +} + #[test] fn end_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { From 8e14ecc2c0d8588745fb6c30e908ad53ad973b07 Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Mon, 18 Dec 2023 18:16:20 +0100 Subject: [PATCH 537/544] Backporting #197, #201, #199 and #200 from `dev` branch to substrate `0.9.30` (#202) Backporting the following PRs from the dev branch: - [#197](https://github.com/Cerebellum-Network/blockchain-node/pull/197) - [#201](https://github.com/Cerebellum-Network/blockchain-node/pull/201) - [#199](https://github.com/Cerebellum-Network/blockchain-node/pull/199) - [#200](https://github.com/Cerebellum-Network/blockchain-node/pull/200) --------- Co-authored-by: Alisher A. Khassanov --- docs/genesis-state.md | 7 +- node/service/chain-specs/example.json | 20 +- pallets/ddc-clusters/src/benchmarking.rs | 126 ++++---- pallets/ddc-clusters/src/lib.rs | 6 - pallets/ddc-clusters/src/mock.rs | 5 +- pallets/ddc-clusters/src/testing_utils.rs | 20 +- pallets/ddc-clusters/src/tests.rs | 67 ++--- pallets/ddc-clusters/src/weights.rs | 113 +++---- pallets/ddc-customers/src/benchmarking.rs | 113 ++++--- pallets/ddc-customers/src/lib.rs | 59 +++- pallets/ddc-customers/src/mock.rs | 15 - pallets/ddc-customers/src/tests.rs | 130 +++++++- pallets/ddc-customers/src/weights.rs | 78 ++--- pallets/ddc-nodes/src/benchmarking.rs | 52 ++-- pallets/ddc-nodes/src/cdn_node.rs | 105 ------- pallets/ddc-nodes/src/lib.rs | 44 +-- pallets/ddc-nodes/src/node.rs | 27 -- pallets/ddc-nodes/src/storage_node.rs | 12 +- pallets/ddc-nodes/src/testing_utils.rs | 12 +- pallets/ddc-nodes/src/tests.rs | 342 +--------------------- pallets/ddc-nodes/src/weights.rs | 85 +++--- pallets/ddc-payouts/src/tests.rs | 6 +- pallets/ddc-payouts/src/weights.rs | 60 ++-- pallets/ddc-staking/README.md | 3 +- pallets/ddc-staking/src/benchmarking.rs | 42 ++- pallets/ddc-staking/src/lib.rs | 163 ++--------- pallets/ddc-staking/src/mock.rs | 69 +---- pallets/ddc-staking/src/testing_utils.rs | 32 +- pallets/ddc-staking/src/tests.rs | 212 +++----------- pallets/ddc-staking/src/weights.rs | 116 ++------ primitives/src/lib.rs | 26 +- 31 files changed, 713 insertions(+), 1454 deletions(-) delete mode 100644 pallets/ddc-nodes/src/cdn_node.rs diff --git a/docs/genesis-state.md b/docs/genesis-state.md index 587683b62..0e1c8b98f 100644 --- a/docs/genesis-state.md +++ b/docs/genesis-state.md @@ -1,4 +1,4 @@ -# State preset +# Genesis state Sometimes we use the blockchain as a part of a test environment. Those tests typically want a certain state of the blockchain. @@ -22,6 +22,11 @@ And a _raw_ form with key-value pairs which will be written to the database. 1. Set genesis state for each module. There is an example in `node/service/example.json`, you can copy everything except the `code` field value from it to the `plain.json`. + > Special note for a `ddcNodes.storageNodes.host` field. + > In the `example.json` it is set as: + > `"host": [ 49, 50, 55, 46, 48, 46, 48, 46, 49 ]`. + > Where the array is an encoded `127.0.0.1` value. + 1. Create a raw form chain spec. ```console diff --git a/node/service/chain-specs/example.json b/node/service/chain-specs/example.json index 7e3b5c97c..e61b43fbc 100644 --- a/node/service/chain-specs/example.json +++ b/node/service/chain-specs/example.json @@ -157,7 +157,6 @@ "maxMembers": 512 }, "ddcStaking": { - "cdns": [], "storages": [] }, "ddcCustomers": { @@ -165,7 +164,8 @@ [ "0x0000000000000000000000000000000000000001", "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - 10000000000 + 10000000000, + false ] ] }, @@ -176,14 +176,23 @@ "provider_id": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "cluster_id": "0x0000000000000000000000000000000000000001", "props": { - "host": [], + "host": [ + 49, + 50, + 55, + 46, + 48, + 46, + 48, + 46, + 49 + ], "http_port": 8080, "grpc_port": 8081, "p2p_port": 8082 } } ], - "cdnNodes": [] }, "ddcClusters": { "clusters": [ @@ -203,9 +212,6 @@ "treasury_share": 0, "validators_share": 0, "cluster_reserve_share": 0, - "cdn_bond_size": 0, - "cdn_chill_delay": 0, - "cdn_unbonding_delay": 0, "storage_bond_size": 0, "storage_chill_delay": 0, "storage_unbonding_delay": 0, diff --git a/pallets/ddc-clusters/src/benchmarking.rs b/pallets/ddc-clusters/src/benchmarking.rs index 9ce6b28d9..2405330d7 100644 --- a/pallets/ddc-clusters/src/benchmarking.rs +++ b/pallets/ddc-clusters/src/benchmarking.rs @@ -22,93 +22,87 @@ benchmarks! { T::AccountId: UncheckedFrom + AsRef<[u8]> } create_cluster { - let cluster_id = ClusterId::from([1; 20]); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; - let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { - treasury_share: Perquintill::default(), - validators_share: Perquintill::default(), - cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), - storage_bond_size: 100u32.into(), - storage_chill_delay: 50u32.into(), - storage_unbonding_delay: 50u32.into(), - unit_per_mb_stored: 10, - unit_per_mb_streamed: 10, - unit_per_put_request: 10, - unit_per_get_request: 10, - }; + let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + storage_bond_size: 100u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; }: _(RawOrigin::Root, cluster_id, user.clone(), user, cluster_params, cluster_gov_params) verify { assert!(Clusters::::contains_key(cluster_id)); } - add_node { - let bytes = [0u8; 32]; - let node_pub_key = NodePubKey::CDNPubKey(AccountId32::from(bytes)); - let cluster_id = ClusterId::from([1; 20]); + add_node { + let bytes = [0u8; 32]; + let node_pub_key = NodePubKey::StoragePubKey(AccountId32::from(bytes)); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); - let _ = ::Currency::make_free_balance_be(&user, balance); - let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); - }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) - verify { - assert!(ClustersNodes::::contains_key(cluster_id, node_pub_key)); - } + let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); + }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) + verify { + assert!(ClustersNodes::::contains_key(cluster_id, node_pub_key)); + } - remove_node { - let bytes = [0u8; 32]; - let node_pub_key = NodePubKey::CDNPubKey(AccountId32::from(bytes)); - let cluster_id = ClusterId::from([1; 20]); + remove_node { + let bytes = [0u8; 32]; + let node_pub_key = NodePubKey::StoragePubKey(AccountId32::from(bytes)); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); - let _ = ::Currency::make_free_balance_be(&user, balance); - let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); - let _ = DdcClusters::::add_node( - RawOrigin::Signed(user.clone()).into(), - cluster_id, - node_pub_key.clone() - ); - }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) - verify { - assert!(!ClustersNodes::::contains_key(cluster_id, node_pub_key)); - } + let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); + let _ = DdcClusters::::add_node( + RawOrigin::Signed(user.clone()).into(), + cluster_id, + node_pub_key.clone() + ); + }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) + verify { + assert!(!ClustersNodes::::contains_key(cluster_id, node_pub_key)); + } set_cluster_params { - let cluster_id = ClusterId::from([1; 20]); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); let user_2 = account::("user", USER_SEED_2, 0u32); - let _ = config_cluster::(user.clone(), cluster_id); - let new_cluster_params = ClusterParams { node_provider_auth_contract: Some(user_2.clone()) }; + let _ = config_cluster::(user.clone(), cluster_id); + let new_cluster_params = ClusterParams { node_provider_auth_contract: Some(user_2.clone()) }; }: _(RawOrigin::Signed(user.clone()), cluster_id, new_cluster_params) verify { - assert_eq!(Clusters::::try_get(cluster_id).unwrap().props, ClusterProps { node_provider_auth_contract: Some(user_2) }); + assert_eq!(Clusters::::try_get(cluster_id).unwrap().props, ClusterProps { node_provider_auth_contract: Some(user_2) }); } set_cluster_gov_params { - let cluster_id = ClusterId::from([1; 20]); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let _ = config_cluster::(user, cluster_id); - let new_cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { - treasury_share: Perquintill::default(), - validators_share: Perquintill::default(), - cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 10u32.into(), - cdn_chill_delay: 5u32.into(), - cdn_unbonding_delay: 5u32.into(), - storage_bond_size: 10u32.into(), - storage_chill_delay: 5u32.into(), - storage_unbonding_delay: 5u32.into(), - unit_per_mb_stored: 1, - unit_per_mb_streamed: 1, - unit_per_put_request: 1, - unit_per_get_request: 1, - }; + let _ = config_cluster::(user, cluster_id); + let new_cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + storage_bond_size: 10u32.into(), + storage_chill_delay: 5u32.into(), + storage_unbonding_delay: 5u32.into(), + unit_per_mb_stored: 1, + unit_per_mb_streamed: 1, + unit_per_put_request: 1, + unit_per_get_request: 1, + }; }: _(RawOrigin::Root, cluster_id, new_cluster_gov_params.clone()) verify { - assert_eq!(ClustersGovParams::::try_get(cluster_id).unwrap(), new_cluster_gov_params); + assert_eq!(ClustersGovParams::::try_get(cluster_id).unwrap(), new_cluster_gov_params); } impl_benchmark_test_suite!( diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index a9c501854..49bbe1f87 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -350,7 +350,6 @@ pub mod pallet { match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_bond_size.saturated_into::()), - NodeType::CDN => Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), } } @@ -396,7 +395,6 @@ pub mod pallet { .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_chill_delay), - NodeType::CDN => Ok(cluster_gov_params.cdn_chill_delay), } } @@ -408,7 +406,6 @@ pub mod pallet { .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_unbonding_delay), - NodeType::CDN => Ok(cluster_gov_params.cdn_unbonding_delay), } } @@ -418,9 +415,6 @@ pub mod pallet { let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; Ok(ClusterBondingParams { - cdn_bond_size: cluster_gov_params.cdn_bond_size.saturated_into::(), - cdn_chill_delay: cluster_gov_params.cdn_chill_delay, - cdn_unbonding_delay: cluster_gov_params.cdn_unbonding_delay, storage_bond_size: cluster_gov_params.storage_bond_size.saturated_into::(), storage_chill_delay: cluster_gov_params.storage_chill_delay, storage_unbonding_delay: cluster_gov_params.storage_unbonding_delay, diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs index d9beb473d..ab7e449bb 100644 --- a/pallets/ddc-clusters/src/mock.rs +++ b/pallets/ddc-clusters/src/mock.rs @@ -247,9 +247,6 @@ impl ExtBuilder { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -259,7 +256,7 @@ impl ExtBuilder { unit_per_get_request: 10, }; - let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([0; 32])); + let node_pub_key = NodePubKey::StoragePubKey(AccountId::from([0; 32])); // For testing purposes only pallet_ddc_clusters::GenesisConfig::::default().build(); diff --git a/pallets/ddc-clusters/src/testing_utils.rs b/pallets/ddc-clusters/src/testing_utils.rs index b32e9ecca..999a066ba 100644 --- a/pallets/ddc-clusters/src/testing_utils.rs +++ b/pallets/ddc-clusters/src/testing_utils.rs @@ -1,7 +1,8 @@ //! DdcStaking pallet benchmarking. use ddc_primitives::{ - CDNNodeParams, ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, + ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, StorageNodeMode, + StorageNodeParams, }; pub use frame_benchmarking::{ account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, @@ -24,9 +25,6 @@ where treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 100u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), @@ -55,7 +53,8 @@ where T::AccountId: UncheckedFrom + AsRef<[u8]>, { let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; - let cdn_node_params = CDNNodeParams { + let storage_node_params = StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -66,9 +65,6 @@ where treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 100u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), @@ -87,9 +83,11 @@ where cluster_gov_params, ); - if let Ok(new_node) = - Node::::new(node_pub_key.clone(), user.clone(), NodeParams::CDNParams(cdn_node_params)) - { + if let Ok(new_node) = Node::::new( + node_pub_key.clone(), + user.clone(), + NodeParams::StorageParams(storage_node_params), + ) { let _ = T::NodeRepository::create(new_node); } diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index b94627f47..948b28d1c 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -2,8 +2,8 @@ use super::{mock::*, *}; use ddc_primitives::{ - CDNNodeParams, ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, - ClusterPricingParams, NodeParams, NodePubKey, + ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, ClusterPricingParams, + NodeParams, NodePubKey, StorageNodeMode, StorageNodeParams, }; use ddc_traits::cluster::ClusterManager; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; @@ -25,9 +25,6 @@ fn create_cluster_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -98,7 +95,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::ClusterDoesNotExist ); @@ -114,9 +111,6 @@ fn add_and_delete_node_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -132,7 +126,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_reserve_id), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::OnlyClusterManager ); @@ -142,12 +136,13 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::AttemptToAddNonExistentNode ); - let cdn_node_params = CDNNodeParams { + let storage_node_params = StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -157,8 +152,8 @@ fn add_and_delete_node_works() { // Node created assert_ok!(DdcNodes::create_node( RuntimeOrigin::signed(cluster_manager_id.clone()), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params) )); // Node doesn't exist @@ -166,7 +161,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::NodeAuthContractCallFailed ); @@ -182,12 +177,12 @@ fn add_and_delete_node_works() { assert_ok!(DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), )); assert!(>::contains_node( &cluster_id, - &NodePubKey::CDNPubKey(node_pub_key.clone()) + &NodePubKey::StoragePubKey(node_pub_key.clone()) )); // Node already assigned @@ -195,7 +190,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::AttemptToAddAlreadyAssignedNode ); @@ -204,7 +199,7 @@ fn add_and_delete_node_works() { System::assert_last_event( Event::ClusterNodeAdded { cluster_id, - node_pub_key: NodePubKey::CDNPubKey(node_pub_key.clone()), + node_pub_key: NodePubKey::StoragePubKey(node_pub_key.clone()), } .into(), ); @@ -213,14 +208,14 @@ fn add_and_delete_node_works() { assert_ok!(DdcClusters::remove_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), )); // Checking that event was emitted System::assert_last_event( Event::ClusterNodeRemoved { cluster_id, - node_pub_key: NodePubKey::CDNPubKey(node_pub_key.clone()), + node_pub_key: NodePubKey::StoragePubKey(node_pub_key.clone()), } .into(), ); @@ -230,7 +225,7 @@ fn add_and_delete_node_works() { DdcClusters::remove_node( RuntimeOrigin::signed(cluster_manager_id), cluster_id, - NodePubKey::CDNPubKey(node_pub_key), + NodePubKey::StoragePubKey(node_pub_key), ), Error::::AttemptToRemoveNotAssignedNode ); @@ -277,7 +272,7 @@ fn add_and_delete_node_works() { let contract_id = Contracts::contract_address(&alice, &wasm_hash, &[]); pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("7a04093d"); - let node_pub_key = NodePubKey::CDNPubKey(node_pub_key); + let node_pub_key = NodePubKey::StoragePubKey(node_pub_key); let call_data = { // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool @@ -334,9 +329,6 @@ fn set_cluster_params_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -382,9 +374,6 @@ fn set_cluster_gov_params_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -448,9 +437,6 @@ fn cluster_visitor_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -473,7 +459,7 @@ fn cluster_visitor_works() { assert_ok!(>::ensure_cluster(&cluster_id)); assert_eq!( - >::get_bond_size(&cluster_id, NodeType::CDN) + >::get_bond_size(&cluster_id, NodeType::Storage) .unwrap(), 100u128 ); @@ -508,7 +494,7 @@ fn cluster_visitor_works() { ); assert_eq!( - >::get_chill_delay(&cluster_id, NodeType::CDN) + >::get_chill_delay(&cluster_id, NodeType::Storage) .unwrap(), 50 ); @@ -519,8 +505,11 @@ fn cluster_visitor_works() { ); assert_eq!( - >::get_unbonding_delay(&cluster_id, NodeType::CDN) - .unwrap(), + >::get_unbonding_delay( + &cluster_id, + NodeType::Storage + ) + .unwrap(), 50 ); assert_eq!( @@ -535,9 +524,6 @@ fn cluster_visitor_works() { assert_eq!( >::get_bonding_params(&cluster_id).unwrap(), ClusterBondingParams::<::BlockNumber> { - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -560,9 +546,6 @@ fn cluster_creator_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, diff --git a/pallets/ddc-clusters/src/weights.rs b/pallets/ddc-clusters/src/weights.rs index 96e4b735f..af2bb5559 100644 --- a/pallets/ddc-clusters/src/weights.rs +++ b/pallets/ddc-clusters/src/weights.rs @@ -1,27 +1,22 @@ - -//! Autogenerated weights for `pallet_ddc_clusters` +//! Autogenerated weights for pallet_ddc_clusters //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Raids-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere // benchmark // pallet -// --chain -// dev -// --pallet -// pallet_ddc_clusters -// --extrinsic -// * -// --steps -// 20 -// --repeat -// 50 -// --output -// pallets/ddc-clusters/src/weights.rs +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-clusters +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template.hbs +// --output=pallets/ddc-clusters/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -39,24 +34,22 @@ pub trait WeightInfo { fn set_cluster_gov_params() -> Weight; } -/// Weight functions for `pallet_ddc_clusters`. +/// Weights for pallet_ddc_clusters using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcClusters Clusters (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn create_cluster() -> Weight { - // Minimum execution time: 14_000 nanoseconds. - Weight::from_ref_time(15_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(2u64)) + Weight::from_ref_time(15_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Bonded (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: System Account (r:1 w:0) // Storage: Contracts ContractInfoOf (r:1 w:1) // Storage: Contracts CodeStorage (r:1 w:0) @@ -66,54 +59,48 @@ impl WeightInfo for SubstrateWeight { // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) fn add_node() -> Weight { - // Minimum execution time: 307_000 nanoseconds. - Weight::from_ref_time(354_000_000u64) - .saturating_add(T::DbWeight::get().reads(15u64)) - .saturating_add(T::DbWeight::get().writes(5u64)) + Weight::from_ref_time(599_000_000_u64) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcClusters ClustersNodes (r:0 w:1) fn remove_node() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000u64) - .saturating_add(T::DbWeight::get().reads(2u64)) - .saturating_add(T::DbWeight::get().writes(2u64)) + Weight::from_ref_time(24_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:1) fn set_cluster_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn set_cluster_gov_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(17_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: DdcClusters Clusters (r:1 w:1) + // Storage: DdcClusters Clusters (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn create_cluster() -> Weight { - // Minimum execution time: 14_000 nanoseconds. - Weight::from_ref_time(15_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(2u64)) + Weight::from_ref_time(15_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Bonded (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: System Account (r:1 w:0) // Storage: Contracts ContractInfoOf (r:1 w:1) // Storage: Contracts CodeStorage (r:1 w:0) @@ -123,33 +110,29 @@ impl WeightInfo for () { // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) fn add_node() -> Weight { - // Minimum execution time: 307_000 nanoseconds. - Weight::from_ref_time(354_000_000u64) - .saturating_add(RocksDbWeight::get().reads(15u64)) - .saturating_add(RocksDbWeight::get().writes(5u64)) + Weight::from_ref_time(599_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcClusters ClustersNodes (r:0 w:1) fn remove_node() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000u64) - .saturating_add(RocksDbWeight::get().reads(2u64)) - .saturating_add(RocksDbWeight::get().writes(2u64)) + Weight::from_ref_time(24_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:1) fn set_cluster_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn set_cluster_gov_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(17_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/pallets/ddc-customers/src/benchmarking.rs b/pallets/ddc-customers/src/benchmarking.rs index 84d16daec..2a15e69bb 100644 --- a/pallets/ddc-customers/src/benchmarking.rs +++ b/pallets/ddc-customers/src/benchmarking.rs @@ -20,14 +20,10 @@ benchmarks! { create_bucket { let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - - let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 100u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), @@ -37,16 +33,20 @@ benchmarks! { unit_per_get_request: 10, }; - let _ = ::ClusterCreator::create_new_cluster( - ClusterId::from([1; 20]), - user.clone(), - user.clone(), - ClusterParams { node_provider_auth_contract: Some(user.clone()) }, - cluster_gov_params - ); + let _ = ::ClusterCreator::create_new_cluster( + ClusterId::from([1; 20]), + user.clone(), + user.clone(), + ClusterParams { node_provider_auth_contract: Some(user.clone()) }, + cluster_gov_params + ); + + let bucket_params = BucketParams { + is_public: false + }; whitelist_account!(user); - }: _(RawOrigin::Signed(user), cluster_id) + }: _(RawOrigin::Signed(user), cluster_id, bucket_params) verify { assert_eq!(Pallet::::buckets_count(), 1); } @@ -69,7 +69,7 @@ benchmarks! { let _ = ::Currency::make_free_balance_be(&user, balance); let amount = ::Currency::minimum_balance() * 50u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); whitelist_account!(user); }: _(RawOrigin::Signed(user.clone()), amount) @@ -83,71 +83,98 @@ benchmarks! { let _ = ::Currency::make_free_balance_be(&user, balance); let amount = ::Currency::minimum_balance() * 50u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); - whitelist_account!(user); + whitelist_account!(user); }: unlock_deposit(RawOrigin::Signed(user.clone()), amount) verify { assert!(Ledger::::contains_key(user)); } - // Worst case scenario, 31/32 chunks unlocked after the unlocking duration + // Worst case scenario, 31/32 chunks unlocked after the unlocking duration withdraw_unlocked_deposit_update { - System::::set_block_number(1u32.into()); + System::::set_block_number(1u32.into()); let user = account::("user", USER_SEED, 0u32); let balance = ::Currency::minimum_balance() * 2000u32.into(); let _ = ::Currency::make_free_balance_be(&user, balance); let amount = ::Currency::minimum_balance() * 32u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); - for _k in 1 .. 32 { - let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); - } + for _k in 1 .. 32 { + let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); + } - System::::set_block_number(5256001u32.into()); + System::::set_block_number(5256001u32.into()); - whitelist_account!(user); + whitelist_account!(user); }: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) verify { - let ledger = Ledger::::try_get(user).unwrap(); + let ledger = Ledger::::try_get(user).unwrap(); assert_eq!(ledger.active, amount / 32u32.into()); } - // Worst case scenario, everything is removed after the unlocking duration + // Worst case scenario, everything is removed after the unlocking duration withdraw_unlocked_deposit_kill { - System::::set_block_number(1u32.into()); + System::::set_block_number(1u32.into()); let user = account::("user", USER_SEED, 0u32); - let user2 = account::("user", USER_SEED, 1u32); + let user2 = account::("user", USER_SEED, 1u32); let balance = ::Currency::minimum_balance() * 2000u32.into(); let _ = ::Currency::make_free_balance_be(&user, balance); - let _ = ::Currency::make_free_balance_be(&user2, balance); + let _ = ::Currency::make_free_balance_be(&user2, balance); let amount = ::Currency::minimum_balance() * 32u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); - // To keep the balance of pallet positive - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user2).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + // To keep the balance of pallet positive + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user2).into(), amount); - for _k in 1 .. 33 { - let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); - } + for _k in 1 .. 33 { + let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); + } - System::::set_block_number(5256001u32.into()); + System::::set_block_number(5256001u32.into()); - whitelist_account!(user); + whitelist_account!(user); }: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) verify { - assert!(!Ledger::::contains_key(user)); + assert!(!Ledger::::contains_key(user)); } - impl_benchmark_test_suite!( - DdcCustomers, - crate::mock::ExtBuilder.build(), - crate::mock::Test, - ); + set_bucket_params { + let cluster_id = ClusterId::from([1; 20]); + let user = account::("user", USER_SEED, 0u32); + + let bucket_id = 1; + let bucket = Bucket { + bucket_id, + owner_id: user.clone(), + cluster_id, + is_public: false, + }; + + >::set(bucket_id); + >::insert(bucket_id, bucket); + + whitelist_account!(user); + + let bucket_params = BucketParams { + is_public: true + }; + + }: _(RawOrigin::Signed(user), bucket_id, bucket_params) + verify { + let bucket = >::get(bucket_id).unwrap(); + assert!(bucket.is_public); + } + + impl_benchmark_test_suite!( + DdcCustomers, + crate::mock::ExtBuilder.build(), + crate::mock::Test, + ); } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 191af3ecc..f5e1eed3e 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -12,7 +12,7 @@ pub(crate) mod mock; #[cfg(test)] mod tests; -use codec::{Decode, Encode, HasCompact}; +use codec::{Decode, Encode}; use ddc_primitives::{BucketId, ClusterId}; use ddc_traits::{ @@ -59,25 +59,26 @@ pub struct Bucket { bucket_id: BucketId, owner_id: AccountId, cluster_id: ClusterId, + is_public: bool, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -pub struct BucketsDetails { - pub bucket_id: BucketId, - pub amount: Balance, +pub struct BucketParams { + is_public: bool, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] pub struct AccountsLedger { - /// The owner account whose balance is actually locked and can be used for CDN usage. + /// The owner account whose balance is actually locked and can be used to pay for DDC network + /// usage. pub owner: T::AccountId, /// The total amount of the owner's balance that we are currently accounting for. /// It's just `active` plus all the `unlocking` balances. #[codec(compact)] pub total: BalanceOf, - /// The total amount of the owner's balance that will be accessible for CDN payments in any - /// forthcoming rounds. + /// The total amount of the owner's balance that will be accessible for DDC network payouts in + /// any forthcoming rounds. #[codec(compact)] pub active: BalanceOf, /// Any balance that is becoming free, which may eventually be transferred out of the owner @@ -183,6 +184,8 @@ pub mod pallet { Charged(T::AccountId, BalanceOf), /// Bucket with specific id created BucketCreated(BucketId), + /// Bucket with specific id updated + BucketUpdated(BucketId), } #[pallet::error] @@ -218,7 +221,7 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { pub feeder_account: Option, - pub buckets: Vec<(ClusterId, T::AccountId, BalanceOf)>, + pub buckets: Vec<(ClusterId, T::AccountId, BalanceOf, bool)>, } #[cfg(feature = "std")] @@ -248,7 +251,7 @@ pub mod pallet { } } - for &(ref cluster_id, ref owner_id, ref deposit) in &self.buckets { + for &(ref cluster_id, ref owner_id, ref deposit, ref is_public) in &self.buckets { let cur_bucket_id = >::get() .checked_add(1) .ok_or(Error::::ArithmeticOverflow) @@ -259,6 +262,7 @@ pub mod pallet { bucket_id: cur_bucket_id, owner_id: owner_id.clone(), cluster_id: *cluster_id, + is_public: *is_public, }; >::insert(cur_bucket_id, bucket); @@ -282,7 +286,11 @@ pub mod pallet { /// /// Anyone can create a bucket #[pallet::weight(T::WeightInfo::create_bucket())] - pub fn create_bucket(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { + pub fn create_bucket( + origin: OriginFor, + cluster_id: ClusterId, + bucket_params: BucketParams, + ) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = Self::buckets_count().checked_add(1).ok_or(Error::::ArithmeticOverflow)?; @@ -290,7 +298,12 @@ pub mod pallet { ::ClusterVisitor::ensure_cluster(&cluster_id) .map_err(|_| Error::::ClusterDoesNotExist)?; - let bucket = Bucket { bucket_id: cur_bucket_id, owner_id: bucket_owner, cluster_id }; + let bucket = Bucket { + bucket_id: cur_bucket_id, + owner_id: bucket_owner, + cluster_id, + is_public: bucket_params.is_public, + }; >::set(cur_bucket_id); >::insert(cur_bucket_id, bucket); @@ -319,7 +332,7 @@ pub mod pallet { } /// Add some extra amount that have appeared in the owner `free_balance` into the balance up - /// for CDN payments. + /// for DDC network payouts. /// /// The dispatch origin for this call must be _Signed_ by the owner. /// @@ -460,6 +473,28 @@ pub mod pallet { Ok(post_info_weight.into()) } + + /// Sets bucket parameters. + /// + /// The dispatch origin for this call must be _Signed_ by the bucket owner. + /// + /// Emits `BucketUpdated`. + #[pallet::weight(T::WeightInfo::set_bucket_params())] + pub fn set_bucket_params( + origin: OriginFor, + bucket_id: BucketId, + bucket_params: BucketParams, + ) -> DispatchResult { + let owner = ensure_signed(origin)?; + let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; + ensure!(bucket.owner_id == owner, Error::::NotBucketOwner); + + bucket.is_public = bucket_params.is_public; + >::insert(bucket_id, bucket); + Self::deposit_event(Event::::BucketUpdated(bucket_id)); + + Ok(()) + } } impl Pallet { diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index d9e847eb0..56b644f37 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -163,21 +163,6 @@ impl ClusterVisitor for TestClusterVisitor { cluster_id: &ClusterId, ) -> Result, ClusterVisitorError> { Ok(ClusterBondingParams { - cdn_bond_size: >::get_bond_size( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_chill_delay: >::get_chill_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_unbonding_delay: >::get_unbonding_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), storage_bond_size: >::get_bond_size( cluster_id, NodeType::Storage, diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index c378a3961..8d7d80350 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -11,15 +11,25 @@ fn create_bucket_works() { let cluster_id = ClusterId::from([1; 20]); let account_1 = 1; + let bucket_params = BucketParams { is_public: false }; // Bucket created - assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(account_1), cluster_id)); + assert_ok!(DdcCustomers::create_bucket( + RuntimeOrigin::signed(account_1), + cluster_id, + bucket_params.clone() + )); // Check storage assert_eq!(DdcCustomers::buckets_count(), 1); assert_eq!( DdcCustomers::buckets(1), - Some(Bucket { bucket_id: 1, owner_id: account_1, cluster_id }) + Some(Bucket { + bucket_id: 1, + owner_id: account_1, + cluster_id, + is_public: bucket_params.is_public + }) ); // Checking that event was emitted @@ -35,12 +45,22 @@ fn create_two_buckets_works() { let cluster_id = ClusterId::from([1; 20]); let account_1 = 1; + let bucket_1_params = BucketParams { is_public: false }; + let bucket_2_params = BucketParams { is_public: true }; // Buckets created - assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(account_1), cluster_id)); + assert_ok!(DdcCustomers::create_bucket( + RuntimeOrigin::signed(account_1), + cluster_id, + bucket_1_params.clone() + )); assert_eq!(System::events().len(), 1); System::assert_last_event(Event::BucketCreated(1u64).into()); - assert_ok!(DdcCustomers::create_bucket(RuntimeOrigin::signed(account_1), cluster_id)); + assert_ok!(DdcCustomers::create_bucket( + RuntimeOrigin::signed(account_1), + cluster_id, + bucket_2_params.clone() + )); assert_eq!(System::events().len(), 2); System::assert_last_event(Event::BucketCreated(2u64).into()); @@ -48,11 +68,21 @@ fn create_two_buckets_works() { assert_eq!(DdcCustomers::buckets_count(), 2); assert_eq!( DdcCustomers::buckets(1), - Some(Bucket { bucket_id: 1, owner_id: account_1, cluster_id }) + Some(Bucket { + bucket_id: 1, + owner_id: account_1, + cluster_id, + is_public: bucket_1_params.is_public + }) ); assert_eq!( DdcCustomers::buckets(2), - Some(Bucket { bucket_id: 2, owner_id: account_1, cluster_id }) + Some(Bucket { + bucket_id: 2, + owner_id: account_1, + cluster_id, + is_public: bucket_2_params.is_public + }) ); }) } @@ -286,3 +316,91 @@ fn unlock_and_withdraw_deposit_works() { assert_eq!(DdcCustomers::ledger(&account_1), None); }) } + +#[test] +fn set_bucket_params_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + let bucket_owner = 1; + let bucket_params = BucketParams { is_public: false }; + + // Bucket created + assert_ok!(DdcCustomers::create_bucket( + RuntimeOrigin::signed(bucket_owner), + cluster_id, + bucket_params + )); + + // Checking that event was emitted + assert_eq!(System::events().len(), 1); + System::assert_last_event(Event::BucketCreated(1u64).into()); + + let bucket_id = 1; + let update_bucket_params = BucketParams { is_public: true }; + assert_ok!(DdcCustomers::set_bucket_params( + RuntimeOrigin::signed(bucket_owner), + bucket_id, + update_bucket_params.clone() + )); + + assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!( + DdcCustomers::buckets(1), + Some(Bucket { + bucket_id, + owner_id: bucket_owner, + cluster_id, + is_public: update_bucket_params.is_public + }) + ); + + // Checking that event was emitted + assert_eq!(System::events().len(), 2); + System::assert_last_event(Event::BucketUpdated(bucket_id).into()); + }) +} + +#[test] +fn set_bucket_params_checks_work() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let cluster_id = ClusterId::from([1; 20]); + let bucket_owner = 1; + let bucket_params = BucketParams { is_public: false }; + + // Bucket created + assert_ok!(DdcCustomers::create_bucket( + RuntimeOrigin::signed(bucket_owner), + cluster_id, + bucket_params + )); + + // Checking that event was emitted + assert_eq!(System::events().len(), 1); + System::assert_last_event(Event::BucketCreated(1u64).into()); + let bucket_id = 1; + + let non_existent_bucket_id = 2; + assert_noop!( + DdcCustomers::set_bucket_params( + RuntimeOrigin::signed(bucket_owner), + non_existent_bucket_id, + BucketParams { is_public: true } + ), + Error::::NoBucketWithId + ); + + let not_bucket_owner_id = 2; + assert_noop!( + DdcCustomers::set_bucket_params( + RuntimeOrigin::signed(not_bucket_owner_id), + bucket_id, + BucketParams { is_public: true } + ), + Error::::NotBucketOwner + ); + }) +} diff --git a/pallets/ddc-customers/src/weights.rs b/pallets/ddc-customers/src/weights.rs index 66ae43d01..09351dbe1 100644 --- a/pallets/ddc-customers/src/weights.rs +++ b/pallets/ddc-customers/src/weights.rs @@ -1,27 +1,22 @@ - -//! Autogenerated weights for `pallet_ddc_customers` +//! Autogenerated weights for pallet_ddc_customers //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Raids-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere // benchmark // pallet -// --chain -// dev -// --pallet -// pallet_ddc_customers -// --extrinsic -// * -// --steps -// 200 -// --repeat -// 1000 -// --output -// pallets/ddc-customers/src/weights.rs +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-customers +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template.hbs +// --output=pallets/ddc-customers/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -30,7 +25,7 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; -/// Weight functions needed for pallet_ddc_nodes. +/// Weight functions needed for pallet_ddc_customers. pub trait WeightInfo { fn create_bucket() -> Weight; fn deposit() -> Weight; @@ -38,30 +33,31 @@ pub trait WeightInfo { fn unlock_deposit() -> Weight; fn withdraw_unlocked_deposit_update() -> Weight; fn withdraw_unlocked_deposit_kill() -> Weight; + fn set_bucket_params() -> Weight; } -/// Weight functions for `pallet_ddc_customers`. +/// Weights for pallet_ddc_customers using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcCustomers BucketsCount (r:1 w:1) // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcCustomers Buckets (r:0 w:1) fn create_bucket() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(17_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit() -> Weight { - Weight::from_ref_time(26_000_000_u64) + Weight::from_ref_time(28_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit_extra() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(29_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -72,18 +68,25 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_update() -> Weight { - Weight::from_ref_time(14_000_000_u64) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + Weight::from_ref_time(30_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_kill() -> Weight { - Weight::from_ref_time(31_000_000_u64) + Weight::from_ref_time(32_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } + // Storage: DdcCustomers Buckets (r:1 w:1) + fn set_bucket_params() -> Weight { + Weight::from_ref_time(14_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests @@ -92,21 +95,21 @@ impl WeightInfo for () { // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcCustomers Buckets (r:0 w:1) fn create_bucket() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(17_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit() -> Weight { - Weight::from_ref_time(26_000_000_u64) + Weight::from_ref_time(28_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit_extra() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(29_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -117,16 +120,23 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_update() -> Weight { - Weight::from_ref_time(14_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + Weight::from_ref_time(30_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_kill() -> Weight { - Weight::from_ref_time(31_000_000_u64) + Weight::from_ref_time(32_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } -} \ No newline at end of file + // Storage: DdcCustomers Buckets (r:1 w:1) + fn set_bucket_params() -> Weight { + Weight::from_ref_time(14_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/pallets/ddc-nodes/src/benchmarking.rs b/pallets/ddc-nodes/src/benchmarking.rs index 448cde563..451ef0c2a 100644 --- a/pallets/ddc-nodes/src/benchmarking.rs +++ b/pallets/ddc-nodes/src/benchmarking.rs @@ -1,56 +1,56 @@ //! DdcStaking pallet benchmarking. -use super::*; -use crate::{cdn_node::CDNNodeProps, Pallet as DdcNodes}; -use ddc_primitives::CDNNodePubKey; -use testing_utils::*; - -use sp_std::prelude::*; - +use ddc_primitives::{StorageNodeMode, StorageNodePubKey}; pub use frame_benchmarking::{ account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, }; use frame_system::RawOrigin; +use sp_std::prelude::*; +use testing_utils::*; + +use super::*; +use crate::{storage_node::StorageNodeProps, Pallet as DdcNodes}; const USER_SEED: u32 = 999666; benchmarks! { create_node { - let (user, node, cdn_node_params, _) = create_user_and_config::("user", USER_SEED); + let (user, node, storage_node_params, _) = create_user_and_config::("user", USER_SEED); - whitelist_account!(user); - }: _(RawOrigin::Signed(user.clone()), node, cdn_node_params) + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node, storage_node_params) verify { - assert!(CDNNodes::::contains_key(CDNNodePubKey::new([0; 32]))); + assert!(StorageNodes::::contains_key(StorageNodePubKey::new([0; 32]))); } delete_node { - let (user, node, cdn_node_params, _) = create_user_and_config::("user", USER_SEED); + let (user, node, storage_node_params, _) = create_user_and_config::("user", USER_SEED); - DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; + DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), storage_node_params)?; whitelist_account!(user); }: _(RawOrigin::Signed(user.clone()), node) verify { - assert!(!CDNNodes::::contains_key(CDNNodePubKey::new([0; 32]))); + assert!(!StorageNodes::::contains_key(StorageNodePubKey::new([0; 32]))); } set_node_params { - let (user, node, cdn_node_params, cdn_node_params_new) = create_user_and_config::("user", USER_SEED); + let (user, node, storage_node_params, new_storage_node_params) = create_user_and_config::("user", USER_SEED); - DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; + DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), storage_node_params)?; - whitelist_account!(user); - }: _(RawOrigin::Signed(user.clone()), node, cdn_node_params_new) + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node, new_storage_node_params) verify { - assert_eq!(CDNNodes::::try_get( - CDNNodePubKey::new([0; 32])).unwrap().props, - CDNNodeProps { - host: vec![2u8, 255].try_into().unwrap(), - http_port: 45000u16, - grpc_port: 55000u16, - p2p_port: 65000u16, - }); + assert_eq!(StorageNodes::::try_get( + StorageNodePubKey::new([0; 32])).unwrap().props, + StorageNodeProps { + mode: StorageNodeMode::Storage, + host: vec![2u8, 255].try_into().unwrap(), + http_port: 45000u16, + grpc_port: 55000u16, + p2p_port: 65000u16, + }); } impl_benchmark_test_suite!( diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs deleted file mode 100644 index b7f5cf146..000000000 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ /dev/null @@ -1,105 +0,0 @@ -use crate::node::{NodeError, NodeProps, NodeTrait}; -use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, NodeType}; -use frame_support::{parameter_types, BoundedVec}; -use scale_info::TypeInfo; -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; -use sp_runtime::RuntimeDebug; -use sp_std::prelude::*; - -parameter_types! { - pub MaxCDNNodeParamsLen: u16 = 2048; - pub MaxHostLen: u8 = 255; -} - -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -#[scale_info(skip_type_params(T))] -pub struct CDNNode { - pub pub_key: CDNNodePubKey, - pub provider_id: T::AccountId, - pub cluster_id: Option, - pub props: CDNNodeProps, -} - -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNodeProps { - pub host: BoundedVec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, -} - -impl CDNNode { - pub fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result { - match node_pub_key { - NodePubKey::CDNPubKey(pub_key) => match node_params { - NodeParams::CDNParams(node_params) => Ok(CDNNode:: { - provider_id, - pub_key, - cluster_id: None, - props: CDNNodeProps { - host: match node_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), - }, - http_port: node_params.http_port, - grpc_port: node_params.grpc_port, - p2p_port: node_params.p2p_port, - }, - }), - _ => Err(NodeError::InvalidCDNNodeParams), - }, - _ => Err(NodeError::InvalidCDNNodePubKey), - } - } -} - -impl NodeTrait for CDNNode { - fn get_pub_key(&self) -> NodePubKey { - NodePubKey::CDNPubKey(self.pub_key.clone()) - } - fn get_provider_id(&self) -> &T::AccountId { - &self.provider_id - } - fn get_props(&self) -> NodeProps { - NodeProps::CDNProps(self.props.clone()) - } - fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { - self.props = match props { - NodeProps::CDNProps(props) => props, - _ => return Err(NodeError::InvalidCDNNodeProps), - }; - Ok(()) - } - fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { - match node_params { - NodeParams::CDNParams(cdn_params) => { - self.props.host = match cdn_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), - }; - self.props.http_port = cdn_params.http_port; - self.props.grpc_port = cdn_params.grpc_port; - self.props.p2p_port = cdn_params.p2p_port; - }, - _ => return Err(NodeError::InvalidCDNNodeParams), - }; - Ok(()) - } - fn get_cluster_id(&self) -> &Option { - &self.cluster_id - } - fn set_cluster_id(&mut self, cluster_id: Option) { - self.cluster_id = cluster_id; - } - fn get_type(&self) -> NodeType { - NodeType::CDN - } -} diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 3d89e92b7..acf6b430b 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -27,7 +27,7 @@ pub mod benchmarking; #[cfg(any(feature = "runtime-benchmarks", test))] pub mod testing_utils; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, StorageNodePubKey}; +use ddc_primitives::{ClusterId, NodeParams, NodePubKey, StorageNodePubKey}; use ddc_traits::{ node::{NodeCreator, NodeVisitor, NodeVisitorError}, staking::StakingVisitor, @@ -35,15 +35,13 @@ use ddc_traits::{ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; +pub use pallet::*; use sp_std::prelude::*; -pub use pallet::*; -mod cdn_node; mod node; mod storage_node; pub use crate::{ - cdn_node::CDNNode, node::{Node, NodeError, NodeTrait}, storage_node::StorageNode, }; @@ -76,9 +74,6 @@ pub mod pallet { pub enum Error { NodeAlreadyExists, NodeDoesNotExist, - InvalidNodePubKey, - InvalidNodeParams, - NodeParamsExceedsLimit, OnlyNodeProvider, NodeIsAssignedToCluster, HostLenExceedsLimit, @@ -90,20 +85,15 @@ pub mod pallet { pub type StorageNodes = StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; - #[pallet::storage] - #[pallet::getter(fn cdn_nodes)] - pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; - #[pallet::genesis_config] pub struct GenesisConfig { pub storage_nodes: Vec>, - pub cdn_nodes: Vec>, } #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { storage_nodes: Default::default(), cdn_nodes: Default::default() } + GenesisConfig { storage_nodes: Default::default() } } } @@ -113,9 +103,6 @@ pub mod pallet { for storage_node in &self.storage_nodes { >::insert(storage_node.pub_key.clone(), storage_node); } - for cdn_node in &self.cdn_nodes { - >::insert(cdn_node.pub_key.clone(), cdn_node); - } } } @@ -174,18 +161,14 @@ pub mod pallet { #[derive(Debug, PartialEq)] pub enum NodeRepositoryError { StorageNodeAlreadyExists, - CDNNodeAlreadyExists, StorageNodeDoesNotExist, - CDNNodeDoesNotExist, } impl From for Error { fn from(error: NodeRepositoryError) -> Self { match error { NodeRepositoryError::StorageNodeAlreadyExists => Error::::NodeAlreadyExists, - NodeRepositoryError::CDNNodeAlreadyExists => Error::::NodeAlreadyExists, NodeRepositoryError::StorageNodeDoesNotExist => Error::::NodeDoesNotExist, - NodeRepositoryError::CDNNodeDoesNotExist => Error::::NodeDoesNotExist, } } } @@ -200,13 +183,6 @@ pub mod pallet { StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) }, - Node::CDN(cdn_node) => { - if CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err(NodeRepositoryError::CDNNodeAlreadyExists) - } - CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); - Ok(()) - }, } } @@ -216,10 +192,6 @@ pub mod pallet { Ok(storage_node) => Ok(Node::Storage(storage_node)), Err(_) => Err(NodeRepositoryError::StorageNodeDoesNotExist), }, - NodePubKey::CDNPubKey(pub_key) => match CDNNodes::::try_get(pub_key) { - Ok(cdn_node) => Ok(Node::CDN(cdn_node)), - Err(_) => Err(NodeRepositoryError::CDNNodeDoesNotExist), - }, } } @@ -231,12 +203,6 @@ pub mod pallet { } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); }, - Node::CDN(cdn_node) => { - if !CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err(NodeRepositoryError::CDNNodeDoesNotExist) - } - CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); - }, } Ok(()) } @@ -247,10 +213,6 @@ pub mod pallet { StorageNodes::::remove(pub_key); Ok(()) }, - NodePubKey::CDNPubKey(pub_key) => { - CDNNodes::::remove(pub_key); - Ok(()) - }, } } } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index f0a5be5d5..2688400f4 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,7 +1,6 @@ #![allow(clippy::needless_lifetimes)] // ToDo use crate::{ - cdn_node::{CDNNode, CDNNodeProps}, pallet::Error, storage_node::{StorageNode, StorageNodeProps}, ClusterId, @@ -14,14 +13,12 @@ use sp_runtime::RuntimeDebug; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum Node { Storage(StorageNode), - CDN(CDNNode), } // Props fields may include internal protocol properties #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeProps { StorageProps(StorageNodeProps), - CDNProps(CDNNodeProps), } pub trait NodeTrait { @@ -44,8 +41,6 @@ impl Node { match node_pub_key { NodePubKey::StoragePubKey(_) => StorageNode::new(node_pub_key, provider_id, node_params).map(|n| Node::Storage(n)), - NodePubKey::CDNPubKey(_) => - CDNNode::new(node_pub_key, provider_id, node_params).map(|n| Node::CDN(n)), } } } @@ -54,76 +49,54 @@ impl NodeTrait for Node { fn get_pub_key(&self) -> NodePubKey { match &self { Node::Storage(node) => node.get_pub_key(), - Node::CDN(node) => node.get_pub_key(), } } fn get_provider_id(&self) -> &T::AccountId { match &self { Node::Storage(node) => node.get_provider_id(), - Node::CDN(node) => node.get_provider_id(), } } fn get_props(&self) -> NodeProps { match &self { Node::Storage(node) => node.get_props(), - Node::CDN(node) => node.get_props(), } } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { match self { Node::Storage(node) => node.set_props(props), - Node::CDN(node) => node.set_props(props), } } fn set_params(&mut self, params: NodeParams) -> Result<(), NodeError> { match self { Node::Storage(node) => node.set_params(params), - Node::CDN(node) => node.set_params(params), } } fn get_cluster_id(&self) -> &Option { match &self { Node::Storage(node) => node.get_cluster_id(), - Node::CDN(node) => node.get_cluster_id(), } } fn set_cluster_id(&mut self, cluster_id: Option) { match self { Node::Storage(node) => node.set_cluster_id(cluster_id), - Node::CDN(node) => node.set_cluster_id(cluster_id), } } fn get_type(&self) -> NodeType { match &self { Node::Storage(node) => node.get_type(), - Node::CDN(node) => node.get_type(), } } } #[derive(Debug, PartialEq)] pub enum NodeError { - InvalidStorageNodePubKey, - InvalidCDNNodePubKey, - InvalidStorageNodeParams, - InvalidCDNNodeParams, StorageHostLenExceedsLimit, - CDNHostLenExceedsLimit, - InvalidCDNNodeProps, - InvalidStorageNodeProps, } impl From for Error { fn from(error: NodeError) -> Self { match error { - NodeError::InvalidStorageNodePubKey => Error::::InvalidNodePubKey, - NodeError::InvalidCDNNodePubKey => Error::::InvalidNodePubKey, - NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, - NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, NodeError::StorageHostLenExceedsLimit => Error::::HostLenExceedsLimit, - NodeError::CDNHostLenExceedsLimit => Error::::HostLenExceedsLimit, - NodeError::InvalidStorageNodeProps => Error::::InvalidNodeParams, - NodeError::InvalidCDNNodeProps => Error::::InvalidNodeParams, } } } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 14f937c3b..3021409aa 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,6 +1,8 @@ use crate::node::{NodeError, NodeProps, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{ClusterId, NodeParams, NodePubKey, NodeType, StorageNodePubKey}; +use ddc_primitives::{ + ClusterId, NodeParams, NodePubKey, NodeType, StorageNodeMode, StorageNodePubKey, +}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; #[cfg(feature = "std")] @@ -29,6 +31,7 @@ pub struct StorageNodeProps { pub http_port: u16, pub grpc_port: u16, pub p2p_port: u16, + pub mode: StorageNodeMode, } impl StorageNode { @@ -44,6 +47,7 @@ impl StorageNode { pub_key, cluster_id: None, props: StorageNodeProps { + mode: node_params.mode, host: match node_params.host.try_into() { Ok(vec) => vec, Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), @@ -53,9 +57,7 @@ impl StorageNode { p2p_port: node_params.p2p_port, }, }), - _ => Err(NodeError::InvalidStorageNodeParams), }, - _ => Err(NodeError::InvalidStorageNodePubKey), } } } @@ -73,7 +75,6 @@ impl NodeTrait for StorageNode { fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { NodeProps::StorageProps(props) => props, - _ => return Err(NodeError::InvalidStorageNodeProps), }; Ok(()) } @@ -82,13 +83,12 @@ impl NodeTrait for StorageNode { NodeParams::StorageParams(storage_params) => { self.props.host = match storage_params.host.try_into() { Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), + Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), }; self.props.http_port = storage_params.http_port; self.props.grpc_port = storage_params.grpc_port; self.props.p2p_port = storage_params.p2p_port; }, - _ => return Err(NodeError::InvalidStorageNodeParams), }; Ok(()) } diff --git a/pallets/ddc-nodes/src/testing_utils.rs b/pallets/ddc-nodes/src/testing_utils.rs index 8db4dfd35..dd408c320 100644 --- a/pallets/ddc-nodes/src/testing_utils.rs +++ b/pallets/ddc-nodes/src/testing_utils.rs @@ -1,7 +1,7 @@ //! Testing utils for ddc-staking. use crate::{Config, NodePubKey}; -use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams}; +use ddc_primitives::{NodeParams, StorageNodeMode, StorageNodeParams, StorageNodePubKey}; use frame_benchmarking::account; use sp_std::vec; @@ -13,19 +13,21 @@ pub fn create_user_and_config( n: u32, ) -> (T::AccountId, NodePubKey, NodeParams, NodeParams) { let user = account(string, n, SEED); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); - let cdn_node_params = NodeParams::CDNParams(CDNNodeParams { + let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); + let storage_node_params = NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, }); - let cdn_node_params_new = NodeParams::CDNParams(CDNNodeParams { + let new_storage_node_params = NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![2u8, 255], http_port: 45000u16, grpc_port: 55000u16, p2p_port: 65000u16, }); - (user, node, cdn_node_params, cdn_node_params_new) + (user, node, storage_node_params, new_storage_node_params) } diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index ea2c6d8af..aadc801c0 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -1,132 +1,10 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{CDNNodeParams, NodePubKey, StorageNodeParams}; +use ddc_primitives::{NodePubKey, StorageNodeMode, StorageNodeParams}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::AccountId32; -#[test] -fn create_cdn_node_works() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node params are not valid - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::StorageParams(StorageNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::InvalidNodeParams - ); - - // Pub key invalid - assert_noop!( - CDNNode::::new( - NodePubKey::StoragePubKey(node_pub_key.clone()), - 1u64, - NodeParams::CDNParams(cdn_node_params.clone()) - ), - NodeError::InvalidCDNNodePubKey - ); - - // Host length exceeds limit - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8; 256], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::HostLenExceedsLimit - ); - - // Node created - assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - )); - - // Check storage - assert!(CDNNodes::::contains_key(node_pub_key.clone())); - assert!(DdcNodes::exists(&NodePubKey::CDNPubKey(node_pub_key.clone()))); - if let Ok(cluster_id) = - DdcNodes::get_cluster_id(&NodePubKey::CDNPubKey(node_pub_key.clone())) - { - assert_eq!(cluster_id, None); - } - let cdn_node = DdcNodes::cdn_nodes(&node_pub_key).unwrap(); - assert_eq!(cdn_node.pub_key, node_pub_key); - - // Node already exists - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) - ), - Error::::NodeAlreadyExists - ); - - // Checking that event was emitted - assert_eq!(System::events().len(), 1); - System::assert_last_event( - Event::NodeCreated { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - ) - }) -} - -#[test] -fn create_cdn_node_with_node_creator() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node created - assert_ok!(>::create_node( - NodePubKey::CDNPubKey(node_pub_key.clone()), - 1u64, - NodeParams::CDNParams(cdn_node_params) - )); - - // Check storage - assert!(CDNNodes::::contains_key(node_pub_key.clone())); - assert!(DdcNodes::exists(&NodePubKey::CDNPubKey(node_pub_key.clone()))); - if let Ok(cluster_id) = - DdcNodes::get_cluster_id(&NodePubKey::CDNPubKey(node_pub_key.clone())) - { - assert_eq!(cluster_id, None); - } - let cdn_node = DdcNodes::cdn_nodes(&node_pub_key).unwrap(); - assert_eq!(cdn_node.pub_key, node_pub_key); - }) -} - #[test] fn create_storage_node_works() { ExtBuilder.build_and_execute(|| { @@ -134,43 +12,20 @@ fn create_storage_node_works() { let bytes = [0u8; 32]; let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, }; - // Node params are not valid - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::StoragePubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::InvalidNodeParams - ); - - // Pub key invalid - assert_noop!( - StorageNode::::new( - NodePubKey::CDNPubKey(node_pub_key.clone()), - 1u64, - NodeParams::StorageParams(storage_node_params.clone()) - ), - NodeError::InvalidStorageNodePubKey - ); - // Host length exceeds limit assert_noop!( DdcNodes::create_node( RuntimeOrigin::signed(1), NodePubKey::StoragePubKey(node_pub_key.clone()), NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8; 256], http_port: 35000u16, grpc_port: 25000u16, @@ -223,6 +78,7 @@ fn create_storage_node_with_node_creator() { let bytes = [0u8; 32]; let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -244,123 +100,8 @@ fn create_storage_node_with_node_creator() { { assert_eq!(cluster_id, None); } - let cdn_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); - assert_eq!(cdn_node.pub_key, node_pub_key); - }) -} - -#[test] -fn set_cdn_node_params_works() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let storage_node_params = StorageNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node doesn't exist - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - ), - Error::::NodeDoesNotExist - ); - - // Node created - assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - )); - - // Set node params - assert_ok!(DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - )); - - // Node params are not valid - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::StorageParams(storage_node_params) - ), - Error::::InvalidNodeParams - ); - - // Only node provider can set params - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(2), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - ), - Error::::OnlyNodeProvider - ); - - // CDN host length exceeds limit - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8; 256], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::HostLenExceedsLimit - ); - - let bytes_2 = [1u8; 32]; - let node_pub_key_2 = AccountId32::from(bytes_2); - let node = Node::::new( - NodePubKey::CDNPubKey(node_pub_key_2), - 2u64, - NodeParams::CDNParams(cdn_node_params), - ) - .unwrap(); - - // Update should fail if node doesn't exist - assert_noop!( - >::update(node), - NodeRepositoryError::CDNNodeDoesNotExist - ); - - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8; 256], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::HostLenExceedsLimit - ); - - // Checking that event was emitted - assert_eq!(System::events().len(), 2); - System::assert_last_event( - Event::NodeParamsChanged { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - ) + let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + assert_eq!(storage_node.pub_key, node_pub_key); }) } @@ -371,12 +112,7 @@ fn set_storage_node_params_works() { let bytes = [0u8; 32]; let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - let cdn_node_params = CDNNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -407,16 +143,6 @@ fn set_storage_node_params_works() { NodeParams::StorageParams(storage_node_params.clone()) )); - // Node params are not valid - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::StoragePubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) - ), - Error::::InvalidNodeParams - ); - // Only node provider can set params assert_noop!( DdcNodes::set_node_params( @@ -448,6 +174,7 @@ fn set_storage_node_params_works() { RuntimeOrigin::signed(1), NodePubKey::StoragePubKey(node_pub_key.clone()), NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8; 256], http_port: 35000u16, grpc_port: 25000u16, @@ -466,58 +193,6 @@ fn set_storage_node_params_works() { }) } -#[test] -fn delete_cdn_node_works() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node doesn't exist - assert_noop!( - DdcNodes::delete_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()) - ), - Error::::NodeDoesNotExist - ); - - // Create node - assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) - )); - - // Only node provider can delete - assert_noop!( - DdcNodes::delete_node( - RuntimeOrigin::signed(2), - NodePubKey::CDNPubKey(node_pub_key.clone()) - ), - Error::::OnlyNodeProvider - ); - - // Delete node - assert_ok!(DdcNodes::delete_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - )); - - // Checking that event was emitted - assert_eq!(System::events().len(), 2); - System::assert_last_event( - Event::NodeDeleted { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - ) - }) -} - #[test] fn delete_storage_node_works() { ExtBuilder.build_and_execute(|| { @@ -525,6 +200,7 @@ fn delete_storage_node_works() { let bytes = [0u8; 32]; let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, diff --git a/pallets/ddc-nodes/src/weights.rs b/pallets/ddc-nodes/src/weights.rs index 868380f40..bc05729ba 100644 --- a/pallets/ddc-nodes/src/weights.rs +++ b/pallets/ddc-nodes/src/weights.rs @@ -1,27 +1,22 @@ - -//! Autogenerated weights for `pallet_ddc_nodes` +//! Autogenerated weights for pallet_ddc_nodes //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Raids-MBP-2`, CPU: `` -//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere // benchmark // pallet -// --chain -// dev -// --pallet -// pallet_ddc_nodes -// --extrinsic -// * -// --steps -// 200 -// --repeat -// 1000 -// --output -// pallets/ddc-nodes/src/weights.rs +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-nodes +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template.hbs +// --output=pallets/ddc-nodes/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -37,47 +32,49 @@ pub trait WeightInfo { fn set_node_params() -> Weight; } -/// Weights for pallet_ddc_nodes. +/// Weights for pallet_ddc_nodes using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - // Storage: DdcNodes CDNNodes (r:1 w:1) +impl WeightInfo for SubstrateWeight { + // Storage: DdcNodes StorageNodes (r:1 w:1) fn create_node() -> Weight { - Weight::from_ref_time(12_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(12_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(14_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) fn set_node_params() -> Weight { - Weight::from_ref_time(15_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(15_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) fn create_node() -> Weight { - Weight::from_ref_time(12_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(12_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(14_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) fn set_node_params() -> Weight { - Weight::from_ref_time(15_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(15_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} \ No newline at end of file +} diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 4a1a9047e..5b5b50d58 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -1231,7 +1231,7 @@ fn send_rewarding_providers_batch_works() { }; let node_usage1 = NodeUsage { - // CDN + // Storage 1 transferred_bytes: usage1.transferred_bytes * 2 / 3, stored_bytes: 0, number_of_puts: usage1.number_of_puts * 2 / 3, @@ -1239,7 +1239,7 @@ fn send_rewarding_providers_batch_works() { }; let node_usage2 = NodeUsage { - // Storage + // Storage 2 transferred_bytes: 0, stored_bytes: usage1.stored_bytes * 2, number_of_puts: 0, @@ -1247,7 +1247,7 @@ fn send_rewarding_providers_batch_works() { }; let node_usage3 = NodeUsage { - // CDN + Storage + // Storage 1 + Storage 2 transferred_bytes: usage1.transferred_bytes * 2, stored_bytes: usage1.stored_bytes * 3, number_of_puts: usage1.number_of_puts * 2, diff --git a/pallets/ddc-payouts/src/weights.rs b/pallets/ddc-payouts/src/weights.rs index e4764f492..5f0578c31 100644 --- a/pallets/ddc-payouts/src/weights.rs +++ b/pallets/ddc-payouts/src/weights.rs @@ -1,12 +1,12 @@ //! Autogenerated weights for pallet_ddc_payouts //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/debug/cere +// ./target/release/cere // benchmark // pallet // --chain=dev @@ -15,7 +15,7 @@ // --extrinsic=* // --steps=50 // --repeat=20 -// --template=./.maintain/frame-weight-template-clippy.hbs +// --template=./.maintain/frame-weight-template.hbs // --output=pallets/ddc-payouts/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -43,20 +43,20 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) fn set_authorised_caller() -> Weight { - Weight::from_ref_time(251_000_000_u64) + Weight::from_ref_time(11_000_000_u64) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_billing_report() -> Weight { - Weight::from_ref_time(466_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_charging_customers() -> Weight { - Weight::from_ref_time(440_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -68,9 +68,9 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts DebtorCustomers (r:1 w:1) /// The range of component `b` is `[1, 1000]`. fn send_charging_customers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(1_267_000_000_u64) - // Standard Error: 3_691_054 - .saturating_add(Weight::from_ref_time(557_422_673_u64).saturating_mul(b as u64)) + Weight::from_ref_time(12_333_820_u64) + // Standard Error: 298_759 + .saturating_add(Weight::from_ref_time(24_367_120_u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -84,14 +84,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking CounterForValidators (r:1 w:0) // Storage: Staking Validators (r:2 w:0) fn end_charging_customers() -> Weight { - Weight::from_ref_time(1_978_000_000_u64) + Weight::from_ref_time(89_000_000_u64) .saturating_add(T::DbWeight::get().reads(10_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_rewarding_providers() -> Weight { - Weight::from_ref_time(446_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -100,9 +100,9 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:2 w:2) /// The range of component `b` is `[1, 1000]`. fn send_rewarding_providers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(758_000_000_u64) - // Standard Error: 148_210 - .saturating_add(Weight::from_ref_time(336_218_526_u64).saturating_mul(b as u64)) + Weight::from_ref_time(32_000_000_u64) + // Standard Error: 5_087 + .saturating_add(Weight::from_ref_time(14_402_776_u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -111,14 +111,14 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_rewarding_providers() -> Weight { - Weight::from_ref_time(458_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_billing_report() -> Weight { - Weight::from_ref_time(449_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -128,20 +128,20 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) fn set_authorised_caller() -> Weight { - Weight::from_ref_time(251_000_000_u64) + Weight::from_ref_time(11_000_000_u64) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_billing_report() -> Weight { - Weight::from_ref_time(466_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_charging_customers() -> Weight { - Weight::from_ref_time(440_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -153,9 +153,9 @@ impl WeightInfo for () { // Storage: DdcPayouts DebtorCustomers (r:1 w:1) /// The range of component `b` is `[1, 1000]`. fn send_charging_customers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(1_267_000_000_u64) - // Standard Error: 3_691_054 - .saturating_add(Weight::from_ref_time(557_422_673_u64).saturating_mul(b as u64)) + Weight::from_ref_time(12_333_820_u64) + // Standard Error: 298_759 + .saturating_add(Weight::from_ref_time(24_367_120_u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(b as u64))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -169,14 +169,14 @@ impl WeightInfo for () { // Storage: Staking CounterForValidators (r:1 w:0) // Storage: Staking Validators (r:2 w:0) fn end_charging_customers() -> Weight { - Weight::from_ref_time(1_978_000_000_u64) + Weight::from_ref_time(89_000_000_u64) .saturating_add(RocksDbWeight::get().reads(10_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_rewarding_providers() -> Weight { - Weight::from_ref_time(446_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -185,9 +185,9 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:2) /// The range of component `b` is `[1, 1000]`. fn send_rewarding_providers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(758_000_000_u64) - // Standard Error: 148_210 - .saturating_add(Weight::from_ref_time(336_218_526_u64).saturating_mul(b as u64)) + Weight::from_ref_time(32_000_000_u64) + // Standard Error: 5_087 + .saturating_add(Weight::from_ref_time(14_402_776_u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(b as u64))) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -196,15 +196,15 @@ impl WeightInfo for () { // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_rewarding_providers() -> Weight { - Weight::from_ref_time(458_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_billing_report() -> Weight { - Weight::from_ref_time(449_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} +} \ No newline at end of file diff --git a/pallets/ddc-staking/README.md b/pallets/ddc-staking/README.md index f8ac2385a..2db79884a 100644 --- a/pallets/ddc-staking/README.md +++ b/pallets/ddc-staking/README.md @@ -4,13 +4,12 @@ The DDC Staking module is used to manage funds at stake by Cere DDC participants ## Overview -The DDC Staking module is the means by which an account can voluntarily place funds under deposit to join DDC CDN or storage network. +The DDC Staking module is the means by which an account can voluntarily place funds under deposit to join DDC network. ### Terminology - DDC Staking: The process of locking up funds for some time in order to become a participant of the DDC. - Stash account: The account holding an owner's funds used for staking. - Controller account: The account that controls an owner's funds for staking. -- CDN: CDN network participant. - Storage: Storage network participant. - Era: A time period of DDC participants activity data capture and accumulation which will further be used to calculate pay outs. diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 37eb110a1..c1eeff149 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -2,7 +2,7 @@ use super::*; use crate::Pallet as DdcStaking; -use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams, NodeType, StorageNodePubKey}; +use ddc_primitives::{NodeParams, NodeType, StorageNodeMode, StorageNodeParams, StorageNodePubKey}; use testing_utils::*; use frame_support::traits::Currency; @@ -22,11 +22,12 @@ benchmarks! { let controller = create_funded_user::("controller", USER_SEED, 100); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); let _ = T::NodeCreator::create_node( node.clone(), stash.clone(), - NodeParams::CDNParams(CDNNodeParams { + NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -44,7 +45,7 @@ benchmarks! { unbond { // clean up any existing state. - clear_storages_and_cdns::(); + clear_activated_nodes::(); let (stash, controller, _) = create_stash_controller_node::(0, 100)?; let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; @@ -76,7 +77,7 @@ benchmarks! { store { let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(100u128), node_pub_key)?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::Storage).unwrap_or(100u128), node_pub_key)?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -84,32 +85,23 @@ benchmarks! { assert!(Storages::::contains_key(&stash)); } - serve { - let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128), node_pub_key)?; - - whitelist_account!(controller); - }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) - verify { - assert!(CDNs::::contains_key(&stash)); - } chill { // clean up any existing state. - clear_storages_and_cdns::(); + clear_activated_nodes::(); - let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); - let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128), node_pub_key)?; - DdcStaking::::serve(RawOrigin::Signed(cdn_controller.clone()).into(), ClusterId::from([1; 20]))?; - assert!(CDNs::::contains_key(&cdn_stash)); + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); + let (storage_stash, storage_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::Storage).unwrap_or(10u128), node_pub_key)?; + DdcStaking::::store(RawOrigin::Signed(storage_controller.clone()).into(), ClusterId::from([1; 20]))?; + assert!(Storages::::contains_key(&storage_stash)); frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); - DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; - frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or_else(|_| T::BlockNumber::from(10u32))); + DdcStaking::::chill(RawOrigin::Signed(storage_controller.clone()).into())?; + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::Storage).unwrap_or_else(|_| T::BlockNumber::from(10u32))); - whitelist_account!(cdn_controller); - }: _(RawOrigin::Signed(cdn_controller)) + whitelist_account!(storage_controller); + }: _(RawOrigin::Signed(storage_controller)) verify { - assert!(!CDNs::::contains_key(&cdn_stash)); + assert!(!Storages::::contains_key(&storage_stash)); } set_controller { @@ -124,7 +116,7 @@ benchmarks! { set_node { let (stash, _, _) = create_stash_controller_node::(USER_SEED, 100)?; - let new_node = NodePubKey::CDNPubKey(CDNNodePubKey::new([1; 32])); + let new_node = NodePubKey::StoragePubKey(StorageNodePubKey::new([1; 32])); whitelist_account!(stash); }: _(RawOrigin::Signed(stash), new_node.clone()) verify { diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index d7bbad30e..f9e09fcd3 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -1,6 +1,6 @@ //! # DDC Staking Pallet //! -//! The DDC Staking pallet is used to manage funds at stake by CDN and storage network maintainers. +//! The DDC Staking pallet is used to manage funds at stake by DDC network maintainers. //! //! - [`Config`] //! - [`Call`] @@ -181,12 +181,6 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; - /// The map of (wannabe) CDN nodes participants stash keys to the DDC cluster ID they wish to - /// participate into. - #[pallet::storage] - #[pallet::getter(fn cdns)] - pub type CDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// The map of (wannabe) Storage nodes participants stash keys to the DDC cluster ID they /// wish to participate into. #[pallet::storage] @@ -208,15 +202,8 @@ pub mod pallet { #[pallet::getter(fn leaving_storages)] pub type LeavingStorages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - // Map of CDN node provider stash accounts that aim to leave a cluster - #[pallet::storage] - #[pallet::getter(fn leaving_cdns)] - pub type LeavingCDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - #[pallet::genesis_config] pub struct GenesisConfig { - #[allow(clippy::type_complexity)] - pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, #[allow(clippy::type_complexity)] pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, } @@ -224,31 +211,13 @@ pub mod pallet { #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { cdns: Default::default(), storages: Default::default() } + GenesisConfig { storages: Default::default() } } } #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { - // Add initial CDN participants - for &(ref stash, ref controller, ref node, balance, cluster) in &self.cdns { - assert!( - T::Currency::free_balance(stash) >= balance, - "Stash do not have enough balance to participate in CDN." - ); - assert_ok!(Pallet::::bond( - T::RuntimeOrigin::from(Some(stash.clone()).into()), - T::Lookup::unlookup(controller.clone()), - node.clone(), - balance, - )); - assert_ok!(Pallet::::serve( - T::RuntimeOrigin::from(Some(controller.clone()).into()), - cluster, - )); - } - // Add initial storage network participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.storages { assert!( @@ -282,20 +251,20 @@ pub mod pallet { /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` /// from the unlocking queue. \[stash, amount\] Withdrawn(T::AccountId, BalanceOf), - /// An account has stopped participating as either a storage network or CDN participant. + /// An account has stopped participating as DDC network participant. /// \[stash\] Chilled(T::AccountId), - /// An account has declared desire to stop participating in CDN or storage network soon. + /// An account has declared desire to stop participating in DDC network soon. /// \[stash, cluster, block\] ChillSoon(T::AccountId, ClusterId, T::BlockNumber), - /// An account that started participating as either a storage network or CDN participant. + /// An account that started participating as DDC network participant. /// \[stash\] Activated(T::AccountId), /// An account that started unbonding tokens below the minimum value set for the cluster - /// his CDN or Storage node is assigned to \[stash\] + /// his DDC node is assigned to \[stash\] LeaveSoon(T::AccountId), /// An account that unbonded tokens below the minimum value set for the cluster his - /// CDN or Storage node was assigned to \[stash\] + /// DDC node was assigned to \[stash\] Left(T::AccountId), } @@ -309,9 +278,9 @@ pub mod pallet { AlreadyBonded, /// Controller or node is already paired. AlreadyPaired, - /// Cannot have a storage network or CDN participant, with the size less than defined by + /// Cannot have a DDC network participant, with the size less than defined by /// governance (see `BondSize`). If unbonding is the intention, `chill` first to remove - /// one's role as storage/cdn node. + /// one's role as activated DDC node. InsufficientBond, /// Can not schedule more unlock chunks. NoMoreChunks, @@ -332,8 +301,6 @@ pub mod pallet { NoClusterGovParams, /// Conditions for fast chill are not met, try the regular `chill` from FastChillProhibited, - /// Serving operation is called for non-CDN node - ServingProhibited, /// Storing operation is called for non-Storage node StoringProhibited, /// Arithmetic overflow occurred @@ -457,11 +424,7 @@ pub mod pallet { ledger.active = Zero::zero(); } - let min_active_bond = if let Some(cluster_id) = Self::cdns(&ledger.stash) { - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(Into::>::into)?; - bond_size.saturated_into::>() - } else if let Some(cluster_id) = Self::storages(&ledger.stash) { + let min_active_bond = if let Some(cluster_id) = Self::storages(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) .map_err(Into::>::into)?; @@ -488,7 +451,6 @@ pub mod pallet { .map_err(Into::>::into)?; let min_bond_size = match node_pub_key { - NodePubKey::CDNPubKey(_) => bonding_params.cdn_bond_size, NodePubKey::StoragePubKey(_) => bonding_params.storage_bond_size, }; @@ -496,8 +458,6 @@ pub mod pallet { // cluster eventually, we keep its stake till the end of unbonding period. if ledger.active < min_bond_size.saturated_into::>() { match node_pub_key { - NodePubKey::CDNPubKey(_) => - LeavingCDNs::::insert(ledger.stash.clone(), cluster_id), NodePubKey::StoragePubKey(_) => LeavingStorages::::insert(ledger.stash.clone(), cluster_id), }; @@ -506,7 +466,6 @@ pub mod pallet { }; match node_pub_key { - NodePubKey::CDNPubKey(_) => bonding_params.cdn_unbonding_delay, NodePubKey::StoragePubKey(_) => bonding_params.storage_unbonding_delay, } } else { @@ -582,15 +541,12 @@ pub mod pallet { // If provider aimed to leave the cluster and the unbonding period ends, remove // the node from the cluster - if let Some(cluster_id) = - >::get(&stash).or_else(|| >::get(&stash)) - { + if let Some(cluster_id) = >::get(&stash) { // Cluster manager could remove the node from cluster by this moment already, so // it is ok to ignore result. let _ = T::ClusterManager::remove_node(&cluster_id, &node_pub_key); >::remove(&stash); - >::remove(&stash); Self::deposit_event(Event::::Left(stash)); } @@ -599,59 +555,6 @@ pub mod pallet { Ok(()) } - /// Declare the desire to participate in CDN for the origin controller. Also works to cancel - /// a previous "chill". - /// - /// `cluster` is the ID of the DDC cluster the participant wishes to join. - /// - /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The - /// bond size must be greater than or equal to the `CDNBondSize`. - #[pallet::weight(T::WeightInfo::serve())] - pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { - let controller = ensure_signed(origin)?; - - T::ClusterVisitor::ensure_cluster(&cluster_id).map_err(Into::>::into)?; - - let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - // Retrieve the respective bond size from Cluster Visitor - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(Into::>::into)?; - - ensure!( - ledger.active >= bond_size.saturated_into::>(), - Error::::InsufficientBond - ); - let stash = &ledger.stash; - - // Can't participate in CDN if already participating in storage network. - ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); - - // Only CDN node can perform serving (i.e. streaming content) - let node_pub_key = >::get(stash).ok_or(Error::::BadState)?; - ensure!( - matches!(node_pub_key, NodePubKey::CDNPubKey(_)), - Error::::ServingProhibited - ); - - // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::cdns(stash) { - // Switching the cluster is prohibited. The user should chill first. - ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); - // Cancel previous "chill" attempts - Self::reset_chilling(&controller); - return Ok(()) - } else { - // Can't participate in new CDN network if provider hasn't left the previous cluster - // yet - ensure!(!LeavingCDNs::::contains_key(stash), Error::::NodeIsLeaving); - } - - Self::do_add_cdn(stash, cluster_id); - Self::deposit_event(Event::::Activated(stash.clone())); - - Ok(()) - } - /// Declare the desire to participate in storage network for the origin controller. Also /// works to cancel a previous "chill". /// @@ -675,9 +578,6 @@ pub mod pallet { ); let stash = &ledger.stash; - // Can't participate in storage network if already participating in CDN. - ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); - // Only Storage node can perform storing (i.e. saving content) let node_pub_key = >::get(stash).ok_or(Error::::BadState)?; ensure!( @@ -704,15 +604,15 @@ pub mod pallet { Ok(()) } - /// Declare no desire to either participate in storage network or CDN. + /// Declare no desire to either participate in DDC network. /// /// Only in case the delay for the role _origin_ maintains in the cluster is set to zero in /// cluster settings, it removes the participant immediately. Otherwise, it requires at /// least two invocations to effectively remove the participant. The first invocation only /// updates the [`Ledger`] to note the block number at which the participant may "chill" /// (current block + the delay from the cluster settings). The second invocation made at the - /// noted block (or any further block) will remove the participant from the list of CDN or - /// storage network participants. If the cluster settings updated significantly decreasing + /// noted block (or any further block) will remove the participant from the list of DDC + /// network participants. If the cluster settings updated significantly decreasing /// the delay, one may invoke it again to decrease the block at with the participant may /// "chill". But it never increases the block at which the participant may "chill" even when /// the cluster settings updated increasing the delay. @@ -727,11 +627,7 @@ pub mod pallet { let current_block = >::block_number(); // Extract delay from the cluster settings. - let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { - let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::CDN) - .map_err(Into::>::into)?; - (cluster, chill_delay) - } else if let Some(cluster) = Self::storages(&ledger.stash) { + let (cluster, delay) = if let Some(cluster) = Self::storages(&ledger.stash) { let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) .map_err(Into::>::into)?; (cluster, chill_delay) @@ -813,12 +709,10 @@ pub mod pallet { } // Ensure only one node per stash. - ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); // Ensure that provider is not about leaving the cluster as it may cause the removal // of an unexpected node after unbonding. - ensure!(!>::contains_key(&stash), Error::::NodeIsLeaving); ensure!(!>::contains_key(&stash), Error::::NodeIsLeaving); >::insert(new_node.clone(), stash.clone()); @@ -839,9 +733,7 @@ pub mod pallet { let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; ensure!(stash == node_stash, Error::::NotNodeController); - let cluster_id = >::get(&stash) - .or_else(|| >::get(&stash)) - .ok_or(Error::::NodeHasNoStake)?; + let cluster_id = >::get(&stash).ok_or(Error::::NodeHasNoStake)?; let is_cluster_node = T::ClusterManager::contains_node(&cluster_id, &node_pub_key); ensure!(!is_cluster_node, Error::::FastChillProhibited); @@ -875,8 +767,7 @@ pub mod pallet { /// Chill a stash account. fn chill_stash(stash: &T::AccountId) { let chilled_as_storage = Self::do_remove_storage(stash); - let chilled_as_cdn = Self::do_remove_cdn(stash); - if chilled_as_storage || chilled_as_cdn { + if chilled_as_storage { Self::deposit_event(Event::::Chilled(stash.clone())); } } @@ -914,27 +805,12 @@ pub mod pallet { }; Self::do_remove_storage(stash); - Self::do_remove_cdn(stash); frame_system::Pallet::::dec_consumers(stash); Ok(()) } - /// This function will add a CDN participant to the `CDNs` storage map. - /// - /// If the CDN participant already exists, their cluster will be updated. - pub fn do_add_cdn(who: &T::AccountId, cluster: ClusterId) { - CDNs::::insert(who, cluster); - } - - /// This function will remove a CDN participant from the `CDNs` map. - /// - /// Returns true if `who` was removed from `CDNs`, otherwise false. - pub fn do_remove_cdn(who: &T::AccountId) -> bool { - CDNs::::take(who).is_some() - } - /// This function will add a storage network participant to the `Storages` storage map. /// /// If the storage network participant already exists, their cluster will be updated. @@ -983,7 +859,6 @@ pub mod pallet { Self::update_ledger(&controller, &item); match node { NodePubKey::StoragePubKey(_node) => Self::do_add_storage(&stash, cluster_id), - NodePubKey::CDNPubKey(_node) => Self::do_add_cdn(&stash, cluster_id), } Ok(()) @@ -997,11 +872,9 @@ pub mod pallet { ) -> Result { let stash = >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; - let maybe_cdn_in_cluster = CDNs::::get(&stash); let maybe_storage_in_cluster = Storages::::get(&stash); - let has_activated_stake: bool = maybe_cdn_in_cluster - .or(maybe_storage_in_cluster) + let has_activated_stake: bool = maybe_storage_in_cluster .is_some_and(|staking_cluster| staking_cluster == *cluster_id); Ok(has_activated_stake) diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index c1aa469f5..75ff7684b 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -4,8 +4,8 @@ use crate::{self as pallet_ddc_staking, *}; use ddc_primitives::{ - CDNNodePubKey, ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, - ClusterPricingParams, NodeParams, NodePubKey, StorageNodePubKey, + ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams, + NodeParams, NodePubKey, StorageNodePubKey, }; use ddc_traits::{ cluster::{ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError}, @@ -195,21 +195,6 @@ impl ClusterVisitor for TestClusterVisitor { cluster_id: &ClusterId, ) -> Result, ClusterVisitorError> { Ok(ClusterBondingParams { - cdn_bond_size: >::get_bond_size( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_chill_delay: >::get_chill_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_unbonding_delay: >::get_unbonding_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), storage_bond_size: >::get_bond_size( cluster_id, NodeType::Storage, @@ -301,30 +286,18 @@ impl NodeVisitor for MockNodeVisitor { } pub struct ExtBuilder { - has_cdns: bool, has_storages: bool, stakes: BTreeMap, - cdns: Vec<(AccountId, AccountId, Balance, ClusterId)>, storages: Vec<(AccountId, AccountId, Balance, ClusterId)>, } impl Default for ExtBuilder { fn default() -> Self { - Self { - has_cdns: true, - has_storages: true, - stakes: Default::default(), - cdns: Default::default(), - storages: Default::default(), - } + Self { has_storages: true, stakes: Default::default(), storages: Default::default() } } } impl ExtBuilder { - pub fn has_cdns(mut self, has: bool) -> Self { - self.has_cdns = has; - self - } pub fn has_storages(mut self, has: bool) -> Self { self.has_storages = has; self @@ -333,16 +306,6 @@ impl ExtBuilder { self.stakes.insert(who, stake); self } - pub fn add_cdn( - mut self, - stash: AccountId, - controller: AccountId, - stake: Balance, - cluster: ClusterId, - ) -> Self { - self.cdns.push((stash, controller, stake, cluster)); - self - } pub fn add_storage( mut self, stash: AccountId, @@ -363,45 +326,37 @@ impl ExtBuilder { (2, 100), (3, 100), (4, 100), - // cdn controllers + // storage controllers (10, 100), (20, 100), - // storage controllers (30, 100), (40, 100), - // cdn stashes + // storage stashes (11, 100), (21, 100), - // storage stashes (31, 100), (41, 100), ], } .assimilate_storage(&mut storage); - let mut cdns = vec![]; - if self.has_cdns { - cdns = vec![ + let mut storages = vec![]; + if self.has_storages { + storages = vec![ // (stash, controller, node, stake, cluster) ( 11, 10, - NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([12; 32])), 100, ClusterId::from([1; 20]), ), ( 21, 20, - NodePubKey::CDNPubKey(CDNNodePubKey::new([22; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([22; 32])), 100, ClusterId::from([1; 20]), ), - ]; - } - let mut storages = vec![]; - if self.has_storages { - storages = vec![ - // (stash, controller, node, stake, cluster) ( 31, 30, @@ -419,8 +374,8 @@ impl ExtBuilder { ]; } - let _ = pallet_ddc_staking::GenesisConfig:: { cdns, storages } - .assimilate_storage(&mut storage); + let _ = + pallet_ddc_staking::GenesisConfig:: { storages }.assimilate_storage(&mut storage); TestExternalities::new(storage) } diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 7dec075cc..54454b95d 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -2,8 +2,8 @@ use crate::{Pallet as DdcStaking, *}; use ddc_primitives::{ - CDNNodeParams, CDNNodePubKey, ClusterGovParams, ClusterId, ClusterParams, NodeParams, - StorageNodeParams, + ClusterGovParams, ClusterId, ClusterParams, NodeParams, StorageNodeMode, StorageNodeParams, + StorageNodePubKey, }; use frame_benchmarking::account; @@ -15,11 +15,10 @@ use sp_std::prelude::*; const SEED: u32 = 0; -/// This function removes all storage and CDN nodes from storage. -pub fn clear_storages_and_cdns() { +/// This function removes all storage and Storages nodes from storage. +pub fn clear_activated_nodes() { #[allow(unused_must_use)] { - CDNs::::clear(u32::MAX, None); Storages::::clear(u32::MAX, None); } } @@ -57,12 +56,13 @@ pub fn create_stash_controller_node( let controller = create_funded_user::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); T::NodeCreator::create_node( node.clone(), stash.clone(), - NodeParams::CDNParams(CDNNodeParams { + NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -92,23 +92,12 @@ pub fn create_stash_controller_node_with_balance( let node_pub = node_pub_key.clone(); match node_pub_key { - NodePubKey::CDNPubKey(node_pub_key) => { - T::NodeCreator::create_node( - ddc_primitives::NodePubKey::CDNPubKey(node_pub_key), - stash.clone(), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }), - )?; - }, NodePubKey::StoragePubKey(node_pub_key) => { T::NodeCreator::create_node( - NodePubKey::StoragePubKey(node_pub_key), + ddc_primitives::NodePubKey::StoragePubKey(node_pub_key), stash.clone(), NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -124,9 +113,6 @@ pub fn create_stash_controller_node_with_balance( treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 10u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 10u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 358b736ce..53f400101 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,8 +1,7 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; - +use ddc_primitives::StorageNodePubKey; use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; @@ -81,11 +80,11 @@ fn change_controller_works() { // 10 is no longer in control. assert_noop!( - DdcStaking::serve(RuntimeOrigin::signed(10), ClusterId::from([1; 20])), + DdcStaking::store(RuntimeOrigin::signed(10), ClusterId::from([1; 20])), Error::::NotController ); // 3 is a new controller. - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(3), ClusterId::from([1; 20]))); }) } @@ -94,17 +93,17 @@ fn not_enough_inital_bond_flow() { ExtBuilder::default().build_and_execute(|| { System::set_block_number(1); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 5 )); // Not enough tokens bonded to serve assert_noop!( - DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), + DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), Error::::InsufficientBond ); @@ -127,7 +126,7 @@ fn not_enough_inital_bond_flow() { DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 5 ), Error::::AlreadyBonded @@ -145,12 +144,12 @@ fn not_enough_inital_bond_flow() { assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 10 )); // Serving should work - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); }) } @@ -159,15 +158,15 @@ fn unbonding_edge_cases_work() { ExtBuilder::default().build_and_execute(|| { System::set_block_number(1); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 100 )); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(4), 1)); while System::block_number() < 33 { @@ -180,41 +179,6 @@ fn unbonding_edge_cases_work() { }) } -#[test] -fn serve_or_store_should_be_prohibited() { - ExtBuilder::default().build_and_execute(|| { - System::set_block_number(1); - - // Add new CDN participant, account 3 controlled by 4 with node 5. - assert_ok!(DdcStaking::bond( - RuntimeOrigin::signed(3), - 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), - 100 - )); - - // Add new Storage participant, account 1 controlled by 2 with node 3. - assert_ok!(DdcStaking::bond( - RuntimeOrigin::signed(1), - 2, - NodePubKey::StoragePubKey(StorageNodePubKey::new([3; 32])), - 100 - )); - - // Not enough tokens bonded to serve - assert_noop!( - DdcStaking::serve(RuntimeOrigin::signed(2), ClusterId::from([1; 20])), - Error::::ServingProhibited - ); - - // Not enough tokens bonded to store - assert_noop!( - DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), - Error::::StoringProhibited - ); - }) -} - #[test] fn set_node_works() { ExtBuilder::default().build_and_execute(|| { @@ -226,7 +190,7 @@ fn set_node_works() { assert_noop!( DdcStaking::set_node( RuntimeOrigin::signed(10), - NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])) + NodePubKey::StoragePubKey(StorageNodePubKey::new([12; 32])) ), Error::::AlreadyPaired ); @@ -235,21 +199,21 @@ fn set_node_works() { assert_noop!( DdcStaking::set_node( RuntimeOrigin::signed(11), - NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])) + NodePubKey::StoragePubKey(StorageNodePubKey::new([12; 32])) ), Error::::AlreadyInRole ); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(10))); System::set_block_number(11); - // Actual CDN participant removal. + // Actual Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(10))); // Setting node should work assert_ok!(DdcStaking::set_node( RuntimeOrigin::signed(11), - NodePubKey::CDNPubKey(CDNNodePubKey::new([13; 32])) + NodePubKey::StoragePubKey(StorageNodePubKey::new([13; 32])) )); }) } @@ -260,11 +224,11 @@ fn cancel_previous_chill_works() { System::set_block_number(1); let cluster_id = ClusterId::from([1; 20]); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 100 )); @@ -277,16 +241,16 @@ fn cancel_previous_chill_works() { )); // Not enough tokens bonded to serve - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), cluster_id)); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), cluster_id)); assert_ok!(DdcStaking::store(RuntimeOrigin::signed(2), ClusterId::from([1; 20]))); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Not enough tokens bonded to serve - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), cluster_id)); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), cluster_id)); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(2))); // Not enough tokens bonded to serve assert_ok!(DdcStaking::store(RuntimeOrigin::signed(2), cluster_id)); @@ -308,21 +272,21 @@ fn staking_should_work() { DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 0 ), Error::::InsufficientBond ); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 1500 )); System::assert_last_event(Event::Bonded(3, 1500).into()); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([0; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([0; 20]))); System::assert_last_event(Event::Activated(3).into()); // Controller already paired @@ -330,7 +294,7 @@ fn staking_should_work() { DdcStaking::bond( RuntimeOrigin::signed(5), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([10; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([10; 32])), 10 ), Error::::AlreadyPaired @@ -341,13 +305,13 @@ fn staking_should_work() { DdcStaking::bond( RuntimeOrigin::signed(5), 6, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 10 ), Error::::AlreadyPaired ); - // Account 4 controls the stash from account 3, which is 1500 units, 3 is a CDN + // Account 4 controls the stash from account 3, which is 1500 units, 3 is a Storage // participant, 5 is a DDC node. assert_eq!(DdcStaking::bonded(&3), Some(4)); assert_eq!( @@ -360,19 +324,22 @@ fn staking_should_work() { unlocking: Default::default(), }) ); - assert_eq!(DdcStaking::cdns(3), Some(ClusterId::from([0; 20]))); - assert_eq!(DdcStaking::nodes(NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32]))), Some(3)); + assert_eq!(DdcStaking::storages(3), Some(ClusterId::from([0; 20]))); + assert_eq!( + DdcStaking::nodes(NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32]))), + Some(3) + ); // Set initial block timestamp. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); System::assert_last_event(Event::ChillSoon(3, ClusterId::from([0; 20]), 11).into()); // Removal is scheduled, stashed value of 4 is still lock. let chilling = System::block_number() + 10u64; - // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) + // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::Storage) // .unwrap_or(10_u64); assert_eq!( DdcStaking::ledger(&4), @@ -415,92 +382,12 @@ fn staking_should_work() { }) ); - // Actual CDN participant removal. + // Actual Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); System::assert_last_event(Event::Chilled(3).into()); - // Account 3 is no longer a CDN participant. - assert_eq!(DdcStaking::cdns(3), None); - }); -} - -#[test] -fn cdn_full_unbonding_works() { - ExtBuilder::default().build_and_execute(|| { - System::set_block_number(1); - - let provider_stash: u64 = 1; - let provider_controller: u64 = 2; - let cluster_id = ClusterId::from([1; 20]); - let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([1; 32])); - - let lock = MockNodeVisitor::set_and_hold_lock(MockNode { - cluster_id: Some(cluster_id), - exists: true, - }); - - let cdn_bond_size = 10_u128; - let cdn_chill_delay = 10_u64; - let cdn_unbond_delay = 10_u64; - - // Put some money in account that we'll use. - let _ = Balances::make_free_balance_be(&provider_controller, 2000); - let _ = Balances::make_free_balance_be(&provider_stash, 2000); - - // Add new CDN participant, account 1 controlled by 2 with node 1. - assert_ok!(DdcStaking::bond( - RuntimeOrigin::signed(provider_stash), - provider_controller, - node_pub_key.clone(), - cdn_bond_size, // min bond size - )); - System::assert_last_event(Event::Bonded(provider_stash, cdn_bond_size).into()); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(provider_controller), cluster_id)); - System::assert_last_event(Event::Activated(provider_stash).into()); - - assert_eq!(DdcStaking::cdns(provider_stash), Some(cluster_id)); - assert_eq!(DdcStaking::nodes(node_pub_key), Some(provider_stash)); - - // Set block timestamp. - Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - - // Schedule CDN participant removal. - assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); - let chilling = System::block_number() + cdn_chill_delay; - System::assert_last_event(Event::ChillSoon(provider_stash, cluster_id, chilling).into()); - - // Set the block number that allows us to chill. - while System::block_number() < chilling { - System::set_block_number(System::block_number() + 1); - Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - } - - // Actual CDN participant removal. - assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); - System::assert_last_event(Event::Chilled(provider_stash).into()); - - // Account is no longer a CDN participant. - assert_eq!(DdcStaking::cdns(provider_stash), None); - - // Start unbonding all tokens - assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(provider_controller), cdn_bond_size)); - System::assert_has_event(Event::LeaveSoon(provider_stash).into()); - assert_eq!(DdcStaking::leaving_cdns(provider_stash), Some(cluster_id)); - System::assert_last_event(Event::Unbonded(provider_stash, cdn_bond_size).into()); - - let unbonding = System::block_number() + cdn_unbond_delay; - // Set the block number that allows us to chill. - while System::block_number() < unbonding { - System::set_block_number(System::block_number() + 1); - Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - } - - assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(provider_controller))); - System::assert_has_event(Event::Withdrawn(provider_stash, cdn_bond_size).into()); - assert_eq!(DdcStaking::leaving_cdns(provider_stash), None); - System::assert_last_event(Event::Left(provider_stash).into()); - - MockNodeVisitor::reset_and_release_lock(lock); + // Account 3 is no longer a Storage participant. + assert_eq!(DdcStaking::storages(3), None); }); } @@ -595,18 +482,7 @@ fn staking_creator_works() { let controller: u64 = 2; let cluster_id = ClusterId::from([1; 20]); let value = 5; - let cdn_node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([2; 32])); - let storage_node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([2; 32])); - - assert_ok!( - >>::bond_stake_and_participate( - stash, - controller, - cdn_node_pub_key, - value, - cluster_id, - ) - ); + let storage_node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([2; 32])); assert_ok!( >>::bond_stake_and_participate( @@ -625,9 +501,9 @@ fn staking_visitor_works() { // Verifies initial conditions of mock ExtBuilder::default().build_and_execute(|| { let cluster_id = ClusterId::from([1; 20]); - let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])); + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, node_pub_key.clone(), 100)); assert!(>::has_stake(&node_pub_key,)); @@ -638,7 +514,7 @@ fn staking_visitor_works() { assert!(!result); } - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); if let Ok(result) = >::has_activated_stake(&node_pub_key, &cluster_id) diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 5437d12a2..e7157a60d 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -1,8 +1,8 @@ //! Autogenerated weights for pallet_ddc_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-10-10, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `e14`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -10,14 +10,13 @@ // benchmark // pallet // --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-staking +// --extrinsic=* // --steps=50 // --repeat=20 -// --pallet=pallet_ddc_staking -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled // --template=./.maintain/frame-weight-template.hbs -// --output=./pallets/ddc-staking/src +// --output=pallets/ddc-staking/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -32,7 +31,6 @@ pub trait WeightInfo { fn unbond() -> Weight; fn withdraw_unbonded() -> Weight; fn store() -> Weight; - fn serve() -> Weight; fn chill() -> Weight; fn set_controller() -> Weight; fn set_node() -> Weight; @@ -45,93 +43,67 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:1) // Storage: DdcStaking Providers (r:1 w:1) - // Storage: DdcNodes CDNNodes (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(37_000_000_u64) + Weight::from_ref_time(39_000_000_u64) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Providers (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000_u64) - .saturating_add(T::DbWeight::get().reads(7_u64)) + Weight::from_ref_time(37_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Providers (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) - // Storage: DdcStaking LeavingCDNs (r:1 w:0) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - // Minimum execution time: 33_000 nanoseconds. - Weight::from_ref_time(34_000_000_u64) - .saturating_add(T::DbWeight::get().reads(6_u64)) + Weight::from_ref_time(33_000_000_u64) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - // Minimum execution time: 28_000 nanoseconds. - Weight::from_ref_time(29_000_000_u64) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking Providers (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:1) - // Storage: DdcStaking LeavingCDNs (r:1 w:0) - fn serve() -> Weight { - // Minimum execution time: 27_000 nanoseconds. Weight::from_ref_time(28_000_000_u64) - .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - // Minimum execution time: 27_000 nanoseconds. Weight::from_ref_time(28_000_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - // Minimum execution time: 12_000 nanoseconds. - Weight::from_ref_time(13_000_000_u64) + Weight::from_ref_time(14_000_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:2) // Storage: DdcStaking Providers (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking LeavingCDNs (r:1 w:0) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - // Minimum execution time: 13_000 nanoseconds. Weight::from_ref_time(14_000_000_u64) - .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } } @@ -142,93 +114,67 @@ impl WeightInfo for () { // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:1) // Storage: DdcStaking Providers (r:1 w:1) - // Storage: DdcNodes CDNNodes (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(37_000_000_u64) + Weight::from_ref_time(39_000_000_u64) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Providers (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(7_u64)) + Weight::from_ref_time(37_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Providers (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) - // Storage: DdcStaking LeavingCDNs (r:1 w:0) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - // Minimum execution time: 33_000 nanoseconds. - Weight::from_ref_time(34_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(6_u64)) + Weight::from_ref_time(33_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - // Minimum execution time: 28_000 nanoseconds. - Weight::from_ref_time(29_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(7_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking Providers (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:1) - // Storage: DdcStaking LeavingCDNs (r:1 w:0) - fn serve() -> Weight { - // Minimum execution time: 27_000 nanoseconds. Weight::from_ref_time(28_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - // Minimum execution time: 27_000 nanoseconds. Weight::from_ref_time(28_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - // Minimum execution time: 12_000 nanoseconds. - Weight::from_ref_time(13_000_000_u64) + Weight::from_ref_time(14_000_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:2) // Storage: DdcStaking Providers (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking LeavingCDNs (r:1 w:0) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - // Minimum execution time: 13_000 nanoseconds. Weight::from_ref_time(14_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } -} +} \ No newline at end of file diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 456c33299..b6f8af964 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -11,7 +11,6 @@ pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; pub type StorageNodePubKey = AccountId32; -pub type CDNNodePubKey = AccountId32; // ClusterParams includes Governance non-sensetive parameters only #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -27,9 +26,6 @@ pub struct ClusterGovParams { pub treasury_share: Perquintill, pub validators_share: Perquintill, pub cluster_reserve_share: Perquintill, - pub cdn_bond_size: Balance, - pub cdn_chill_delay: BlockNumber, - pub cdn_unbonding_delay: BlockNumber, pub storage_bond_size: Balance, pub storage_chill_delay: BlockNumber, pub storage_unbonding_delay: BlockNumber, @@ -56,9 +52,6 @@ pub struct ClusterFeesParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterBondingParams { - pub cdn_bond_size: u128, - pub cdn_chill_delay: BlockNumber, - pub cdn_unbonding_delay: BlockNumber, pub storage_bond_size: u128, pub storage_chill_delay: BlockNumber, pub storage_unbonding_delay: BlockNumber, @@ -68,20 +61,17 @@ pub struct ClusterBondingParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { StoragePubKey(StorageNodePubKey), - CDNPubKey(CDNNodePubKey), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeType { Storage = 1, - CDN = 2, } impl From for u8 { fn from(node_type: NodeType) -> Self { match node_type { NodeType::Storage => 1, - NodeType::CDN => 2, } } } @@ -91,22 +81,25 @@ impl TryFrom for NodeType { fn try_from(value: u8) -> Result { match value { 1 => Ok(NodeType::Storage), - 2 => Ok(NodeType::CDN), _ => Err(()), } } } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNodeParams { - pub host: Vec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, +pub enum StorageNodeMode { + /// DDC Storage node operates with enabled caching in RAM and stores data in Hard Drive + Full = 1, + /// DDC Storage node operates with disabled caching in RAM and stores data in Hard Drive + Storage = 2, + /// DDC Storage node operates with enabled caching in RAM and doesn't store data in Hard Drive + Cache = 3, } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeParams { + pub mode: StorageNodeMode, pub host: Vec, pub http_port: u16, pub grpc_port: u16, @@ -117,5 +110,4 @@ pub struct StorageNodeParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeParams { StorageParams(StorageNodeParams), - CDNParams(CDNNodeParams), } From 51b208ba5ff389c4719596b56fd9e3ecd9700b9d Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:44:58 +0200 Subject: [PATCH 538/544] Payout dust (#203) --- pallets/ddc-payouts/src/lib.rs | 56 ++++-- pallets/ddc-payouts/src/mock.rs | 21 ++- pallets/ddc-payouts/src/tests.rs | 283 ++++++++++++++++++++++++++++++- primitives/src/lib.rs | 3 + runtime/cere-dev/src/lib.rs | 7 +- 5 files changed, 346 insertions(+), 24 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 4b309dd0d..9851394ea 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -25,7 +25,7 @@ pub(crate) mod mock; #[cfg(test)] mod tests; -use ddc_primitives::{ClusterId, DdcEra}; +use ddc_primitives::{ClusterId, DdcEra, MILLICENTS}; use ddc_traits::{ cluster::{ClusterCreator as ClusterCreatorType, ClusterVisitor as ClusterVisitorType}, customer::{ @@ -43,7 +43,7 @@ use frame_support::{ }; use frame_system::pallet_prelude::*; pub use pallet::*; -use sp_runtime::{PerThing, Perquintill}; +use sp_runtime::{traits::Convert, PerThing, Perquintill}; use sp_std::prelude::*; type BatchIndex = u16; @@ -96,9 +96,14 @@ pub struct CustomerCharge { pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +pub type VoteScoreOf = + <::NominatorsAndValidatorsList as frame_election_provider_support::SortedListProvider< + ::AccountId, + >>::Score; + parameter_types! { pub MaxBatchesCount: u16 = 1000; - pub MaxDust: u16 = 20000; + pub MaxDust: u128 = MILLICENTS; pub MaxBatchSize: u16 = 1000; } @@ -124,9 +129,10 @@ pub mod pallet { type CustomerDepositor: CustomerDepositorType; type TreasuryVisitor: PalletVisitorType; type ClusterVisitor: ClusterVisitorType; - type ValidatorList: SortedListProvider; + type NominatorsAndValidatorsList: SortedListProvider; type ClusterCreator: ClusterCreatorType>; type WeightInfo: WeightInfo; + type VoteScoreToU64: Convert, u64>; } #[pallet::event] @@ -230,6 +236,7 @@ pub mod pallet { ArithmeticOverflow, NotExpectedClusterState, BatchSizeIsOutOfBounds, + ScoreRetrievalError, } #[pallet::storage] @@ -672,6 +679,7 @@ pub mod pallet { Error::::BatchIndexAlreadyProcessed ); + let max_dust = MaxDust::get().saturated_into::>(); let mut updated_billing_report = billing_report.clone(); for payee in payees { let node_reward = get_node_reward::( @@ -699,7 +707,7 @@ pub mod pallet { ) - ::Currency::minimum_balance(); if reward > vault_balance { - if reward - vault_balance > MaxDust::get().into() { + if reward - vault_balance > max_dust { Self::deposit_event(Event::::NotDistributedReward { cluster_id, era, @@ -775,8 +783,7 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - if expected_amount_to_reward - billing_report.total_distributed_reward > - MaxDust::get().into() + if expected_amount_to_reward - billing_report.total_distributed_reward > MaxDust::get() { Self::deposit_event(Event::::NotDistributedOverallReward { cluster_id, @@ -847,20 +854,41 @@ pub mod pallet { ) } + fn get_current_exposure_ratios( + ) -> Result, DispatchError> { + let mut total_score = 0; + let mut individual_scores: Vec<(T::AccountId, u64)> = Vec::new(); + for staker_id in T::NominatorsAndValidatorsList::iter() { + let s = T::NominatorsAndValidatorsList::get_score(&staker_id) + .map_err(|_| Error::::ScoreRetrievalError)?; + let score = T::VoteScoreToU64::convert(s); + total_score += score; + + individual_scores.push((staker_id, score)); + } + + let mut result = Vec::new(); + for (staker_id, score) in individual_scores { + let ratio = Perquintill::from_rational(score, total_score); + result.push((staker_id, ratio)); + } + + Ok(result) + } + fn charge_validator_fees( validators_fee: u128, vault: &T::AccountId, ) -> DispatchResult { - let amount_to_deduct = validators_fee - .checked_div(T::ValidatorList::count().try_into().unwrap()) - .ok_or(Error::::ArithmeticOverflow)? - .saturated_into::>(); + let stakers = get_current_exposure_ratios::()?; + + for (staker_id, ratio) in stakers.iter() { + let amount_to_deduct = *ratio * validators_fee; - for validator_account_id in T::ValidatorList::iter() { ::Currency::transfer( vault, - &validator_account_id, - amount_to_deduct, + staker_id, + amount_to_deduct.saturated_into::>(), ExistenceRequirement::AllowDeath, )?; } diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 23fd03310..27807fc03 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -25,7 +25,7 @@ use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ testing::Header, - traits::{BlakeTwo256, IdentityLookup}, + traits::{BlakeTwo256, Identity, IdentityLookup}, DispatchError, Perquintill, }; use sp_std::prelude::*; @@ -110,8 +110,10 @@ impl crate::pallet::Config for Test { type CustomerDepositor = TestCustomerDepositor; type ClusterVisitor = TestClusterVisitor; type TreasuryVisitor = TestTreasuryVisitor; - type ValidatorList = TestValidatorVisitor; + type NominatorsAndValidatorsList = TestValidatorVisitor; type ClusterCreator = TestClusterCreator; + + type VoteScoreToU64 = Identity; type WeightInfo = (); } @@ -192,6 +194,11 @@ pub const TREASURY_ACCOUNT_ID: AccountId = 888; pub const VALIDATOR1_ACCOUNT_ID: AccountId = 111; pub const VALIDATOR2_ACCOUNT_ID: AccountId = 222; pub const VALIDATOR3_ACCOUNT_ID: AccountId = 333; + +pub const VALIDATOR1_SCORE: u64 = 30; +pub const VALIDATOR2_SCORE: u64 = 45; +pub const VALIDATOR3_SCORE: u64 = 25; + pub const PARTIAL_CHARGE: u128 = 100; pub const USER3_BALANCE: u128 = 1000; @@ -268,8 +275,14 @@ impl SortedListProvider for TestValidator // nothing to do on insert. Ok(()) } - fn get_score(_id: &T::AccountId) -> Result { - unimplemented!() + fn get_score(validator_id: &T::AccountId) -> Result { + if *validator_id == create_account_id_from_u128::(VALIDATOR1_ACCOUNT_ID) { + Ok(VALIDATOR1_SCORE) + } else if *validator_id == create_account_id_from_u128::(VALIDATOR2_ACCOUNT_ID) { + Ok(VALIDATOR2_SCORE) + } else { + Ok(VALIDATOR3_SCORE) + } } fn on_update(_: &T::AccountId, _weight: Self::Score) -> Result<(), Self::Error> { // nothing to do on update. diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 5b5b50d58..3aa413af1 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -742,13 +742,25 @@ fn end_charging_customers_works() { assert_eq!(balance, get_fees(&cluster_id).cluster_reserve_share * charge); balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); - assert_eq!(balance, get_fees(&cluster_id).validators_share * charge / 3); + let mut ratio = Perquintill::from_rational( + VALIDATOR1_SCORE, + VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, + ); + assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); - assert_eq!(balance, get_fees(&cluster_id).validators_share * charge / 3); + ratio = Perquintill::from_rational( + VALIDATOR2_SCORE, + VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, + ); + assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); - assert_eq!(balance, get_fees(&cluster_id).validators_share * charge / 3); + ratio = Perquintill::from_rational( + VALIDATOR3_SCORE, + VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, + ); + assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); assert_eq!( report_after.total_customer_charge.transfer, @@ -1965,6 +1977,271 @@ fn send_rewarding_providers_batch_100nodes_large_usage_works() { }) } +#[test] +fn send_rewarding_providers_batch_100nodes_small_large_usage_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let num_nodes = 100; + let num_users = 5; + let dac_account = 123u128; + let bank = 1u128; + let cluster_id = ONE_CLUSTER_ID; + let era = 100; + let user_batch_size = 10; + let node_batch_size = 10; + let mut batch_user_index = 0; + let mut batch_node_index = 0; + let usage1 = CustomerUsage { + transferred_bytes: 1024, + stored_bytes: 1024, + number_of_puts: 1, + number_of_gets: 1, + }; + + let node_usage1 = NodeUsage { + // CDN + transferred_bytes: Perquintill::from_float(0.75) * usage1.transferred_bytes, + stored_bytes: 0, + number_of_puts: Perquintill::from_float(0.75) * usage1.number_of_puts, + number_of_gets: Perquintill::from_float(0.75) * usage1.number_of_gets, + }; + + let node_usage2 = NodeUsage { + // Storage + transferred_bytes: 0, + stored_bytes: usage1.stored_bytes * 2, + number_of_puts: 0, + number_of_gets: 0, + }; + + let node_usage3 = NodeUsage { + // CDN + Storage + transferred_bytes: usage1.transferred_bytes * 2, + stored_bytes: usage1.stored_bytes * 3, + number_of_puts: usage1.number_of_puts * 2, + number_of_gets: usage1.number_of_gets * 2, + }; + + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut total_nodes_usage = NodeUsage::default(); + for i in 10..10 + num_nodes { + let ratio = match i % 5 { + 0 => Perquintill::from_float(1_000_000.0), + 1 => Perquintill::from_float(0.5), + 2 => Perquintill::from_float(100_000_000.0), + 3 => Perquintill::from_float(0.25), + 4 => Perquintill::from_float(10_000_000_000.0), + _ => unreachable!(), + }; + let mut node_usage = match i % 3 { + 0 => node_usage1.clone(), + 1 => node_usage2.clone(), + 2 => node_usage3.clone(), + _ => unreachable!(), + }; + node_usage.transferred_bytes = ratio * node_usage.transferred_bytes; + node_usage.stored_bytes = ratio * node_usage.stored_bytes; + node_usage.number_of_puts = ratio * node_usage.number_of_puts; + node_usage.number_of_gets = ratio * node_usage.number_of_gets; + + total_nodes_usage.transferred_bytes += node_usage.transferred_bytes; + total_nodes_usage.stored_bytes += node_usage.stored_bytes; + total_nodes_usage.number_of_puts += node_usage.number_of_puts; + total_nodes_usage.number_of_gets += node_usage.number_of_gets; + + node_batch.push((i, node_usage)); + if node_batch.len() == node_batch_size { + payees.push(node_batch.clone()); + node_batch.clear(); + } + } + if !node_batch.is_empty() { + payees.push(node_batch.clone()); + } + + let mut total_charge = 0u128; + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(u128, CustomerUsage)> = Vec::new(); + for user_id in 1000..1000 + num_users { + let ratio = match user_id % 5 { + 0 => Perquintill::from_float(1_000_000.0), + 1 => Perquintill::from_float(10_000_000.0), + 2 => Perquintill::from_float(100_000_000.0), + 3 => Perquintill::from_float(1_000_000_000.0), + 4 => Perquintill::from_float(10_000_000_000.0), + _ => unreachable!(), + }; + + let mut user_usage = usage1.clone(); + user_usage.transferred_bytes = ratio * user_usage.transferred_bytes; + user_usage.stored_bytes = ratio * user_usage.stored_bytes; + user_usage.number_of_puts = ratio * user_usage.number_of_puts; + user_usage.number_of_gets = ratio * user_usage.number_of_gets; + + let expected_charge = calculate_charge(cluster_id, user_usage.clone()); + Balances::transfer( + RuntimeOrigin::signed(bank), + user_id, + (expected_charge * 2).max(Balances::minimum_balance()), + ) + .unwrap(); + total_charge += expected_charge; + + user_batch.push((user_id, user_usage)); + if user_batch.len() == user_batch_size { + payers.push(user_batch.clone()); + user_batch.clear(); + } + } + if !user_batch.is_empty() { + payers.push(user_batch.clone()); + } + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payers.len() - 1) as u16, + )); + + for batch in payers.iter() { + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_user_index, + batch.to_vec(), + )); + + for (customer_id, usage) in batch.iter() { + let charge = calculate_charge(cluster_id, usage.clone()); + + System::assert_has_event( + Event::Charged { + cluster_id, + era, + customer_id: *customer_id, + batch_index: batch_user_index, + amount: charge, + } + .into(), + ); + } + batch_user_index += 1; + } + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let balance1 = Balances::free_balance(report_before.vault); + let balance2 = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance1, balance2); + assert_eq!(report_before.vault, DdcPayouts::account_id()); + assert_eq!(balance1 - Balances::minimum_balance(), total_charge); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let total_left_from_one = (get_fees(&cluster_id).treasury_share + + get_fees(&cluster_id).validators_share + + get_fees(&cluster_id).cluster_reserve_share) + .left_from_one(); + + let total_charge = report_after.total_customer_charge.transfer + + report_before.total_customer_charge.storage + + report_before.total_customer_charge.puts + + report_before.total_customer_charge.gets; + let balance_after = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(total_charge, balance_after - Balances::minimum_balance()); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payees.len() - 1) as u16, + total_nodes_usage.clone(), + )); + + for batch in payees.iter() { + let before_batch = Balances::free_balance(DdcPayouts::account_id()); + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_node_index, + batch.to_vec(), + )); + + let mut batch_charge = 0; + for (node1, node_usage1) in batch.iter() { + let ratio1_transfer = Perquintill::from_rational( + node_usage1.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + let transfer_charge = ratio1_transfer * report_after.total_customer_charge.transfer; + + let ratio1_storage = Perquintill::from_rational( + node_usage1.stored_bytes, + total_nodes_usage.stored_bytes, + ); + let storage_charge = ratio1_storage * report_after.total_customer_charge.storage; + + let ratio1_puts = Perquintill::from_rational( + node_usage1.number_of_puts, + total_nodes_usage.number_of_puts, + ); + let puts_charge = ratio1_puts * report_after.total_customer_charge.puts; + + let ratio1_gets = Perquintill::from_rational( + node_usage1.number_of_gets, + total_nodes_usage.number_of_gets, + ); + let gets_charge = ratio1_gets * report_after.total_customer_charge.gets; + + let balance_node1 = Balances::free_balance(node1); + assert!( + (transfer_charge + storage_charge + puts_charge + gets_charge) - balance_node1 < + MAX_DUST.into() + ); + + batch_charge += transfer_charge + storage_charge + puts_charge + gets_charge; + } + let after_batch = Balances::free_balance(DdcPayouts::account_id()); + assert!(batch_charge + after_batch - before_batch < MAX_DUST.into()); + + batch_node_index += 1; + } + assert!(Balances::free_balance(DdcPayouts::account_id()) < MAX_DUST.into()); + }) +} + #[test] fn end_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index b6f8af964..1c8fba03d 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -7,6 +7,9 @@ use serde::{Deserialize, Serialize}; use sp_core::hash::H160; use sp_runtime::{AccountId32, Perquintill, RuntimeDebug}; +pub const MILLICENTS: u128 = 100_000; +pub const CENTS: u128 = 1_000 * MILLICENTS; // assume this is worth about a cent. +pub const DOLLARS: u128 = 100 * CENTS; pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 9b70d24a7..3eee2eb70 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -73,8 +73,8 @@ use sp_runtime::{ curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, AccountIdConversion, BlakeTwo256, Block as BlockT, ConvertInto, NumberFor, - OpaqueKeys, SaturatedConversion, StaticLookup, + self, AccountIdConversion, BlakeTwo256, Block as BlockT, ConvertInto, + Identity as IdentityConvert, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, @@ -1377,9 +1377,10 @@ impl pallet_ddc_payouts::Config for Runtime { type CustomerDepositor = DdcCustomers; type ClusterVisitor = DdcClusters; type TreasuryVisitor = TreasureWrapper; - type ValidatorList = pallet_staking::UseValidatorsMap; + type NominatorsAndValidatorsList = pallet_staking::UseNominatorsAndValidatorsMap; type ClusterCreator = DdcClusters; type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; + type VoteScoreToU64 = IdentityConvert; // used for UseNominatorsAndValidatorsMap } construct_runtime!( From bc71d5d0ab2b962082d428b35d84396cb17e1cbe Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Tue, 19 Dec 2023 22:15:47 +0100 Subject: [PATCH 539/544] Backporting #204 and #189 from `dev` branch to substrate `0.9.30` (#205) Backporting the following PRs from the dev branch: - [#204](https://github.com/Cerebellum-Network/blockchain-node/pull/204) - [#189](https://github.com/Cerebellum-Network/blockchain-node/pull/189) --------- Co-authored-by: Alisher A. Khassanov Co-authored-by: Raid5594 <52794079+Raid5594@users.noreply.github.com> --- Cargo.lock | 6 ++ node/service/chain-specs/example.json | 3 +- runtime/cere-dev/Cargo.toml | 26 +++++---- runtime/cere-dev/src/lib.rs | 8 +-- runtime/cere/Cargo.toml | 30 ++++++++-- runtime/cere/src/lib.rs | 81 ++++++++++++++++++++++++++- 6 files changed, 129 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6b76c111..34672105c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -976,6 +976,7 @@ version = "4.8.1" dependencies = [ "cere-runtime-common", "cere-runtime-constants", + "ddc-traits", "frame-benchmarking", "frame-election-provider-support", "frame-executive", @@ -1000,7 +1001,12 @@ dependencies = [ "pallet-contracts", "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", + "pallet-ddc-clusters", + "pallet-ddc-customers", "pallet-ddc-metrics-offchain-worker", + "pallet-ddc-nodes", + "pallet-ddc-payouts", + "pallet-ddc-staking", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", diff --git a/node/service/chain-specs/example.json b/node/service/chain-specs/example.json index e61b43fbc..6014d0a00 100644 --- a/node/service/chain-specs/example.json +++ b/node/service/chain-specs/example.json @@ -189,7 +189,8 @@ ], "http_port": 8080, "grpc_port": 8081, - "p2p_port": 8082 + "p2p_port": 8082, + "mode": "Storage" } } ], diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 87821e239..38c924efa 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -37,9 +37,6 @@ sp-transaction-pool = { default-features = false, git = "https://github.com/pari sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies -cere-dev-runtime-constants = { path = "./constants", default-features = false } -cere-runtime-common = { path = "../common", default-features = false } -ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -54,25 +51,16 @@ pallet-babe = { default-features = false, git = "https://github.com/paritytech/s pallet-bags-list = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-child-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-collective = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } -pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } -pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } -pallet-ddc-payouts = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-payouts" } -pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-multi-phase = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-support-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } -pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-fast-unstake = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -103,6 +91,20 @@ pallet-treasury = { default-features = false, git = "https://github.com/parityte pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +# cere dependencies +cere-dev-runtime-constants = { path = "./constants", default-features = false } +cere-runtime-common = { path = "../common", default-features = false } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } +pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-payouts = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-payouts" } +pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } +pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } +pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 3eee2eb70..3f866da77 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1330,7 +1330,7 @@ impl pallet_ddc_staking::Config for Runtime { parameter_types! { pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake - pub const UnlockingDelay: BlockNumber = 5256000u32; // 1 hour * 24 * 365 = 1 day; (1 hour is 600 blocks) + pub const UnlockingDelay: BlockNumber = 100800_u32; // 1 hour * 24 * 7 = 7 days; (1 hour is 600 blocks) } impl pallet_ddc_customers::Config for Runtime { @@ -1362,8 +1362,8 @@ parameter_types! { pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); } -pub struct TreasureWrapper; -impl PalletVisitor for TreasureWrapper { +pub struct TreasuryWrapper; +impl PalletVisitor for TreasuryWrapper { fn get_account_id() -> T::AccountId { TreasuryPalletId::get().into_account_truncating() } @@ -1376,7 +1376,7 @@ impl pallet_ddc_payouts::Config for Runtime { type CustomerCharger = DdcCustomers; type CustomerDepositor = DdcCustomers; type ClusterVisitor = DdcClusters; - type TreasuryVisitor = TreasureWrapper; + type TreasuryVisitor = TreasuryWrapper; type NominatorsAndValidatorsList = pallet_staking::UseNominatorsAndValidatorsMap; type ClusterCreator = DdcClusters; type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 2ce9a430f..9984b8d7e 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -37,8 +37,6 @@ sp-transaction-pool = { default-features = false, git = "https://github.com/pari sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } # frame dependencies -cere-runtime-common = { path = "../common", default-features = false } -cere-runtime-constants = { path = "./constants", default-features = false } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -53,20 +51,16 @@ pallet-babe = { default-features = false, git = "https://github.com/paritytech/s pallet-bags-list = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } pallet-chainbridge = { version = "4.8.1", default-features = false, path = "../../pallets/chainbridge" } pallet-child-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-collective = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-multi-phase = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-election-provider-support-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } -pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } pallet-fast-unstake = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.30" } pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -97,6 +91,20 @@ pallet-treasury = { default-features = false, git = "https://github.com/parityte pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +# cere dependencies +cere-runtime-common = { path = "../common", default-features = false } +cere-runtime-constants = { path = "./constants", default-features = false } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +pallet-cere-ddc = { version = "4.8.1", default-features = false, path = "../../pallets/ddc" } +pallet-ddc-clusters = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-clusters" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-nodes = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-payouts = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-payouts" } +pallet-ddc-staking = { version = "4.8.1", default-features = false, path = "../../pallets/ddc-staking" } +pallet-erc20 = { version = "4.8.1", default-features = false, path = "../../pallets/erc20" } +pallet-erc721 = { version = "4.8.1", default-features = false, path = "../../pallets/erc721" } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -172,6 +180,11 @@ std = [ "sp-io/std", "pallet-child-bounties/std", "pallet-ddc-metrics-offchain-worker/std", + "pallet-ddc-clusters/std", + "pallet-ddc-customers/std", + "pallet-ddc-nodes/std", + "pallet-ddc-payouts/std", + "pallet-ddc-staking/std", "cere-runtime-common/std", "cere-runtime-constants/std", ] @@ -187,6 +200,11 @@ runtime-benchmarks = [ "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", + "pallet-ddc-customers/runtime-benchmarks", + "pallet-ddc-clusters/runtime-benchmarks", + "pallet-ddc-nodes/runtime-benchmarks", + "pallet-ddc-staking/runtime-benchmarks", + "pallet-ddc-payouts/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-election-provider-support-benchmarking/runtime-benchmarks", diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index f7eef4df6..7d6398fdc 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -23,6 +23,7 @@ #![recursion_limit = "256"] use codec::{Decode, Encode, MaxEncodedLen}; +use ddc_traits::pallet::PalletVisitor; use frame_election_provider_support::{onchain, BalancingConfig, SequentialPhragmen, VoteWeight}; use frame_support::{ construct_runtime, @@ -67,8 +68,8 @@ use sp_runtime::{ curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, BlakeTwo256, Block as BlockT, ConvertInto, NumberFor, OpaqueKeys, - SaturatedConversion, StaticLookup, + self, AccountIdConversion, BlakeTwo256, Block as BlockT, ConvertInto, + Identity as IdentityConvert, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, @@ -1312,6 +1313,72 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { type RuntimeCall = RuntimeCall; } +parameter_types! { + pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake + pub const UnlockingDelay: BlockNumber = 100800_u32; // 1 hour * 24 * 7 = 7 days; (1 hour is 600 blocks) +} + +impl pallet_ddc_customers::Config for Runtime { + type UnlockingDelay = UnlockingDelay; + type Currency = Balances; + type PalletId = DdcCustomersPalletId; + type RuntimeEvent = RuntimeEvent; + type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; + type WeightInfo = pallet_ddc_customers::weights::SubstrateWeight; +} + +impl pallet_ddc_clusters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type NodeRepository = pallet_ddc_nodes::Pallet; + type StakingVisitor = pallet_ddc_staking::Pallet; + type StakerCreator = pallet_ddc_staking::Pallet; + type Currency = Balances; + type WeightInfo = pallet_ddc_clusters::weights::SubstrateWeight; +} + +impl pallet_ddc_nodes::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StakingVisitor = pallet_ddc_staking::Pallet; + type WeightInfo = pallet_ddc_nodes::weights::SubstrateWeight; +} + +parameter_types! { + pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); +} + +pub struct TreasuryWrapper; +impl PalletVisitor for TreasuryWrapper { + fn get_account_id() -> T::AccountId { + TreasuryPalletId::get().into_account_truncating() + } +} + +impl pallet_ddc_payouts::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type PalletId = PayoutsPalletId; + type Currency = Balances; + type CustomerCharger = DdcCustomers; + type CustomerDepositor = DdcCustomers; + type ClusterVisitor = DdcClusters; + type TreasuryVisitor = TreasuryWrapper; + type NominatorsAndValidatorsList = pallet_staking::UseNominatorsAndValidatorsMap; + type ClusterCreator = DdcClusters; + type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; + type VoteScoreToU64 = IdentityConvert; // used for UseNominatorsAndValidatorsMap +} + +impl pallet_ddc_staking::Config for Runtime { + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; + type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; + type ClusterManager = pallet_ddc_clusters::Pallet; + type NodeVisitor = pallet_ddc_nodes::Pallet; + type NodeCreator = pallet_ddc_nodes::Pallet; +} + construct_runtime!( pub enum Runtime where Block = Block, @@ -1363,6 +1430,11 @@ construct_runtime!( Erc721: pallet_erc721::{Pallet, Call, Storage, Event}, Erc20: pallet_erc20::{Pallet, Call, Storage, Event}, DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Storage, Event}, + DdcStaking: pallet_ddc_staking, + DdcCustomers: pallet_ddc_customers, + DdcNodes: pallet_ddc_nodes, + DdcClusters: pallet_ddc_clusters, + DdcPayouts: pallet_ddc_payouts } ); @@ -1439,6 +1511,11 @@ mod benches { [pallet_child_bounties, ChildBounties] [pallet_collective, Council] [pallet_contracts, Contracts] + [pallet_ddc_customers, DdcCustomers] + [pallet_ddc_clusters, DdcClusters] + [pallet_ddc_staking, DdcStaking] + [pallet_ddc_nodes, DdcNodes] + [pallet_ddc_payouts, DdcPayouts] [pallet_democracy, Democracy] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] [pallet_election_provider_support_benchmarking, EPSBench::] From aca442df08be7d84fdbd68051cb3c4713a46be47 Mon Sep 17 00:00:00 2001 From: Rakan Al-Huneiti Date: Thu, 21 Dec 2023 14:03:44 +0300 Subject: [PATCH 540/544] Testnet runtime upgrade - v4.8.2 - Substrate v0.9.30 (#209) - [x] Increment runtime version - [x] Increment spec version - [x] Generate pallet benchmarks (@yahortsaryk) - [ ] Generate WASM file - [ ] Test Runtime upgrade on a local testnet clone (@rakanalh) - [ ] Perform testnet runtime upgrade. --------- Co-authored-by: yahortsaryk --- pallets/ddc-clusters/src/weights.rs | 26 +++++----- pallets/ddc-customers/src/weights.rs | 36 ++++++------- pallets/ddc-nodes/src/weights.rs | 20 +++---- pallets/ddc-payouts/src/weights.rs | 78 +++++++++++++++------------- pallets/ddc-staking/src/weights.rs | 34 ++++++------ runtime/cere/src/lib.rs | 4 +- 6 files changed, 101 insertions(+), 97 deletions(-) diff --git a/pallets/ddc-clusters/src/weights.rs b/pallets/ddc-clusters/src/weights.rs index af2bb5559..92f58e898 100644 --- a/pallets/ddc-clusters/src/weights.rs +++ b/pallets/ddc-clusters/src/weights.rs @@ -1,9 +1,9 @@ //! Autogenerated weights for pallet_ddc_clusters //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bench`, CPU: `DO-Premium-AMD` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere @@ -40,7 +40,7 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcClusters Clusters (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn create_cluster() -> Weight { - Weight::from_ref_time(15_000_000_u64) + Weight::from_ref_time(243_795_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -59,7 +59,7 @@ impl WeightInfo for SubstrateWeight { // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) fn add_node() -> Weight { - Weight::from_ref_time(599_000_000_u64) + Weight::from_ref_time(37_168_211_000_u64) .saturating_add(T::DbWeight::get().reads(14_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -67,20 +67,20 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcClusters ClustersNodes (r:0 w:1) fn remove_node() -> Weight { - Weight::from_ref_time(24_000_000_u64) + Weight::from_ref_time(290_065_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:1) fn set_cluster_params() -> Weight { - Weight::from_ref_time(16_000_000_u64) + Weight::from_ref_time(161_977_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn set_cluster_gov_params() -> Weight { - Weight::from_ref_time(17_000_000_u64) + Weight::from_ref_time(164_837_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -91,7 +91,7 @@ impl WeightInfo for () { // Storage: DdcClusters Clusters (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn create_cluster() -> Weight { - Weight::from_ref_time(15_000_000_u64) + Weight::from_ref_time(243_795_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -110,7 +110,7 @@ impl WeightInfo for () { // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) fn add_node() -> Weight { - Weight::from_ref_time(599_000_000_u64) + Weight::from_ref_time(37_168_211_000_u64) .saturating_add(RocksDbWeight::get().reads(14_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -118,20 +118,20 @@ impl WeightInfo for () { // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcClusters ClustersNodes (r:0 w:1) fn remove_node() -> Weight { - Weight::from_ref_time(24_000_000_u64) + Weight::from_ref_time(290_065_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:1) fn set_cluster_params() -> Weight { - Weight::from_ref_time(16_000_000_u64) + Weight::from_ref_time(161_977_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn set_cluster_gov_params() -> Weight { - Weight::from_ref_time(17_000_000_u64) + Weight::from_ref_time(164_837_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/ddc-customers/src/weights.rs b/pallets/ddc-customers/src/weights.rs index 09351dbe1..0a3c999dc 100644 --- a/pallets/ddc-customers/src/weights.rs +++ b/pallets/ddc-customers/src/weights.rs @@ -1,9 +1,9 @@ //! Autogenerated weights for pallet_ddc_customers //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bench`, CPU: `DO-Premium-AMD` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere @@ -43,47 +43,47 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcCustomers Buckets (r:0 w:1) fn create_bucket() -> Weight { - Weight::from_ref_time(17_000_000_u64) + Weight::from_ref_time(156_518_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(439_562_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit_extra() -> Weight { - Weight::from_ref_time(29_000_000_u64) + Weight::from_ref_time(582_699_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) fn unlock_deposit() -> Weight { - Weight::from_ref_time(16_000_000_u64) + Weight::from_ref_time(208_316_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_update() -> Weight { - Weight::from_ref_time(30_000_000_u64) + Weight::from_ref_time(451_983_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_kill() -> Weight { - Weight::from_ref_time(32_000_000_u64) + Weight::from_ref_time(599_908_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Buckets (r:1 w:1) fn set_bucket_params() -> Weight { - Weight::from_ref_time(14_000_000_u64) + Weight::from_ref_time(155_437_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -95,48 +95,48 @@ impl WeightInfo for () { // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcCustomers Buckets (r:0 w:1) fn create_bucket() -> Weight { - Weight::from_ref_time(17_000_000_u64) + Weight::from_ref_time(156_518_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(439_562_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit_extra() -> Weight { - Weight::from_ref_time(29_000_000_u64) + Weight::from_ref_time(582_699_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) fn unlock_deposit() -> Weight { - Weight::from_ref_time(16_000_000_u64) + Weight::from_ref_time(208_316_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_update() -> Weight { - Weight::from_ref_time(30_000_000_u64) + Weight::from_ref_time(451_983_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_kill() -> Weight { - Weight::from_ref_time(32_000_000_u64) + Weight::from_ref_time(599_908_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Buckets (r:1 w:1) fn set_bucket_params() -> Weight { - Weight::from_ref_time(14_000_000_u64) + Weight::from_ref_time(155_437_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} +} \ No newline at end of file diff --git a/pallets/ddc-nodes/src/weights.rs b/pallets/ddc-nodes/src/weights.rs index bc05729ba..a14e02181 100644 --- a/pallets/ddc-nodes/src/weights.rs +++ b/pallets/ddc-nodes/src/weights.rs @@ -1,9 +1,9 @@ //! Autogenerated weights for pallet_ddc_nodes //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bench`, CPU: `DO-Premium-AMD` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere @@ -37,20 +37,20 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcNodes StorageNodes (r:1 w:1) fn create_node() -> Weight { - Weight::from_ref_time(12_000_000_u64) + Weight::from_ref_time(154_888_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(16_000_000_u64) + Weight::from_ref_time(191_006_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) fn set_node_params() -> Weight { - Weight::from_ref_time(15_000_000_u64) + Weight::from_ref_time(271_445_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -60,21 +60,21 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: DdcNodes StorageNodes (r:1 w:1) fn create_node() -> Weight { - Weight::from_ref_time(12_000_000_u64) + Weight::from_ref_time(154_888_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(16_000_000_u64) + Weight::from_ref_time(191_006_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) fn set_node_params() -> Weight { - Weight::from_ref_time(15_000_000_u64) + Weight::from_ref_time(271_445_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} +} \ No newline at end of file diff --git a/pallets/ddc-payouts/src/weights.rs b/pallets/ddc-payouts/src/weights.rs index 5f0578c31..a8ba246c7 100644 --- a/pallets/ddc-payouts/src/weights.rs +++ b/pallets/ddc-payouts/src/weights.rs @@ -1,9 +1,9 @@ //! Autogenerated weights for pallet_ddc_payouts //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bench`, CPU: `DO-Premium-AMD` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere @@ -43,20 +43,20 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) fn set_authorised_caller() -> Weight { - Weight::from_ref_time(11_000_000_u64) + Weight::from_ref_time(90_258_000_u64) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_billing_report() -> Weight { - Weight::from_ref_time(19_000_000_u64) + Weight::from_ref_time(214_646_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_charging_customers() -> Weight { - Weight::from_ref_time(19_000_000_u64) + Weight::from_ref_time(228_676_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -68,9 +68,9 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts DebtorCustomers (r:1 w:1) /// The range of component `b` is `[1, 1000]`. fn send_charging_customers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(12_333_820_u64) - // Standard Error: 298_759 - .saturating_add(Weight::from_ref_time(24_367_120_u64).saturating_mul(b as u64)) + Weight::from_ref_time(891_324_000_u64) + // Standard Error: 3_864_375 + .saturating_add(Weight::from_ref_time(558_679_506_u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -81,17 +81,19 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: System Account (r:3 w:3) // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: Staking CounterForValidators (r:1 w:0) // Storage: Staking Validators (r:2 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking Nominators (r:1 w:0) fn end_charging_customers() -> Weight { - Weight::from_ref_time(89_000_000_u64) - .saturating_add(T::DbWeight::get().reads(10_u64)) + Weight::from_ref_time(1_691_550_000_u64) + .saturating_add(T::DbWeight::get().reads(12_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_rewarding_providers() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(234_686_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -100,25 +102,25 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:2 w:2) /// The range of component `b` is `[1, 1000]`. fn send_rewarding_providers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(32_000_000_u64) - // Standard Error: 5_087 - .saturating_add(Weight::from_ref_time(14_402_776_u64).saturating_mul(b as u64)) - .saturating_add(T::DbWeight::get().reads(3_u64)) + Weight::from_ref_time(565_710_000_u64) + // Standard Error: 854_032 + .saturating_add(Weight::from_ref_time(408_429_599_u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b as u64))) - .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(b as u64))) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_rewarding_providers() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(274_535_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_billing_report() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(232_626_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -128,20 +130,20 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) fn set_authorised_caller() -> Weight { - Weight::from_ref_time(11_000_000_u64) + Weight::from_ref_time(90_258_000_u64) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_billing_report() -> Weight { - Weight::from_ref_time(19_000_000_u64) + Weight::from_ref_time(214_646_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_charging_customers() -> Weight { - Weight::from_ref_time(19_000_000_u64) + Weight::from_ref_time(228_676_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -153,9 +155,9 @@ impl WeightInfo for () { // Storage: DdcPayouts DebtorCustomers (r:1 w:1) /// The range of component `b` is `[1, 1000]`. fn send_charging_customers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(12_333_820_u64) - // Standard Error: 298_759 - .saturating_add(Weight::from_ref_time(24_367_120_u64).saturating_mul(b as u64)) + Weight::from_ref_time(891_324_000_u64) + // Standard Error: 3_864_375 + .saturating_add(Weight::from_ref_time(558_679_506_u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(b as u64))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -166,17 +168,19 @@ impl WeightInfo for () { // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: System Account (r:3 w:3) // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: Staking CounterForValidators (r:1 w:0) // Storage: Staking Validators (r:2 w:0) + // Storage: Staking Bonded (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking Nominators (r:1 w:0) fn end_charging_customers() -> Weight { - Weight::from_ref_time(89_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(10_u64)) + Weight::from_ref_time(1_691_550_000_u64) + .saturating_add(RocksDbWeight::get().reads(12_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_rewarding_providers() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(234_686_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -185,25 +189,25 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:2) /// The range of component `b` is `[1, 1000]`. fn send_rewarding_providers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(32_000_000_u64) - // Standard Error: 5_087 - .saturating_add(Weight::from_ref_time(14_402_776_u64).saturating_mul(b as u64)) - .saturating_add(RocksDbWeight::get().reads(3_u64)) + Weight::from_ref_time(565_710_000_u64) + // Standard Error: 854_032 + .saturating_add(Weight::from_ref_time(408_429_599_u64).saturating_mul(b as u64)) + .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(b as u64))) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(b as u64))) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_rewarding_providers() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(274_535_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_billing_report() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(232_626_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index e7157a60d..f31efef30 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -1,9 +1,9 @@ //! Autogenerated weights for pallet_ddc_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-20, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bench`, CPU: `DO-Premium-AMD` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere @@ -46,7 +46,7 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(39_000_000_u64) + Weight::from_ref_time(472_772_000_u64) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -57,7 +57,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(37_000_000_u64) + Weight::from_ref_time(425_643_000_u64) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -67,7 +67,7 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:1 w:1) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(33_000_000_u64) + Weight::from_ref_time(355_174_000_u64) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -78,7 +78,7 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(256_886_000_u64) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -86,14 +86,14 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(337_644_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(14_000_000_u64) + Weight::from_ref_time(162_697_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -102,7 +102,7 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - Weight::from_ref_time(14_000_000_u64) + Weight::from_ref_time(151_137_000_u64) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -117,7 +117,7 @@ impl WeightInfo for () { // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(39_000_000_u64) + Weight::from_ref_time(472_772_000_u64) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -128,7 +128,7 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(37_000_000_u64) + Weight::from_ref_time(425_643_000_u64) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -138,7 +138,7 @@ impl WeightInfo for () { // Storage: System Account (r:1 w:1) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(33_000_000_u64) + Weight::from_ref_time(355_174_000_u64) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -149,7 +149,7 @@ impl WeightInfo for () { // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(256_886_000_u64) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -157,14 +157,14 @@ impl WeightInfo for () { // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(337_644_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(14_000_000_u64) + Weight::from_ref_time(162_697_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -173,7 +173,7 @@ impl WeightInfo for () { // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - Weight::from_ref_time(14_000_000_u64) + Weight::from_ref_time(151_137_000_u64) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 7d6398fdc..0f08f7af1 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -126,10 +126,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48009, + spec_version: 48201, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 5, + transaction_version: 6, state_version: 0, }; From 1b626e6630a90c969895c92f355e26b9eb9a52b1 Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Fri, 22 Dec 2023 10:46:03 +0100 Subject: [PATCH 541/544] Backporting #207 and #211 from `dev` branch to substrate `0.9.30` (#212) Backporting the following PRs from the dev branch: - [#207](https://github.com/Cerebellum-Network/blockchain-node/pull/207) - [#211](https://github.com/Cerebellum-Network/blockchain-node/pull/211) --------- Co-authored-by: Alisher A. Khassanov --- node/service/chain-specs/example.json | 14 ++- pallets/ddc-clusters/src/testing_utils.rs | 4 +- pallets/ddc-clusters/src/tests.rs | 110 +++++++++++++++++++++- pallets/ddc-nodes/src/benchmarking.rs | 4 +- pallets/ddc-nodes/src/lib.rs | 1 + pallets/ddc-nodes/src/node.rs | 2 + pallets/ddc-nodes/src/storage_node.rs | 15 ++- pallets/ddc-nodes/src/testing_utils.rs | 8 +- pallets/ddc-nodes/src/tests.rs | 102 +++++++++++++++++++- pallets/ddc-nodes/src/weights.rs | 14 +-- pallets/ddc-payouts/src/lib.rs | 13 ++- pallets/ddc-payouts/src/mock.rs | 8 +- pallets/ddc-staking/src/benchmarking.rs | 4 +- pallets/ddc-staking/src/testing_utils.rs | 8 +- primitives/src/lib.rs | 2 + 15 files changed, 281 insertions(+), 28 deletions(-) diff --git a/node/service/chain-specs/example.json b/node/service/chain-specs/example.json index 6014d0a00..5ad984508 100644 --- a/node/service/chain-specs/example.json +++ b/node/service/chain-specs/example.json @@ -187,13 +187,15 @@ 46, 49 ], + "domain": [], + "ssl": false, "http_port": 8080, "grpc_port": 8081, "p2p_port": 8082, "mode": "Storage" } } - ], + ] }, "ddcClusters": { "clusters": [ @@ -233,6 +235,16 @@ ] ] ] + }, + "ddcPayouts": { + "authorisedCaller": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "debtorCustomers": [ + [ + "0x0000000000000000000000000000000000000001", + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 10000000000 + ] + ] } } } diff --git a/pallets/ddc-clusters/src/testing_utils.rs b/pallets/ddc-clusters/src/testing_utils.rs index 999a066ba..5acb0dc42 100644 --- a/pallets/ddc-clusters/src/testing_utils.rs +++ b/pallets/ddc-clusters/src/testing_utils.rs @@ -55,7 +55,9 @@ where let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; let storage_node_params = StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index 948b28d1c..b79ede63f 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -57,6 +57,51 @@ fn create_cluster_works() { cluster_gov_params.clone() )); + let created_cluster = DdcClusters::clusters(cluster_id).unwrap(); + assert_eq!(created_cluster.cluster_id, cluster_id); + assert_eq!(created_cluster.manager_id, cluster_manager_id); + assert_eq!(created_cluster.reserve_id, cluster_reserve_id); + assert_eq!(created_cluster.props.node_provider_auth_contract, Some(auth_contract.clone())); + + let created_cluster_gov_params = DdcClusters::clusters_gov_params(cluster_id).unwrap(); + assert_eq!(created_cluster_gov_params.treasury_share, cluster_gov_params.treasury_share); + assert_eq!( + created_cluster_gov_params.validators_share, + cluster_gov_params.validators_share + ); + assert_eq!( + created_cluster_gov_params.cluster_reserve_share, + cluster_gov_params.cluster_reserve_share + ); + assert_eq!( + created_cluster_gov_params.storage_bond_size, + cluster_gov_params.storage_bond_size + ); + assert_eq!( + created_cluster_gov_params.storage_chill_delay, + cluster_gov_params.storage_chill_delay + ); + assert_eq!( + created_cluster_gov_params.storage_unbonding_delay, + cluster_gov_params.storage_unbonding_delay + ); + assert_eq!( + created_cluster_gov_params.unit_per_mb_stored, + cluster_gov_params.unit_per_mb_stored + ); + assert_eq!( + created_cluster_gov_params.unit_per_mb_streamed, + cluster_gov_params.unit_per_mb_streamed + ); + assert_eq!( + created_cluster_gov_params.unit_per_put_request, + cluster_gov_params.unit_per_put_request + ); + assert_eq!( + created_cluster_gov_params.unit_per_get_request, + cluster_gov_params.unit_per_get_request + ); + // Creating cluster with same id should fail assert_noop!( DdcClusters::create_cluster( @@ -143,7 +188,9 @@ fn add_and_delete_node_works() { let storage_node_params = StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -351,9 +398,12 @@ fn set_cluster_params_works() { assert_ok!(DdcClusters::set_cluster_params( RuntimeOrigin::signed(cluster_manager_id), cluster_id, - ClusterParams { node_provider_auth_contract: Some(auth_contract_2) }, + ClusterParams { node_provider_auth_contract: Some(auth_contract_2.clone()) }, )); + let updated_cluster = DdcClusters::clusters(cluster_id).unwrap(); + assert_eq!(updated_cluster.props.node_provider_auth_contract, Some(auth_contract_2)); + // Checking that event was emitted assert_eq!(System::events().len(), 2); System::assert_last_event(Event::ClusterParamsSet { cluster_id }.into()) @@ -406,17 +456,69 @@ fn set_cluster_gov_params_works() { DdcClusters::set_cluster_gov_params( RuntimeOrigin::signed(cluster_manager_id), cluster_id, - cluster_gov_params.clone() + cluster_gov_params ), BadOrigin ); + let updated_gov_params: ClusterGovParams = ClusterGovParams { + treasury_share: Perquintill::from_float(0.06), + validators_share: Perquintill::from_float(0.02), + cluster_reserve_share: Perquintill::from_float(0.03), + storage_bond_size: 1000, + storage_chill_delay: 500, + storage_unbonding_delay: 500, + unit_per_mb_stored: 100, + unit_per_mb_streamed: 100, + unit_per_put_request: 100, + unit_per_get_request: 100, + }; + assert_ok!(DdcClusters::set_cluster_gov_params( RuntimeOrigin::root(), cluster_id, - cluster_gov_params + updated_gov_params.clone() )); + let updated_cluster_gov_params = DdcClusters::clusters_gov_params(cluster_id).unwrap(); + assert_eq!(updated_cluster_gov_params.treasury_share, updated_gov_params.treasury_share); + assert_eq!( + updated_cluster_gov_params.validators_share, + updated_gov_params.validators_share + ); + assert_eq!( + updated_cluster_gov_params.cluster_reserve_share, + updated_gov_params.cluster_reserve_share + ); + assert_eq!( + updated_cluster_gov_params.storage_bond_size, + updated_gov_params.storage_bond_size + ); + assert_eq!( + updated_cluster_gov_params.storage_chill_delay, + updated_gov_params.storage_chill_delay + ); + assert_eq!( + updated_cluster_gov_params.storage_unbonding_delay, + updated_gov_params.storage_unbonding_delay + ); + assert_eq!( + updated_cluster_gov_params.unit_per_mb_stored, + updated_gov_params.unit_per_mb_stored + ); + assert_eq!( + updated_cluster_gov_params.unit_per_mb_streamed, + updated_gov_params.unit_per_mb_streamed + ); + assert_eq!( + updated_cluster_gov_params.unit_per_put_request, + updated_gov_params.unit_per_put_request + ); + assert_eq!( + updated_cluster_gov_params.unit_per_get_request, + updated_gov_params.unit_per_get_request + ); + // Checking that event was emitted assert_eq!(System::events().len(), 2); System::assert_last_event(Event::ClusterGovParamsSet { cluster_id }.into()) diff --git a/pallets/ddc-nodes/src/benchmarking.rs b/pallets/ddc-nodes/src/benchmarking.rs index 451ef0c2a..b13012d4c 100644 --- a/pallets/ddc-nodes/src/benchmarking.rs +++ b/pallets/ddc-nodes/src/benchmarking.rs @@ -46,7 +46,9 @@ benchmarks! { StorageNodePubKey::new([0; 32])).unwrap().props, StorageNodeProps { mode: StorageNodeMode::Storage, - host: vec![2u8, 255].try_into().unwrap(), + host: vec![3u8; 255].try_into().unwrap(), + domain: vec![4u8; 255].try_into().unwrap(), + ssl: true, http_port: 45000u16, grpc_port: 55000u16, p2p_port: 65000u16, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index acf6b430b..e849d158b 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -77,6 +77,7 @@ pub mod pallet { OnlyNodeProvider, NodeIsAssignedToCluster, HostLenExceedsLimit, + DomainLenExceedsLimit, NodeHasDanglingStake, } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 2688400f4..e277431d8 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -91,12 +91,14 @@ impl NodeTrait for Node { #[derive(Debug, PartialEq)] pub enum NodeError { StorageHostLenExceedsLimit, + StorageDomainLenExceedsLimit, } impl From for Error { fn from(error: NodeError) -> Self { match error { NodeError::StorageHostLenExceedsLimit => Error::::HostLenExceedsLimit, + NodeError::StorageDomainLenExceedsLimit => Error::::DomainLenExceedsLimit, } } } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 3021409aa..c2034d74c 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -10,8 +10,8 @@ use serde::{Deserialize, Serialize}; use sp_runtime::RuntimeDebug; parameter_types! { - pub MaxStorageNodeParamsLen: u16 = 2048; pub MaxHostLen: u8 = 255; + pub MaxDomainLen: u8 = 255; } #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -28,6 +28,8 @@ pub struct StorageNode { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct StorageNodeProps { pub host: BoundedVec, + pub domain: BoundedVec, + pub ssl: bool, pub http_port: u16, pub grpc_port: u16, pub p2p_port: u16, @@ -52,6 +54,11 @@ impl StorageNode { Ok(vec) => vec, Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), }, + domain: match node_params.domain.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageDomainLenExceedsLimit), + }, + ssl: node_params.ssl, http_port: node_params.http_port, grpc_port: node_params.grpc_port, p2p_port: node_params.p2p_port, @@ -81,10 +88,16 @@ impl NodeTrait for StorageNode { fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { match node_params { NodeParams::StorageParams(storage_params) => { + self.props.mode = storage_params.mode; self.props.host = match storage_params.host.try_into() { Ok(vec) => vec, Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), }; + self.props.domain = match storage_params.domain.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageDomainLenExceedsLimit), + }; + self.props.ssl = storage_params.ssl; self.props.http_port = storage_params.http_port; self.props.grpc_port = storage_params.grpc_port; self.props.p2p_port = storage_params.p2p_port; diff --git a/pallets/ddc-nodes/src/testing_utils.rs b/pallets/ddc-nodes/src/testing_utils.rs index dd408c320..8ebe3f7bc 100644 --- a/pallets/ddc-nodes/src/testing_utils.rs +++ b/pallets/ddc-nodes/src/testing_utils.rs @@ -16,7 +16,9 @@ pub fn create_user_and_config( let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); let storage_node_params = NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: false, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -24,7 +26,9 @@ pub fn create_user_and_config( let new_storage_node_params = NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![2u8, 255], + host: vec![3u8; 255], + domain: vec![4u8; 255], + ssl: true, http_port: 45000u16, grpc_port: 55000u16, p2p_port: 65000u16, diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index aadc801c0..1f1657ad9 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -4,6 +4,7 @@ use super::{mock::*, *}; use ddc_primitives::{NodePubKey, StorageNodeMode, StorageNodeParams}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::AccountId32; +use storage_node::{MaxDomainLen, MaxHostLen}; #[test] fn create_storage_node_works() { @@ -13,7 +14,9 @@ fn create_storage_node_works() { let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -27,6 +30,8 @@ fn create_storage_node_works() { NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, host: vec![1u8; 256], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -35,6 +40,24 @@ fn create_storage_node_works() { Error::::HostLenExceedsLimit ); + // Host length exceeds limit + assert_noop!( + DdcNodes::create_node( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, + host: vec![1u8; 255], + domain: vec![2u8; 256], + ssl: true, + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::DomainLenExceedsLimit + ); + // Node created assert_ok!(DdcNodes::create_node( RuntimeOrigin::signed(1), @@ -42,6 +65,23 @@ fn create_storage_node_works() { NodeParams::StorageParams(storage_node_params.clone()) )); + let created_storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let expected_host: BoundedVec = + storage_node_params.clone().host.try_into().unwrap(); + let expected_domain: BoundedVec = + storage_node_params.clone().domain.try_into().unwrap(); + + assert_eq!(created_storage_node.pub_key, node_pub_key); + assert_eq!(created_storage_node.provider_id, 1); + assert_eq!(created_storage_node.cluster_id, None); + assert_eq!(created_storage_node.props.host, expected_host); + assert_eq!(created_storage_node.props.domain, expected_domain); + assert_eq!(created_storage_node.props.ssl, storage_node_params.ssl); + assert_eq!(created_storage_node.props.http_port, storage_node_params.http_port); + assert_eq!(created_storage_node.props.grpc_port, storage_node_params.grpc_port); + assert_eq!(created_storage_node.props.p2p_port, storage_node_params.p2p_port); + assert_eq!(created_storage_node.props.mode, storage_node_params.mode); + // Check storage assert!(StorageNodes::::contains_key(node_pub_key.clone())); assert!(DdcNodes::exists(&NodePubKey::StoragePubKey(node_pub_key.clone()))); @@ -79,7 +119,9 @@ fn create_storage_node_with_node_creator() { let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -113,7 +155,9 @@ fn set_storage_node_params_works() { let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -136,13 +180,39 @@ fn set_storage_node_params_works() { NodeParams::StorageParams(storage_node_params.clone()) )); + let updated_params = StorageNodeParams { + mode: StorageNodeMode::Full, + host: vec![3u8; 255], + domain: vec![4u8; 255], + ssl: false, + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }; + // Set node params assert_ok!(DdcNodes::set_node_params( RuntimeOrigin::signed(1), NodePubKey::StoragePubKey(node_pub_key.clone()), - NodeParams::StorageParams(storage_node_params.clone()) + NodeParams::StorageParams(updated_params.clone()) )); + let updated_storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let expected_host: BoundedVec = updated_params.host.try_into().unwrap(); + let expected_domain: BoundedVec = + updated_params.domain.try_into().unwrap(); + + assert_eq!(updated_storage_node.pub_key, node_pub_key); + assert_eq!(updated_storage_node.provider_id, 1); + assert_eq!(updated_storage_node.cluster_id, None); + assert_eq!(updated_storage_node.props.host, expected_host); + assert_eq!(updated_storage_node.props.domain, expected_domain); + assert_eq!(updated_storage_node.props.ssl, updated_params.ssl); + assert_eq!(updated_storage_node.props.http_port, updated_params.http_port); + assert_eq!(updated_storage_node.props.grpc_port, updated_params.grpc_port); + assert_eq!(updated_storage_node.props.p2p_port, updated_params.p2p_port); + assert_eq!(updated_storage_node.props.mode, updated_params.mode); + // Only node provider can set params assert_noop!( DdcNodes::set_node_params( @@ -176,6 +246,8 @@ fn set_storage_node_params_works() { NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, host: vec![1u8; 256], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -184,6 +256,24 @@ fn set_storage_node_params_works() { Error::::HostLenExceedsLimit ); + // Storage domain length exceeds limit + assert_noop!( + DdcNodes::set_node_params( + RuntimeOrigin::signed(1), + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(StorageNodeParams { + mode: StorageNodeMode::Storage, + host: vec![1u8; 255], + domain: vec![2u8; 256], + ssl: true, + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + ), + Error::::DomainLenExceedsLimit + ); + // Checking that event was emitted assert_eq!(System::events().len(), 2); System::assert_last_event( @@ -201,7 +291,9 @@ fn delete_storage_node_works() { let node_pub_key = AccountId32::from(bytes); let storage_node_params = StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 255], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, diff --git a/pallets/ddc-nodes/src/weights.rs b/pallets/ddc-nodes/src/weights.rs index a14e02181..784708100 100644 --- a/pallets/ddc-nodes/src/weights.rs +++ b/pallets/ddc-nodes/src/weights.rs @@ -1,7 +1,7 @@ //! Autogenerated weights for pallet_ddc_nodes //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-20, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `bench`, CPU: `DO-Premium-AMD` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 @@ -37,20 +37,20 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcNodes StorageNodes (r:1 w:1) fn create_node() -> Weight { - Weight::from_ref_time(154_888_000_u64) + Weight::from_ref_time(179_667_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(191_006_000_u64) + Weight::from_ref_time(180_906_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) fn set_node_params() -> Weight { - Weight::from_ref_time(271_445_000_u64) + Weight::from_ref_time(228_136_000_u64) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -60,20 +60,20 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: DdcNodes StorageNodes (r:1 w:1) fn create_node() -> Weight { - Weight::from_ref_time(154_888_000_u64) + Weight::from_ref_time(179_667_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(191_006_000_u64) + Weight::from_ref_time(180_906_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcNodes StorageNodes (r:1 w:1) fn set_node_params() -> Weight { - Weight::from_ref_time(271_445_000_u64) + Weight::from_ref_time(228_136_000_u64) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 9851394ea..7c329162f 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -983,12 +983,18 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { pub feeder_account: Option, + pub authorised_caller: Option, + pub debtor_customers: Vec<(ClusterId, T::AccountId, u128)>, } #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { feeder_account: None } + GenesisConfig { + feeder_account: None, + authorised_caller: Default::default(), + debtor_customers: Default::default(), + } } } @@ -1010,6 +1016,11 @@ pub mod pallet { let _ = ::Currency::make_free_balance_be(&account_id, min); } } + + AuthorisedCaller::::set(self.authorised_caller.clone()); + for (cluster_id, customer_id, debt) in &self.debtor_customers { + DebtorCustomers::::insert(cluster_id, customer_id, debt); + } } } diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 27807fc03..e81e40e08 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -398,8 +398,12 @@ impl ExtBuilder { } .assimilate_storage(&mut storage); - let _payout_genesis = pallet_ddc_payouts::GenesisConfig:: { feeder_account: None } - .assimilate_storage(&mut storage); + let _payout_genesis = pallet_ddc_payouts::GenesisConfig:: { + feeder_account: None, + debtor_customers: Default::default(), + authorised_caller: None, + } + .assimilate_storage(&mut storage); TestExternalities::new(storage) } diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index c1eeff149..4b1138753 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -28,7 +28,9 @@ benchmarks! { stash.clone(), NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 256], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 54454b95d..5b2ffd33b 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -63,7 +63,9 @@ pub fn create_stash_controller_node( stash.clone(), NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 256], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, @@ -98,7 +100,9 @@ pub fn create_stash_controller_node_with_balance( stash.clone(), NodeParams::StorageParams(StorageNodeParams { mode: StorageNodeMode::Storage, - host: vec![1u8, 255], + host: vec![1u8; 255], + domain: vec![2u8; 256], + ssl: true, http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 1c8fba03d..06a5dcfde 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -104,6 +104,8 @@ pub enum StorageNodeMode { pub struct StorageNodeParams { pub mode: StorageNodeMode, pub host: Vec, + pub domain: Vec, + pub ssl: bool, pub http_port: u16, pub grpc_port: u16, pub p2p_port: u16, From ff776f0be638acf746ac8cc07f05fd08aa0195d2 Mon Sep 17 00:00:00 2001 From: aie0 <149175774+aie0@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:05:32 +0200 Subject: [PATCH 542/544] Payouts random tests (#213) --- pallets/ddc-payouts/src/benchmarking.rs | 4 +- pallets/ddc-payouts/src/lib.rs | 14 +- pallets/ddc-payouts/src/mock.rs | 34 +++- pallets/ddc-payouts/src/tests.rs | 238 +++++++++++++++++++++++- 4 files changed, 271 insertions(+), 19 deletions(-) diff --git a/pallets/ddc-payouts/src/benchmarking.rs b/pallets/ddc-payouts/src/benchmarking.rs index 80c6528cb..3967a85cd 100644 --- a/pallets/ddc-payouts/src/benchmarking.rs +++ b/pallets/ddc-payouts/src/benchmarking.rs @@ -350,8 +350,8 @@ benchmarks! { let total_node_usage = NodeUsage { transferred_bytes: 200000000u64.saturating_mul(b.into()), // 200 mb per provider stored_bytes: 100000000u64.saturating_mul(b.into()), // 100 mb per provider - number_of_gets: 10u128.saturating_mul(b.into()), // 10 gets per provider - number_of_puts: 5u128.saturating_mul(b.into()), // 5 puts per provider + number_of_gets: 10u64.saturating_mul(b.into()), // 10 gets per provider + number_of_puts: 10u64.saturating_mul(b.into()), // 5 puts per provider }; let charging_max_batch_index = 0; let mut charging_processed_batches : BoundedBTreeSet = BoundedBTreeSet::default(); diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 7c329162f..a883a27f3 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -53,8 +53,8 @@ type BatchIndex = u16; pub struct CustomerUsage { pub transferred_bytes: u64, pub stored_bytes: u64, - pub number_of_puts: u128, - pub number_of_gets: u128, + pub number_of_puts: u64, + pub number_of_gets: u64, } /// Stores usage of node provider @@ -62,8 +62,8 @@ pub struct CustomerUsage { pub struct NodeUsage { pub transferred_bytes: u64, pub stored_bytes: u64, - pub number_of_puts: u128, - pub number_of_gets: u128, + pub number_of_puts: u64, + pub number_of_gets: u64, } /// Stores reward in tokens(units) of node provider as per NodeUsage @@ -951,13 +951,11 @@ pub mod pallet { })() .ok_or(Error::::ArithmeticOverflow)?; - total.gets = usage - .number_of_gets + total.gets = (usage.number_of_gets as u128) .checked_mul(pricing.unit_per_get_request) .ok_or(Error::::ArithmeticOverflow)?; - total.puts = usage - .number_of_puts + total.puts = (usage.number_of_puts as u128) .checked_mul(pricing.unit_per_put_request) .ok_or(Error::::ArithmeticOverflow)?; diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index e81e40e08..8230c6508 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -5,7 +5,7 @@ use crate::{self as pallet_ddc_payouts, *}; use ddc_primitives::{ ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams, - NodeType, + NodeType, DOLLARS, }; use ddc_traits::{ cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError}, @@ -16,7 +16,7 @@ use frame_election_provider_support::SortedListProvider; use frame_support::{ construct_runtime, parameter_types, - traits::{ConstU32, ConstU64, Everything}, + traits::{ConstU32, ConstU64, Everything, Randomness}, weights::constants::RocksDbWeight, PalletId, }; @@ -59,6 +59,21 @@ parameter_types! { pub static ExistentialDeposit: Balance = 1; } +#[derive(Default, Clone)] +pub struct MockRandomness(H256); + +impl Randomness for MockRandomness { + fn random(subject: &[u8]) -> (H256, BlockNumber) { + let (mut r, b) = Self::random_seed(); + r.as_mut()[0..subject.len()].copy_from_slice(subject); + (r, b) + } + + fn random_seed() -> (H256, BlockNumber) { + (H256::default(), BlockNumber::default()) + } +} + impl frame_system::Config for Test { type BaseCallFilter = Everything; type BlockWeights = (); @@ -204,6 +219,7 @@ pub const USER3_BALANCE: u128 = 1000; pub const FREE_CLUSTER_ID: ClusterId = ClusterId::zero(); pub const ONE_CLUSTER_ID: ClusterId = ClusterId::repeat_byte(5u8); +pub const CERE_CLUSTER_ID: ClusterId = ClusterId::repeat_byte(10u8); pub const PRICING_PARAMS: ClusterPricingParams = ClusterPricingParams { unit_per_mb_streamed: 2_000_000, @@ -219,6 +235,13 @@ pub const PRICING_PARAMS_ONE: ClusterPricingParams = ClusterPricingParams { unit_per_get_request: 10_000_000_000, }; +pub const PRICING_PARAMS_CERE: ClusterPricingParams = ClusterPricingParams { + unit_per_mb_streamed: DOLLARS, + unit_per_mb_stored: DOLLARS, + unit_per_put_request: DOLLARS, + unit_per_get_request: DOLLARS, +}; + pub const PRICING_FEES: ClusterFeesParams = ClusterFeesParams { treasury_share: Perquintill::from_percent(1), validators_share: Perquintill::from_percent(10), @@ -315,7 +338,10 @@ impl SortedListProvider for TestValidator } pub fn get_fees(cluster_id: &ClusterId) -> ClusterFeesParams { - if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { + if *cluster_id == FREE_CLUSTER_ID || + *cluster_id == ONE_CLUSTER_ID || + *cluster_id == CERE_CLUSTER_ID + { PRICING_FEES_ZERO } else { PRICING_FEES @@ -325,6 +351,8 @@ pub fn get_fees(cluster_id: &ClusterId) -> ClusterFeesParams { pub fn get_pricing(cluster_id: &ClusterId) -> ClusterPricingParams { if *cluster_id == FREE_CLUSTER_ID || *cluster_id == ONE_CLUSTER_ID { PRICING_PARAMS_ONE + } else if *cluster_id == CERE_CLUSTER_ID { + PRICING_PARAMS_CERE } else { PRICING_PARAMS } diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 3aa413af1..d5f70e8ea 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -2,8 +2,10 @@ use super::{mock::*, *}; use ddc_primitives::ClusterId; -use frame_support::{assert_noop, assert_ok, error::BadOrigin}; +use frame_support::{assert_noop, assert_ok, error::BadOrigin, traits::Randomness}; +use sp_core::H256; use sp_runtime::Perquintill; + #[test] fn set_authorised_caller_works() { ExtBuilder.build_and_execute(|| { @@ -265,8 +267,8 @@ fn calculate_charge_parts(cluster_id: ClusterId, usage: CustomerUsage) -> Custom byte_unit::MEBIBYTE, storage: (pricing_params.unit_per_mb_stored * usage.stored_bytes as u128) / byte_unit::MEBIBYTE, - puts: pricing_params.unit_per_put_request * usage.number_of_puts, - gets: pricing_params.unit_per_get_request * usage.number_of_gets, + puts: pricing_params.unit_per_put_request * (usage.number_of_puts as u128), + gets: pricing_params.unit_per_get_request * (usage.number_of_gets as u128), } } @@ -1461,7 +1463,7 @@ fn send_rewarding_providers_batch_works() { } #[test] -fn send_rewarding_providers_batch_100nodes_small_usage_works() { +fn send_rewarding_providers_batch_100_nodes_small_usage_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); @@ -1713,7 +1715,7 @@ fn send_rewarding_providers_batch_100nodes_small_usage_works() { } #[test] -fn send_rewarding_providers_batch_100nodes_large_usage_works() { +fn send_rewarding_providers_batch_100_nodes_large_usage_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); @@ -1978,7 +1980,7 @@ fn send_rewarding_providers_batch_100nodes_large_usage_works() { } #[test] -fn send_rewarding_providers_batch_100nodes_small_large_usage_works() { +fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); @@ -2242,6 +2244,230 @@ fn send_rewarding_providers_batch_100nodes_small_large_usage_works() { }) } +fn generate_random_u64>(_: &T, min: u64, max: u64) -> u64 { + let (random_seed, _) = T::random_seed(); + let random_raw = u64::from_be_bytes(random_seed.as_bytes()[0..8].try_into().unwrap()); + + min.saturating_add(random_raw % (max.saturating_sub(min).saturating_add(1))) +} + +#[test] +fn send_rewarding_providers_batch_100_nodes_random_usage_works() { + ExtBuilder.build_and_execute(|| { + System::set_block_number(1); + + let mock_randomness = MockRandomness::default(); + let min: u64 = 1024; + let max: u64 = 1024 * 1024; + let num_nodes = 100; + let num_users = 100; + let dac_account = 123u128; + let bank = 1u128; + let cluster_id = CERE_CLUSTER_ID; + let era = 100; + let user_batch_size = 10; + let node_batch_size = 10; + let mut batch_user_index = 0; + let mut batch_node_index = 0; + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut total_nodes_usage = NodeUsage::default(); + for i in 10..10 + num_nodes { + let node_usage = NodeUsage { + transferred_bytes: generate_random_u64(&mock_randomness, min, max), + stored_bytes: generate_random_u64(&mock_randomness, min, max), + number_of_puts: generate_random_u64(&mock_randomness, min, max), + number_of_gets: generate_random_u64(&mock_randomness, min, max), + }; + + total_nodes_usage.transferred_bytes += node_usage.transferred_bytes; + total_nodes_usage.stored_bytes += node_usage.stored_bytes; + total_nodes_usage.number_of_puts += node_usage.number_of_puts; + total_nodes_usage.number_of_gets += node_usage.number_of_gets; + + node_batch.push((i, node_usage)); + if node_batch.len() == node_batch_size { + payees.push(node_batch.clone()); + node_batch.clear(); + } + } + if !node_batch.is_empty() { + payees.push(node_batch.clone()); + } + + let mut total_charge = 0u128; + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(u128, CustomerUsage)> = Vec::new(); + for user_id in 1000..1000 + num_users { + let user_usage = CustomerUsage { + transferred_bytes: generate_random_u64(&mock_randomness, min, max), + stored_bytes: generate_random_u64(&mock_randomness, min, max), + number_of_puts: generate_random_u64(&mock_randomness, min, max), + number_of_gets: generate_random_u64(&mock_randomness, min, max), + }; + + let expected_charge = calculate_charge(cluster_id, user_usage.clone()); + Balances::transfer( + RuntimeOrigin::signed(bank), + user_id, + (expected_charge * 2).max(Balances::minimum_balance()), + ) + .unwrap(); + total_charge += expected_charge; + + user_batch.push((user_id, user_usage)); + if user_batch.len() == user_batch_size { + payers.push(user_batch.clone()); + user_batch.clear(); + } + } + if !user_batch.is_empty() { + payers.push(user_batch.clone()); + } + + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::begin_billing_report( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + assert_ok!(DdcPayouts::begin_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payers.len() - 1) as u16, + )); + + for batch in payers.iter() { + assert_ok!(DdcPayouts::send_charging_customers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_user_index, + batch.to_vec(), + )); + + for (customer_id, usage) in batch.iter() { + let charge = calculate_charge(cluster_id, usage.clone()); + + System::assert_has_event( + Event::Charged { + cluster_id, + era, + customer_id: *customer_id, + batch_index: batch_user_index, + amount: charge, + } + .into(), + ); + } + batch_user_index += 1; + } + + let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let balance1 = Balances::free_balance(report_before.vault); + let balance2 = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(balance1, balance2); + assert_eq!(report_before.vault, DdcPayouts::account_id()); + assert_eq!(balance1 - Balances::minimum_balance(), total_charge); + + assert_ok!(DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + )); + + let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let total_left_from_one = (get_fees(&cluster_id).treasury_share + + get_fees(&cluster_id).validators_share + + get_fees(&cluster_id).cluster_reserve_share) + .left_from_one(); + + let total_charge = report_after.total_customer_charge.transfer + + report_before.total_customer_charge.storage + + report_before.total_customer_charge.puts + + report_before.total_customer_charge.gets; + let balance_after = Balances::free_balance(DdcPayouts::account_id()); + assert_eq!(total_charge, balance_after - Balances::minimum_balance()); + + assert_eq!( + report_after.total_customer_charge.transfer, + total_left_from_one * report_before.total_customer_charge.transfer + ); + assert_eq!( + report_after.total_customer_charge.storage, + total_left_from_one * report_before.total_customer_charge.storage + ); + assert_eq!( + report_after.total_customer_charge.puts, + total_left_from_one * report_before.total_customer_charge.puts + ); + assert_eq!( + report_after.total_customer_charge.gets, + total_left_from_one * report_before.total_customer_charge.gets + ); + + assert_ok!(DdcPayouts::begin_rewarding_providers( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + (payees.len() - 1) as u16, + total_nodes_usage.clone(), + )); + + for batch in payees.iter() { + let before_batch = Balances::free_balance(DdcPayouts::account_id()); + assert_ok!(DdcPayouts::send_rewarding_providers_batch( + RuntimeOrigin::signed(dac_account), + cluster_id, + era, + batch_node_index, + batch.to_vec(), + )); + + let mut batch_charge = 0; + for (node1, node_usage1) in batch.iter() { + let ratio1_transfer = Perquintill::from_rational( + node_usage1.transferred_bytes, + total_nodes_usage.transferred_bytes, + ); + let transfer_charge = ratio1_transfer * report_after.total_customer_charge.transfer; + + let ratio1_storage = Perquintill::from_rational( + node_usage1.stored_bytes, + total_nodes_usage.stored_bytes, + ); + let storage_charge = ratio1_storage * report_after.total_customer_charge.storage; + + let ratio1_puts = Perquintill::from_rational( + node_usage1.number_of_puts, + total_nodes_usage.number_of_puts, + ); + let puts_charge = ratio1_puts * report_after.total_customer_charge.puts; + + let ratio1_gets = Perquintill::from_rational( + node_usage1.number_of_gets, + total_nodes_usage.number_of_gets, + ); + let gets_charge = ratio1_gets * report_after.total_customer_charge.gets; + + let balance_node1 = Balances::free_balance(node1); + assert!( + (transfer_charge + storage_charge + puts_charge + gets_charge) - balance_node1 < + MAX_DUST.into() + ); + + batch_charge += transfer_charge + storage_charge + puts_charge + gets_charge; + } + let after_batch = Balances::free_balance(DdcPayouts::account_id()); + assert!(batch_charge + after_batch - before_batch < MAX_DUST.into()); + + batch_node_index += 1; + } + assert!(Balances::free_balance(DdcPayouts::account_id()) < MAX_DUST.into()); + }) +} + #[test] fn end_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { From 59390156b759532c51044b1c5c39c2f6b44beb7f Mon Sep 17 00:00:00 2001 From: Rakan Al-Huneiti Date: Fri, 22 Dec 2023 15:28:08 +0300 Subject: [PATCH 543/544] Testnet runtime upgrade - v4.8.2 - Substrate v0.9.30-2 (#214) --- runtime/cere/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 0f08f7af1..e147f7f7a 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -126,10 +126,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 48201, + spec_version: 48202, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 6, + transaction_version: 7, state_version: 0, }; From bc66f95865382aa8612ec609ab3e8a538f43aa4f Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Fri, 29 Dec 2023 13:14:17 +0100 Subject: [PATCH 544/544] CHANGELOG is updated (#215) --- CHANGELOG.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 780fcf968..6766a6c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,12 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument and `--dac-url` argument to specify DAC endpoint. It will only work on the nodes with validation and offchain workers enabled as well. -- [D] Several calls for `pallet-ddc-staking` to distribute rewards. -- [D] Third kind of account in DDC Staking for DDC nodes (along with stash and controller). -- [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance. -- [Zombienet](https://github.com/paritytech/zombienet) configurations to test block building and spawn a network for DDC validation debugging. -- New `ddc-primitives` crate with DDC common types definition +- [C,D] New `pallet-ddc-nodes` is added which allows registering a DDC node within the network with specific settings. +- [C,D] New `pallet-ddc-clusters` is added which allows launching a DDC cluster in the network and managing it. +- [C,D] New `pallet-ddc-staking` is added which allows making bonds for DDC nodes before joining a DDC cluster. +- [C,D] New `pallet-ddc-customers` is added which allows depositing tokens and creating buckets for DDC customers. +- [C,D] New `pallet-ddc-payouts` is added which allows processing payouts to DDC nodes providers based on DAC validation results. +- New `ddc-primitives` crate with DDC common types definition. +- New `ddc-traits` crate with DDC common traits definition. ### Changed