feat: messaging precompiles#584
Conversation
486964c to
564f9ac
Compare
Daanvdplas
left a comment
There was a problem hiding this comment.
Damn, it really is a super cool feature. Well done on the conversion, I see you made several improvements along the way which were remaining todos, amazing!
I have not been able to dive into the details, as well as benchmarks, but the overall features and integration tests look very good. Next week I will make this my priority.
Curious, would it ever be possible to return the result of the destination chain when doing an xcm send?
And are there still big open standing issues unsolved, I remember something along the lines of child tries for ismp benchmarking (?). This is not a problem but I would like to have a look at this for the next review to get a better understanding.
The precompiles and contracts look super clean, that with the complexity of these protocols, incredible!
c00106e to
0021908
Compare
0516545 to
76e8e85
Compare
Thats what the example already shows? pop-node/pop-api-vnext/examples/messaging/lib.rs Lines 97 to 133 in 76e8e85 The pop-node/pop-api-vnext/examples/messaging/lib.rs Lines 145 to 170 in 76e8e85
The ismp child trie benchmarking has been overcome using the same approach as pallet-contracts/revive: pop-node/pallets/api-vnext/src/messaging/benchmarking.rs Lines 132 to 137 in 76e8e85 |
6ca0ba9 to
d3bb37d
Compare
| /// The weight to be used for callback responses to this contract. | ||
| gas_limit: Weight, | ||
| /// The storage deposit limit for callback responses to this contract. | ||
| storage_deposit_limit: U256, |
There was a problem hiding this comment.
Could you explain why you set those values here?
There was a problem hiding this comment.
The contract must effectively specify the values required as limits when the response is dispatched back to the contract via
pop-node/runtime/devnet/src/config/api/mod.rs
Line 284 in c08c5b9
The cost of the gas_limit specified at the time of request is reserved, with any unused weight/cost being refunded after callback execution. The storage deposit limit covers the max amount that should be reserved for any state that the receiving contract creates. Whilst this is typically the same contract, there is now the dest field on the callback which allows specification of a contract address other than the caller for a more powerful implementation.
Destination state machine could use larger type, so standardise on the same type provided by ismp.
34bdfa5 to
28ab13e
Compare
* build(deps): disable default-features for serde * feat(api-vnext): new 'pallet' to provide fungible api(s) via precompiles * feat(devnet): add fungibles precompiles * build(deps): propagate runtime-benchmarks feature * build: disable doctest based on incompatible comments in .sol files * fix(precompiles/interfaces): use calldata specifiers for string parameters * style(precompiles/interfaces): formatting * refactor: use upcoming assetidextractor from pallet-assets * refactor(api-vnext): resolve clippy warnings * style: formatting * feat(pop-api): add initial fungibles api and example * chore: rename example directory * docs: remove trailing slash in comment * refactor(pop-api): improvements to implementation * test(devnet): improvements to fungibles precompile contract test * refactor(pop-api): remove redundant code for manual precompile calls * refactor(fungibles): ensure feature parity with prior implementation * refactor(pop-api): use explicit sol encoding for precompile contract refs * docs(examples): update parameter description based on review comment * docs(api): add public function doc * docs(example): update constructor parameter doc style to match messages * docs(example): use account instead of address in doc comments * docs(example): add todo prefix to comment * docs(api): add public function doc * test(api): remove additional check deemed unnecessary * docs(api): add fungibles doc comments * refactor(precompiles): add license and version requirement * refactor(precompiles): update return types after rebase * test(api): resolve breaking changes after rebase * test(api): improve fungibles precompile tests after rebase * test(api): improve erc20 precompile tests after rebase * test(api): define precompile constants within mock runtime * refactor(api): use asset id extractors from pallet-assets * test(devnet): resolve breaking changes after rebase * refactor(api): import soltype * refactor(api): correct fungibles trait parameter names * refactor(devnet): simplify selector implementations * test(api): add initial integration tests * ci: add job for pop-api-vnext integration tests * test(api): minimal implementation of transfer test Solidity error handling still unsupported. * ci: set rustflags for pop-api-vnext integration tests * test(runtime): disable precompiles with contract test Disabled until it can be replaced completely by integration tests. * test(api): add transfer_from test * ci: exclude pop-api-integration-tests from test and coverage jobs * test(api): add approve test * test(api): add contract.account_id() helper * test(api): add increase/decrease allowance tests * refactor(api): separate out fungibles errors module * feat(api): add fungibles events * test(api): add create test * test(api): add start_destroy test * test(api): make contract instantiation origin explicit to simplify api * test(api): add set_metadata test * test(api): update expectation message to .polkavm * test(api): add clear_metadata test * test(api): reuse sol types to ease encoding * test(api): add mint test * test(api): add burn test * test(api): add create with instantiation test * feat(api): initial precompile benchmarking * refactor(api): charge weight for increase/decrease allowance calls * refactor(api): improve decrease allowance implementation * feat(api): add clear_metadata benchmark * feat(api): add set_metadata benchmark Also adds a few additional improvements. * feat(api): add start_destroy benchmark * feat(api): add create benchmark * refactor(api): move benchmark assertion into block * refactor(api): use call_precompile helper Provides decoding to ease assertions. * feat(api): add mint benchmark * feat(api): add burn benchmark * feat(api): add transfer benchmark * feat(api): add transfer_from benchmark * refactor(api/fungibles/benchmarking): add copy trait bound to asset id to eliminate manual clones * refactor(api/fungibles): refund appropriate burn weight on failure * style(api/fungibles): formatting * refactor(api/fungibles/erc20): charge benchmarked weight Uses benchmarks from the fungibles precompile which should be exactly the same for these functions. * chore(api): add cargo.lock * test(devnet): set gas limit now that precompiles charge weight * test(devnet): remove contract and selector integration tests as available elsewhere now * test(api): add selectors test * test(api): add initial tests * test(api): remove unnecessary helper * test(api): add increase/decrease tests * test(api): add create test * test(api): add start_destroy test * test(api): add set_metadata test * test(api): add clear_metadata test * test(api): add mint test * test(api): add burn test * test(api): add exists test * refactor(api): share total_supply implementation * refactor(api): share balance implementation * refactor(api): share allowance implementation * refactor(api): share metadata implementation * test(api): explicitly endow when more than ed required * refactor(api): reorganize for versioning * style: formatting * build(deps): update ink after sol-abi improvements merged * ci: explicitly cache pallet-revive-fixtures output * test(api/integration-tests): fix imports after refactor * ci: remove cached pallet-revive fixtures * ci: only list if directory exists * ci(init): make crate caching configurable * ci(init): bump rust-cache version * refactor(pallets/api): address clippy warning * docs(api): add missing precompile index comment * refactor(pallets/api): ensure weight charge updated on both approve success and failure * refactor(pallets-api): update event handling based on reference implementation * docs: remove todo comment * test(api/integration-tests): constructor encoding Uses `all` encoding to support multiple constructors after solidity constructor support added. * docs(api): fix transfer comment * docs(api): port readmes * refactor(pallets/api): simplify u256 conversion * refactor(pallets/api): relocate benchmarking call setup and resolve issues * refactor(api): update ink, eliminating manual encoding/decoding * fix(api): add missing imports after refactor * refactor: implement initial precompile reverts * test(api): add initial error checks * refactor(api): improved fungibles error handling * refactor(api): improved erc20 error handling * build(deps): add missing base64 feature * refactor: resolve missing imports/trait bounds for runtime-benchmarks * refactor(pallets/api): resolve clippy warnings * test(pallets/api): fix minimum balance consideration with transfer * test(pallets/api): remove unnecessary println * test(pallets/api): fix minimum balance consideration with transfer benchmark * fix(api): allow removal of approval with zero value allowance * refactor(api): check set_metadata result after refactoring * chore: update cargo.lock after rebase * style: formatting after rebase * chore(api): update cargo.lock for contracts * docs(api): remove todos * ci: enable global cache disabling * ci: reenable crate caching * docs(pallets/api): remove token id size todo after discussion * test(api): relocate and reduce initial value, gas and storage limits * refactor(pallets/api): ensure all errors apart from insufficient gas result in revert * refactor(api): ensure full error coverage * test(api): update expected errors * chore(api): update cargo.lock * chore: update cargo.lock * refactor(pallets/api): simplify origin * refactor(pallets/api): fix imports * refactor(api): reuse selectors * feat: messaging precompiles (#584) * feat(pallets/api): add messaging precompiles * feat(devnet): add messaging pallet * feat(api): add initial messaging apis * feat(api): add messaging example * refactor(api): update callback encoding * build(pallets/api): add empty ismp feature * refactor: port on_initialize hook implementation * style: formatting * build(pallets/api): adjust ismp feature * feat(pallets/api): add messaging benchmarks * refactor(ismp): use u64 height Destination state machine could use larger type, so standardise on the same type provided by ismp. * refactor(api): update imports after rebase * style: formatting after rebase * fix: remove duplicate imports after rebase * refactor(api): add initial messaging error handling * test(api): add error tests * test(pallets/api): add remove tests * test(pallets/api): add new_query tests * test(pallets/api): add call tests * test(pallets/api): add process_callback_weight tests * test(pallets/api): add deposit_callback_event tests * test(pallets/api): add fee management test * test(pallets/api): add xcm_response tests * test(pallets/api): add ismp tests * refactor: limit ismp_response helper to tests * refactor(pallets/api): use try_convert * refactor(pallets/api): update messaging weights * refactor(pallets/api): use global message identifier Stores contract address in message to ensure authorised removal. Additional benefits beyond reduced storage requirements are that any contract can poll and use responses until originator removes. * refactor(pallets/api): update weights after benchmarking * fix(pallets/api): replace bounded_vec! usage within benchmarks * refactor(pallets/api): callback response interfaces and encoding * refactor(api): precompile and callback trait and type encoding improvements * feat(devnet): add messaging precompiles * test(api): add initial messaging integration tests * test(api): update ink dependency * refactor(api): update ink dependency * test(api): restore onpostresponse handler * test(pallets/api): fix tests after refactor * test(api): add ismp post integration tests * refactor(pallets/api): rename response handler functions due to selector clashes A workaround for ink which does not allow two traits to be implemented with a message with the same resulting selector. * refactor(api): rename response handler functions due to selector clashes * test(api): add xcm messaging integration tests * build(api): updating ink to master * docs(pallets/api): remove unnecessary todos * docs(api): remove unnecessary todos * docs(api): add hashed_account function docs * feat(pallets/api): add (para) id getter to messaging precompiles * feat(api): add (para) id getter to apis * test(api): add (para) id getter integration test * refactor(api): update messaging example with improvements * refactor(api): improve return types of xcm execute and send helpers * refactor(api): use ink_abi cfg for callback encoding * refactor(pallets/api): restore ismp deposits * test(pallets/api): increase message deposit * docs(pallets/api): update comments on necessary clones of bytes type during abi encoding Data needs to be encoded for persistence if callback fails and therefore cannot be owned. * refactor(pallets/api): better handling of invalid callback encoding * test(api): apply reduced initial value, gas, storage limits * fix(pallets/api): surface storage deposit limit into callback specification * fix(api): allow specification of storage deposit limit for callback * test(api): ensure storage deposit limit works Also adjusts gas limits based on contract changes. * refactor(devnet): update callbackexecutor.execute implementation to use storage deposit limit * refactor(api): update messaging example contract with storage deposit limit * fix(pallets/api): allow caller to specify ismp post recipient module/address * fix(api): allow caller to specify ismp post recipient module/address * test(api): specify ismp post recipient mpdule/address * refactor(devnet): configure max ismp post module/address length as 32 bytes * docs(pallets/api): remove messageid size todo u64::MAX provides a sufficiently large number for message identifier and aligns with the same type used by XCM for query identifiers. * refactor(pallets/api): add simple on_accept benchmark for consistency, along with supporting module weight tests * refactor(devnet): name ismp module via import alias * refactor(devnet): add ismp weight provider * docs(pallets/api): remove todo after tests added * test(pallets/api): add integrity test to ensure maxresponselen * refactor(pallets/api): update integrity test to include values * refactor(pallets/api): update tryconvert usages to dispatcherror after rebase * chore: update cargo.lock * chore(api): update cargo.lock for messaging contract * refactor(pallets/api): use improved origin * refactor(pallets/api): wrap fallible calls in closure to map errors * refactor(pallets/api): use try_convert to simplify safe conversion * refactor(pallets/api): ensure all errors apart from insufficient gas result in revert * refactor(api): ensure full error coverage * test(api): update callback gas limits * docs(api): add readmes * docs(api): relocate messaging within readme * docs(pallet-api): add weights overview from original pr * docs(pallets-api): relocate weights.md * docs(pallet-api): add description to messaging module * docs(pallet-api): add readme * docs(pallet-api): add initial messaging readme * docs(pallets/api): add diagrams to messaging readme --------- Co-authored-by: Frank Bell <frank@r0gue.io>
* chore: update to stable2506 * refactor(pallets): remove deprecated runtimeevent config item * refactor(runtime/common): add missing weights after sdk uplift * refactor(runtime/common): remove unused import * refactor(devnet): update revive api implementation * refactor(devnet): add relayparentoffset config item * refactor(devnet): update assets config * refactor(devnet): update revive config * refactor(devnet): update api config * refactor(devnet): remove unused imports * refactor(testnet): add relayparentoffset config item * refactor(testnet): update api config * refactor(testnet): update revive config * refactor(testnet): update governance config * refactor(testnet): update revive api implementation * refactor(mainnet): update revive api implementation * refactor(mainnet): update governance config * refactor(mainnet): update revive config * refactor(mainnet): add relayparentoffset config item * refactor(mainnet): replace fee_asset with worst_case_for_trader * refactor(node): add shared trie cache parameter to storage benchmarking command * refactor(node): silence clippy warning * refactor(node): address service breaking changes * chore: update cargo.lock * chore(api): update cargo.lock * refactor(pallets): remove deprecated runtimeevent config item * test(fungibles): disambiguate allowance * test(mainnet): update revive integrity tests * build(deps): bump frame-metadata to resolve dependency clash * ci: restore runtime-benchmarks checks * test(mainnet): update metadata integrity test after v16 stabilisation * refactor(runtimes): use max_pov_size constant * test(integration-tests): updated expected ref_time for xcm attempted event * test(testnet): update metadata integrity test after v16 stabilisation * build(deps): update stable2506 revision * chore: update cargo.lock * refactor(runtime): update revive config after revision change * chore: update toolchain to stable * build(deps): update contract-build to branch supporting valid contract builds on rust stable * build(extension): add missing feature flag to contract * chore: update cargo.lock * build(deps): update to stable2506 release Also bumps other deps in line with versions defined within the stable2506 release. * refactor(runtime): address breaking changes * refactor(node): add notification metrics to service * chore: update cargo.lock * chore(api): update cargo.lock * feat: fungibles precompiles (#573) * build(deps): disable default-features for serde * feat(api-vnext): new 'pallet' to provide fungible api(s) via precompiles * feat(devnet): add fungibles precompiles * build(deps): propagate runtime-benchmarks feature * build: disable doctest based on incompatible comments in .sol files * fix(precompiles/interfaces): use calldata specifiers for string parameters * style(precompiles/interfaces): formatting * refactor: use upcoming assetidextractor from pallet-assets * refactor(api-vnext): resolve clippy warnings * style: formatting * feat(pop-api): add initial fungibles api and example * chore: rename example directory * docs: remove trailing slash in comment * refactor(pop-api): improvements to implementation * test(devnet): improvements to fungibles precompile contract test * refactor(pop-api): remove redundant code for manual precompile calls * refactor(fungibles): ensure feature parity with prior implementation * refactor(pop-api): use explicit sol encoding for precompile contract refs * docs(examples): update parameter description based on review comment * docs(api): add public function doc * docs(example): update constructor parameter doc style to match messages * docs(example): use account instead of address in doc comments * docs(example): add todo prefix to comment * docs(api): add public function doc * test(api): remove additional check deemed unnecessary * docs(api): add fungibles doc comments * refactor(precompiles): add license and version requirement * refactor(precompiles): update return types after rebase * test(api): resolve breaking changes after rebase * test(api): improve fungibles precompile tests after rebase * test(api): improve erc20 precompile tests after rebase * test(api): define precompile constants within mock runtime * refactor(api): use asset id extractors from pallet-assets * test(devnet): resolve breaking changes after rebase * refactor(api): import soltype * refactor(api): correct fungibles trait parameter names * refactor(devnet): simplify selector implementations * test(api): add initial integration tests * ci: add job for pop-api-vnext integration tests * test(api): minimal implementation of transfer test Solidity error handling still unsupported. * ci: set rustflags for pop-api-vnext integration tests * test(runtime): disable precompiles with contract test Disabled until it can be replaced completely by integration tests. * test(api): add transfer_from test * ci: exclude pop-api-integration-tests from test and coverage jobs * test(api): add approve test * test(api): add contract.account_id() helper * test(api): add increase/decrease allowance tests * refactor(api): separate out fungibles errors module * feat(api): add fungibles events * test(api): add create test * test(api): add start_destroy test * test(api): make contract instantiation origin explicit to simplify api * test(api): add set_metadata test * test(api): update expectation message to .polkavm * test(api): add clear_metadata test * test(api): reuse sol types to ease encoding * test(api): add mint test * test(api): add burn test * test(api): add create with instantiation test * feat(api): initial precompile benchmarking * refactor(api): charge weight for increase/decrease allowance calls * refactor(api): improve decrease allowance implementation * feat(api): add clear_metadata benchmark * feat(api): add set_metadata benchmark Also adds a few additional improvements. * feat(api): add start_destroy benchmark * feat(api): add create benchmark * refactor(api): move benchmark assertion into block * refactor(api): use call_precompile helper Provides decoding to ease assertions. * feat(api): add mint benchmark * feat(api): add burn benchmark * feat(api): add transfer benchmark * feat(api): add transfer_from benchmark * refactor(api/fungibles/benchmarking): add copy trait bound to asset id to eliminate manual clones * refactor(api/fungibles): refund appropriate burn weight on failure * style(api/fungibles): formatting * refactor(api/fungibles/erc20): charge benchmarked weight Uses benchmarks from the fungibles precompile which should be exactly the same for these functions. * chore(api): add cargo.lock * test(devnet): set gas limit now that precompiles charge weight * test(devnet): remove contract and selector integration tests as available elsewhere now * test(api): add selectors test * test(api): add initial tests * test(api): remove unnecessary helper * test(api): add increase/decrease tests * test(api): add create test * test(api): add start_destroy test * test(api): add set_metadata test * test(api): add clear_metadata test * test(api): add mint test * test(api): add burn test * test(api): add exists test * refactor(api): share total_supply implementation * refactor(api): share balance implementation * refactor(api): share allowance implementation * refactor(api): share metadata implementation * test(api): explicitly endow when more than ed required * refactor(api): reorganize for versioning * style: formatting * build(deps): update ink after sol-abi improvements merged * ci: explicitly cache pallet-revive-fixtures output * test(api/integration-tests): fix imports after refactor * ci: remove cached pallet-revive fixtures * ci: only list if directory exists * ci(init): make crate caching configurable * ci(init): bump rust-cache version * refactor(pallets/api): address clippy warning * docs(api): add missing precompile index comment * refactor(pallets/api): ensure weight charge updated on both approve success and failure * refactor(pallets-api): update event handling based on reference implementation * docs: remove todo comment * test(api/integration-tests): constructor encoding Uses `all` encoding to support multiple constructors after solidity constructor support added. * docs(api): fix transfer comment * docs(api): port readmes * refactor(pallets/api): simplify u256 conversion * refactor(pallets/api): relocate benchmarking call setup and resolve issues * refactor(api): update ink, eliminating manual encoding/decoding * fix(api): add missing imports after refactor * refactor: implement initial precompile reverts * test(api): add initial error checks * refactor(api): improved fungibles error handling * refactor(api): improved erc20 error handling * build(deps): add missing base64 feature * refactor: resolve missing imports/trait bounds for runtime-benchmarks * refactor(pallets/api): resolve clippy warnings * test(pallets/api): fix minimum balance consideration with transfer * test(pallets/api): remove unnecessary println * test(pallets/api): fix minimum balance consideration with transfer benchmark * fix(api): allow removal of approval with zero value allowance * refactor(api): check set_metadata result after refactoring * chore: update cargo.lock after rebase * style: formatting after rebase * chore(api): update cargo.lock for contracts * docs(api): remove todos * ci: enable global cache disabling * ci: reenable crate caching * docs(pallets/api): remove token id size todo after discussion * test(api): relocate and reduce initial value, gas and storage limits * refactor(pallets/api): ensure all errors apart from insufficient gas result in revert * refactor(api): ensure full error coverage * test(api): update expected errors * chore(api): update cargo.lock * chore: update cargo.lock * refactor(pallets/api): simplify origin * refactor(pallets/api): fix imports * refactor(api): reuse selectors * feat: messaging precompiles (#584) * feat(pallets/api): add messaging precompiles * feat(devnet): add messaging pallet * feat(api): add initial messaging apis * feat(api): add messaging example * refactor(api): update callback encoding * build(pallets/api): add empty ismp feature * refactor: port on_initialize hook implementation * style: formatting * build(pallets/api): adjust ismp feature * feat(pallets/api): add messaging benchmarks * refactor(ismp): use u64 height Destination state machine could use larger type, so standardise on the same type provided by ismp. * refactor(api): update imports after rebase * style: formatting after rebase * fix: remove duplicate imports after rebase * refactor(api): add initial messaging error handling * test(api): add error tests * test(pallets/api): add remove tests * test(pallets/api): add new_query tests * test(pallets/api): add call tests * test(pallets/api): add process_callback_weight tests * test(pallets/api): add deposit_callback_event tests * test(pallets/api): add fee management test * test(pallets/api): add xcm_response tests * test(pallets/api): add ismp tests * refactor: limit ismp_response helper to tests * refactor(pallets/api): use try_convert * refactor(pallets/api): update messaging weights * refactor(pallets/api): use global message identifier Stores contract address in message to ensure authorised removal. Additional benefits beyond reduced storage requirements are that any contract can poll and use responses until originator removes. * refactor(pallets/api): update weights after benchmarking * fix(pallets/api): replace bounded_vec! usage within benchmarks * refactor(pallets/api): callback response interfaces and encoding * refactor(api): precompile and callback trait and type encoding improvements * feat(devnet): add messaging precompiles * test(api): add initial messaging integration tests * test(api): update ink dependency * refactor(api): update ink dependency * test(api): restore onpostresponse handler * test(pallets/api): fix tests after refactor * test(api): add ismp post integration tests * refactor(pallets/api): rename response handler functions due to selector clashes A workaround for ink which does not allow two traits to be implemented with a message with the same resulting selector. * refactor(api): rename response handler functions due to selector clashes * test(api): add xcm messaging integration tests * build(api): updating ink to master * docs(pallets/api): remove unnecessary todos * docs(api): remove unnecessary todos * docs(api): add hashed_account function docs * feat(pallets/api): add (para) id getter to messaging precompiles * feat(api): add (para) id getter to apis * test(api): add (para) id getter integration test * refactor(api): update messaging example with improvements * refactor(api): improve return types of xcm execute and send helpers * refactor(api): use ink_abi cfg for callback encoding * refactor(pallets/api): restore ismp deposits * test(pallets/api): increase message deposit * docs(pallets/api): update comments on necessary clones of bytes type during abi encoding Data needs to be encoded for persistence if callback fails and therefore cannot be owned. * refactor(pallets/api): better handling of invalid callback encoding * test(api): apply reduced initial value, gas, storage limits * fix(pallets/api): surface storage deposit limit into callback specification * fix(api): allow specification of storage deposit limit for callback * test(api): ensure storage deposit limit works Also adjusts gas limits based on contract changes. * refactor(devnet): update callbackexecutor.execute implementation to use storage deposit limit * refactor(api): update messaging example contract with storage deposit limit * fix(pallets/api): allow caller to specify ismp post recipient module/address * fix(api): allow caller to specify ismp post recipient module/address * test(api): specify ismp post recipient mpdule/address * refactor(devnet): configure max ismp post module/address length as 32 bytes * docs(pallets/api): remove messageid size todo u64::MAX provides a sufficiently large number for message identifier and aligns with the same type used by XCM for query identifiers. * refactor(pallets/api): add simple on_accept benchmark for consistency, along with supporting module weight tests * refactor(devnet): name ismp module via import alias * refactor(devnet): add ismp weight provider * docs(pallets/api): remove todo after tests added * test(pallets/api): add integrity test to ensure maxresponselen * refactor(pallets/api): update integrity test to include values * refactor(pallets/api): update tryconvert usages to dispatcherror after rebase * chore: update cargo.lock * chore(api): update cargo.lock for messaging contract * refactor(pallets/api): use improved origin * refactor(pallets/api): wrap fallible calls in closure to map errors * refactor(pallets/api): use try_convert to simplify safe conversion * refactor(pallets/api): ensure all errors apart from insufficient gas result in revert * refactor(api): ensure full error coverage * test(api): update callback gas limits * docs(api): add readmes * docs(api): relocate messaging within readme * docs(pallet-api): add weights overview from original pr * docs(pallets-api): relocate weights.md * docs(pallet-api): add description to messaging module * docs(pallet-api): add readme * docs(pallet-api): add initial messaging readme * docs(pallets/api): add diagrams to messaging readme --------- Co-authored-by: Frank Bell <frank@r0gue.io> --------- Co-authored-by: Frank Bell <frank@r0gue.io>
An adaptation of #528 to use precompiles for ISMP/XCM messaging.
NOTE: there is currently a single failing test, which is an integrity test added to the messaging pallet. It effectively highlights the fact that a max encoded XCM response is potentially prohibitively large. Most response are probably tiny in comparison, so a more practical approach might be to measure the largest xcm responses in practice and size accordingly. I have intentionally left this as a failing test as I feel it needs further consideration.
ISMP
The following diagram illustrates the flow of the ISMP implementation:
flowchart TB A["Contract"] -- Ismp::get/post --> B["messaging::ISMP Precompile"] B -- transports::ismp::get/post --> n4["Take Deposit"] n1["runtime::Router"] -- ISMPModule::on_response --> n2["messaging::ISMP Module"] n2 --> n3["Callback?"] D["Relayer"] -- "pallet-ismp::handle(messages)" --> n1 n3 -- "<span style=padding-left:><span style=padding-left:>onGetResponse/onPostReponse</span></span>" --> A C["pallet-ismp::ISMP Dispatcher"] -.- D n4 -- IsmpDispatcher::dispatch_request --> C C --> n5["Persist Request/Message"] n4@{ shape: rounded} n1@{ shape: rect} n2@{ shape: rect} n3@{ shape: diam} D@{ shape: hex} n5@{ shape: rounded}XCM
The following diagram illustrates the flow of the XCM implementation:
flowchart TB A["Contract"] -- Xcm::newQuery --> B["messaging::XCM Precompile"] B -- transports::xcm::new_query --> n4["Take Deposit"] n1["xcm_executor"] -- Pallet::xcm_response --> n2["messaging::Pallet"] n2 --> n3["Callback?"] D["XCM"] -- </br> --> n1 n3 -- onQueryResponse --> A C["pallet-xcm"] -.- D n4 -- Xcm::new_notify_query --> C C --> n5["Persist Request/Message"] A -- Xcm::send --> B B -- Pallet::send --> C n4@{ shape: rounded} n1@{ shape: rect} n2@{ shape: rect} n3@{ shape: diam} D@{ shape: hex} n5@{ shape: rounded}Outstanding Items
The following items remain as outstanding:
new_queryhelpers in the ink api crate, as well as the precompile itself, should ensure that if a callback is specified, it specifies non-zero weight. This is just a simple check to avoid callbacks failing later, but is no means sufficiently robust as the developer will always need to ensure that sufficient weight is specified.bytesto an expected ismp/xcm response type: a callback for an ISMP get is strongly typed asVec<StorageValue>but a call toget_responsesimply returns an opaque blob of bytes.get_responseto include encoding specification: persisted responses are scale-encoded, meaning that if a contract uses get_reponse for an ISMP response, it will be scale-encoded bytes. This differs to the callback, which would be encoded as per the callback specification. Adding anencodingfield to theget_responsefunction should be sufficient to resolve this.top_up_callback_weightfunctionality was not ported due to time constraints. It should be an easy add to the existing precompile(s). Additional consideration should be given to the storage deposit limit which was omitted in the previous implementation.[sc-3823]