Change how RPCs eth_call and eth_estimateGas handle "Pending" (#11127)
* Change how RPCs eth_call and eth_estimateGas handle "Pending"
Before this PR we would return a rather confusing error when calling `eth_call` and `eth_estimateGas` with `"Pending"`, e.g.:
```
{"jsonrpc":"2.0","error":{"code":-32000,"message":"This request is not supported because your node is running with state pruning. Run with --pruning=archive."},"id":"e237678f6648ed12ff05a74933d06d17"}
```
In reality what is going on is that users often use `"Pending"` when they really mean `"Latest"` (e.g. MyCrypto…) and when the block in question is not actually pending. This changes our behaviour for these two RPC calls to fall back to `"Latest"` when the query with `"Pending"` fails.
Note that we already behave this way for many other RPCs:
- eth_call (after this PR)
- eth_estimateGas (after this PR)
- eth_getBalance
- eth_getCode
- eth_getStorageAt
Closes https://github.com/paritytech/parity-ethereum/issues/10096
* Fetch jsonrpc from git
* No real need to wait for new jsonrpc
* Add tests for calling eth_call/eth_estimateGas with "Pending"
* Fix a todo, add another
* Change client.latest_state to return the best header as well so we avoid potential data races and do less work
* Impl review suggestions
* Update rpc/src/v1/impls/eth.rs
Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>
* Review grumbles
* update docs
This commit is contained in:
@@ -93,8 +93,8 @@ impl StateClient for TestMinerService {
|
||||
// State will not be used by test client anyway, since all methods that accept state are mocked
|
||||
type State = TestState;
|
||||
|
||||
fn latest_state(&self) -> Self::State {
|
||||
TestState
|
||||
fn latest_state_and_header(&self) -> (Self::State, Header) {
|
||||
(TestState, Header::default())
|
||||
}
|
||||
|
||||
fn state_at(&self, _id: BlockId) -> Option<Self::State> {
|
||||
|
||||
@@ -663,6 +663,43 @@ fn rpc_eth_call_latest() {
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_call_pending() {
|
||||
let tester = EthTester::default();
|
||||
tester.client.set_execution_result(Ok(Executed {
|
||||
exception: None,
|
||||
gas: U256::zero(),
|
||||
gas_used: U256::from(0xff30),
|
||||
refunded: U256::from(0x5),
|
||||
cumulative_gas_used: U256::zero(),
|
||||
logs: vec![],
|
||||
contracts_created: vec![],
|
||||
output: vec![0x12, 0x34, 0xff],
|
||||
trace: vec![],
|
||||
vm_trace: None,
|
||||
state_diff: None,
|
||||
}));
|
||||
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_call",
|
||||
"params": [{
|
||||
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
|
||||
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
||||
"gas": "0x76c0",
|
||||
"gasPrice": "0x9184e72a000",
|
||||
"value": "0x9184e72a",
|
||||
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
|
||||
},
|
||||
"pending"],
|
||||
"id": 1
|
||||
}"#;
|
||||
// Falls back to "Latest" and gives the same result.
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x1234ff","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_call() {
|
||||
let tester = EthTester::default();
|
||||
@@ -770,6 +807,43 @@ fn rpc_eth_estimate_gas() {
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_estimate_gas_pending() {
|
||||
let tester = EthTester::default();
|
||||
tester.client.set_execution_result(Ok(Executed {
|
||||
exception: None,
|
||||
gas: U256::zero(),
|
||||
gas_used: U256::from(0xff30),
|
||||
refunded: U256::from(0x5),
|
||||
cumulative_gas_used: U256::zero(),
|
||||
logs: vec![],
|
||||
contracts_created: vec![],
|
||||
output: vec![0x12, 0x34, 0xff],
|
||||
trace: vec![],
|
||||
vm_trace: None,
|
||||
state_diff: None,
|
||||
}));
|
||||
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_estimateGas",
|
||||
"params": [{
|
||||
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
|
||||
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
||||
"gas": "0x76c0",
|
||||
"gasPrice": "0x9184e72a000",
|
||||
"value": "0x9184e72a",
|
||||
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
|
||||
},
|
||||
"pending"],
|
||||
"id": 1
|
||||
}"#;
|
||||
// Falls back to "Latest" so the result is the same
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x5208","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_estimate_gas_default_block() {
|
||||
let tester = EthTester::default();
|
||||
|
||||
Reference in New Issue
Block a user