Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ea646b5
introduce transactional processing for xcm instructions
vstam1 Mar 24, 2023
cb8930d
merge master
vstam1 Mar 31, 2023
334307b
add Executor rollback on instruction error
vstam1 Apr 5, 2023
b1c1686
add transactional processing on xcm instrutions
vstam1 Apr 5, 2023
672012b
fix tests
vstam1 Apr 5, 2023
2f249f6
add clone to FixedRateOfFungiable
vstam1 Apr 5, 2023
b97a9ef
fix tests
vstam1 Apr 5, 2023
3524945
add FrameTransactionalProcessor to xcm-builder mock
vstam1 Apr 6, 2023
3dbe380
fmt
vstam1 Apr 6, 2023
497d955
more tests
vstam1 Apr 6, 2023
f2abce5
merge master
vstam1 May 2, 2023
c65ef90
small comment
vstam1 May 2, 2023
91c29de
move to unsafe transactional processing for frame
vstam1 Jun 1, 2023
358d025
change FrameTransactionProcessor and merge master
vstam1 Jun 13, 2023
fa4ea4a
Merge remote-tracking branch 'origin/master' into vstam1/xcm-transact…
Jun 13, 2023
d1d97f5
merge master
vstam1 Aug 2, 2023
e1b0bd2
fmt
vstam1 Aug 2, 2023
1b24683
add bool to processing trait to consider the rollback of registers
vstam1 Aug 3, 2023
68bea8a
add comments
vstam1 Aug 3, 2023
9aa5831
Merge remote-tracking branch 'origin/master' into vstam1/xcm-transact…
Aug 3, 2023
8fbd67b
address feedback
vstam1 Aug 3, 2023
49359bc
address feedback on function name
vstam1 Aug 4, 2023
3fe888e
fix register cloning
vstam1 Aug 4, 2023
3f5a2ff
Merge remote-tracking branch 'origin/master' into vstam1/xcm-transact…
Aug 7, 2023
908fbf0
address feedback
vstam1 Aug 7, 2023
c4120b5
update vm cloning to only cloning specific registers
vstam1 Aug 24, 2023
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
9 changes: 5 additions & 4 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
WithComputedOrigin,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, FrameTransactionalProcessor,
IsChildSystemParachain, IsConcrete, MintLocation, OriginToPluralityVoice,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::traits::WithOriginFilter;

Expand Down Expand Up @@ -331,6 +331,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
type SafeCallFilter = SafeCallFilter;
type TransactionalProcessor = FrameTransactionalProcessor;
}

parameter_types! {
Expand Down
7 changes: 4 additions & 3 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter,
FixedWeightBounds, IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WithComputedOrigin,
FixedWeightBounds, FrameTransactionalProcessor, IsConcrete, MintLocation,
OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin,
};
use xcm_executor::traits::WithOriginFilter;

Expand Down Expand Up @@ -350,6 +350,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
type SafeCallFilter = SafeCallFilter;
type TransactionalProcessor = FrameTransactionalProcessor;
}

parameter_types! {
Expand Down
8 changes: 5 additions & 3 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, FrameTransactionalProcessor,
IsChildSystemParachain, IsConcrete, MintLocation, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WeightInfoBounds, WithComputedOrigin,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -308,6 +309,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
type SafeCallFilter = SafeCallFilter;
type TransactionalProcessor = FrameTransactionalProcessor;
}

parameter_types! {
Expand Down
8 changes: 5 additions & 3 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
CurrencyAdapter as XcmCurrencyAdapter, FrameTransactionalProcessor, IsChildSystemParachain,
IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
WithComputedOrigin,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -245,6 +246,7 @@ impl xcm_executor::Config for XcmConfig {
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
type SafeCallFilter = SafeCallFilter;
type TransactionalProcessor = FrameTransactionalProcessor;
}

/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location
Expand Down
3 changes: 3 additions & 0 deletions xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ pub use universal_exports::{
HaulBlobError, HaulBlobExporter, NetworkExportTable, SovereignPaidRemoteExporter,
UnpaidLocalExporter, UnpaidRemoteExporter,
};

mod transactional;
pub use transactional::FrameTransactionalProcessor;
44 changes: 44 additions & 0 deletions xcm/xcm-builder/src/transactional.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use frame_support::{
pallet_prelude::DispatchError,
storage::{with_transaction, TransactionOutcome},
};
use xcm::latest::prelude::*;
use xcm_executor::traits::ProcessTransaction;

pub struct FrameTransactionalProcessor;
impl ProcessTransaction for FrameTransactionalProcessor {
Comment thread
vstam1 marked this conversation as resolved.
fn process_transaction<F>(f: F) -> Result<(), XcmError>
where
F: FnOnce() -> Result<(), XcmError>,
{
let transaction_outcome =
with_transaction(|| -> TransactionOutcome<Result<_, DispatchError>> {
let outcome = f();
match &outcome {
Ok(_) => TransactionOutcome::Commit(Ok(None)),
Err(err) => TransactionOutcome::Rollback(Ok(Some(*err))),
Comment thread
vstam1 marked this conversation as resolved.
Outdated
}
});
match transaction_outcome {
Ok(None) => Ok(()),
Ok(Some(err)) => Err(err),
Err(err) => Err(XcmError::FailedToTransactAsset(err.into())),
Comment thread
vstam1 marked this conversation as resolved.
Outdated
}
}
}
6 changes: 4 additions & 2 deletions xcm/xcm-executor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

use crate::traits::{
AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm,
FeeManager, OnResponse, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds,
WeightTrader,
FeeManager, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset,
VersionChangeNotifier, WeightBounds, WeightTrader,
};
use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo, Parameter, PostDispatchInfo},
Expand Down Expand Up @@ -106,4 +106,6 @@ pub trait Config {
/// Use this type to explicitly whitelist calls that cannot undergo recursion. This is a
/// temporary measure until we properly account for proof size weights for XCM instructions.
type SafeCallFilter: Contains<Self::RuntimeCall>;

type TransactionalProcessor: ProcessTransaction;
Comment thread
KiChjang marked this conversation as resolved.
}
24 changes: 15 additions & 9 deletions xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use xcm::latest::prelude::*;
pub mod traits;
use traits::{
validate_export, AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin,
DropAssets, Enact, ExportXcm, FeeManager, FeeReason, OnResponse, ShouldExecute, TransactAsset,
VersionChangeNotifier, WeightBounds, WeightTrader,
DropAssets, Enact, ExportXcm, FeeManager, FeeReason, OnResponse, ProcessTransaction,
ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader,
};

mod assets;
Expand Down Expand Up @@ -473,13 +473,19 @@ impl<Config: config::Config> XcmExecutor<Config> {
);
match instr {
WithdrawAsset(assets) => {
// Take `assets` from the origin account (on-chain) and place in holding.
let origin = *self.origin_ref().ok_or(XcmError::BadOrigin)?;
for asset in assets.into_inner().into_iter() {
Config::AssetTransactor::withdraw_asset(&asset, &origin, Some(&self.context))?;
self.subsume_asset(asset)?;
}
Ok(())
Config::TransactionalProcessor::process_transaction(|| -> Result<(), XcmError> {
Comment thread
vstam1 marked this conversation as resolved.
Outdated
// Take `assets` from the origin account (on-chain) and place in holding.
let origin = *self.origin_ref().ok_or(XcmError::BadOrigin)?;
for asset in assets.into_inner().into_iter() {
Config::AssetTransactor::withdraw_asset(
&asset,
&origin,
Some(&self.context),
)?;
self.subsume_asset(asset)?;
}
Ok(())
})
},
ReserveAssetDeposited(assets) => {
// check whether we trust origin to be our reserve location for this asset.
Expand Down
6 changes: 4 additions & 2 deletions xcm/xcm-executor/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub use token_matching::{
};
mod on_response;
pub use on_response::{OnResponse, VersionChangeNotifier};
mod process_transaction;
pub use process_transaction::ProcessTransaction;
mod should_execute;
pub use should_execute::ShouldExecute;
mod transact_asset;
Expand All @@ -51,7 +53,7 @@ pub mod prelude {
export_xcm, validate_export, AssetExchange, AssetLock, ClaimAssets, Convert, ConvertOrigin,
Decoded, DropAssets, Enact, Encoded, Error, ExportXcm, FeeManager, FeeReason, Identity,
JustTry, LockError, MatchesFungible, MatchesFungibles, MatchesNonFungible,
MatchesNonFungibles, OnResponse, ShouldExecute, TransactAsset, VersionChangeNotifier,
WeightBounds, WeightTrader, WithOriginFilter,
MatchesNonFungibles, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset,
VersionChangeNotifier, WeightBounds, WeightTrader, WithOriginFilter,
};
}
23 changes: 23 additions & 0 deletions xcm/xcm-executor/src/traits/process_transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
Comment thread
vstam1 marked this conversation as resolved.
Outdated
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use xcm::latest::prelude::*;

pub trait ProcessTransaction {
fn process_transaction<F>(f: F) -> Result<(), XcmError>
Comment thread
vstam1 marked this conversation as resolved.
Outdated
where
F: FnOnce() -> Result<(), XcmError>;
}