-
Notifications
You must be signed in to change notification settings - Fork 1.6k
XCM v2: Scripting, Query responses, Exception handling and Error reporting #3629
Conversation
Also some minor fix for v0/v1
|
What will happen to https://github.com/paritytech/xcm-format ? Do we want to keep it up to date? Definitely need some RPC or something to help estimate weights on dest chain. The name This assumes transaction_version remains the same. Maybe it should be included in the payload somewhere to assert that's the case? |
| pub type Result = result::Result<(), Error>; | ||
|
|
||
| /// Local weight type; execution time in picoseconds. | ||
| pub type Weight = u64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really dumb question: did we decide that we can't reuse the weights system in FRAME, and thus we have to define the Weight type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XCM is independent of Frame.
Yes.
Exporting the
Not sure what you mean here. We already have polkadot-fellows/xcm-format#22 as a later change to manage transction versioning for |
KiChjang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see any big issues with functionality, only some observations and comments on them. They don't really block this PR from landing, so I'm approving.
shawntabrizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing too controversial here from a first pass. will be able to look deeper as i complete and merge my weight pr
|
I made a note that probably we want to use |
* master: staking-miner: remove need of a file to pass the seed (#3680) Companion for 9619 (Private Events) (#3712) Fix Try-Runtime (#3725) XCM v2: Scripting, Query responses, Exception handling and Error reporting (#3629) Bump async-trait from 0.1.50 to 0.1.51 (#3721) allow some overhead in MERKLE_NODE_MAX_SIZE (#3724) Bump itertools from 0.10.0 to 0.10.1 (#3719) Bump tokio from 1.10.0 to 1.10.1 (#3717) Bump trybuild from 1.0.43 to 1.0.45 (#3713) Don't err on deactivated leaf during valiation. (#3708) Bump libc from 0.2.99 to 0.2.100 (#3703)
Moves XCM away from a hybrid script/structured language and into a pure script model. This means no recusion and an equivalence between
Orderand instruction (Xcm).Advantages are:
BuyExecutionandReportOutcome.Disadvantages are:
holdingis now available to instructions as well as orders, and there are several other specialised registers.To alleviate the latter issue and especially if global machine state increases further, a later version of XCM may introduce instructions which utilise hierarchy to reduce global state.
Query responses
pallet_xcmcan (and probably should) now be used as anOnResponsehandler. Three functions are provided to create queries and poll for their response:new_query: A helper function to return a unique and registered query ID.take_response: A function to query and (if available) return the response of a previous XCM query created withnew_query.new_notify_query: A helper function to return a unique query ID registered to dispatch a given handler once the outcome is returned. Such a query cannot be polled withtake_responseas it will be forgotten as soon as it returns and has its handler called.Additional functions are provided for dealing with specifically outcome reporting (see later).
Exception handling
We now have an exception handling system built into the XCM executor; there are two new code registers in the VM state as well as a third register for storing an error. If regular code execution ends with an error, the error is placed in the Error Register and any XCM instructions in the Error Handler Register are removed from it and then executed. If the execution completes with no error then the Error Handler contents are cleared without being executed. Once there is no error handler to be executed (either due to the Error Handler Register being empty or because no error occured), then the Appendix Register is emptied and its code executed. This continues until there are no errors/error handler code, and no further code in the Appendix Register.
New XCM instructions:
SetAppendix: to set the Appendix (code) Register;SetErrorHandler: to set the Error Handler (code) Register.Weight management
The apparent (pre-execution) weight of the
SetAppendixandSetErrorHandlerinstructions include the weight of the inner code that they are setting the register to, even though it may never actually get executed. Once it becomes clear that some such code will not be executed, then the weight of that code is accrued into the surplus (and may be refunded with the use theRefundSurplusif previously purchased). This happens in two situations:Error (outcome) reporting and the Error Register
This introduces XCM instruction outcome reporting with two new API functions in
pallet_xcm::Palletto help use it:report_outcome_notify: A helper function which is able to alter a given XCM into one whose outcome (success/failure) will be passed into a provided handler (which must be a dispatchable function).report_outcome: A helper function which is able to alter a given XCM into one whose outcome (success/failure) will be recorded and is queryable by thetake_responsefunction. A query identifier is returned to be used as the argument totake_response.These functions work through the use of
SetAppendix(which allows code to be executed even if an error occurs), the Error Register andReportError(which sends an XCM ofQueryResponsecontaining the current value of the Error Register to the named destination).In general (should you wish to author your own XCM), the Error Register may be used with two new instructions
ReportErrorandClearError:ReportError: sends aQueryRepsonsewith the contents of the Error Register;ClearError: resets the Error Register;Additional changes
ClearOriginwhich removes the origin (thereby preventing further instructions from executing with its associated privileges, useful forInitiateTeleportandInitiateReserveWithdraw).Responsetype,Order::QueryBalanceandXcm::QueryResponse.All
Xcmitems andOrderitems are merged intoInstructionenum.Xcmbecomes a unit struct of inner typeVec<Instruction>.All
Xcmitems which included a fieldVec<Order>to be executed in the local context now have those fields removed (they're no longer needed since theOrders can be placed asInstructions immediately afterwards in theXcmvector). For the remote context,xcm: Xcmis used as the field name/type.Compatibility
v1messages can be auto-converted tov2provided:BuyExecution::instructionsis empty.RelayedFromis unused.v2messages can be auto-converted tov1provided:v1::Xcmitem is used for local execution in a singlev2::Xcmand it must be at the begining.BuyExecution::weight_limitisLimited.ClearOriginif used, may only follow immediately afterReceiveTeleportedAssetorReserveAssetDeposited. The latter two may not appear with it.DescendOrigin,ReportOutcome,RefundSurplusare not used.Migrating
XCM fragments
Xcm::andOrder::becomeInstruction::.orders/effectsfields describing effects on the remote side are renamedxcm.WithdrawAsset,ReceiveTeleportedAsset,DepositReserveAssethave noeffectsfield; contents should be moved to follow the instruction in the containingVec.BuyExecution:weight_limit, which replacesdebtandweight; it should be set toLimitedwith the inner value being the sum ofweightanddebt, or, alternatively justUnlimited.instructionsis not empty, then contents should be moved to followBuyExecutionin the containingVec.feesandweight.RelayedFrombecomesDescendOrigin;RelayedFrom::instructionremoved and contents should be moved to followRelayedFromin the containingVec.XCM Pallet
pallet_xcm::Confignow contains two more itemsOriginandCall; they should just be defined to the corresponding outer types:pallet_xcmhas a specialOriginwhich must be specified in theconstruct_runtime!macro.XCM builder tools
The
FixedWeightBoundstype now has an additional type argumentM: Get<u32>, which should provide the maximum number of instructions including for the contents of all code register set instructions (which are naturally recursive in nature with regards weight calculation). This limits the complexity of the weight calculation to something manageable, even in the face of recursive bombs of the form:Most of the time you should just change:
to:
and add a parameter type:
TODO
on_reportnew_querynew_query_notifyv1->v2v2->v1