referrerpolicy=no-referrer-when-downgrade

pallet_xcm/
errors.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Errors for the XCM pallet.
18
19use codec::{Decode, DecodeWithMemTracking, Encode};
20use frame_support::PalletError;
21use scale_info::TypeInfo;
22use xcm::latest::Error as XcmError;
23
24#[derive(
25	Copy, Clone, Encode, Decode, DecodeWithMemTracking, Eq, PartialEq, Debug, TypeInfo, PalletError,
26)]
27pub enum ExecutionError {
28	// Errors that happen due to instructions being executed. These alone are defined in the
29	// XCM specification.
30	/// An arithmetic overflow happened.
31	#[codec(index = 0)]
32	Overflow,
33	/// The instruction is intentionally unsupported.
34	#[codec(index = 1)]
35	Unimplemented,
36	/// Origin Register does not contain a value value for a reserve transfer notification.
37	#[codec(index = 2)]
38	UntrustedReserveLocation,
39	/// Origin Register does not contain a value value for a teleport notification.
40	#[codec(index = 3)]
41	UntrustedTeleportLocation,
42	/// `MultiLocation` value too large to descend further.
43	#[codec(index = 4)]
44	LocationFull,
45	/// `MultiLocation` value ascend more parents than known ancestors of local location.
46	#[codec(index = 5)]
47	LocationNotInvertible,
48	/// The Origin Register does not contain a valid value for instruction.
49	#[codec(index = 6)]
50	BadOrigin,
51	/// The location parameter is not a valid value for the instruction.
52	#[codec(index = 7)]
53	InvalidLocation,
54	/// The given asset is not handled.
55	#[codec(index = 8)]
56	AssetNotFound,
57	/// An asset transaction (like withdraw or deposit) failed (typically due to type conversions).
58	#[codec(index = 9)]
59	FailedToTransactAsset,
60	/// An asset cannot be withdrawn, potentially due to lack of ownership, availability or rights.
61	#[codec(index = 10)]
62	NotWithdrawable,
63	/// An asset cannot be deposited under the ownership of a particular location.
64	#[codec(index = 11)]
65	LocationCannotHold,
66	/// Attempt to send a message greater than the maximum supported by the transport protocol.
67	#[codec(index = 12)]
68	ExceedsMaxMessageSize,
69	/// The given message cannot be translated into a format supported by the destination.
70	#[codec(index = 13)]
71	DestinationUnsupported,
72	/// Destination is routable, but there is some issue with the transport mechanism.
73	#[codec(index = 14)]
74	Transport,
75	/// Destination is known to be unroutable.
76	#[codec(index = 15)]
77	Unroutable,
78	/// Used by `ClaimAsset` when the given claim could not be recognized/found.
79	#[codec(index = 16)]
80	UnknownClaim,
81	/// Used by `Transact` when the functor cannot be decoded.
82	#[codec(index = 17)]
83	FailedToDecode,
84	/// Used by `Transact` to indicate that the given weight limit could be breached by the
85	/// functor.
86	#[codec(index = 18)]
87	MaxWeightInvalid,
88	/// Used by `BuyExecution` when the Holding Register does not contain payable fees.
89	#[codec(index = 19)]
90	NotHoldingFees,
91	/// Used by `BuyExecution` when the fees declared to purchase weight are insufficient.
92	#[codec(index = 20)]
93	TooExpensive,
94	/// Used by the `Trap` instruction to force an error intentionally. Its code is included.
95	#[codec(index = 21)]
96	Trap,
97	/// Used by `ExpectAsset`, `ExpectError` and `ExpectOrigin` when the expectation was not true.
98	#[codec(index = 22)]
99	ExpectationFalse,
100	/// The provided pallet index was not found.
101	#[codec(index = 23)]
102	PalletNotFound,
103	/// The given pallet's name is different to that expected.
104	#[codec(index = 24)]
105	NameMismatch,
106	/// The given pallet's version has an incompatible version to that expected.
107	#[codec(index = 25)]
108	VersionIncompatible,
109	/// The given operation would lead to an overflow of the Holding Register.
110	#[codec(index = 26)]
111	HoldingWouldOverflow,
112	/// The message was unable to be exported.
113	#[codec(index = 27)]
114	ExportError,
115	/// `MultiLocation` value failed to be reanchored.
116	#[codec(index = 28)]
117	ReanchorFailed,
118	/// No deal is possible under the given constraints.
119	#[codec(index = 29)]
120	NoDeal,
121	/// Fees were required which the origin could not pay.
122	#[codec(index = 30)]
123	FeesNotMet,
124	/// Some other error with locking.
125	#[codec(index = 31)]
126	LockError,
127	/// The state was not in a condition where the operation was valid to make.
128	#[codec(index = 32)]
129	NoPermission,
130	/// The universal location of the local consensus is improper.
131	#[codec(index = 33)]
132	Unanchored,
133	/// An asset cannot be deposited, probably because (too much of) it already exists.
134	#[codec(index = 34)]
135	NotDepositable,
136	/// Too many assets matched the given asset filter.
137	#[codec(index = 35)]
138	TooManyAssets,
139	// Errors that happen prior to instructions being executed. These fall outside of the XCM
140	// spec.
141	/// XCM version not able to be handled.
142	UnhandledXcmVersion,
143	/// Execution of the XCM would potentially result in a greater weight used than weight limit.
144	WeightLimitReached,
145	/// The XCM did not pass the barrier condition for execution.
146	///
147	/// The barrier condition differs on different chains and in different circumstances, but
148	/// generally it means that the conditions surrounding the message were not such that the chain
149	/// considers the message worth spending time executing. Since most chains lift the barrier to
150	/// execution on appropriate payment, presentation of an NFT voucher, or based on the message
151	/// origin, it means that none of those were the case.
152	Barrier,
153	/// The weight of an XCM message is not computable ahead of execution.
154	WeightNotComputable,
155	/// Recursion stack limit reached
156	// TODO(https://github.com/paritytech/polkadot-sdk/issues/6199): This should have a fixed index since
157	// we use it in `FrameTransactionalProcessor` // which is used in instructions.
158	// Or we should create a different error for that.
159	ExceedsStackLimit,
160}
161
162impl From<XcmError> for ExecutionError {
163	fn from(error: XcmError) -> Self {
164		match error {
165			XcmError::Overflow => Self::Overflow,
166			XcmError::Unimplemented => Self::Unimplemented,
167			XcmError::UntrustedReserveLocation => Self::UntrustedReserveLocation,
168			XcmError::UntrustedTeleportLocation => Self::UntrustedTeleportLocation,
169			XcmError::LocationFull => Self::LocationFull,
170			XcmError::LocationNotInvertible => Self::LocationNotInvertible,
171			XcmError::BadOrigin => Self::BadOrigin,
172			XcmError::InvalidLocation => Self::InvalidLocation,
173			XcmError::AssetNotFound => Self::AssetNotFound,
174			XcmError::FailedToTransactAsset(_) => Self::FailedToTransactAsset,
175			XcmError::NotWithdrawable => Self::NotWithdrawable,
176			XcmError::LocationCannotHold => Self::LocationCannotHold,
177			XcmError::ExceedsMaxMessageSize => Self::ExceedsMaxMessageSize,
178			XcmError::DestinationUnsupported => Self::DestinationUnsupported,
179			XcmError::Transport(_) => Self::Transport,
180			XcmError::Unroutable => Self::Unroutable,
181			XcmError::UnknownClaim => Self::UnknownClaim,
182			XcmError::FailedToDecode => Self::FailedToDecode,
183			XcmError::MaxWeightInvalid => Self::MaxWeightInvalid,
184			XcmError::NotHoldingFees => Self::NotHoldingFees,
185			XcmError::TooExpensive => Self::TooExpensive,
186			XcmError::Trap(_) => Self::Trap,
187			XcmError::ExpectationFalse => Self::ExpectationFalse,
188			XcmError::PalletNotFound => Self::PalletNotFound,
189			XcmError::NameMismatch => Self::NameMismatch,
190			XcmError::VersionIncompatible => Self::VersionIncompatible,
191			XcmError::HoldingWouldOverflow => Self::HoldingWouldOverflow,
192			XcmError::ExportError => Self::ExportError,
193			XcmError::ReanchorFailed => Self::ReanchorFailed,
194			XcmError::NoDeal => Self::NoDeal,
195			XcmError::FeesNotMet => Self::FeesNotMet,
196			XcmError::LockError => Self::LockError,
197			XcmError::NoPermission => Self::NoPermission,
198			XcmError::Unanchored => Self::Unanchored,
199			XcmError::NotDepositable => Self::NotDepositable,
200			XcmError::TooManyAssets => Self::TooManyAssets,
201			XcmError::UnhandledXcmVersion => Self::UnhandledXcmVersion,
202			XcmError::WeightLimitReached(_) => Self::WeightLimitReached,
203			XcmError::Barrier => Self::Barrier,
204			XcmError::WeightNotComputable => Self::WeightNotComputable,
205			XcmError::ExceedsStackLimit => Self::ExceedsStackLimit,
206		}
207	}
208}