Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to call arbitrary runtime apis using RelayChainInterface #5521

Merged

Conversation

tmpolaczyk
Copy link
Contributor

@tmpolaczyk tmpolaczyk commented Aug 29, 2024

When using the relay chain though a Arc<dyn RelayChainInterface> there is no way to call arbitrary runtime apis. Both implementations of that trait allow this, so it feels natural to expose this functionality in the trait.

This PR adds a call_runtime_api method to RelayChainInterface trait, and a separate function also named call_runtime_api which allows the caller to specify the input and output types, as opposed to having to encode them. This generic function cannot be part of the trait because a dyn Trait object cannot have generic methods.

hash: PHash,
payload: &[u8],
) -> RelayChainResult<Vec<u8>> {
use sp_api::{CallApiAt, CallApiAtParams, CallContext, __private::Extensions};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module is called __private out of a reason ;)

at: hash,
function: method_name,
arguments: payload.to_vec(),
overlayed_changes: &RefCell::new(overlayed_changes),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
overlayed_changes: &RefCell::new(overlayed_changes),
overlayed_changes: &RefCell::new(Default::default()),

@@ -364,3 +380,18 @@ where
(**self).version(relay_parent).await
}
}

pub async fn call_remote_runtime_function<R>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It saves the caller from having to manually do the Decode::decode. I can remove it if you want, but I think it's useful.

cumulus/client/relay-chain-interface/src/lib.rs Outdated Show resolved Hide resolved
@tmpolaczyk tmpolaczyk force-pushed the tomasz-relaychaininterface-runtime-api branch from e60932b to f276916 Compare September 2, 2024 09:10
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 3/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7212188

@tmpolaczyk
Copy link
Contributor Author

@bkchr solved your comments, anything else missing?

@tmpolaczyk tmpolaczyk force-pushed the tomasz-relaychaininterface-runtime-api branch from 58bad1e to 5c19396 Compare September 4, 2024 12:58
@girazoki
Copy link
Contributor

@bkchr can you help us get the CI passing? Just from a first glance I dont see anything wrong for prdoc but maybe I am missing something...,

@bkchr bkchr added the T0-node This PR/Issue is related to the topic “node”. label Sep 18, 2024
@bkchr bkchr requested a review from skunert September 18, 2024 21:07
@bkchr bkchr added this pull request to the merge queue Sep 19, 2024
@bkchr bkchr removed this pull request from the merge queue due to a manual request Sep 19, 2024
@bkchr bkchr added this pull request to the merge queue Sep 20, 2024
Merged via the queue into paritytech:master with commit 5a43147 Sep 20, 2024
203 of 208 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants