Skip to content

Commit

Permalink
try fix errors in chronicle testing and update runtime imports and ty…
Browse files Browse the repository at this point in the history
…pes as well
  • Loading branch information
4meta5 committed Oct 16, 2024
1 parent fc46177 commit df2a815
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
22 changes: 11 additions & 11 deletions chronicle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use time_primitives::traits::IdentifyAccount;
use time_primitives::{
sr25519, AccountId, Balance, BatchId, BlockHash, BlockNumber, ChainName, ChainNetwork,
Commitment, Gateway, GatewayMessage, MemberStatus, NetworkId, PeerId, ProofOfKnowledge,
PublicKey, ShardId, ShardStatus, Task, TaskId, TaskResult,
sr25519, AccountId, Balance, BatchId, BlockHash, BlockNumber, Gateway, GatewayMessage,
MemberStatus, NetworkId, PeerId, ProofOfKnowledge, PublicKey, ShardId, ShardStatus, Task,
TaskId, TaskResult,
};
use tokio::time::Duration;
use tss::{sum_commitments, VerifiableSecretSharingCommitment, VerifyingKey};

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MockNetwork {
pub chain_name: ChainName,
pub chain_network: ChainNetwork,
pub chain_name: String,
pub chain_network: String,
}

impl MockNetwork {
pub fn new(chain_name: ChainName, chain_network: ChainNetwork) -> Self {
pub fn new(chain_name: String, chain_network: String) -> Self {
Self { chain_name, chain_network }
}
}
Expand All @@ -30,7 +30,7 @@ impl MockNetwork {
pub struct MockShard {
pub members: Vec<(AccountId, MemberStatus)>,
pub threshold: u16,
pub commitments: Vec<Commitment>,
pub commitments: Vec<Vec<TssPublicKey>>,
pub online: usize,
}

Expand Down Expand Up @@ -89,7 +89,7 @@ impl Mock {
mock
}

pub fn create_network(&self, chain_name: ChainName, chain_network: ChainNetwork) -> NetworkId {
pub fn create_network(&self, chain_name: String, chain_network: String) -> NetworkId {
let mock_network = MockNetwork::new(chain_name, chain_network);
let mut networks = self.networks.lock().unwrap();
if let Some(existing_id) =
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Runtime for Mock {
.boxed()
}

async fn get_network(&self, network: NetworkId) -> Result<Option<(ChainName, ChainNetwork)>> {
async fn get_network(&self, network: NetworkId) -> Result<Option<(String, String)>> {
Ok(self
.networks
.lock()
Expand Down Expand Up @@ -248,7 +248,7 @@ impl Runtime for Mock {
Ok(ShardStatus::Created)
}

async fn get_shard_commitment(&self, shard_id: ShardId) -> Result<Option<Commitment>> {
async fn get_shard_commitment(&self, shard_id: ShardId) -> Result<Option<Vec<TssPublicKey>>> {
let shards = self.shards.lock().unwrap();
let Some(shard) = shards.get(&shard_id) else {
return Ok(None);
Expand Down Expand Up @@ -318,7 +318,7 @@ impl Runtime for Mock {
async fn submit_commitment(
&self,
shard_id: ShardId,
commitment: Commitment,
commitment: Vec<TssPublicKey>,
_proof_of_knowledge: ProofOfKnowledge,
) -> Result<()> {
let mut shards = self.shards.lock().unwrap();
Expand Down
17 changes: 9 additions & 8 deletions runtimes/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ use sp_runtime::{
Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill, RuntimeDebug,
ApplyExtrinsicResult, BoundedVec, FixedPointNumber, Perbill, Percent, Permill, Perquintill,
RuntimeDebug,
};
use sp_std::prelude::*;
#[cfg(any(feature = "std", test))]
Expand All @@ -82,10 +83,10 @@ use sp_version::RuntimeVersion;
use static_assertions::const_assert;

pub use time_primitives::{
AccountId, Balance, BatchId, BlockHash, BlockNumber, ChainName, ChainNetwork, Commitment,
ErrorMsg, Gateway, GatewayMessage, MemberStatus, MembersInterface, Moment, NetworkId,
NetworksInterface, Nonce, PeerId, ProofOfKnowledge, PublicKey, ShardId, ShardStatus, Signature,
Task, TaskId, TaskResult, TssPublicKey, TssSignature, ANLOG,
AccountId, Balance, BatchId, BlockHash, BlockNumber, ChainNetwork, Gateway, GatewayMessage,
MemberStatus, MembersInterface, Moment, NetworkId, NetworksInterface, Nonce, PeerId,
ProofOfKnowledge, PublicKey, ShardId, ShardStatus, Signature, Task, TaskId, TaskResult,
TssPublicKey, TssSignature, ANLOG, MAX_ERROR_LEN, MAX_SHARD_SIZE,
};

/// weightToFee implementation
Expand Down Expand Up @@ -1898,7 +1899,7 @@ impl_runtime_apis! {
}

impl time_primitives::NetworksApi<Block> for Runtime {
fn get_network(network_id: NetworkId) -> Option<(ChainName, ChainNetwork)> {
fn get_network(network_id: NetworkId) -> Option<ChainNetwork> {
Networks::get_network(network_id)
}

Expand Down Expand Up @@ -1930,7 +1931,7 @@ impl_runtime_apis! {
Shards::get_shard_status(shard_id)
}

fn get_shard_commitment(shard_id: ShardId) -> Option<Commitment> {
fn get_shard_commitment(shard_id: ShardId) -> Option<BoundedVec<TssPublicKey, ConstU32<MAX_SHARD_SIZE>>> {
Shards::get_shard_commitment(shard_id)
}
}
Expand All @@ -1948,7 +1949,7 @@ impl_runtime_apis! {
Tasks::get_task_submitter(task_id)
}

fn get_task_result(task_id: TaskId) -> Option<Result<(), ErrorMsg>>{
fn get_task_result(task_id: TaskId) -> Option<Result<(), BoundedVec<u8, ConstU32<MAX_ERROR_LEN>>>> {
Tasks::get_task_result(task_id)
}

Expand Down
14 changes: 7 additions & 7 deletions runtimes/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ pub use runtime_common::{
};

pub use time_primitives::{
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,
AccountId, Balance, BatchId, BlockNumber, ChainNetwork, Gateway, GatewayMessage, MemberStatus,
MembersInterface, NetworkId, NetworksInterface, PeerId, ProofOfKnowledge, PublicKey, ShardId,
ShardStatus, Signature, Task, TaskId, TaskResult, TssPublicKey, TssSignature, ANLOG,
MAX_ERROR_LEN, MAX_ERROR_LEN, MAX_SHARD_SIZE,
};

// A few exports that help ease life for downstream crates.
Expand Down Expand Up @@ -1427,7 +1427,7 @@ impl_runtime_apis! {
}

impl time_primitives::NetworksApi<Block> for Runtime {
fn get_network(network_id: NetworkId) -> Option<(ChainName, ChainNetwork)> {
fn get_network(network_id: NetworkId) -> Option<ChainNetwork> {
Networks::get_network(network_id)
}

Expand Down Expand Up @@ -1459,7 +1459,7 @@ impl_runtime_apis! {
Shards::get_shard_status(shard_id)
}

fn get_shard_commitment(shard_id: ShardId) -> Option<Commitment> {
fn get_shard_commitment(shard_id: ShardId) -> Option<BoundedVec<TssPublicKey, ConstU32<MAX_SHARD_SIZE>>> {
Shards::get_shard_commitment(shard_id)
}
}
Expand All @@ -1481,7 +1481,7 @@ impl_runtime_apis! {
Tasks::get_task_submitter(task_id)
}

fn get_task_result(task_id: TaskId) -> Option<Result<(), ErrorMsg>>{
fn get_task_result(task_id: TaskId) -> Option<Result<(), BoundedVec<u8, ConstU32<MAX_ERROR_LEN>>>>{
Tasks::get_task_result(task_id)
}

Expand Down

0 comments on commit df2a815

Please sign in to comment.