This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
XCM v2: Scripting, Query responses, Exception handling and Error reporting #3629
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Also some minor fix for v0/v1
gavofyork
changed the title
XCM v2: Request responses & error reporting
XCM v2: Query responses & Error reporting
Aug 12, 2021
gavofyork
added
the
A3-in_progress
Pull request is in progress. No review needed at this stage.
label
Aug 12, 2021
47 tasks
Closed
KiChjang
reviewed
Aug 25, 2021
KiChjang
approved these changes
Aug 25, 2021
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
approved these changes
Aug 25, 2021
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 |
ordian
added a commit
that referenced
this pull request
Aug 26, 2021
ordian
added a commit
that referenced
this pull request
Aug 27, 2021
* 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)
6 tasks
17 tasks
19 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
A0-please_review
Pull request needs code review.
C1-low
PR touches the given topic and has a low impact on builders.
D9-needsaudit 👮
PR contains changes to fund-managing logic that should be properly reviewed and externally audited.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Moves XCM away from a hybrid script/structured language and into a pure script model. This means no recusion and an equivalence between
Order
and instruction (Xcm
).Advantages are:
BuyExecution
andReportOutcome
.Disadvantages are:
holding
is 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_xcm
can (and probably should) now be used as anOnResponse
handler. 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_response
as 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
SetAppendix
andSetErrorHandler
instructions 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 theRefundSurplus
if 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::Pallet
to 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_response
function. 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 ofQueryResponse
containing 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
ReportError
andClearError
:ReportError
: sends aQueryRepsonse
with the contents of the Error Register;ClearError
: resets the Error Register;Additional changes
ClearOrigin
which removes the origin (thereby preventing further instructions from executing with its associated privileges, useful forInitiateTeleport
andInitiateReserveWithdraw
).Response
type,Order::QueryBalance
andXcm::QueryResponse
.All
Xcm
items andOrder
items are merged intoInstruction
enum.Xcm
becomes a unit struct of inner typeVec<Instruction>
.All
Xcm
items which included a fieldVec<Order>
to be executed in the local context now have those fields removed (they're no longer needed since theOrder
s can be placed asInstruction
s immediately afterwards in theXcm
vector). For the remote context,xcm: Xcm
is used as the field name/type.Compatibility
v1
messages can be auto-converted tov2
provided:BuyExecution::instructions
is empty.RelayedFrom
is unused.v2
messages can be auto-converted tov1
provided:v1::Xcm
item is used for local execution in a singlev2::Xcm
and it must be at the begining.BuyExecution::weight_limit
isLimited
.ClearOrigin
if used, may only follow immediately afterReceiveTeleportedAsset
orReserveAssetDeposited
. The latter two may not appear with it.DescendOrigin
,ReportOutcome
,RefundSurplus
are not used.Migrating
XCM fragments
Xcm::
andOrder::
becomeInstruction::
.orders
/effects
fields describing effects on the remote side are renamedxcm
.WithdrawAsset
,ReceiveTeleportedAsset
,DepositReserveAsset
have noeffects
field; contents should be moved to follow the instruction in the containingVec
.BuyExecution
:weight_limit
, which replacesdebt
andweight
; it should be set toLimited
with the inner value being the sum ofweight
anddebt
, or, alternatively justUnlimited
.instructions
is not empty, then contents should be moved to followBuyExecution
in the containingVec
.fees
andweight
.RelayedFrom
becomesDescendOrigin
;RelayedFrom::instruction
removed and contents should be moved to followRelayedFrom
in the containingVec
.XCM Pallet
pallet_xcm::Config
now contains two more itemsOrigin
andCall
; they should just be defined to the corresponding outer types:pallet_xcm
has a specialOrigin
which must be specified in theconstruct_runtime!
macro.XCM builder tools
The
FixedWeightBounds
type 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_report
new_query
new_query_notify
v1
->v2
v2
->v1