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

[TASK] Add rpc api for is_known_root method #325

Closed
salman01zp opened this issue May 4, 2023 · 1 comment · Fixed by #327
Closed

[TASK] Add rpc api for is_known_root method #325

salman01zp opened this issue May 4, 2023 · 1 comment · Fixed by #327

Comments

@salman01zp
Copy link
Contributor

salman01zp commented May 4, 2023

Summary

Add RPC api to validate if the given root is a known root, this will be used by the relayer to validate leaves before caching.

https://github.com/webb-tools/protocol-substrate/blob/main/pallets/mt/src/lib.rs#L492-#L509

#[method(name = "mt_isKnownRoot")]
fn is_known_root(
	&self,
	tree_id: u32,
	target_root: Element,
	at: Option<BlockHash>,
) -> RpcResult<bool>;

@shekohex
Copy link
Collaborator

shekohex commented May 4, 2023

This Like a two part operation here.

Runtime API:
So for you to do this, you need to declare it for the runtime API first like here:

https://github.com/webb-tools/protocol-substrate/blob/f0c637dc00625f65a7df28acd2d5f463c5f833c3/pallets/mt/rpc/runtime-api/src/lib.rs#L5-L10

And then you will need to implement that Runtime API in the */runtime/lib.rs like so:
https://github.com/webb-tools/protocol-substrate/blob/f0c637dc00625f65a7df28acd2d5f463c5f833c3/standalone/runtime/src/lib.rs#L1743-L1752

RPC:
And here for the RPC
https://github.com/webb-tools/protocol-substrate/blob/f0c637dc00625f65a7df28acd2d5f463c5f833c3/pallets/mt/rpc/src/lib.rs#L32-L51

Then you just implement it inside the RPC

This an example implementation of the get_leaves

https://github.com/webb-tools/protocol-substrate/blob/f0c637dc00625f65a7df28acd2d5f463c5f833c3/pallets/mt/rpc/src/lib.rs#L75-L94

And that's it actually.

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

Successfully merging a pull request may close this issue.

2 participants