Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bound extrinsic inputs #1185

Merged
merged 32 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8e6902b
init by starting to bound all task pallet extrinsics
4meta5 Oct 7, 2024
332021d
tasks pallet unit tests and benchmarking updated with boundedvecs
4meta5 Oct 7, 2024
3106d5a
rm strings from tasksapi and runtimeapis altogether
4meta5 Oct 7, 2024
533c7ce
bound shard commitment
4meta5 Oct 7, 2024
ec02eac
update shards benchmark to use bounded commitment
4meta5 Oct 7, 2024
334feff
network register network replace unbounded strings
4meta5 Oct 7, 2024
0685724
dmail bound path and to fields
4meta5 Oct 7, 2024
af487d6
Merge branch 'development' into amar-bound-tx-inputs-postv2
4meta5 Oct 8, 2024
f6279ca
fix
4meta5 Oct 8, 2024
5805057
runtimes: update pallet weights
github-actions[bot] Oct 9, 2024
acac726
Merge branch 'development' into amar-bound-tx-inputs-postv2
4meta5 Oct 11, 2024
bf9bc8e
fix testnet test setup for network struct
4meta5 Oct 11, 2024
496bd60
fix
4meta5 Oct 11, 2024
71bc841
fix another merge conflict
4meta5 Oct 11, 2024
d7d6c0f
runtimes: update pallet weights
github-actions[bot] Oct 11, 2024
623b60e
Merge branch 'development' into amar-bound-tx-inputs-postv2
4meta5 Oct 12, 2024
6236bd4
runtimes: update pallet weights
github-actions[bot] Oct 12, 2024
7340918
Update shard.rs
4meta5 Oct 12, 2024
16ff0af
Merge branch 'development' into amar-bound-tx-inputs-postv2
4meta5 Oct 15, 2024
673055c
Update subxt to bounded types (#1212)
4meta5 Oct 17, 2024
182d349
Merge branch 'development' into amar-bound-tx-inputs-postv2
4meta5 Oct 17, 2024
d927cfc
Merge branch 'amar-bound-tx-inputs-postv2' of https://github.com/Anal…
4meta5 Oct 17, 2024
9cc220b
Merge branch 'development' into amar-bound-tx-inputs-postv2
4meta5 Oct 17, 2024
e71d41c
fix
4meta5 Oct 17, 2024
e0240f5
try fix subxt didnt learn shit just wasted time and therefore analogs…
4meta5 Oct 17, 2024
f90ce92
runtimes: update pallet weights
github-actions[bot] Oct 17, 2024
8ce3e13
deref and clone to convert static to t
4meta5 Oct 17, 2024
e338d7b
Merge branch 'amar-bound-tx-inputs-postv2' of https://github.com/Anal…
4meta5 Oct 17, 2024
d79707f
ok clippy chill
4meta5 Oct 17, 2024
f6a6f41
update chronicle
4meta5 Oct 18, 2024
252cf6c
update tc cli
4meta5 Oct 18, 2024
06918f6
update chronicle mock and tests
4meta5 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions pallets/dmail/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ use crate::Pallet;

use scale_info::prelude::string::String;

use frame_system::RawOrigin;
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 scale_codec::Encode;
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();
Expand All @@ -27,7 +22,9 @@ benchmarks! {
for _ in 0..b {
path.push('b');
}
}: _(RawOrigin::Signed(caller), to, path)
let to = DmailTo::truncate_from(to.as_str().encode());
let path = DmailPath::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);
Expand Down
6 changes: 3 additions & 3 deletions pallets/dmail/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use polkadot_sdk::{frame_support, frame_system};

use frame_support::assert_ok;
use frame_system::RawOrigin;

use scale_codec::Encode;
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::truncate_from("Self".encode());
let path: DmailPath = DmailPath::truncate_from("//self".encode());
let sender: AccountId = [1; 32].into();
let event = DmailMessage {
owner: sender.clone(),
Expand Down
16 changes: 8 additions & 8 deletions pallets/networks/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::Pallet;
use frame_system::RawOrigin;
use polkadot_sdk::frame_benchmarking::benchmarks;
use polkadot_sdk::frame_system;
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 time_primitives::{
ChainName, ChainNetwork, Network, NetworkConfig, CHAIN_NAME_LEN, CHAIN_NET_LEN,
};

fn mock_network_config() -> NetworkConfig {
NetworkConfig {
Expand All @@ -22,8 +22,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::truncate_from(chain_name.as_str().encode()),
chain_network: ChainNetwork::truncate_from(chain_network.as_str().encode()),
gateway: [0; 32],
gateway_block: 99,
config: mock_network_config(),
Expand All @@ -32,8 +32,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 {
Expand Down
7 changes: 4 additions & 3 deletions pallets/networks/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ 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 scale_codec::Encode;
use time_primitives::{ChainName, ChainNetwork, Network, NetworkConfig};

fn mock_network_config() -> NetworkConfig {
NetworkConfig {
Expand All @@ -17,8 +18,8 @@ fn mock_network_config() -> NetworkConfig {
fn mock_network() -> Network {
Network {
id: 42,
chain_name: "Ethereum".into(),
chain_network: "Mainnet".into(),
chain_name: ChainName::truncate_from("Ethereum".encode()),
chain_network: ChainNetwork::truncate_from("Mainnet".encode()),
gateway: [0; 32],
gateway_block: 99,
config: mock_network_config(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/shards/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn get_commitment(member: [u8; 32]) -> Commitment {
panic!("Invalid member")
},
};
vec![commitment]
Commitment::truncate_from(vec![commitment])
}
pub fn get_proof_of_knowledge(member: [u8; 32]) -> ProofOfKnowledge {
match member {
Expand Down
2 changes: 1 addition & 1 deletion pallets/shards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub mod pallet {
///
/// # Flow
/// 1. Retrieve and return the commitment from [`ShardCommitment`] storage.
pub fn get_shard_commitment(shard_id: ShardId) -> Option<Vec<TssPublicKey>> {
pub fn get_shard_commitment(shard_id: ShardId) -> Option<Commitment> {
ShardCommitment::<T>::get(shard_id)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/shards/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use schnorr_evm::proof_of_knowledge::construct_proof_of_knowledge;
use schnorr_evm::VerifyingKey;

use time_primitives::{
AccountId, NetworkId, PeerId, PublicKey, ShardId, ShardStatus, ShardsInterface,
AccountId, Commitment, NetworkId, PeerId, PublicKey, ShardId, ShardStatus, ShardsInterface,
};

const ETHEREUM: NetworkId = 0;
Expand Down Expand Up @@ -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::truncate_from(member.commitment(threshold)),
member.proof_of_knowledge(),
));
roll(1);
Expand Down Expand Up @@ -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::truncate_from(member.commitment(threshold)),
member.proof_of_knowledge(),
));
}
Expand Down
8 changes: 4 additions & 4 deletions pallets/tasks/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use pallet_shards::{ShardCommitment, ShardState};
use polkadot_sdk::{frame_benchmarking, frame_support, frame_system, sp_std};
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
Expand All @@ -32,7 +32,7 @@ fn create_simple_task<T: Config + pallet_shards::Config>() {
1,
);
ShardState::<T>::insert(0, ShardStatus::Online);
ShardCommitment::<T>::insert(0, vec![PUBKEY]);
ShardCommitment::<T>::insert(0, Commitment::truncate_from(vec![PUBKEY]));
Pallet::<T>::shard_online(0, ETHEREUM);
Pallet::<T>::create_task(ETHEREUM, Task::ReadGatewayEvents { blocks: 0..10 });
}
Expand All @@ -45,7 +45,7 @@ benchmarks! {
create_simple_task::<T>();
Pallet::<T>::assign_task(0, 0);
Pallet::<T>::on_initialize(frame_system::Pallet::<T>::block_number());
let result = TaskResult::ReadGatewayEvents { events: vec![], signature: SIGNATURE };
let result = TaskResult::ReadGatewayEvents { events: GmpEvents::truncate_from(vec![]), signature: SIGNATURE };
}: _(RawOrigin::Signed([0u8; 32].into()), 0, result) verify {}

schedule_tasks {
Expand Down
13 changes: 6 additions & 7 deletions pallets/tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};

Expand Down Expand Up @@ -194,7 +193,7 @@ pub mod pallet {

#[pallet::storage]
pub type TaskOutput<T: Config> =
StorageMap<_, Blake2_128Concat, TaskId, Result<(), String>, OptionQuery>;
StorageMap<_, Blake2_128Concat, TaskId, Result<(), ErrorMsg>, OptionQuery>;

#[pallet::storage]
pub type TaskNetwork<T: Config> =
Expand Down Expand Up @@ -245,7 +244,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
Expand Down Expand Up @@ -414,7 +413,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::<T>::insert(task_id, result.clone());
if let Some(shard) = TaskShard::<T>::take(task_id) {
ShardTasks::<T>::remove(shard, task_id);
Expand Down Expand Up @@ -614,7 +613,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<Result<(), String>> {
pub fn get_task_result(task_id: TaskId) -> Option<Result<(), ErrorMsg>> {
TaskOutput::<T>::get(task_id)
}

Expand Down
20 changes: 13 additions & 7 deletions pallets/tasks/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use frame_support::assert_ok;
use frame_system::RawOrigin;
use pallet_shards::{ShardCommitment, ShardState};
use polkadot_sdk::{frame_support, frame_system};
use scale_codec::Encode;
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;
Expand All @@ -20,7 +21,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::<Test>::insert(shard_id, vec![pub_key]);
ShardCommitment::<Test>::insert(shard_id, Commitment::truncate_from(vec![pub_key]));
ShardState::<Test>::insert(shard_id, ShardStatus::Online);
Tasks::shard_online(shard_id, network);
shard_id
Expand All @@ -42,7 +43,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::truncate_from(events.to_vec()),
signature,
};
assert_ok!(Tasks::submit_task_result(
Expand All @@ -56,7 +57,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::truncate_from(error.encode())
}
));
}

Expand Down Expand Up @@ -225,7 +228,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::truncate_from("error message".encode())))
);
})
}

Expand Down
11 changes: 7 additions & 4 deletions primitives/src/dmail.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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;
pub type DmailTo = BoundedVec<u8, ConstU32<DMAIL_TO_LEN>>;
pub type DmailPath = BoundedVec<u8, ConstU32<DMAIL_PATH_LEN>>;

#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Clone, Debug)]
pub struct DmailMessage {
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sp_api::decl_runtime_apis! {
fn get_task(task_id: TaskId) -> Option<Task>;
fn get_task_shard(task_id: TaskId) -> Option<ShardId>;
fn get_task_submitter(task_id: TaskId) -> Option<PublicKey>;
fn get_task_result(task_id: TaskId) -> Option<Result<(), String>>;
fn get_task_result(task_id: TaskId) -> Option<Result<(), ErrorMsg>>;
fn get_batch_message(batch_id: BatchId) -> Option<GatewayMessage>;
}

Expand Down
9 changes: 6 additions & 3 deletions primitives/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;
pub type ChainName = BoundedVec<u8, ConstU32<CHAIN_NAME_LEN>>;
pub type ChainNetwork = BoundedVec<u8, ConstU32<CHAIN_NET_LEN>>;

#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo, Serialize, Deserialize)]
pub struct Network {
Expand Down
6 changes: 5 additions & 1 deletion primitives/src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ 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};

use scale_codec::{Decode, Encode};
use scale_info::prelude::vec::Vec;
use scale_info::TypeInfo;

/// Absolute 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<TssPublicKey>;
pub type Commitment = BoundedVec<TssPublicKey, ConstU32<MAX_SHARD_SIZE>>;

#[cfg(feature = "std")]
pub mod serde_tss_public_key {
Expand Down
Loading