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 all 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
1 change: 1 addition & 0 deletions state-chain/chains/src/btc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub enum PreviousOrCurrent {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BitcoinCrypto;
impl ChainCrypto for BitcoinCrypto {
const NAME: &'static str = "Bitcoin";
type UtxoChain = ConstBool<true>;

type AggKey = AggKey;
Expand Down
1 change: 1 addition & 0 deletions state-chain/chains/src/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ impl ChannelLifecycleHooks for PolkadotChannelState {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PolkadotCrypto;
impl ChainCrypto for PolkadotCrypto {
const NAME: &'static str = "Polkadot";
type UtxoChain = ConstBool<false>;

type AggKey = PolkadotPublicKey;
Expand Down
1 change: 1 addition & 0 deletions state-chain/chains/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct DepositDetails {
pub struct EvmCrypto;

impl ChainCrypto for EvmCrypto {
const NAME: &'static str = "EVM";
type UtxoChain = ConstBool<false>;

type AggKey = evm::AggKey;
Expand Down
1 change: 1 addition & 0 deletions state-chain/chains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ pub trait Chain: Member + Parameter + ChainInstanceAlias {

/// Common crypto-related types and operations for some external chain.
pub trait ChainCrypto: ChainCryptoInstanceAlias {
const NAME: &'static str;
type UtxoChain: Get<bool>;

/// The chain's `AggKey` format. The AggKey is the threshold key that controls the vault.
Expand Down
1 change: 1 addition & 0 deletions state-chain/chains/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ pub const BAD_AGG_KEY_POST_HANDOVER: MockAggKey = MockAggKey(*b"bad!");
#[derive(Copy, Clone, RuntimeDebug, Default, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct MockEthereumChainCrypto;
impl ChainCrypto for MockEthereumChainCrypto {
const NAME: &'static str = "MockEthereum";
type UtxoChain = ConstBool<false>;

type AggKey = MockAggKey;
Expand Down
1 change: 1 addition & 0 deletions state-chain/chains/src/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl FeeRefundCalculator<NoneChain> for () {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NoneChainCrypto;
impl ChainCrypto for NoneChainCrypto {
const NAME: &'static str = "None";
type UtxoChain = ConstBool<false>;
type AggKey = ();
type Payload = ();
Expand Down
1 change: 1 addition & 0 deletions state-chain/chains/src/sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Chain for Solana {
pub struct SolanaCrypto;

impl ChainCrypto for SolanaCrypto {
const NAME: &'static str = "Solana";
type UtxoChain = ConstBool<false>;
type KeyHandoverIsRequired = ConstBool<false>;

Expand Down
90 changes: 85 additions & 5 deletions state-chain/pallets/cf-threshold-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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_primitives::{
Expand Down Expand Up @@ -234,8 +234,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 +251,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 @@ -1199,6 +1197,88 @@ pub mod pallet {
}
}

macro_rules! append_chain_to_name {
($name:ident) => {
match T::TargetChainCrypto::NAME {
"EVM" => concat!(stringify!($name), "EVM"),
"Polkadot" => concat!(stringify!($name), "Polkadot"),
"Bitcoin" => concat!(stringify!($name), "Bitcoin"),
"Solana" => concat!(stringify!($name), "Solana"),
_ => concat!(stringify!($name), "Other"),
}
};
}

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>>()
.type_name(append_chain_to_name!(RequestContext))
.name("request_context")
})
.field(|f| {
f.ty::<BTreeSet<T::ValidatorId>>()
.type_name("BTreeSet<T::ValidatorId>")
.name("remaining_respondents")
})
.field(|f| {
f.ty::<BTreeMap<T::ValidatorId, AuthorityCount>>()
.type_name("BTreeMap<T::ValidatorId, AuthorityCount>")
.name("blame_counts")
})
.field(|f| {
f.ty::<BTreeSet<T::ValidatorId>>()
.type_name("BTreeSet<T::ValidatorId>")
.name("candidates")
})
.field(|f| f.ty::<EpochIndex>().type_name("EpochIndex").name("epoch"))
.field(|f| {
f.ty::<<T::TargetChainCrypto as ChainCrypto>::AggKey>()
.type_name(append_chain_to_name!(Key))
.name("key")
})
.field(|f| {
f.ty::<ThresholdCeremonyType>()
.type_name("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>().type_name("RequestId").name("request_id"))
.field(|f| {
f.ty::<AttemptCount>().type_name("AttemptCount").name("attempt_count")
})
.field(|f| {
f.ty::<PayloadFor<T, I>>()
.type_name(append_chain_to_name!(PayloadFor))
.name("payload")
}),
)
}
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Initiate a new signature request, returning the request id.
fn inner_request_signature(
Expand Down
Loading