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

fix: scale types for pending ceremonies #5286

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
73 changes: 67 additions & 6 deletions state-chain/pallets/cf-threshold-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ mod response_status;
use response_status::ResponseStatus;

use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale_info::{build::Fields, Path, Type, TypeInfo};

use cf_chains::ChainCrypto;
use cf_chains::{Chain, ChainCrypto};
use cf_primitives::{
AuthorityCount, CeremonyId, EpochIndex, ThresholdSignatureRequestId as RequestId,
};
Expand Down Expand Up @@ -222,6 +222,7 @@ macro_rules! handle_key_ceremony_report {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use cf_chains::Chain;
use cf_primitives::FlipBalance;
use cf_traits::{
AccountRoleRegistry, AsyncResult, CfeMultisigRequest, ThresholdSignerNomination,
Expand All @@ -234,8 +235,7 @@ pub mod pallet {
};
use frame_system::ensure_none;
/// Context for tracking the progress of a threshold signature ceremony.
#[derive(Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, TypeInfo)]
#[scale_info(skip_type_params(T, I))]
#[derive(Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode)]
pub struct CeremonyContext<T: Config<I>, I: 'static> {
pub request_context: RequestContext<T, I>,
/// The respondents that have yet to reply.
Expand All @@ -252,8 +252,7 @@ pub mod pallet {
pub threshold_ceremony_type: ThresholdCeremonyType,
}

#[derive(Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, TypeInfo)]
#[scale_info(skip_type_params(T, I))]
#[derive(Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode)]
pub struct RequestContext<T: Config<I>, I: 'static> {
pub request_id: RequestId,
/// The number of ceremonies attempted so far, excluding the current one.
Expand Down Expand Up @@ -364,6 +363,8 @@ pub mod pallet {
/// A marker trait identifying the chain that we are signing for.
type TargetChainCrypto: ChainCrypto;

type TargetChain: Chain;

dandanlen marked this conversation as resolved.
Show resolved Hide resolved
/// trait to activate chains that use this pallet's key
type VaultActivator: VaultActivator<Self::TargetChainCrypto>;

Expand Down Expand Up @@ -1199,6 +1200,66 @@ pub mod pallet {
}
}

macro_rules! append_chain_to_name {
($name:ident) => {
match T::TargetChain::NAME {
"Ethereum" => concat!(stringify!($name), "Ethereum"),
"Polkadot" => concat!(stringify!($name), "Polkadot"),
"Bitcoin" => concat!(stringify!($name), "Bitcoin"),
"Arbitrum" => concat!(stringify!($name), "Arbitrum"),
"Solana" => concat!(stringify!($name), "Solana"),
_ => concat!(stringify!($name), "Other"),
}
dandanlen marked this conversation as resolved.
Show resolved Hide resolved
};
}

impl<T, I> TypeInfo for pallet::CeremonyContext<T, I>
where
T: Config<I>,
I: 'static,
{
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new(append_chain_to_name!(CeremonyContext), module_path!()))
.composite(
Fields::named()
.field(|f| {
f.ty::<RequestContext<T, I>>().name(append_chain_to_name!(RequestContext))
})
.field(|f| f.ty::<BTreeSet<T::ValidatorId>>().name("remaining_respondents"))
.field(|f| {
f.ty::<BTreeMap<T::ValidatorId, AuthorityCount>>().name("blame_counts")
})
.field(|f| f.ty::<BTreeSet<T::ValidatorId>>().name("candidates"))
.field(|f| f.ty::<EpochIndex>().name("epoch"))
.field(|f| {
f.ty::<<T::TargetChainCrypto as ChainCrypto>::AggKey>()
.name(append_chain_to_name!(Key))
})
.field(|f| f.ty::<ThresholdCeremonyType>().name("threshold_ceremony_type")),
)
}
}

impl<T, I> TypeInfo for pallet::RequestContext<T, I>
where
T: Config<I>,
I: 'static,
{
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new(append_chain_to_name!(RequestContext), module_path!()))
.composite(
Fields::named()
.field(|f| f.ty::<RequestId>().name("request_id"))
.field(|f| f.ty::<AttemptCount>().name("attempt_count"))
.field(|f| f.ty::<PayloadFor<T, I>>().name(append_chain_to_name!(PayloadFor))),
dandanlen marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Initiate a new signature request, returning the request id.
fn inner_request_signature(
Expand Down
3 changes: 2 additions & 1 deletion state-chain/pallets/cf-threshold-signature/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use cf_chains::{
mocks::{MockAggKey, MockEthereumChainCrypto, MockThresholdSignature},
ChainCrypto,
ChainCrypto, Ethereum,
};
use cf_primitives::{AuthorityCount, CeremonyId, FlipBalance, FLIPPERINOS_PER_FLIP, GENESIS_EPOCH};
use cf_traits::{
Expand Down Expand Up @@ -174,6 +174,7 @@ impl pallet_cf_threshold_signature::Config<Instance1> for Test {
type RuntimeOrigin = RuntimeOrigin;
type ThresholdCallable = MockCallback<MockEthereumChainCrypto>;
type TargetChainCrypto = MockEthereumChainCrypto;
type TargetChain = Ethereum;
type ThresholdSignerNomination = MockNominator;
type VaultActivator = MockVaultActivator;
type OffenceReporter = MockOffenceReporter;
Expand Down
4 changes: 4 additions & 0 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ impl pallet_cf_threshold_signature::Config<Instance16> for Runtime {
type ThresholdCallable = RuntimeCall;
type ThresholdSignerNomination = chainflip::RandomSignerNomination;
type TargetChainCrypto = EvmCrypto;
type TargetChain = Arbitrum;
dandanlen marked this conversation as resolved.
Show resolved Hide resolved
type VaultActivator = EvmVaultActivator<EthereumVault, ArbitrumVault>;
type OffenceReporter = Reputation;
type CeremonyRetryDelay = ConstU32<1>;
Expand All @@ -804,6 +805,7 @@ impl pallet_cf_threshold_signature::Config<Instance2> for Runtime {
type ThresholdCallable = RuntimeCall;
type ThresholdSignerNomination = chainflip::RandomSignerNomination;
type TargetChainCrypto = PolkadotCrypto;
type TargetChain = Polkadot;
type VaultActivator = PolkadotVault;
type OffenceReporter = Reputation;
type CeremonyRetryDelay = ConstU32<1>;
Expand All @@ -820,6 +822,7 @@ impl pallet_cf_threshold_signature::Config<Instance3> for Runtime {
type ThresholdCallable = RuntimeCall;
type ThresholdSignerNomination = chainflip::RandomSignerNomination;
type TargetChainCrypto = BitcoinCrypto;
type TargetChain = Bitcoin;
type VaultActivator = BitcoinVault;
type OffenceReporter = Reputation;
type CeremonyRetryDelay = ConstU32<1>;
Expand All @@ -836,6 +839,7 @@ impl pallet_cf_threshold_signature::Config<Instance5> for Runtime {
type ThresholdCallable = RuntimeCall;
type ThresholdSignerNomination = chainflip::RandomSignerNomination;
type TargetChainCrypto = SolanaCrypto;
type TargetChain = Solana;
type VaultActivator = SolanaVault;
type OffenceReporter = Reputation;
type CeremonyRetryDelay = ConstU32<1>;
Expand Down
Loading