diff --git a/Cargo.lock b/Cargo.lock index f7d0de175..dbda906e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2294,7 +2294,9 @@ dependencies = [ "getrandom 0.2.15", "gmp", "hex", + "parity-scale-codec", "peernet", + "polkadot-sdk", "prometheus_exporter", "schnorr-evm", "serde", @@ -18913,6 +18915,8 @@ dependencies = [ "futures", "gmp", "hex", + "parity-scale-codec", + "polkadot-sdk", "reqwest", "serde", "serde_yaml", diff --git a/chronicle/Cargo.toml b/chronicle/Cargo.toml index 51887dcf8..051c35985 100644 --- a/chronicle/Cargo.toml +++ b/chronicle/Cargo.toml @@ -23,7 +23,10 @@ tc-subxt.workspace = true tokio.workspace = true tracing.workspace = true tss.workspace = true - +polkadot-sdk = { workspace = true, features = [ + "sp-runtime", +]} +scale-codec.workspace = true bincode = "1.3.3" bip39 = "2.0.0" getrandom = "0.2.15" diff --git a/chronicle/src/lib.rs b/chronicle/src/lib.rs index 9df334080..b42520577 100644 --- a/chronicle/src/lib.rs +++ b/chronicle/src/lib.rs @@ -5,6 +5,7 @@ use crate::tasks::TaskParams; use anyhow::Result; use futures::channel::mpsc; use gmp::Backend; +use scale_codec::Decode; use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; @@ -75,10 +76,12 @@ pub async fn run_chronicle(config: ChronicleConfig, substrate: Arc) }; }; let (tss_tx, tss_rx) = mpsc::channel(10); + let blockchain = String::decode(&mut chain.0.to_vec().as_slice()).unwrap_or_default(); + let network = String::decode(&mut subchain.0.to_vec().as_slice()).unwrap_or_default(); let connector_params = ConnectorParams { network_id: config.network_id, - blockchain: chain, - network: subchain, + blockchain, + network, url: config.target_url, mnemonic: config.target_mnemonic, }; @@ -148,9 +151,11 @@ pub async fn run_chronicle(config: ChronicleConfig, substrate: Arc) mod tests { use super::*; use crate::mock::Mock; + use polkadot_sdk::sp_runtime::BoundedVec; + use scale_codec::Encode; use std::time::Duration; use time_primitives::traits::IdentifyAccount; - use time_primitives::{AccountId, ShardStatus, Task}; + use time_primitives::{AccountId, ChainName, ChainNetwork, ShardStatus, Task}; /// Asynchronous test helper to run Chronicle. /// @@ -197,7 +202,10 @@ mod tests { std::panic::set_hook(Box::new(tracing_panic::panic_hook)); let mock = Mock::default().instance(42); - let network_id = mock.create_network("rust".into(), "rust".into()); + let network_id = mock.create_network( + ChainName(BoundedVec::truncate_from("rust".encode())), + ChainNetwork(BoundedVec::truncate_from("rust".encode())), + ); // Spawn multiple threads to run the Chronicle application. for id in 0..3 { let instance = mock.instance(id); diff --git a/chronicle/src/mock.rs b/chronicle/src/mock.rs index d9f16611b..69c9c242c 100644 --- a/chronicle/src/mock.rs +++ b/chronicle/src/mock.rs @@ -2,6 +2,7 @@ use crate::runtime::Runtime; use anyhow::Result; use futures::stream::BoxStream; use futures::{stream, StreamExt}; +use polkadot_sdk::sp_runtime::BoundedVec; use schnorr_evm::k256::ProjectivePoint; use std::collections::HashMap; use std::sync::{Arc, Mutex}; @@ -117,7 +118,11 @@ impl Mock { let mut shards = self.shards.lock().unwrap(); let shard = shards.get_mut(&shard_id).unwrap(); let public_key = VerifyingKey::new(ProjectivePoint::GENERATOR).to_bytes().unwrap(); - shard.commitments = vec![vec![public_key; threshold as _]; shard.members.len()]; + shard.commitments = + vec![ + Commitment(BoundedVec::truncate_from(vec![public_key; threshold as _])); + shard.members.len() + ]; shard.online = shard.members.len(); shard_id } @@ -260,11 +265,13 @@ impl Runtime for Mock { .commitments .iter() .map(|commitment| { - VerifiableSecretSharingCommitment::deserialize(commitment.clone()).unwrap() + VerifiableSecretSharingCommitment::deserialize(commitment.0.to_vec()).unwrap() }) .collect(); let commitments = commitments.iter().collect::>(); - Ok(Some(sum_commitments(&commitments).unwrap().serialize())) + Ok(Some(Commitment(BoundedVec::truncate_from( + sum_commitments(&commitments).unwrap().serialize(), + )))) } async fn get_shard_tasks(&self, shard_id: ShardId) -> Result> { diff --git a/chronicle/src/shards/service.rs b/chronicle/src/shards/service.rs index 1690762e5..f3e8c162d 100644 --- a/chronicle/src/shards/service.rs +++ b/chronicle/src/shards/service.rs @@ -11,6 +11,7 @@ use futures::{ stream::FuturesUnordered, Future, FutureExt, Stream, StreamExt, }; +use polkadot_sdk::sp_runtime::BoundedVec; use std::sync::Arc; use std::{ collections::{BTreeMap, BTreeSet, HashMap}, @@ -19,7 +20,8 @@ use std::{ task::Poll, }; use time_primitives::{ - BlockHash, BlockNumber, ShardId, ShardStatus, TaskId, TssSignature, TssSigningRequest, + BlockHash, BlockNumber, Commitment, ShardId, ShardStatus, TaskId, TssSignature, + TssSigningRequest, }; use tokio::time::{sleep, Duration}; use tracing::{event, span, Level, Span}; @@ -131,7 +133,8 @@ where let commitment = if let Some(commitment) = self.substrate.get_shard_commitment(shard_id).await? { - let commitment = VerifiableSecretSharingCommitment::deserialize(commitment)?; + let commitment = + VerifiableSecretSharingCommitment::deserialize(commitment.0.to_vec())?; Some(commitment) } else { None @@ -159,7 +162,7 @@ where continue; } let commitment = self.substrate.get_shard_commitment(shard_id).await?.unwrap(); - let commitment = VerifiableSecretSharingCommitment::deserialize(commitment)?; + let commitment = VerifiableSecretSharingCommitment::deserialize(commitment.0.to_vec())?; tss.on_commit(commitment); self.poll_actions(&span, shard_id, block_number).await; } @@ -287,7 +290,7 @@ where self.substrate .submit_commitment( shard_id, - commitment.serialize(), + Commitment(BoundedVec::truncate_from(commitment.serialize())), proof_of_knowledge.serialize(), ) .await diff --git a/chronicle/src/tasks/mod.rs b/chronicle/src/tasks/mod.rs index 3e7c11023..af44576c0 100644 --- a/chronicle/src/tasks/mod.rs +++ b/chronicle/src/tasks/mod.rs @@ -3,11 +3,13 @@ use crate::TW_LOG; use anyhow::{Context, Result}; use futures::channel::{mpsc, oneshot}; use futures::{SinkExt, Stream}; +use polkadot_sdk::sp_runtime::BoundedVec; +use scale_codec::Encode; use std::sync::Arc; use std::{collections::BTreeMap, pin::Pin}; use time_primitives::{ - Address, BlockHash, BlockNumber, GmpParams, IConnector, NetworkId, ShardId, Task, TaskId, - TaskResult, TssSignature, TssSigningRequest, + Address, BlockHash, BlockNumber, ErrorMsg, GmpEvents, GmpParams, IConnector, NetworkId, + ShardId, Task, TaskId, TaskResult, TssSignature, TssSigningRequest, }; use tokio::task::JoinHandle; use tracing::{event, span, Level}; @@ -104,7 +106,10 @@ impl TaskParams { tracing::info!(target: TW_LOG, task_id, "read {} events", events.len(),); let payload = time_primitives::encode_gmp_events(task_id, &events); let signature = self.tss_sign(block_number, shard_id, task_id, payload).await?; - Some(TaskResult::ReadGatewayEvents { events, signature }) + Some(TaskResult::ReadGatewayEvents { + events: GmpEvents(BoundedVec::truncate_from(events)), + signature, + }) }, Task::SubmitGatewayMessage { batch_id } => { let msg = @@ -113,11 +118,14 @@ impl TaskParams { let signature = self.tss_sign(block_number, shard_id, task_id, payload.to_vec()).await?; let signer = - self.runtime.get_shard_commitment(shard_id).await?.context("invalid shard")?[0]; - if let Err(error) = + self.runtime.get_shard_commitment(shard_id).await?.context("invalid shard")?.0 + [0]; + if let Err(e) = self.connector.submit_commands(gateway, batch_id, msg, signer, signature).await { - Some(TaskResult::SubmitGatewayMessage { error }) + Some(TaskResult::SubmitGatewayMessage { + error: ErrorMsg(BoundedVec::truncate_from(e.encode())), + }) } else { None } diff --git a/pallets/dmail/src/benchmarking.rs b/pallets/dmail/src/benchmarking.rs index 203fa1cc3..c140e07a1 100644 --- a/pallets/dmail/src/benchmarking.rs +++ b/pallets/dmail/src/benchmarking.rs @@ -3,21 +3,17 @@ use crate::Pallet; use scale_info::prelude::string::String; -use polkadot_sdk::frame_benchmarking::benchmarks; -use polkadot_sdk::frame_system; - use frame_system::RawOrigin; -use time_primitives::AccountId; - -//TODO: choose & enforce MAX in code -const MAX_LENGTH: u32 = 1000; -pub const ALICE: [u8; 32] = [1u8; 32]; +use polkadot_sdk::frame_benchmarking::benchmarks; +use polkadot_sdk::{frame_system, sp_runtime}; +use scale_codec::Encode; +use sp_runtime::BoundedVec; +use time_primitives::{DmailPath, DmailTo, DMAIL_PATH_LEN, DMAIL_TO_LEN}; benchmarks! { send_email { - let a in 1..MAX_LENGTH; - let b in 1..MAX_LENGTH; - let caller: AccountId = ALICE.into(); + let a in 1..DMAIL_TO_LEN; + let b in 1..DMAIL_PATH_LEN; let mut to = String::new(); let mut path = String::new(); @@ -27,7 +23,9 @@ benchmarks! { for _ in 0..b { path.push('b'); } - }: _(RawOrigin::Signed(caller), to, path) + let to = DmailTo(BoundedVec::truncate_from(to.as_str().encode())); + let path = DmailPath(BoundedVec::truncate_from(path.as_str().encode())); + }: _(RawOrigin::Signed([0u8; 32].into()), to, path) verify {} impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/dmail/src/lib.rs b/pallets/dmail/src/lib.rs index 2ff7a93cf..edde1b530 100644 --- a/pallets/dmail/src/lib.rs +++ b/pallets/dmail/src/lib.rs @@ -49,7 +49,7 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::send_email(to.len() as u32, path.len() as u32))] + #[pallet::weight(T::WeightInfo::send_email(to.0.len() as u32, path.0.len() as u32))] pub fn send_email(origin: OriginFor, to: DmailTo, path: DmailPath) -> DispatchResult { let owner = ensure_signed(origin)?; let message = DmailMessage { owner, to, path }; diff --git a/pallets/dmail/src/tests.rs b/pallets/dmail/src/tests.rs index 69e165d0a..1d7c98764 100644 --- a/pallets/dmail/src/tests.rs +++ b/pallets/dmail/src/tests.rs @@ -1,17 +1,18 @@ use crate::mock::*; use crate::Event; -use polkadot_sdk::{frame_support, frame_system}; +use polkadot_sdk::{frame_support, frame_system, sp_runtime}; use frame_support::assert_ok; use frame_system::RawOrigin; - +use scale_codec::Encode; +use sp_runtime::BoundedVec; use time_primitives::{DmailMessage, DmailPath, DmailTo}; #[test] fn test_dmail_event() { - let to: DmailTo = "Self".into(); - let path: DmailPath = "//self".into(); + let to: DmailTo = DmailTo(BoundedVec::truncate_from("Self".encode())); + let path: DmailPath = DmailPath(BoundedVec::truncate_from("//self".encode())); let sender: AccountId = [1; 32].into(); let event = DmailMessage { owner: sender.clone(), diff --git a/pallets/networks/src/benchmarking.rs b/pallets/networks/src/benchmarking.rs index 6f55d3ed0..8bb08e870 100644 --- a/pallets/networks/src/benchmarking.rs +++ b/pallets/networks/src/benchmarking.rs @@ -3,12 +3,13 @@ use crate::Pallet; use frame_system::RawOrigin; use polkadot_sdk::frame_benchmarking::benchmarks; -use polkadot_sdk::frame_system; +use polkadot_sdk::{frame_system, sp_runtime}; +use scale_codec::Encode; use scale_info::prelude::string::String; -use time_primitives::{Network, NetworkConfig}; - -//TODO: choose & enforce MAX in code -const MAX_LENGTH: u32 = 1000; +use sp_runtime::BoundedVec; +use time_primitives::{ + ChainName, ChainNetwork, Network, NetworkConfig, CHAIN_NAME_LEN, CHAIN_NET_LEN, +}; fn mock_network_config() -> NetworkConfig { NetworkConfig { @@ -22,8 +23,8 @@ fn mock_network_config() -> NetworkConfig { fn mock_network(chain_name: String, chain_network: String) -> Network { Network { id: 42, - chain_name, - chain_network, + chain_name: ChainName(BoundedVec::truncate_from(chain_name.as_str().encode())), + chain_network: ChainNetwork(BoundedVec::truncate_from(chain_network.as_str().encode())), gateway: [0; 32], gateway_block: 99, config: mock_network_config(), @@ -32,8 +33,8 @@ fn mock_network(chain_name: String, chain_network: String) -> Network { benchmarks! { register_network { - let a in 1..MAX_LENGTH; - let b in 1..MAX_LENGTH; + let a in 1..CHAIN_NAME_LEN; + let b in 1..CHAIN_NET_LEN; let mut name = String::new(); let mut network = String::new(); for _ in 0..a { diff --git a/pallets/networks/src/lib.rs b/pallets/networks/src/lib.rs index 288d0cb5b..c8ae27f87 100644 --- a/pallets/networks/src/lib.rs +++ b/pallets/networks/src/lib.rs @@ -200,7 +200,7 @@ pub mod pallet { /// 3. Emit the [`Event::NetworkRegistered`] event with the new `NetworkId`. /// 4. Return `Ok(())` to indicate success. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::register_network(network.chain_name.len() as u32, network.chain_network.len() as u32))] + #[pallet::weight(T::WeightInfo::register_network(network.chain_name.0.len() as u32, network.chain_network.0.len() as u32))] pub fn register_network(origin: OriginFor, network: Network) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; Self::insert_network(&network)?; diff --git a/pallets/networks/src/tests.rs b/pallets/networks/src/tests.rs index 5a36c4241..3f81799f4 100644 --- a/pallets/networks/src/tests.rs +++ b/pallets/networks/src/tests.rs @@ -2,8 +2,10 @@ use crate::{self as pallet_networks}; use crate::{mock::*, Error}; use frame_support::{assert_noop, assert_ok}; use frame_system::RawOrigin; -use polkadot_sdk::{frame_support, frame_system}; -use time_primitives::{Network, NetworkConfig}; +use polkadot_sdk::{frame_support, frame_system, sp_runtime}; +use scale_codec::Encode; +use sp_runtime::BoundedVec; +use time_primitives::{ChainName, ChainNetwork, Network, NetworkConfig}; fn mock_network_config() -> NetworkConfig { NetworkConfig { @@ -17,8 +19,8 @@ fn mock_network_config() -> NetworkConfig { fn mock_network() -> Network { Network { id: 42, - chain_name: "Ethereum".into(), - chain_network: "Mainnet".into(), + chain_name: ChainName(BoundedVec::truncate_from("Ethereum".encode())), + chain_network: ChainNetwork(BoundedVec::truncate_from("Mainnet".encode())), gateway: [0; 32], gateway_block: 99, config: mock_network_config(), diff --git a/pallets/shards/src/benchmarking.rs b/pallets/shards/src/benchmarking.rs index 013668482..2b3f9376c 100644 --- a/pallets/shards/src/benchmarking.rs +++ b/pallets/shards/src/benchmarking.rs @@ -1,13 +1,13 @@ use super::*; use crate::Pallet; -use polkadot_sdk::{ - frame_benchmarking, frame_support, frame_system, pallet_balances, sp_core, sp_std, -}; - use frame_benchmarking::benchmarks; use frame_support::traits::{Currency, Get}; use frame_system::RawOrigin; +use polkadot_sdk::{ + frame_benchmarking, frame_support, frame_system, pallet_balances, sp_core, sp_runtime, sp_std, +}; +use sp_runtime::BoundedVec; use sp_std::vec; use sp_std::vec::Vec; @@ -69,7 +69,7 @@ pub fn get_commitment(member: [u8; 32]) -> Commitment { panic!("Invalid member") }, }; - vec![commitment] + Commitment(BoundedVec::truncate_from(vec![commitment])) } pub fn get_proof_of_knowledge(member: [u8; 32]) -> ProofOfKnowledge { match member { diff --git a/pallets/shards/src/lib.rs b/pallets/shards/src/lib.rs index 8dffbe044..f48982ec1 100644 --- a/pallets/shards/src/lib.rs +++ b/pallets/shards/src/lib.rs @@ -254,10 +254,10 @@ pub mod pallet { ); let threshold = ShardThreshold::::get(shard_id).unwrap_or_default(); ensure!( - commitment.len() == threshold as usize, + commitment.0.len() == threshold as usize, Error::::CommitmentLenNotEqualToThreshold ); - for c in &commitment { + for c in &commitment.0 { ensure!( VerifyingKey::from_bytes(*c).is_ok(), Error::::InvalidVerifyingKeyInCommitment @@ -267,7 +267,7 @@ pub mod pallet { T::Members::member_peer_id(&member).ok_or(Error::::MemberPeerIdNotFound)?; schnorr_evm::proof_of_knowledge::verify_proof_of_knowledge( &peer_id, - &commitment, + &commitment.0, proof_of_knowledge, ) .map_err(|_| Error::::InvalidProofOfKnowledge)?; @@ -277,7 +277,7 @@ pub mod pallet { .filter_map(|(_, status)| status.commitment().cloned()) .reduce(|mut group_commitment, commitment| { for (group_commitment, commitment) in - group_commitment.iter_mut().zip(commitment.iter()) + group_commitment.0.iter_mut().zip(commitment.0.iter()) { *group_commitment = VerifyingKey::new( VerifyingKey::from_bytes(*group_commitment) @@ -327,7 +327,7 @@ pub mod pallet { .all(|(_, status)| status == MemberStatus::Ready) { >::insert(shard_id, ShardStatus::Online); - Self::deposit_event(Event::ShardOnline(shard_id, commitment[0])); + Self::deposit_event(Event::ShardOnline(shard_id, commitment.0[0])); T::Tasks::shard_online(shard_id, network); } Ok(()) @@ -443,7 +443,7 @@ pub mod pallet { /// /// # Flow /// 1. Retrieve and return the commitment from [`ShardCommitment`] storage. - pub fn get_shard_commitment(shard_id: ShardId) -> Option> { + pub fn get_shard_commitment(shard_id: ShardId) -> Option { ShardCommitment::::get(shard_id) } } @@ -614,7 +614,7 @@ pub mod pallet { /// 1. Retrieves the commitment [`Vec`] associated with the `shard_id` from [`ShardCommitment`]. /// 2. Returns the first element of the commitment [`TssPublicKey`] if it exists; otherwise, returns `None`. fn tss_public_key(shard_id: ShardId) -> Option { - ShardCommitment::::get(shard_id).map(|commitment| commitment[0]) + ShardCommitment::::get(shard_id).map(|commitment| commitment.0[0]) } } } diff --git a/pallets/shards/src/tests.rs b/pallets/shards/src/tests.rs index e04563acc..3dcf87b05 100644 --- a/pallets/shards/src/tests.rs +++ b/pallets/shards/src/tests.rs @@ -1,19 +1,19 @@ use crate::mock::*; use crate::{Event, ShardMembers, ShardNetwork, ShardState}; -use polkadot_sdk::{frame_support, frame_system, pallet_balances, sp_core}; +use polkadot_sdk::{frame_support, frame_system, pallet_balances, sp_core, sp_runtime}; use frame_support::assert_ok; use frame_support::traits::{Currency, Get}; use frame_system::RawOrigin; - use schnorr_evm::k256::elliptic_curve::PrimeField; use schnorr_evm::k256::{ProjectivePoint, Scalar}; use schnorr_evm::proof_of_knowledge::construct_proof_of_knowledge; use schnorr_evm::VerifyingKey; +use sp_runtime::BoundedVec; use time_primitives::{ - AccountId, NetworkId, PeerId, PublicKey, ShardId, ShardStatus, ShardsInterface, + AccountId, Commitment, NetworkId, PeerId, PublicKey, ShardId, ShardStatus, ShardsInterface, }; const ETHEREUM: NetworkId = 0; @@ -88,7 +88,7 @@ fn create_shard(shard_id: ShardId, shard: &[Member], threshold: u16) { assert_ok!(Shards::commit( RawOrigin::Signed(member.account_id.clone()).into(), shard_id as _, - member.commitment(threshold), + Commitment(BoundedVec::truncate_from(member.commitment(threshold))), member.proof_of_knowledge(), )); roll(1); @@ -139,7 +139,7 @@ fn test_register_shard() { assert_ok!(Shards::commit( RawOrigin::Signed(member.account_id.clone()).into(), shard_id as _, - member.commitment(threshold), + Commitment(BoundedVec::truncate_from(member.commitment(threshold))), member.proof_of_knowledge(), )); } diff --git a/pallets/tasks/src/benchmarking.rs b/pallets/tasks/src/benchmarking.rs index bdf49efe6..e17aad0aa 100644 --- a/pallets/tasks/src/benchmarking.rs +++ b/pallets/tasks/src/benchmarking.rs @@ -5,11 +5,12 @@ use frame_support::traits::OnInitialize; use frame_system::RawOrigin; use pallet_networks::NetworkGatewayAddress; use pallet_shards::{ShardCommitment, ShardState}; -use polkadot_sdk::{frame_benchmarking, frame_support, frame_system, sp_std}; +use polkadot_sdk::{frame_benchmarking, frame_support, frame_system, sp_runtime, sp_std}; +use sp_runtime::BoundedVec; use sp_std::vec; use time_primitives::{ - NetworkId, ShardStatus, ShardsInterface, Task, TaskResult, TasksInterface, TssPublicKey, - TssSignature, + Commitment, GmpEvents, NetworkId, ShardStatus, ShardsInterface, Task, TaskResult, + TasksInterface, TssPublicKey, TssSignature, }; // Generated by running tests::bench_helper::print_valid_result @@ -32,7 +33,7 @@ fn create_simple_task() { 1, ); ShardState::::insert(shard_id, ShardStatus::Online); - ShardCommitment::::insert(shard_id, vec![PUBKEY]); + ShardCommitment::::insert(shard_id, Commitment(BoundedVec::truncate_from(vec![PUBKEY]))); Pallet::::shard_online(shard_id, ETHEREUM); Pallet::::create_task(ETHEREUM, Task::ReadGatewayEvents { blocks: 0..10 }); } @@ -44,7 +45,7 @@ benchmarks! { NetworkGatewayAddress::::insert(0, [0; 32]); create_simple_task::(); Pallet::::on_initialize(frame_system::Pallet::::block_number()); - let result = TaskResult::ReadGatewayEvents { events: vec![], signature: SIGNATURE }; + let result = TaskResult::ReadGatewayEvents { events: GmpEvents(BoundedVec::truncate_from(vec![])), signature: SIGNATURE }; }: _(RawOrigin::Signed([0u8; 32].into()), 0, result) verify {} schedule_tasks { diff --git a/pallets/tasks/src/lib.rs b/pallets/tasks/src/lib.rs index eb76eb202..fadc91251 100644 --- a/pallets/tasks/src/lib.rs +++ b/pallets/tasks/src/lib.rs @@ -51,7 +51,6 @@ mod tests; #[polkadot_sdk::frame_support::pallet] pub mod pallet { use crate::queue::*; - use scale_info::prelude::string::String; use polkadot_sdk::{ frame_support, frame_system, pallet_balances, pallet_treasury, sp_runtime, sp_std, @@ -68,8 +67,8 @@ pub mod pallet { use sp_std::vec::Vec; use time_primitives::{ - AccountId, Balance, BatchBuilder, BatchId, GatewayMessage, GatewayOp, GmpEvent, MessageId, - NetworkId, NetworksInterface, PublicKey, ShardId, ShardsInterface, Task, TaskId, + AccountId, Balance, BatchBuilder, BatchId, ErrorMsg, GatewayMessage, GatewayOp, GmpEvent, + MessageId, NetworkId, NetworksInterface, PublicKey, ShardId, ShardsInterface, Task, TaskId, TaskResult, TasksInterface, TssPublicKey, TssSignature, }; @@ -201,7 +200,7 @@ pub mod pallet { #[pallet::storage] pub type TaskOutput = - StorageMap<_, Blake2_128Concat, TaskId, Result<(), String>, OptionQuery>; + StorageMap<_, Blake2_128Concat, TaskId, Result<(), ErrorMsg>, OptionQuery>; #[pallet::storage] pub type TaskNetwork = @@ -252,7 +251,7 @@ pub mod pallet { /// the record id that uniquely identify TaskCreated(TaskId), /// Task succeeded with optional error message - TaskResult(TaskId, Result<(), String>), + TaskResult(TaskId, Result<(), ErrorMsg>), /// Set the maximum number of assigned tasks for all shards on the network ShardTaskLimitSet(NetworkId, u32), /// Set the network batch size @@ -321,7 +320,7 @@ pub mod pallet { TaskResult::ReadGatewayEvents { events, signature }, ) => { // verify signature - let bytes = time_primitives::encode_gmp_events(task_id, &events); + let bytes = time_primitives::encode_gmp_events(task_id, &events.0); Self::verify_signature(shard, &bytes, signature)?; // start next batch let start = blocks.end; @@ -329,7 +328,7 @@ pub mod pallet { let end = start + size; Self::create_task(network, Task::ReadGatewayEvents { blocks: start..end }); // process events - for event in events { + for event in events.0 { match event { GmpEvent::ShardRegistered(pubkey) => { ShardRegistered::::insert(pubkey, ()); @@ -424,7 +423,7 @@ pub mod pallet { task_id } - fn finish_task(network: NetworkId, task_id: TaskId, result: Result<(), String>) { + fn finish_task(network: NetworkId, task_id: TaskId, result: Result<(), ErrorMsg>) { TaskOutput::::insert(task_id, result.clone()); if let Some(shard) = TaskShard::::take(task_id) { ShardTasks::::remove(shard, task_id); @@ -635,7 +634,7 @@ pub mod pallet { /// Retrieves the result of a given task. /// Look up the `TaskResult` associated with the provided `task_id` in the storage. - pub fn get_task_result(task_id: TaskId) -> Option> { + pub fn get_task_result(task_id: TaskId) -> Option> { TaskOutput::::get(task_id) } diff --git a/pallets/tasks/src/tests.rs b/pallets/tasks/src/tests.rs index 748c53c52..151c5a300 100644 --- a/pallets/tasks/src/tests.rs +++ b/pallets/tasks/src/tests.rs @@ -4,11 +4,13 @@ use crate::{BatchIdCounter, ShardRegistered}; use frame_support::assert_ok; use frame_system::RawOrigin; use pallet_shards::{ShardCommitment, ShardState}; -use polkadot_sdk::{frame_support, frame_system}; +use polkadot_sdk::{frame_support, frame_system, sp_runtime}; +use scale_codec::Encode; +use sp_runtime::BoundedVec; use time_primitives::{ - traits::IdentifyAccount, GatewayMessage, GatewayOp, GmpEvent, GmpMessage, MockTssSigner, - NetworkId, PublicKey, ShardId, ShardStatus, ShardsInterface, Task, TaskId, TaskResult, - TasksInterface, TssPublicKey, TssSignature, + traits::IdentifyAccount, Commitment, ErrorMsg, GatewayMessage, GatewayOp, GmpEvent, GmpEvents, + GmpMessage, MockTssSigner, NetworkId, PublicKey, ShardId, ShardStatus, ShardsInterface, Task, + TaskId, TaskResult, TasksInterface, TssPublicKey, TssSignature, }; const ETHEREUM: NetworkId = 0; @@ -20,7 +22,7 @@ fn create_shard(network: NetworkId, n: u8, t: u16) -> ShardId { } let shard_id = Shards::create_shard(network, members, t).0; let pub_key = MockTssSigner::new(shard_id).public_key(); - ShardCommitment::::insert(shard_id, vec![pub_key]); + ShardCommitment::::insert(shard_id, Commitment(BoundedVec::truncate_from(vec![pub_key]))); ShardState::::insert(shard_id, ShardStatus::Online); Tasks::shard_online(shard_id, network); shard_id @@ -42,7 +44,7 @@ fn register_shard(shard: ShardId) { fn submit_gateway_events(shard: ShardId, task_id: TaskId, events: &[GmpEvent]) { let signature = MockTssSigner::new(shard).sign_gmp_events(task_id, events); let result = TaskResult::ReadGatewayEvents { - events: events.to_vec(), + events: GmpEvents(BoundedVec::truncate_from(events.to_vec())), signature, }; assert_ok!(Tasks::submit_task_result( @@ -56,7 +58,9 @@ fn submit_submission_error(account: PublicKey, task: TaskId, error: &str) { assert_ok!(Tasks::submit_task_result( RawOrigin::Signed(account.into_account()).into(), task, - TaskResult::SubmitGatewayMessage { error: error.to_string() } + TaskResult::SubmitGatewayMessage { + error: ErrorMsg(BoundedVec::truncate_from(error.encode())) + } )); } @@ -225,7 +229,10 @@ fn test_msg_execution_error_completes_submit_task() { assert!(Tasks::get_task_result(1).is_none()); let account = Tasks::get_task_submitter(1).unwrap(); submit_submission_error(account, 1, "error message"); - assert_eq!(Tasks::get_task_result(1), Some(Err("error message".to_string()))); + assert_eq!( + Tasks::get_task_result(1), + Some(Err(ErrorMsg(BoundedVec::truncate_from("error message".encode())))) + ); }) } diff --git a/primitives/src/dmail.rs b/primitives/src/dmail.rs index b4bd8bfe6..ee081ef7f 100644 --- a/primitives/src/dmail.rs +++ b/primitives/src/dmail.rs @@ -1,10 +1,15 @@ +use crate::AccountId; +use polkadot_sdk::{sp_core::ConstU32, sp_runtime::BoundedVec}; use scale_codec::{Decode, Encode}; -use scale_info::{prelude::string::String, TypeInfo}; +use scale_info::TypeInfo; -use crate::AccountId; +pub const DMAIL_TO_LEN: u32 = 64; +pub const DMAIL_PATH_LEN: u32 = 64; -pub type DmailTo = String; -pub type DmailPath = String; +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)] +pub struct DmailTo(pub BoundedVec>); +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)] +pub struct DmailPath(pub BoundedVec>); #[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)] pub struct DmailMessage { diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 4c22a0c0e..c21b118eb 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -117,7 +117,7 @@ sp_api::decl_runtime_apis! { fn get_task(task_id: TaskId) -> Option; fn get_task_shard(task_id: TaskId) -> Option; fn get_task_submitter(task_id: TaskId) -> Option; - fn get_task_result(task_id: TaskId) -> Option>; + fn get_task_result(task_id: TaskId) -> Option>; fn get_batch_message(batch_id: BatchId) -> Option; } diff --git a/primitives/src/network.rs b/primitives/src/network.rs index 7b7989df7..6915418a9 100644 --- a/primitives/src/network.rs +++ b/primitives/src/network.rs @@ -1,12 +1,17 @@ use crate::Gateway; +use polkadot_sdk::{sp_core::ConstU32, sp_runtime::BoundedVec}; use scale_codec::{Decode, Encode}; -use scale_info::prelude::string::String; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; +pub const CHAIN_NAME_LEN: u32 = 50; +pub const CHAIN_NET_LEN: u32 = 50; + pub type NetworkId = u16; -pub type ChainName = String; -pub type ChainNetwork = String; +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] +pub struct ChainName(pub BoundedVec>); +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] +pub struct ChainNetwork(pub BoundedVec>); #[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo, Serialize, Deserialize)] pub struct Network { diff --git a/primitives/src/shard.rs b/primitives/src/shard.rs index 2b2565d4e..f1e5ae2b3 100644 --- a/primitives/src/shard.rs +++ b/primitives/src/shard.rs @@ -5,6 +5,7 @@ use crate::{ }; #[cfg(feature = "std")] use futures::channel::oneshot; +use polkadot_sdk::{sp_core::ConstU32, sp_runtime::BoundedVec}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -12,13 +13,17 @@ use scale_codec::{Decode, Encode}; use scale_info::prelude::vec::Vec; use scale_info::TypeInfo; +/// Upper bound for shard sizes +const MAX_SHARD_SIZE: u32 = 100; + pub type TssPublicKey = [u8; 33]; pub type TssSignature = [u8; 64]; pub type TssHash = [u8; 32]; pub type PeerId = [u8; 32]; pub type ShardId = u64; pub type ProofOfKnowledge = [u8; 65]; -pub type Commitment = Vec; +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)] +pub struct Commitment(pub BoundedVec>); #[cfg(feature = "std")] pub mod serde_tss_public_key { diff --git a/primitives/src/task.rs b/primitives/src/task.rs index c41dfc432..4c2155e9c 100644 --- a/primitives/src/task.rs +++ b/primitives/src/task.rs @@ -1,7 +1,8 @@ use crate::{BatchId, GmpEvent, TssSignature, ANLOG}; use core::ops::Range; +use polkadot_sdk::{sp_core::ConstU32, sp_runtime::BoundedVec}; use scale_codec::{Decode, Encode}; -use scale_info::{prelude::string::String, prelude::vec::Vec, TypeInfo}; +use scale_info::{prelude::vec::Vec, TypeInfo}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -60,15 +61,26 @@ pub fn encode_gmp_events(task_id: TaskId, events: &[GmpEvent]) -> Vec { (task_id, events).encode() } +const MAX_GMP_EVENTS: u32 = 1_000; +const MAX_ERROR_LEN: u32 = 500; +/// Bounded vec alias for GMP events submitted in results +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)] +pub struct GmpEvents(pub BoundedVec>); +/// Bounded vec alias for SubmitGatewayMessage error +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)] +pub struct ErrorMsg(pub BoundedVec>); + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Decode, Encode, TypeInfo, PartialEq)] pub enum TaskResult { ReadGatewayEvents { - events: Vec, + events: GmpEvents, #[cfg_attr(feature = "std", serde(with = "crate::shard::serde_tss_signature"))] signature: TssSignature, }, SubmitGatewayMessage { - error: String, + error: ErrorMsg, }, } diff --git a/runtimes/mainnet/src/lib.rs b/runtimes/mainnet/src/lib.rs index de293dc86..71c59345a 100644 --- a/runtimes/mainnet/src/lib.rs +++ b/runtimes/mainnet/src/lib.rs @@ -58,7 +58,6 @@ use pallet_session::historical as pallet_session_historical; pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; -use scale_info::prelude::string::String; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_grandpa::AuthorityId as GrandpaId; @@ -84,9 +83,9 @@ use static_assertions::const_assert; pub use time_primitives::{ AccountId, Balance, BatchId, BlockHash, BlockNumber, ChainName, ChainNetwork, Commitment, - Gateway, GatewayMessage, MemberStatus, MembersInterface, Moment, NetworkId, NetworksInterface, - Nonce, PeerId, ProofOfKnowledge, PublicKey, ShardId, ShardStatus, Signature, Task, TaskId, - TaskResult, TssPublicKey, TssSignature, ANLOG, + ErrorMsg, Gateway, GatewayMessage, MemberStatus, MembersInterface, Moment, NetworkId, + NetworksInterface, Nonce, PeerId, ProofOfKnowledge, PublicKey, ShardId, ShardStatus, Signature, + Task, TaskId, TaskResult, TssPublicKey, TssSignature, ANLOG, }; /// weightToFee implementation @@ -1958,7 +1957,7 @@ impl_runtime_apis! { Tasks::get_task_submitter(task_id) } - fn get_task_result(task_id: TaskId) -> Option>{ + fn get_task_result(task_id: TaskId) -> Option>{ Tasks::get_task_result(task_id) } diff --git a/runtimes/mainnet/src/weights/dmail.rs b/runtimes/mainnet/src/weights/dmail.rs index a6b819c3a..4ab29f1fe 100644 --- a/runtimes/mainnet/src/weights/dmail.rs +++ b/runtimes/mainnet/src/weights/dmail.rs @@ -33,20 +33,18 @@ use core::marker::PhantomData; /// Weight functions for `pallet_dmail`. pub struct WeightInfo(PhantomData); impl pallet_dmail::WeightInfo for WeightInfo { - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - fn send_email(a: u32, b: u32, ) -> Weight { + /// The range of component `a` is `[1, 64]`. + /// The range of component `b` is `[1, 64]`. + /// The range of component `a` is `[1, 64]`. + /// The range of component `b` is `[1, 64]`. + fn send_email(_a: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_055_000 picoseconds. - Weight::from_parts(8_869_443, 0) + // Minimum execution time: 7_164_000 picoseconds. + Weight::from_parts(8_515_330, 0) .saturating_add(Weight::from_parts(0, 0)) - // Standard Error: 36 - .saturating_add(Weight::from_parts(835, 0).saturating_mul(a.into())) - // Standard Error: 36 - .saturating_add(Weight::from_parts(750, 0).saturating_mul(b.into())) + // Standard Error: 861 + .saturating_add(Weight::from_parts(3_398, 0).saturating_mul(b.into())) } } diff --git a/runtimes/mainnet/src/weights/elections.rs b/runtimes/mainnet/src/weights/elections.rs index acf486b65..a2fb91cb4 100644 --- a/runtimes/mainnet/src/weights/elections.rs +++ b/runtimes/mainnet/src/weights/elections.rs @@ -43,8 +43,8 @@ impl pallet_elections::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `123` // Estimated: `3588` - // Minimum execution time: 12_003_000 picoseconds. - Weight::from_parts(12_654_000, 0) + // Minimum execution time: 11_993_000 picoseconds. + Weight::from_parts(12_583_000, 0) .saturating_add(Weight::from_parts(0, 3588)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/runtimes/mainnet/src/weights/members.rs b/runtimes/mainnet/src/weights/members.rs index 4017d9419..54cb33ceb 100644 --- a/runtimes/mainnet/src/weights/members.rs +++ b/runtimes/mainnet/src/weights/members.rs @@ -57,8 +57,8 @@ impl pallet_members::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `244` // Estimated: `3709` - // Minimum execution time: 61_975_000 picoseconds. - Weight::from_parts(64_350_000, 0) + // Minimum execution time: 64_369_000 picoseconds. + Weight::from_parts(68_278_000, 0) .saturating_add(Weight::from_parts(0, 3709)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(8)) @@ -73,8 +73,8 @@ impl pallet_members::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `293` // Estimated: `3758` - // Minimum execution time: 22_001_000 picoseconds. - Weight::from_parts(23_513_000, 0) + // Minimum execution time: 22_822_000 picoseconds. + Weight::from_parts(24_736_000, 0) .saturating_add(Weight::from_parts(0, 3758)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -101,8 +101,8 @@ impl pallet_members::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `380` // Estimated: `3845` - // Minimum execution time: 56_625_000 picoseconds. - Weight::from_parts(58_380_000, 0) + // Minimum execution time: 58_530_000 picoseconds. + Weight::from_parts(61_827_000, 0) .saturating_add(Weight::from_parts(0, 3845)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(8)) diff --git a/runtimes/mainnet/src/weights/networks.rs b/runtimes/mainnet/src/weights/networks.rs index 5300efc42..709c561ea 100644 --- a/runtimes/mainnet/src/weights/networks.rs +++ b/runtimes/mainnet/src/weights/networks.rs @@ -59,17 +59,21 @@ impl pallet_networks::WeightInfo for WeightInfo { /// Proof: `Tasks::ReadEventsTask` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `Tasks::TaskNetwork` (r:0 w:1) /// Proof: `Tasks::TaskNetwork` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - fn register_network(_a: u32, _b: u32, ) -> Weight { + /// The range of component `a` is `[1, 50]`. + /// The range of component `b` is `[1, 50]`. + /// The range of component `a` is `[1, 50]`. + /// The range of component `b` is `[1, 50]`. + fn register_network(a: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `118` // Estimated: `3583` - // Minimum execution time: 60_023_000 picoseconds. - Weight::from_parts(83_802_835, 0) + // Minimum execution time: 53_310_000 picoseconds. + Weight::from_parts(54_471_678, 0) .saturating_add(Weight::from_parts(0, 3583)) + // Standard Error: 10_531 + .saturating_add(Weight::from_parts(60_857, 0).saturating_mul(a.into())) + // Standard Error: 10_531 + .saturating_add(Weight::from_parts(29_084, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(13)) } @@ -87,8 +91,8 @@ impl pallet_networks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `277` // Estimated: `3742` - // Minimum execution time: 23_184_000 picoseconds. - Weight::from_parts(36_999_000, 0) + // Minimum execution time: 21_210_000 picoseconds. + Weight::from_parts(21_981_000, 0) .saturating_add(Weight::from_parts(0, 3742)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(4)) diff --git a/runtimes/mainnet/src/weights/shards.rs b/runtimes/mainnet/src/weights/shards.rs index 9dce1b258..564af0897 100644 --- a/runtimes/mainnet/src/weights/shards.rs +++ b/runtimes/mainnet/src/weights/shards.rs @@ -47,8 +47,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `757` // Estimated: `11647` - // Minimum execution time: 513_211_000 picoseconds. - Weight::from_parts(518_160_000, 0) + // Minimum execution time: 513_722_000 picoseconds. + Weight::from_parts(519_011_000, 0) .saturating_add(Weight::from_parts(0, 11647)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) @@ -69,8 +69,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `591` // Estimated: `11481` - // Minimum execution time: 58_900_000 picoseconds. - Weight::from_parts(61_415_000, 0) + // Minimum execution time: 58_890_000 picoseconds. + Weight::from_parts(61_324_000, 0) .saturating_add(Weight::from_parts(0, 11481)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(3)) @@ -99,8 +99,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `453` // Estimated: `11343` - // Minimum execution time: 70_763_000 picoseconds. - Weight::from_parts(74_139_000, 0) + // Minimum execution time: 70_382_000 picoseconds. + Weight::from_parts(74_119_000, 0) .saturating_add(Weight::from_parts(0, 11343)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(14)) @@ -111,8 +111,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `6` // Estimated: `3471` - // Minimum execution time: 3_437_000 picoseconds. - Weight::from_parts(3_667_000, 0) + // Minimum execution time: 3_297_000 picoseconds. + Weight::from_parts(3_577_000, 0) .saturating_add(Weight::from_parts(0, 3471)) .saturating_add(T::DbWeight::get().reads(1)) } diff --git a/runtimes/mainnet/src/weights/tasks.rs b/runtimes/mainnet/src/weights/tasks.rs index 5750e3be5..60ebb8990 100644 --- a/runtimes/mainnet/src/weights/tasks.rs +++ b/runtimes/mainnet/src/weights/tasks.rs @@ -69,8 +69,8 @@ impl pallet_tasks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `1380` // Estimated: `12270` - // Minimum execution time: 619_449_000 picoseconds. - Weight::from_parts(636_430_000, 0) + // Minimum execution time: 624_519_000 picoseconds. + Weight::from_parts(652_491_000, 0) .saturating_add(Weight::from_parts(0, 12270)) .saturating_add(T::DbWeight::get().reads(19)) .saturating_add(T::DbWeight::get().writes(14)) @@ -99,11 +99,11 @@ impl pallet_tasks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `1538 + b * (95 ±0)` // Estimated: `7370 + b * (2571 ±0)` - // Minimum execution time: 59_492_000 picoseconds. - Weight::from_parts(60_825_000, 0) + // Minimum execution time: 59_822_000 picoseconds. + Weight::from_parts(7_743_225, 0) .saturating_add(Weight::from_parts(0, 7370)) - // Standard Error: 16_006 - .saturating_add(Weight::from_parts(10_373_801, 0).saturating_mul(b.into())) + // Standard Error: 12_643 + .saturating_add(Weight::from_parts(10_623_107, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(3)) @@ -123,11 +123,11 @@ impl pallet_tasks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `958` // Estimated: `6794 + b * (1 ±0)` - // Minimum execution time: 24_886_000 picoseconds. - Weight::from_parts(46_097_548, 0) + // Minimum execution time: 24_746_000 picoseconds. + Weight::from_parts(42_091_648, 0) .saturating_add(Weight::from_parts(0, 6794)) - // Standard Error: 327 - .saturating_add(Weight::from_parts(10_346, 0).saturating_mul(b.into())) + // Standard Error: 325 + .saturating_add(Weight::from_parts(13_552, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) } diff --git a/runtimes/mainnet/src/weights/timegraph.rs b/runtimes/mainnet/src/weights/timegraph.rs index 5a065a4d0..f73b009cc 100644 --- a/runtimes/mainnet/src/weights/timegraph.rs +++ b/runtimes/mainnet/src/weights/timegraph.rs @@ -39,8 +39,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `3468` - // Minimum execution time: 33_162_000 picoseconds. - Weight::from_parts(34_725_000, 0) + // Minimum execution time: 31_579_000 picoseconds. + Weight::from_parts(32_752_000, 0) .saturating_add(Weight::from_parts(0, 3468)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -53,8 +53,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `3468` - // Minimum execution time: 32_971_000 picoseconds. - Weight::from_parts(34_445_000, 0) + // Minimum execution time: 31_849_000 picoseconds. + Weight::from_parts(33_092_000, 0) .saturating_add(Weight::from_parts(0, 3468)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -69,8 +69,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `272` // Estimated: `6196` - // Minimum execution time: 84_187_000 picoseconds. - Weight::from_parts(85_631_000, 0) + // Minimum execution time: 79_319_000 picoseconds. + Weight::from_parts(81_873_000, 0) .saturating_add(Weight::from_parts(0, 6196)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) @@ -85,8 +85,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `285` // Estimated: `3593` - // Minimum execution time: 81_293_000 picoseconds. - Weight::from_parts(82_704_000, 0) + // Minimum execution time: 75_982_000 picoseconds. + Weight::from_parts(77_726_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -97,8 +97,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `1488` - // Minimum execution time: 9_378_000 picoseconds. - Weight::from_parts(9_898_000, 0) + // Minimum execution time: 8_986_000 picoseconds. + Weight::from_parts(9_718_000, 0) .saturating_add(Weight::from_parts(0, 1488)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -109,8 +109,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `1488` - // Minimum execution time: 9_477_000 picoseconds. - Weight::from_parts(10_129_000, 0) + // Minimum execution time: 8_957_000 picoseconds. + Weight::from_parts(9_768_000, 0) .saturating_add(Weight::from_parts(0, 1488)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -121,8 +121,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `1488` - // Minimum execution time: 9_126_000 picoseconds. - Weight::from_parts(16_951_000, 0) + // Minimum execution time: 8_736_000 picoseconds. + Weight::from_parts(9_858_000, 0) .saturating_add(Weight::from_parts(0, 1488)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/runtimes/testnet/src/lib.rs b/runtimes/testnet/src/lib.rs index d64b98f49..018129ec7 100644 --- a/runtimes/testnet/src/lib.rs +++ b/runtimes/testnet/src/lib.rs @@ -31,7 +31,6 @@ use frame_support::{ }; use frame_system::EnsureRootWithSuccess; use frame_system::{limits::BlockWeights, EnsureRoot}; -use scale_info::prelude::string::String; use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf}; use pallet_grandpa::{ @@ -75,8 +74,8 @@ pub use runtime_common::{ }; pub use time_primitives::{ - AccountId, Balance, BatchId, BlockNumber, ChainName, ChainNetwork, Commitment, Gateway, - GatewayMessage, MemberStatus, MembersInterface, NetworkId, NetworksInterface, PeerId, + AccountId, Balance, BatchId, BlockNumber, ChainName, ChainNetwork, Commitment, ErrorMsg, + Gateway, GatewayMessage, MemberStatus, MembersInterface, NetworkId, NetworksInterface, PeerId, ProofOfKnowledge, PublicKey, ShardId, ShardStatus, Signature, Task, TaskId, TaskResult, TssPublicKey, TssSignature, ANLOG, }; @@ -1491,7 +1490,7 @@ impl_runtime_apis! { Tasks::get_task_submitter(task_id) } - fn get_task_result(task_id: TaskId) -> Option> { + fn get_task_result(task_id: TaskId) -> Option>{ Tasks::get_task_result(task_id) } diff --git a/runtimes/testnet/src/tests.rs b/runtimes/testnet/src/tests.rs index afabdd7e4..0ec768a41 100644 --- a/runtimes/testnet/src/tests.rs +++ b/runtimes/testnet/src/tests.rs @@ -1,15 +1,13 @@ /// Integration tests use crate::*; -//use polkadot_sdk::*; - use frame_support::assert_ok; use frame_support::traits::{OnFinalize, OnInitialize, WhitelistedStorageKeys}; use frame_system::RawOrigin; use pallet_shards::ShardMembers; -// use pallet_tasks::TaskSigner; use sp_core::hexdisplay::HexDisplay; use sp_core::Pair; +use sp_runtime::BoundedVec; use std::collections::HashSet; use time_primitives::{ AccountId, ElectionsInterface, Network, NetworkConfig, NetworkId, PublicKey, ShardStatus, @@ -32,8 +30,8 @@ fn get_peer_id(random_num: [u8; 32]) -> [u8; 32] { fn network() -> Network { Network { id: ETHEREUM, - chain_name: "ethereum".into(), - chain_network: "dev".into(), + chain_name: ChainName(BoundedVec::truncate_from("ethereum".encode())), + chain_network: ChainNetwork(BoundedVec::truncate_from("dev".encode())), gateway: [0u8; 32], gateway_block: 0, config: NetworkConfig { diff --git a/runtimes/testnet/src/weights/dmail.rs b/runtimes/testnet/src/weights/dmail.rs index 3ecffb7e8..8b065b571 100644 --- a/runtimes/testnet/src/weights/dmail.rs +++ b/runtimes/testnet/src/weights/dmail.rs @@ -33,20 +33,20 @@ use core::marker::PhantomData; /// Weight functions for `pallet_dmail`. pub struct WeightInfo(PhantomData); impl pallet_dmail::WeightInfo for WeightInfo { - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. + /// The range of component `a` is `[1, 64]`. + /// The range of component `b` is `[1, 64]`. + /// The range of component `a` is `[1, 64]`. + /// The range of component `b` is `[1, 64]`. fn send_email(a: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_654_000 picoseconds. - Weight::from_parts(6_116_844, 0) + // Minimum execution time: 6_642_000 picoseconds. + Weight::from_parts(7_015_701, 0) .saturating_add(Weight::from_parts(0, 0)) - // Standard Error: 129 - .saturating_add(Weight::from_parts(2_026, 0).saturating_mul(a.into())) - // Standard Error: 129 - .saturating_add(Weight::from_parts(3_401, 0).saturating_mul(b.into())) + // Standard Error: 567 + .saturating_add(Weight::from_parts(6_583, 0).saturating_mul(a.into())) + // Standard Error: 567 + .saturating_add(Weight::from_parts(5_645, 0).saturating_mul(b.into())) } } diff --git a/runtimes/testnet/src/weights/elections.rs b/runtimes/testnet/src/weights/elections.rs index e27428fa0..51fc9da98 100644 --- a/runtimes/testnet/src/weights/elections.rs +++ b/runtimes/testnet/src/weights/elections.rs @@ -43,8 +43,8 @@ impl pallet_elections::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `123` // Estimated: `3588` - // Minimum execution time: 11_491_000 picoseconds. - Weight::from_parts(12_062_000, 0) + // Minimum execution time: 11_961_000 picoseconds. + Weight::from_parts(12_453_000, 0) .saturating_add(Weight::from_parts(0, 3588)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/runtimes/testnet/src/weights/members.rs b/runtimes/testnet/src/weights/members.rs index c6345afed..4a418aecc 100644 --- a/runtimes/testnet/src/weights/members.rs +++ b/runtimes/testnet/src/weights/members.rs @@ -57,8 +57,8 @@ impl pallet_members::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `244` // Estimated: `3709` - // Minimum execution time: 65_542_000 picoseconds. - Weight::from_parts(69_010_000, 0) + // Minimum execution time: 66_054_000 picoseconds. + Weight::from_parts(69_099_000, 0) .saturating_add(Weight::from_parts(0, 3709)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(8)) @@ -73,8 +73,8 @@ impl pallet_members::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `293` // Estimated: `3758` - // Minimum execution time: 22_693_000 picoseconds. - Weight::from_parts(24_525_000, 0) + // Minimum execution time: 23_124_000 picoseconds. + Weight::from_parts(23_955_000, 0) .saturating_add(Weight::from_parts(0, 3758)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -101,8 +101,8 @@ impl pallet_members::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `380` // Estimated: `3845` - // Minimum execution time: 59_099_000 picoseconds. - Weight::from_parts(62_786_000, 0) + // Minimum execution time: 60_333_000 picoseconds. + Weight::from_parts(62_366_000, 0) .saturating_add(Weight::from_parts(0, 3845)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(8)) diff --git a/runtimes/testnet/src/weights/networks.rs b/runtimes/testnet/src/weights/networks.rs index b19ac9c60..f6eea99bf 100644 --- a/runtimes/testnet/src/weights/networks.rs +++ b/runtimes/testnet/src/weights/networks.rs @@ -59,21 +59,19 @@ impl pallet_networks::WeightInfo for WeightInfo { /// Proof: `Tasks::ReadEventsTask` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `Tasks::TaskNetwork` (r:0 w:1) /// Proof: `Tasks::TaskNetwork` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - /// The range of component `a` is `[1, 1000]`. - /// The range of component `b` is `[1, 1000]`. - fn register_network(a: u32, b: u32, ) -> Weight { + /// The range of component `a` is `[1, 50]`. + /// The range of component `b` is `[1, 50]`. + /// The range of component `a` is `[1, 50]`. + /// The range of component `b` is `[1, 50]`. + fn register_network(a: u32, _b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `118` // Estimated: `3583` - // Minimum execution time: 55_134_000 picoseconds. - Weight::from_parts(57_970_092, 0) + // Minimum execution time: 53_539_000 picoseconds. + Weight::from_parts(58_286_350, 0) .saturating_add(Weight::from_parts(0, 3583)) - // Standard Error: 87 - .saturating_add(Weight::from_parts(574, 0).saturating_mul(a.into())) - // Standard Error: 87 - .saturating_add(Weight::from_parts(797, 0).saturating_mul(b.into())) + // Standard Error: 4_425 + .saturating_add(Weight::from_parts(3_419, 0).saturating_mul(a.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(13)) } @@ -91,8 +89,8 @@ impl pallet_networks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `277` // Estimated: `3742` - // Minimum execution time: 21_601_000 picoseconds. - Weight::from_parts(22_211_000, 0) + // Minimum execution time: 21_230_000 picoseconds. + Weight::from_parts(22_212_000, 0) .saturating_add(Weight::from_parts(0, 3742)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(4)) diff --git a/runtimes/testnet/src/weights/shards.rs b/runtimes/testnet/src/weights/shards.rs index 95bdd203a..ce4ce35f2 100644 --- a/runtimes/testnet/src/weights/shards.rs +++ b/runtimes/testnet/src/weights/shards.rs @@ -47,8 +47,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `757` // Estimated: `11647` - // Minimum execution time: 515_173_000 picoseconds. - Weight::from_parts(528_048_000, 0) + // Minimum execution time: 509_142_000 picoseconds. + Weight::from_parts(518_480_000, 0) .saturating_add(Weight::from_parts(0, 11647)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) @@ -69,8 +69,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `591` // Estimated: `11481` - // Minimum execution time: 58_459_000 picoseconds. - Weight::from_parts(61_836_000, 0) + // Minimum execution time: 59_151_000 picoseconds. + Weight::from_parts(61_624_000, 0) .saturating_add(Weight::from_parts(0, 11481)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(3)) @@ -99,8 +99,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `453` // Estimated: `11343` - // Minimum execution time: 71_644_000 picoseconds. - Weight::from_parts(76_944_000, 0) + // Minimum execution time: 72_565_000 picoseconds. + Weight::from_parts(76_703_000, 0) .saturating_add(Weight::from_parts(0, 11343)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(14)) @@ -111,8 +111,8 @@ impl pallet_shards::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `6` // Estimated: `3471` - // Minimum execution time: 3_476_000 picoseconds. - Weight::from_parts(3_767_000, 0) + // Minimum execution time: 3_547_000 picoseconds. + Weight::from_parts(3_787_000, 0) .saturating_add(Weight::from_parts(0, 3471)) .saturating_add(T::DbWeight::get().reads(1)) } diff --git a/runtimes/testnet/src/weights/tasks.rs b/runtimes/testnet/src/weights/tasks.rs index 3dd8694d9..4fdcc9d6d 100644 --- a/runtimes/testnet/src/weights/tasks.rs +++ b/runtimes/testnet/src/weights/tasks.rs @@ -69,8 +69,8 @@ impl pallet_tasks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `1380` // Estimated: `12270` - // Minimum execution time: 629_468_000 picoseconds. - Weight::from_parts(656_669_000, 0) + // Minimum execution time: 632_403_000 picoseconds. + Weight::from_parts(647_720_000, 0) .saturating_add(Weight::from_parts(0, 12270)) .saturating_add(T::DbWeight::get().reads(19)) .saturating_add(T::DbWeight::get().writes(14)) @@ -99,11 +99,11 @@ impl pallet_tasks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `1538 + b * (95 ±0)` // Estimated: `7370 + b * (2571 ±0)` - // Minimum execution time: 60_694_000 picoseconds. - Weight::from_parts(61_965_000, 0) + // Minimum execution time: 60_524_000 picoseconds. + Weight::from_parts(770_202, 0) .saturating_add(Weight::from_parts(0, 7370)) - // Standard Error: 6_794 - .saturating_add(Weight::from_parts(10_493_673, 0).saturating_mul(b.into())) + // Standard Error: 10_099 + .saturating_add(Weight::from_parts(10_683_689, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(3)) @@ -123,11 +123,11 @@ impl pallet_tasks::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `958` // Estimated: `6794 + b * (1 ±0)` - // Minimum execution time: 25_037_000 picoseconds. - Weight::from_parts(41_059_226, 0) + // Minimum execution time: 24_566_000 picoseconds. + Weight::from_parts(40_559_014, 0) .saturating_add(Weight::from_parts(0, 6794)) - // Standard Error: 348 - .saturating_add(Weight::from_parts(16_127, 0).saturating_mul(b.into())) + // Standard Error: 298 + .saturating_add(Weight::from_parts(16_559, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) } diff --git a/runtimes/testnet/src/weights/timegraph.rs b/runtimes/testnet/src/weights/timegraph.rs index 823110025..46e4b4b76 100644 --- a/runtimes/testnet/src/weights/timegraph.rs +++ b/runtimes/testnet/src/weights/timegraph.rs @@ -39,8 +39,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `3468` - // Minimum execution time: 31_999_000 picoseconds. - Weight::from_parts(33_293_000, 0) + // Minimum execution time: 34_344_000 picoseconds. + Weight::from_parts(36_608_000, 0) .saturating_add(Weight::from_parts(0, 3468)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -53,8 +53,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `3468` - // Minimum execution time: 32_611_000 picoseconds. - Weight::from_parts(34_383_000, 0) + // Minimum execution time: 35_105_000 picoseconds. + Weight::from_parts(37_470_000, 0) .saturating_add(Weight::from_parts(0, 3468)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -69,8 +69,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `272` // Estimated: `6196` - // Minimum execution time: 83_497_000 picoseconds. - Weight::from_parts(85_461_000, 0) + // Minimum execution time: 88_284_000 picoseconds. + Weight::from_parts(89_968_000, 0) .saturating_add(Weight::from_parts(0, 6196)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) @@ -85,8 +85,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `285` // Estimated: `3593` - // Minimum execution time: 80_771_000 picoseconds. - Weight::from_parts(83_026_000, 0) + // Minimum execution time: 85_661_000 picoseconds. + Weight::from_parts(92_805_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -97,8 +97,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `1488` - // Minimum execution time: 9_267_000 picoseconds. - Weight::from_parts(9_719_000, 0) + // Minimum execution time: 9_206_000 picoseconds. + Weight::from_parts(9_888_000, 0) .saturating_add(Weight::from_parts(0, 1488)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -109,8 +109,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `1488` - // Minimum execution time: 9_137_000 picoseconds. - Weight::from_parts(9_798_000, 0) + // Minimum execution time: 9_327_000 picoseconds. + Weight::from_parts(9_828_000, 0) .saturating_add(Weight::from_parts(0, 1488)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -121,8 +121,8 @@ impl pallet_timegraph::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `3` // Estimated: `1488` - // Minimum execution time: 9_106_000 picoseconds. - Weight::from_parts(9_578_000, 0) + // Minimum execution time: 9_057_000 picoseconds. + Weight::from_parts(9_518_000, 0) .saturating_add(Weight::from_parts(0, 1488)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/tc-cli/Cargo.toml b/tc-cli/Cargo.toml index 96715b3d0..7a80edb69 100644 --- a/tc-cli/Cargo.toml +++ b/tc-cli/Cargo.toml @@ -20,6 +20,8 @@ serde_yaml = "0.9.34" surf = { version = "2.3.2", default-features = false, features = [ "h1-client-rustls" ] } tabled = "0.16.0" tc-subxt.workspace = true +scale-codec.workspace = true +polkadot-sdk = { workspace = true, features = ["sp-runtime"]} time-primitives = { workspace = true, default-features = true } tokio = { workspace = true, features = [ "macros", "rt-multi-thread", "signal" ]} tracing.workspace = true diff --git a/tc-cli/src/lib.rs b/tc-cli/src/lib.rs index e271a18b6..c354ab5ff 100644 --- a/tc-cli/src/lib.rs +++ b/tc-cli/src/lib.rs @@ -1,6 +1,8 @@ use crate::config::Config; use anyhow::{Context, Result}; use futures::stream::{BoxStream, StreamExt}; +use polkadot_sdk::sp_runtime::BoundedVec; +use scale_codec::{Decode, Encode}; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::ops::Range; @@ -9,9 +11,9 @@ use std::sync::Arc; use std::time::Duration; use tc_subxt::SubxtClient; use time_primitives::{ - AccountId, Address, BatchId, BlockHash, BlockNumber, ConnectorParams, Gateway, GatewayMessage, - GmpEvent, GmpMessage, IConnectorAdmin, MemberStatus, MessageId, NetworkConfig, NetworkId, - PublicKey, Route, ShardId, ShardStatus, TaskId, TssPublicKey, + AccountId, Address, BatchId, BlockHash, BlockNumber, ChainName, ChainNetwork, ConnectorParams, + Gateway, GatewayMessage, GmpEvent, GmpMessage, IConnectorAdmin, MemberStatus, MessageId, + NetworkConfig, NetworkId, PublicKey, Route, ShardId, ShardStatus, TaskId, TssPublicKey, }; mod config; @@ -376,8 +378,10 @@ impl Tc { let sync_status = self.sync_status(network).await?; networks.push(Network { network, - chain_name, - chain_network, + chain_name: String::decode(&mut chain_name.0.to_vec().as_slice()) + .unwrap_or_default(), + chain_network: String::decode(&mut chain_network.0.to_vec().as_slice()) + .unwrap_or_default(), gateway, gateway_balance, admin, @@ -425,7 +429,7 @@ impl Tc { e.insert(self.registered_shards(network).await?); } let status = self.runtime.shard_status(shard).await?; - let key = self.runtime.shard_commitment(shard).await?.map(|c| c[0]); + let key = self.runtime.shard_commitment(shard).await?.map(|c| c.0[0]); let size = self.runtime.shard_members(shard).await?.len() as u16; let threshold = self.runtime.shard_threshold(shard).await?; let mut registered = false; @@ -480,7 +484,9 @@ impl Tc { task, network: self.runtime.task_network(task).await?.context("invalid task id")?, descriptor: self.runtime.task(task).await?.context("invalid task id")?, - output: self.runtime.task_output(task).await?, + output: self.runtime.task_output(task).await?.map(|o| { + o.map_err(|e| String::decode(&mut e.0.to_vec().as_slice()).unwrap_or_default()) + }), shard: self.runtime.assigned_shard(task).await?, submitter: self.runtime.task_submitter(task).await?, }) @@ -561,8 +567,8 @@ impl Tc { self.runtime .register_network(time_primitives::Network { id: network, - chain_name: config.blockchain.clone(), - chain_network: config.network.clone(), + chain_name: ChainName(BoundedVec::truncate_from(config.blockchain.encode())), + chain_network: ChainNetwork(BoundedVec::truncate_from(config.network.encode())), gateway, gateway_block: block, config: NetworkConfig { diff --git a/tc-subxt/metadata/build.rs b/tc-subxt/metadata/build.rs index fcd9fa10b..e4a3d9a20 100644 --- a/tc-subxt/metadata/build.rs +++ b/tc-subxt/metadata/build.rs @@ -6,16 +6,23 @@ fn substitute(path: &str, with: &str) -> String { fn derive(path: &Path, module: &str) -> String { let simple_types = [ + "time_primitives::dmail::DmailTo", + "time_primitives::dmail::DmailPath", "time_primitives::gmp::GmpMessage", "time_primitives::gmp::GatewayOp", "time_primitives::gmp::GatewayMessage", "time_primitives::gmp::GmpEvent", + "time_primitives::network::ChainName", + "time_primitives::network::ChainNetwork", "time_primitives::network::Network", "time_primitives::network::NetworkConfig", + "time_primitives::shard::Commitment", "time_primitives::shard::MemberStatus", "time_primitives::shard::ShardStatus", "time_primitives::task::Task", "time_primitives::task::TaskResult", + "time_primitives::task::GmpEvents", + "time_primitives::task::ErrorMsg", ]; let others = [ ("sp_core::crypto::AccountId32", "time_primitives::AccountId"), diff --git a/tc-subxt/src/api/networks.rs b/tc-subxt/src/api/networks.rs index 6930d331a..0b843ee5c 100644 --- a/tc-subxt/src/api/networks.rs +++ b/tc-subxt/src/api/networks.rs @@ -2,7 +2,7 @@ use crate::worker::Tx; use crate::{metadata_scope, SubxtClient}; use anyhow::Result; use futures::channel::oneshot; -use time_primitives::{Gateway, Network, NetworkConfig, NetworkId}; +use time_primitives::{ChainName, ChainNetwork, Gateway, Network, NetworkConfig, NetworkId}; impl SubxtClient { pub async fn register_network(&self, network: Network) -> Result<()> { @@ -35,11 +35,15 @@ impl SubxtClient { Ok(networks) } - pub async fn network_name(&self, network: NetworkId) -> Result> { - let data = metadata_scope!(self.metadata, { + pub async fn network_name( + &self, + network: NetworkId, + ) -> Result> { + let data: Option<(ChainName, ChainNetwork)> = metadata_scope!(self.metadata, { let runtime_call = metadata::apis().networks_api().get_network(network); self.client.runtime_api().at_latest().await?.call(runtime_call).await? - }); + }) + .map(|(name, net)| ((*name).clone(), (*net).clone())); Ok(data) } diff --git a/tc-subxt/src/api/shards.rs b/tc-subxt/src/api/shards.rs index d1375c822..d3225880c 100644 --- a/tc-subxt/src/api/shards.rs +++ b/tc-subxt/src/api/shards.rs @@ -80,12 +80,14 @@ impl SubxtClient { pub async fn shard_commitment(&self, shard_id: ShardId) -> Result> { metadata_scope!(self.metadata, { let runtime_call = metadata::apis().shards_api().get_shard_commitment(shard_id); - Ok(self.client.runtime_api().at_latest().await?.call(runtime_call).await?) + let output = self.client.runtime_api().at_latest().await?.call(runtime_call).await?; + let output_converted = output.map(|static_commitment| (*static_commitment).clone()); + Ok(output_converted) }) } pub async fn shard_public_key(&self, shard_id: ShardId) -> Result> { - Ok(self.shard_commitment(shard_id).await?.map(|v| v[0])) + Ok(self.shard_commitment(shard_id).await?.map(|v| v.0[0])) } pub async fn submit_commitment( diff --git a/tc-subxt/src/api/tasks.rs b/tc-subxt/src/api/tasks.rs index ad0921b3b..8da289206 100644 --- a/tc-subxt/src/api/tasks.rs +++ b/tc-subxt/src/api/tasks.rs @@ -3,7 +3,8 @@ use crate::{metadata_scope, SubxtClient}; use anyhow::Result; use futures::channel::oneshot; use time_primitives::{ - BatchId, GatewayMessage, MessageId, NetworkId, PublicKey, ShardId, Task, TaskId, TaskResult, + BatchId, ErrorMsg, GatewayMessage, MessageId, NetworkId, PublicKey, ShardId, Task, TaskId, + TaskResult, }; impl SubxtClient { @@ -56,11 +57,16 @@ impl SubxtClient { }) } - pub async fn task_output(&self, task_id: TaskId) -> Result>> { + pub async fn task_output(&self, task_id: TaskId) -> Result>> { metadata_scope!(self.metadata, { let storage_query = metadata::storage().tasks().task_output(task_id); let output = self.client.storage().at_latest().await?.fetch(&storage_query).await?; - Ok(output) + let output_converted = match output { + Some(Ok(())) => Some(Ok(())), + Some(Err(static_err)) => Some(Err((*static_err).clone())), + None => None, + }; + Ok(output_converted) }) } diff --git a/tc-subxt/src/worker.rs b/tc-subxt/src/worker.rs index 76e5f887f..9e4d3fb1b 100644 --- a/tc-subxt/src/worker.rs +++ b/tc-subxt/src/worker.rs @@ -172,6 +172,7 @@ impl SubxtWorker { commitment, proof_of_knowledge, } => { + let commitment = subxt::utils::Static(commitment); let payload = metadata::tx().shards().commit(shard_id, commitment, proof_of_knowledge); self.create_signed_payload(&payload).await