Skip to content

Commit d1fafa8

Browse files
pgherveouactions-userathei
authored
[pallet-revive] eth-prc fix geth diff (#6608)
* Add a bunch of differential tests to ensure that responses from eth-rpc matches the one from `geth` - These [tests](https://github.com/paritytech/polkadot-sdk/blob/pg/fix-geth-diff/substrate/frame/revive/rpc/examples/js/src/geth-diff.test.ts) are not run in CI for now but can be run locally with ```bash cd revive/rpc/examples/js bun test ``` * EVM RPC server will not fail gas_estimation if no gas is specified, I updated pallet-revive to add an extra `skip_transfer` boolean check to replicate this behavior in our pallet * `eth_transact` and `bare_eth_transact` api have been updated to use `GenericTransaction` directly as this is what is used by `eth_estimateGas` and `eth_call` ## TODO - [ ] Add tests the new `skip_transfer` flag --------- Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Alexander Theißen <[email protected]>
1 parent 5e0bcb0 commit d1fafa8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1553
-1248
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
124124
spec_name: alloc::borrow::Cow::Borrowed("westmint"),
125125
impl_name: alloc::borrow::Cow::Borrowed("westmint"),
126126
authoring_version: 1,
127-
spec_version: 1_016_006,
127+
spec_version: 1_016_008,
128128
impl_version: 0,
129129
apis: RUNTIME_API_VERSIONS,
130130
transaction_version: 16,
@@ -2081,18 +2081,10 @@ impl_runtime_apis! {
20812081
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
20822082
System::account_nonce(account)
20832083
}
2084-
fn eth_transact(
2085-
from: H160,
2086-
dest: Option<H160>,
2087-
value: U256,
2088-
input: Vec<u8>,
2089-
gas_limit: Option<Weight>,
2090-
storage_deposit_limit: Option<Balance>,
2091-
) -> pallet_revive::EthContractResult<Balance>
2084+
2085+
fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
20922086
{
2093-
use pallet_revive::AddressMapper;
2094-
let blockweights = <Runtime as frame_system::Config>::BlockWeights::get();
2095-
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);
2087+
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
20962088

20972089
let encoded_size = |pallet_call| {
20982090
let call = RuntimeCall::Revive(pallet_call);
@@ -2101,15 +2093,9 @@ impl_runtime_apis! {
21012093
};
21022094

21032095
Revive::bare_eth_transact(
2104-
origin,
2105-
dest,
2106-
value,
2107-
input,
2108-
gas_limit.unwrap_or(blockweights.max_block),
2109-
storage_deposit_limit.unwrap_or(u128::MAX),
2096+
tx,
2097+
blockweights.max_block,
21102098
encoded_size,
2111-
pallet_revive::DebugInfo::UnsafeDebug,
2112-
pallet_revive::CollectEvents::UnsafeCollect,
21132099
)
21142100
}
21152101

@@ -2127,7 +2113,7 @@ impl_runtime_apis! {
21272113
dest,
21282114
value,
21292115
gas_limit.unwrap_or(blockweights.max_block),
2130-
storage_deposit_limit.unwrap_or(u128::MAX),
2116+
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
21312117
input_data,
21322118
pallet_revive::DebugInfo::UnsafeDebug,
21332119
pallet_revive::CollectEvents::UnsafeCollect,
@@ -2149,7 +2135,7 @@ impl_runtime_apis! {
21492135
RuntimeOrigin::signed(origin),
21502136
value,
21512137
gas_limit.unwrap_or(blockweights.max_block),
2152-
storage_deposit_limit.unwrap_or(u128::MAX),
2138+
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
21532139
code,
21542140
data,
21552141
salt,

prdoc/pr_6608.prdoc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
title: '[pallet-revive] eth-prc fix geth diff'
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
* Add a bunch of differential tests to ensure that responses from eth-rpc matches the one from `geth`
6+
* EVM RPC server will not fail gas_estimation if no gas is specified, I updated pallet-revive to add an extra `skip_transfer` boolean check to replicate this behavior in our pallet
7+
* `eth_transact` and `bare_eth_transact` api have been updated to use `GenericTransaction` directly as this is what is used by `eth_estimateGas` and `eth_call`
8+
crates:
9+
- name: pallet-revive-eth-rpc
10+
bump: minor
11+
- name: pallet-revive
12+
bump: minor
13+
- name: asset-hub-westend-runtime
14+
bump: minor

substrate/bin/node/runtime/src/lib.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -3218,18 +3218,9 @@ impl_runtime_apis! {
32183218
System::account_nonce(account)
32193219
}
32203220

3221-
fn eth_transact(
3222-
from: H160,
3223-
dest: Option<H160>,
3224-
value: U256,
3225-
input: Vec<u8>,
3226-
gas_limit: Option<Weight>,
3227-
storage_deposit_limit: Option<Balance>,
3228-
) -> pallet_revive::EthContractResult<Balance>
3221+
fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
32293222
{
3230-
use pallet_revive::AddressMapper;
32313223
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
3232-
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);
32333224

32343225
let encoded_size = |pallet_call| {
32353226
let call = RuntimeCall::Revive(pallet_call);
@@ -3238,15 +3229,9 @@ impl_runtime_apis! {
32383229
};
32393230

32403231
Revive::bare_eth_transact(
3241-
origin,
3242-
dest,
3243-
value,
3244-
input,
3245-
gas_limit.unwrap_or(blockweights.max_block),
3246-
storage_deposit_limit.unwrap_or(u128::MAX),
3232+
tx,
3233+
blockweights.max_block,
32473234
encoded_size,
3248-
pallet_revive::DebugInfo::UnsafeDebug,
3249-
pallet_revive::CollectEvents::UnsafeCollect,
32503235
)
32513236
}
32523237

@@ -3263,7 +3248,7 @@ impl_runtime_apis! {
32633248
dest,
32643249
value,
32653250
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
3266-
storage_deposit_limit.unwrap_or(u128::MAX),
3251+
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
32673252
input_data,
32683253
pallet_revive::DebugInfo::UnsafeDebug,
32693254
pallet_revive::CollectEvents::UnsafeCollect,
@@ -3284,7 +3269,7 @@ impl_runtime_apis! {
32843269
RuntimeOrigin::signed(origin),
32853270
value,
32863271
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
3287-
storage_deposit_limit.unwrap_or(u128::MAX),
3272+
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
32883273
code,
32893274
data,
32903275
salt,

substrate/frame/revive/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pallet-revive-fixtures = { workspace = true, default-features = true }
6565
secp256k1 = { workspace = true, features = ["recovery"] }
6666
serde_json = { workspace = true }
6767
hex-literal = { workspace = true }
68+
env_logger = { workspace = true }
6869

6970
# Polkadot SDK Dependencies
7071
pallet-balances = { workspace = true, default-features = true }

substrate/frame/revive/mock-network/src/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use frame_support::traits::{fungibles::Mutate, Currency};
2424
use frame_system::RawOrigin;
2525
use pallet_revive::{
2626
test_utils::{self, builder::*},
27-
Code,
27+
Code, DepositLimit,
2828
};
2929
use pallet_revive_fixtures::compile_module;
3030
use pallet_revive_uapi::ReturnErrorCode;
@@ -52,7 +52,7 @@ fn instantiate_test_contract(name: &str) -> Contract<parachain::Runtime> {
5252
RawOrigin::Signed(ALICE).into(),
5353
Code::Upload(wasm),
5454
)
55-
.storage_deposit_limit(1_000_000_000_000)
55+
.storage_deposit_limit(DepositLimit::Balance(1_000_000_000_000))
5656
.build_and_unwrap_contract()
5757
});
5858

substrate/frame/revive/rpc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ hex = { workspace = true }
6767
hex-literal = { workspace = true, optional = true }
6868
scale-info = { workspace = true }
6969
secp256k1 = { workspace = true, optional = true, features = ["recovery"] }
70-
env_logger = { workspace = true }
7170
ethabi = { version = "18.0.0" }
7271

7372
[features]
7473
example = ["hex-literal", "rlp", "secp256k1", "subxt-signer"]
7574

7675
[dev-dependencies]
76+
env_logger = { workspace = true }
7777
static_init = { workspace = true }
7878
hex-literal = { workspace = true }
7979
pallet-revive-fixtures = { workspace = true }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
export const abi = [
2+
{
3+
inputs: [
4+
{
5+
internalType: 'string',
6+
name: 'message',
7+
type: 'string',
8+
},
9+
],
10+
name: 'CustomError',
11+
type: 'error',
12+
},
13+
{
14+
inputs: [
15+
{
16+
internalType: 'bool',
17+
name: 'newState',
18+
type: 'bool',
19+
},
20+
],
21+
name: 'setState',
22+
outputs: [],
23+
stateMutability: 'nonpayable',
24+
type: 'function',
25+
},
26+
{
27+
inputs: [],
28+
name: 'state',
29+
outputs: [
30+
{
31+
internalType: 'bool',
32+
name: '',
33+
type: 'bool',
34+
},
35+
],
36+
stateMutability: 'view',
37+
type: 'function',
38+
},
39+
{
40+
inputs: [],
41+
name: 'triggerAssertError',
42+
outputs: [],
43+
stateMutability: 'pure',
44+
type: 'function',
45+
},
46+
{
47+
inputs: [],
48+
name: 'triggerCustomError',
49+
outputs: [],
50+
stateMutability: 'pure',
51+
type: 'function',
52+
},
53+
{
54+
inputs: [],
55+
name: 'triggerDivisionByZero',
56+
outputs: [
57+
{
58+
internalType: 'uint256',
59+
name: '',
60+
type: 'uint256',
61+
},
62+
],
63+
stateMutability: 'pure',
64+
type: 'function',
65+
},
66+
{
67+
inputs: [],
68+
name: 'triggerOutOfBoundsError',
69+
outputs: [
70+
{
71+
internalType: 'uint256',
72+
name: '',
73+
type: 'uint256',
74+
},
75+
],
76+
stateMutability: 'pure',
77+
type: 'function',
78+
},
79+
{
80+
inputs: [],
81+
name: 'triggerRequireError',
82+
outputs: [],
83+
stateMutability: 'pure',
84+
type: 'function',
85+
},
86+
{
87+
inputs: [],
88+
name: 'triggerRevertError',
89+
outputs: [],
90+
stateMutability: 'pure',
91+
type: 'function',
92+
},
93+
{
94+
inputs: [
95+
{
96+
internalType: 'uint256',
97+
name: 'value',
98+
type: 'uint256',
99+
},
100+
],
101+
name: 'valueMatch',
102+
outputs: [],
103+
stateMutability: 'payable',
104+
type: 'function',
105+
},
106+
] as const

substrate/frame/revive/rpc/examples/js/abi/event.json

-34
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export const abi = [
2+
{
3+
anonymous: false,
4+
inputs: [
5+
{
6+
indexed: true,
7+
internalType: 'address',
8+
name: 'sender',
9+
type: 'address',
10+
},
11+
{
12+
indexed: false,
13+
internalType: 'uint256',
14+
name: 'value',
15+
type: 'uint256',
16+
},
17+
{
18+
indexed: false,
19+
internalType: 'string',
20+
name: 'message',
21+
type: 'string',
22+
},
23+
],
24+
name: 'ExampleEvent',
25+
type: 'event',
26+
},
27+
{
28+
inputs: [],
29+
name: 'triggerEvent',
30+
outputs: [],
31+
stateMutability: 'nonpayable',
32+
type: 'function',
33+
},
34+
] as const

0 commit comments

Comments
 (0)