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

[pallet-revive] Add Ethereum JSON-RPC server #5953

Merged
merged 52 commits into from
Oct 18, 2024

Conversation

pgherveou
Copy link
Contributor

@pgherveou pgherveou commented Oct 7, 2024

No description provided.

@pgherveou pgherveou changed the base branch from master to pg/revive-rpc-fixes-v2 October 7, 2024 13:16
@pgherveou pgherveou force-pushed the pg/revive-rpc-server branch 5 times, most recently from d80a5ce to d931a80 Compare October 9, 2024 10:47
@pgherveou pgherveou marked this pull request as ready for review October 10, 2024 15:25
@pgherveou pgherveou requested a review from a team as a code owner October 10, 2024 15:25
Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

Great that it works with vanilla ether.js now. This is how it should have been.

Copy link
Member

Choose a reason for hiding this comment

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

Should have a better name than just "demo". Maybe "rpc_demo".

Comment on lines 20 to 34
#[subxt::subxt(
runtime_metadata_path = "kitchensink.scale",
substitute_type(
path = "pallet_revive::primitives::EthContractResult<A>",
with = "::subxt::utils::Static<::pallet_revive::EthContractResult<A>>"
),
substitute_type(
path = "pallet_revive::primitives::EthTransactKind",
with = "::subxt::utils::Static<::pallet_revive::EthTransactKind>"
),
substitute_type(
path = "sp_weights::weight_v2::Weight",
with = "::subxt::utils::Static<::sp_weights::Weight>"
)
)]
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to use the dynamic API of subxt here. Otherwise the pallet ids and so on will be hardcoded to whatever kitchensink is using, right?

Or how do we make sure that this will be compatible across different runtimes (westend ah, kusama ah, polkadot ah)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes correct, the only thing that can break I believe is the encoding of the dispatchable, since the index will differ for each runtime, I was planning to go with feature flag to start with, until I find a more suitable solution, will look into their dynamic API as well.

Comment on lines +33 to +35
pub extern "C" fn call() {
input!(128, data: [u8],);
api::deposit_event(&[], data);
Copy link
Member

Choose a reason for hiding this comment

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

Can we assert the selector here? ether.js should derive a selector from the provided ABI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah right yes it does, might be easier to add the assert in the js code directly, since that's where we define the "fake ABI"

Copy link
Member

Choose a reason for hiding this comment

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

I think we want the assert here, too. So we can make sure that the selector actually reaches the contract.

log::info!(target: LOG_TARGET, "method: {method} params: {params}");
let resp = service.call(req).await;
if resp.is_success() {
log::info!(target: LOG_TARGET, "✅ rpc: {method}");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that for eth_call response is very useful. Could we print it out in dev mode?

@pgherveou pgherveou merged commit 5894fb5 into pg/revive-rpc-fixes-v2 Oct 18, 2024
61 of 72 checks passed
@pgherveou pgherveou deleted the pg/revive-rpc-server branch October 18, 2024 21:53
@pgherveou pgherveou restored the pg/revive-rpc-server branch October 19, 2024 08:56
@pgherveou
Copy link
Contributor Author

arg bad merge, not sure what I have done here, will recreate the PR

github-merge-queue bot pushed a commit that referenced this pull request Oct 22, 2024
This PR introduces the necessary changes to pallet-revive for
integrating with our Ethereum JSON-RPC.
The RPC proxy itself will be added in a follow up.

## Changes

- A new pallet::call `Call::eth_transact`. This is used as a wrapper to
accept unsigned Ethereum transaction, valid call will be routed to
`Call::call` or `Call::instantiate_with_code`

- A custom UncheckedExtrinsic struct, that wraps the generic one usually
and add the ability to check eth_transact calls sent from an Ethereum
JSON-RPC proxy.
- Generated types and traits to support implementing a JSON-RPC Ethereum
proxy.

## Flow Overview:
- A user submits a transaction via MetaMask or another
Ethereum-compatible wallet.
- The proxy dry run the transaction and add metadata to the call (gas
limit in Weight, storage deposit limit, and length of bytecode and
constructor input for contract instantiation)
- The raw transaction, along with the additional metadata, is submitted
to the node as an unsigned extrinsic.
- On the runtime, our custom UncheckedExtrinsic define a custom
Checkable implementation that converts the unsigned extrinsics into
checked one
 - It recovers the signer
- validates the payload, and injects signed extensions, allowing the
system to increment the nonce and charge the appropriate fees.
- re-route the call to pallet-revive::Call::call or
pallet-revive::Call::instantiateWithCode

## Dependencies

- paritytech/polkavm#188

## Follow up PRs
- #5926  
- #6147 (previously #5953)
- #5502

---------

Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: Cyrill Leutwiler <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Oct 28, 2024
Redo of #5953

---------

Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
mordamax pushed a commit to paritytech-stg/polkadot-sdk that referenced this pull request Oct 29, 2024
Redo of paritytech#5953

---------

Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
mordamax pushed a commit to paritytech-stg/polkadot-sdk that referenced this pull request Oct 29, 2024
Redo of paritytech#5953

---------

Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants