Skip to content

Commit 3d78ce7

Browse files
committed
ensure minting funds after falliable checks and skip transfer checks on XDM when disabled
1 parent b8015ee commit 3d78ce7

File tree

11 files changed

+57
-15
lines changed

11 files changed

+57
-15
lines changed

crates/pallet-domains/src/lib.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use alloc::boxed::Box;
3535
use alloc::collections::btree_map::BTreeMap;
3636
#[cfg(not(feature = "std"))]
3737
use alloc::vec::Vec;
38+
use core::marker::PhantomData;
3839
use domain_runtime_primitives::EthereumAccountId;
3940
use frame_support::ensure;
4041
use frame_support::pallet_prelude::{RuntimeDebug, StorageVersion};
@@ -52,9 +53,10 @@ use sp_consensus_subspace::WrappedPotOutput;
5253
use sp_core::H256;
5354
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
5455
use sp_domains::{
55-
DomainBundleLimit, DomainId, DomainInstanceData, ExecutionReceipt, OpaqueBundle, OperatorId,
56-
OperatorPublicKey, OperatorRewardSource, OperatorSignature, ProofOfElection, RuntimeId,
57-
SealedSingletonReceipt, DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT, EMPTY_EXTRINSIC_ROOT,
56+
ChainId, DomainBundleLimit, DomainId, DomainInstanceData, ExecutionReceipt, OpaqueBundle,
57+
OperatorId, OperatorPublicKey, OperatorRewardSource, OperatorSignature, ProofOfElection,
58+
RuntimeId, SealedSingletonReceipt, DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT,
59+
EMPTY_EXTRINSIC_ROOT,
5860
};
5961
use sp_domains_fraud_proof::fraud_proof::{
6062
DomainRuntimeCodeAt, FraudProof, FraudProofVariant, InvalidBlockFeesProof,
@@ -171,6 +173,19 @@ impl<O: Into<Result<RawOrigin, O>> + From<RawOrigin>> EnsureOrigin<O> for Ensure
171173
}
172174
}
173175

176+
/// Impl the sp_domains::SkipBalanceChecks for Domains.
177+
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
178+
pub struct DomainsSkipBalanceChecks<T>(PhantomData<T>);
179+
180+
impl<T: Config> sp_domains::SkipBalanceChecks for DomainsSkipBalanceChecks<T> {
181+
fn should_skip_balance_check(chain_id: ChainId) -> bool {
182+
match chain_id {
183+
ChainId::Consensus => false,
184+
ChainId::Domain(domain_id) => SkipBalanceChecks::<T>::get().contains(&domain_id),
185+
}
186+
}
187+
}
188+
174189
/// The current storage version.
175190
const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);
176191

crates/sp-domains/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,16 @@ pub enum OperatorRewardSource<Number> {
16221622
Dummy,
16231623
}
16241624

1625+
pub trait SkipBalanceChecks {
1626+
fn should_skip_balance_check(chain_id: ChainId) -> bool;
1627+
}
1628+
1629+
impl SkipBalanceChecks for () {
1630+
fn should_skip_balance_check(_chain_id: ChainId) -> bool {
1631+
false
1632+
}
1633+
}
1634+
16251635
sp_api::decl_runtime_apis! {
16261636
/// APIs used to access the domains pallet.
16271637
// When updating this version, document new APIs with "Only present in API versions" comments.

crates/subspace-runtime/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ impl pallet_transporter::Config for Runtime {
808808
type Sender = Messenger;
809809
type AccountIdConverter = AccountIdConverter;
810810
type WeightInfo = pallet_transporter::weights::SubstrateWeight<Runtime>;
811+
type SkipBalanceTransferChecks = pallet_domains::DomainsSkipBalanceChecks<Runtime>;
811812
}
812813

813814
parameter_types! {

domains/pallets/messenger/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ macro_rules! impl_runtime {
180180
type Sender = Messenger;
181181
type AccountIdConverter = MockAccountIdConverter;
182182
type WeightInfo = ();
183+
type SkipBalanceTransferChecks = ();
183184
}
184185

185186
pub const USER_ACCOUNT: AccountId = 1;

domains/pallets/transporter/src/lib.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use frame_support::traits::Currency;
3737
pub use pallet::*;
3838
use parity_scale_codec::{Decode, Encode};
3939
use scale_info::TypeInfo;
40-
use sp_domains::{DomainId, DomainsTransfersTracker, Transfers};
40+
use sp_domains::{DomainId, DomainsTransfersTracker, SkipBalanceChecks, Transfers};
4141
use sp_messenger::endpoint::EndpointResponse;
4242
use sp_messenger::messages::ChainId;
4343
use sp_messenger::NoteChainTransfer;
@@ -83,7 +83,7 @@ mod pallet {
8383
use frame_support::weights::Weight;
8484
use frame_system::pallet_prelude::*;
8585
use parity_scale_codec::{Decode, Encode};
86-
use sp_domains::{DomainId, DomainsTransfersTracker, Transfers};
86+
use sp_domains::{DomainId, DomainsTransfersTracker, SkipBalanceChecks, Transfers};
8787
use sp_messenger::endpoint::{
8888
Endpoint, EndpointHandler as EndpointHandlerT, EndpointId, EndpointRequest,
8989
EndpointResponse, Sender,
@@ -114,6 +114,9 @@ mod pallet {
114114

115115
/// Weight information for extrinsics in this pallet.
116116
type WeightInfo: WeightInfo;
117+
118+
/// Skip Balance transfer checks
119+
type SkipBalanceTransferChecks: SkipBalanceChecks;
117120
}
118121

119122
/// Pallet transporter to move funds between chains.
@@ -348,7 +351,9 @@ mod pallet {
348351
// if this is consensus chain, then reject the transfer
349352
// else update the Transfers storage with rejected transfer
350353
if T::SelfChainId::get().is_consensus_chain() {
351-
Pallet::<T>::reject_transfer(src_chain_id, T::SelfChainId::get(), amount)?;
354+
if !T::SkipBalanceTransferChecks::should_skip_balance_check(src_chain_id) {
355+
Pallet::<T>::reject_transfer(src_chain_id, T::SelfChainId::get(), amount)?;
356+
}
352357
} else {
353358
ChainTransfers::<T>::try_mutate(|transfers| {
354359
Pallet::<T>::update_transfer_rejected(transfers, src_chain_id, amount)
@@ -397,16 +402,17 @@ mod pallet {
397402
let account_id =
398403
T::AccountIdConverter::try_convert_back(transfer.sender.account_id)
399404
.ok_or(Error::<T>::InvalidAccountId)?;
400-
let _imbalance = T::Currency::deposit_creating(&account_id, transfer.amount);
401405

402406
// if this is consensus chain, then revert the transfer
403407
// else update the Transfers storage with reverted transfer
404408
if T::SelfChainId::get().is_consensus_chain() {
405-
Pallet::<T>::claim_rejected_transfer(
406-
T::SelfChainId::get(),
407-
dst_chain_id,
408-
transfer.amount,
409-
)?;
409+
if !T::SkipBalanceTransferChecks::should_skip_balance_check(dst_chain_id) {
410+
Pallet::<T>::claim_rejected_transfer(
411+
T::SelfChainId::get(),
412+
dst_chain_id,
413+
transfer.amount,
414+
)?;
415+
}
410416
} else {
411417
ChainTransfers::<T>::try_mutate(|transfers| {
412418
Pallet::<T>::update_transfer_revert(
@@ -417,6 +423,7 @@ mod pallet {
417423
})?;
418424
}
419425

426+
let _imbalance = T::Currency::deposit_creating(&account_id, transfer.amount);
420427
frame_system::Pallet::<T>::deposit_event(
421428
Into::<<T as Config>::RuntimeEvent>::into(
422429
Event::<T>::OutgoingTransferFailed {
@@ -606,18 +613,20 @@ impl<T: Config> Pallet<T> {
606613
let account_id = T::AccountIdConverter::try_convert_back(req.receiver.account_id)
607614
.ok_or(Error::<T>::InvalidAccountId)?;
608615

609-
let _imbalance = T::Currency::deposit_creating(&account_id, req.amount);
610-
611616
// if this is consensus chain, then confirm the transfer
612617
// else add transfer to storage to send through ER to consensus chain
613618
if T::SelfChainId::get().is_consensus_chain() {
614-
Pallet::<T>::confirm_transfer(src_chain_id, T::SelfChainId::get(), req.amount)?
619+
if !T::SkipBalanceTransferChecks::should_skip_balance_check(src_chain_id) {
620+
Pallet::<T>::confirm_transfer(src_chain_id, T::SelfChainId::get(), req.amount)?
621+
}
615622
} else {
616623
ChainTransfers::<T>::try_mutate(|transfers| {
617624
Pallet::<T>::update_transfer_in(transfers, src_chain_id, req.amount)
618625
})?;
619626
}
620627

628+
let _imbalance = T::Currency::deposit_creating(&account_id, req.amount);
629+
621630
frame_system::Pallet::<T>::deposit_event(Into::<<T as Config>::RuntimeEvent>::into(
622631
Event::<T>::IncomingTransferSuccessful {
623632
chain_id: src_chain_id,

domains/pallets/transporter/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl Config for MockRuntime {
171171
type Sender = Messenger;
172172
type AccountIdConverter = MockAccountIdConverter;
173173
type WeightInfo = ();
174+
type SkipBalanceTransferChecks = ();
174175
}
175176

176177
pub const USER_ACCOUNT: AccountId = 1;

domains/runtime/auto-id/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ impl pallet_transporter::Config for Runtime {
470470
type Sender = Messenger;
471471
type AccountIdConverter = domain_runtime_primitives::AccountIdConverter;
472472
type WeightInfo = pallet_transporter::weights::SubstrateWeight<Runtime>;
473+
type SkipBalanceTransferChecks = ();
473474
}
474475

475476
impl pallet_domain_id::Config for Runtime {}

domains/runtime/evm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ impl pallet_transporter::Config for Runtime {
617617
type Sender = Messenger;
618618
type AccountIdConverter = domain_runtime_primitives::AccountId20Converter;
619619
type WeightInfo = pallet_transporter::weights::SubstrateWeight<Runtime>;
620+
type SkipBalanceTransferChecks = ();
620621
}
621622

622623
impl pallet_evm_chain_id::Config for Runtime {}

domains/test/runtime/auto-id/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ impl pallet_transporter::Config for Runtime {
468468
type Sender = Messenger;
469469
type AccountIdConverter = domain_runtime_primitives::AccountIdConverter;
470470
type WeightInfo = pallet_transporter::weights::SubstrateWeight<Runtime>;
471+
type SkipBalanceTransferChecks = ();
471472
}
472473

473474
impl pallet_domain_id::Config for Runtime {}

domains/test/runtime/evm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ impl pallet_transporter::Config for Runtime {
655655
type Sender = Messenger;
656656
type AccountIdConverter = domain_runtime_primitives::AccountId20Converter;
657657
type WeightInfo = pallet_transporter::weights::SubstrateWeight<Runtime>;
658+
type SkipBalanceTransferChecks = ();
658659
}
659660

660661
impl pallet_evm_chain_id::Config for Runtime {}

test/subspace-test-runtime/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ impl pallet_transporter::Config for Runtime {
764764
type Sender = Messenger;
765765
type AccountIdConverter = AccountIdConverter;
766766
type WeightInfo = pallet_transporter::weights::SubstrateWeight<Runtime>;
767+
type SkipBalanceTransferChecks = ();
767768
}
768769

769770
parameter_types! {

0 commit comments

Comments
 (0)