Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Pre-generate runtime API clients to use on light nodes #3875

Closed
svyatonik opened this issue Oct 22, 2019 · 7 comments
Closed

Pre-generate runtime API clients to use on light nodes #3875

svyatonik opened this issue Oct 22, 2019 · 7 comments

Comments

@svyatonik
Copy link
Contributor

We may want to (remotely) call some runtime methods from the light nodes. Currently, the call must be manually encoded like in this example:

fetcher.remote_call(RemoteCallRequest {
	block: best_hash,
	header: best_header,
	method: "AccountNonceApi_account_nonce".into(),
	call_data: account.encode(),
	retry_count: None,
})

I'm suggesting to extend decl_runtime_apis! macro (or add some additional macro) that will generate structure to be used on light nodes for calling some (we do not need it for everything) runtime methods. It could be something like that for declaring (mind the : Light):

decl_runtime_apis! {
	pub trait TaggedTransactionQueue: Light {
		fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity;
	}
}

The example usage of generated client:

LightTaggedTransactionQueue::at_header(fetcher, hash, header)
	.validate_transaction(transaction)
@bkchr
Copy link
Member

bkchr commented Oct 22, 2019

Why not just implement CallRuntimeAt for something that sends the data to a full node and sends back the result?
Then you can just use any runtime api without any change.

@svyatonik
Copy link
Contributor Author

Thanks, that is probably be a better option - haven't thought about implementations details yet. The main concern is that currently we need to hardcode method name + manually encode method arguments + manually decode method return.

@bkchr
Copy link
Member

bkchr commented Oct 22, 2019

CallRuntimeAt already gets the function name as &str and the encoded parameters :)

@svyatonik
Copy link
Contributor Author

Yes I know, I'm describing the current situation with calling runtime methods from light client. If it'll be possible, we'll use CallRuntimeAt.

@bkchr
Copy link
Member

bkchr commented Oct 22, 2019

Yeah understood this. If there is anything where we can improve the runtime api, just write me :)

But don't you already have the special call_executor implementation for light clients. Shouldn't that be usable as well?

@svyatonik
Copy link
Contributor Author

OK, thanks.

I've removed remote calls support from light' CallExecutor recently to: (1) avoid blocking io threads (2) avoid unplanned (and unpredictable) runtime calls from light client. So now whenever we need to call into runtime from the light client, we need to explicitly use Fetcher.

@EmmanuellNorbertTulbure

Is this still relevant @svyatonik ? Asking to know if I should migrate it or not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants