@@ -71,19 +71,6 @@ enum TransferKind {
7171}
7272use TransferKind :: * ;
7373
74- #[ derive(
75- scale_info:: TypeInfo , Default , Encode , Decode , Clone , Eq , PartialEq , Debug , MaxEncodedLen , DecodeWithMemTracking ,
76- ) ]
77- pub enum MigrationPhase {
78- /// Not started
79- #[ default]
80- NotStarted ,
81- /// Started
82- InProgress ,
83- /// Completed
84- Completed ,
85- }
86-
8774#[ frame_support:: pallet]
8875pub mod module {
8976 use super :: * ;
@@ -148,14 +135,8 @@ pub mod module {
148135 /// The id of the RateLimiter.
149136 #[ pallet:: constant]
150137 type RateLimiterId : Get < <Self :: RateLimiter as RateLimiter >:: RateLimiterId > ;
151-
152- /// The origin that can change the migration phase.
153- type MigrationPhaseUpdateOrigin : EnsureOrigin < Self :: RuntimeOrigin > ;
154138 }
155139
156- #[ pallet:: storage]
157- pub type MigrationStatus < T : Config > = StorageValue < _ , MigrationPhase , ValueQuery > ;
158-
159140 #[ pallet:: event]
160141 #[ pallet:: generate_deposit( fn deposit_event) ]
161142 pub enum Event < T : Config > {
@@ -166,8 +147,6 @@ pub mod module {
166147 fee : Asset ,
167148 dest : Location ,
168149 } ,
169- /// Migration phase changed.
170- MigrationPhaseChanged { migration_phase : MigrationPhase } ,
171150 }
172151
173152 #[ pallet:: error]
@@ -416,17 +395,9 @@ pub mod module {
416395 Self :: do_transfer_assets ( who, assets. clone ( ) , fee. clone ( ) , dest, dest_weight_limit) . map ( |_| ( ) )
417396 }
418397
419- #[ pallet:: call_index( 6 ) ]
420- #[ pallet:: weight( frame_support:: weights:: Weight :: from_parts( 10000 , 0 ) ) ]
421- pub fn set_migration_phase ( origin : OriginFor < T > , migration_phase : MigrationPhase ) -> DispatchResult {
422- T :: MigrationPhaseUpdateOrigin :: ensure_origin ( origin) ?;
423-
424- MigrationStatus :: < T > :: set ( migration_phase. clone ( ) ) ;
425-
426- Self :: deposit_event ( Event :: < T > :: MigrationPhaseChanged { migration_phase } ) ;
427-
428- Ok ( ( ) )
429- }
398+ // #[pallet::call_index(6)]
399+ // pub fn set_migration_phase(origin: OriginFor<T>, migration_phase:
400+ // MigrationPhase) -> DispatchResult {}
430401 }
431402
432403 impl < T : Config > Pallet < T > {
@@ -598,7 +569,7 @@ pub mod module {
598569 if asset_len > 1 && fee_reserve != non_fee_reserve {
599570 // Current only support `ToReserve` with relay-chain asset as fee. other case
600571 // like `NonReserve` or `SelfReserve` with relay-chain fee is not support.
601- ensure ! ( non_fee_reserve == Self :: chain_part( & dest) , Error :: <T >:: InvalidAsset ) ;
572+ ensure ! ( non_fee_reserve == chain_part( & dest) , Error :: <T >:: InvalidAsset ) ;
602573
603574 let reserve_location = non_fee_reserve. clone ( ) . ok_or ( Error :: < T > :: AssetHasNoReserve ) ?;
604575 let min_xcm_fee = T :: MinXcmFee :: get ( & reserve_location) . ok_or ( Error :: < T > :: MinXcmFeeNotDefined ) ?;
@@ -623,7 +594,7 @@ pub mod module {
623594
624595 let mut override_recipient = T :: SelfLocation :: get ( ) ;
625596 if override_recipient == Location :: here ( ) {
626- let dest_chain_part = Self :: chain_part ( & dest) . ok_or ( Error :: < T > :: InvalidDest ) ?;
597+ let dest_chain_part = chain_part ( & dest) . ok_or ( Error :: < T > :: InvalidDest ) ?;
627598 let ancestry = T :: UniversalLocation :: get ( ) ;
628599 let _ = override_recipient
629600 . reanchor ( & dest_chain_part, & ancestry)
@@ -633,7 +604,7 @@ pub mod module {
633604 // First xcm sent to fee reserve chain and routed to dest chain.
634605 // We can use `MinXcmFee` configuration to decide which target parachain use
635606 // teleport. But as current there's only one case which is Parachain send back
636- // asset to Statemine/t , So we set `use_teleport` to always `true` in this case.
607+ // asset to AssetHub , So we set `use_teleport` to always `true` in this case.
637608 Self :: execute_and_send_reserve_kind_xcm (
638609 origin_location. clone ( ) ,
639610 assets_to_fee_reserve,
@@ -717,10 +688,12 @@ pub mod module {
717688 let mut hash = msg. using_encoded ( sp_io:: hashing:: blake2_256) ;
718689
719690 let weight = T :: Weigher :: weight ( & mut msg, Weight :: MAX ) . map_err ( |_| Error :: < T > :: UnweighableMessage ) ?;
720- T :: XcmExecutor :: prepare_and_execute ( origin_location, msg, & mut hash, weight, weight)
691+ T :: XcmExecutor :: prepare_and_execute ( origin_location. clone ( ) , msg. clone ( ) , & mut hash, weight, weight)
721692 . ensure_complete ( )
722693 . map_err ( |error| {
723- log:: error!( "Failed execute transfer message with {error:?}" ) ;
694+ log:: error!(
695+ "Failed execute transfer message with {error:?}, origin: {origin_location:?}, msg: {msg:?}"
696+ ) ;
724697 Error :: < T > :: XcmExecutionFailed
725698 } ) ?;
726699
@@ -850,7 +823,7 @@ pub mod module {
850823
851824 /// Ensure has the `dest` has chain part and recipient part.
852825 fn ensure_valid_dest ( dest : & Location ) -> Result < ( Location , Location ) , DispatchError > {
853- if let ( Some ( dest) , Some ( recipient) ) = ( Self :: chain_part ( dest) , Self :: non_chain_part ( dest) ) {
826+ if let ( Some ( dest) , Some ( recipient) ) = ( chain_part ( dest) , non_chain_part ( dest) ) {
854827 Ok ( ( dest, recipient) )
855828 } else {
856829 Err ( Error :: < T > :: InvalidDest . into ( ) )
@@ -896,41 +869,6 @@ pub mod module {
896869 let asset = assets. get ( reserve_idx) ;
897870 asset. and_then ( T :: ReserveProvider :: reserve)
898871 }
899-
900- /// Returns the "chain" location part. It could be parent, sibling
901- /// parachain, or child parachain.
902- pub fn chain_part ( location : & Location ) -> Option < Location > {
903- match ( location. parents , location. first_interior ( ) ) {
904- // sibling parachain
905- ( 1 , Some ( Parachain ( id) ) ) => Some ( Location :: new ( 1 , [ Parachain ( * id) ] ) ) ,
906- // parent
907- ( 1 , _) => match MigrationStatus :: < T > :: get ( ) {
908- // RelayChain
909- MigrationPhase :: NotStarted => Some ( Location :: parent ( ) ) ,
910- // Disable transfer when migration is in progress
911- MigrationPhase :: InProgress => None ,
912- // AssetHub
913- MigrationPhase :: Completed => Some ( Location :: new ( 1 , [ Parachain ( ASSET_HUB_ID ) ] ) ) ,
914- } ,
915- // children parachain
916- ( 0 , Some ( Parachain ( id) ) ) => Some ( Location :: new ( 0 , [ Parachain ( * id) ] ) ) ,
917- _ => None ,
918- }
919- }
920-
921- /// Returns "non-chain" location part.
922- pub fn non_chain_part ( location : & Location ) -> Option < Location > {
923- let mut junctions = location. interior ( ) . clone ( ) ;
924- while is_chain_junction ( junctions. first ( ) ) {
925- let _ = junctions. take_first ( ) ;
926- }
927-
928- if junctions != Here {
929- Some ( Location :: new ( 0 , junctions) )
930- } else {
931- None
932- }
933- }
934872 }
935873
936874 pub struct XtokensWeight < T > ( PhantomData < T > ) ;
@@ -1140,26 +1078,54 @@ fn is_chain_junction(junction: Option<&Junction>) -> bool {
11401078}
11411079
11421080// Provide reserve in absolute path view
1143- pub struct AbsoluteReserveProviderMigrationPhase < T > ( PhantomData < T > ) ;
1081+ pub struct AbsoluteReserveProvider ;
11441082
1145- impl < T : Config > Reserve for AbsoluteReserveProviderMigrationPhase < T > {
1083+ impl Reserve for AbsoluteReserveProvider {
11461084 fn reserve ( asset : & Asset ) -> Option < Location > {
11471085 let AssetId ( location) = & asset. id ;
1148- Pallet :: < T > :: chain_part ( location)
1086+ chain_part ( location)
11491087 }
11501088}
11511089
11521090// Provide reserve in relative path view
11531091// Self tokens are represeneted as Here
1154- pub struct RelativeReserveProviderMigrationPhase < T > ( PhantomData < T > ) ;
1092+ pub struct RelativeReserveProvider ;
11551093
1156- impl < T : Config > Reserve for RelativeReserveProviderMigrationPhase < T > {
1094+ impl Reserve for RelativeReserveProvider {
11571095 fn reserve ( asset : & Asset ) -> Option < Location > {
11581096 let AssetId ( location) = & asset. id ;
11591097 if location. parents == 0 && !is_chain_junction ( location. first_interior ( ) ) {
11601098 Some ( Location :: here ( ) )
11611099 } else {
1162- Pallet :: < T > :: chain_part ( location)
1100+ chain_part ( location)
11631101 }
11641102 }
11651103}
1104+
1105+ /// Returns the "chain" location part. It could be parent, sibling
1106+ /// parachain, or child parachain.
1107+ pub fn chain_part ( location : & Location ) -> Option < Location > {
1108+ match ( location. parents , location. first_interior ( ) ) {
1109+ // sibling parachain
1110+ ( 1 , Some ( Parachain ( id) ) ) => Some ( Location :: new ( 1 , [ Parachain ( * id) ] ) ) ,
1111+ // parent -> assethub
1112+ ( 1 , _) => Some ( Location :: new ( 1 , [ Parachain ( ASSET_HUB_ID ) ] ) ) ,
1113+ // children parachain
1114+ ( 0 , Some ( Parachain ( id) ) ) => Some ( Location :: new ( 0 , [ Parachain ( * id) ] ) ) ,
1115+ _ => None ,
1116+ }
1117+ }
1118+
1119+ /// Returns "non-chain" location part.
1120+ pub fn non_chain_part ( location : & Location ) -> Option < Location > {
1121+ let mut junctions = location. interior ( ) . clone ( ) ;
1122+ while is_chain_junction ( junctions. first ( ) ) {
1123+ let _ = junctions. take_first ( ) ;
1124+ }
1125+
1126+ if junctions != Here {
1127+ Some ( Location :: new ( 0 , junctions) )
1128+ } else {
1129+ None
1130+ }
1131+ }
0 commit comments