Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 92c42b6

Browse files
dvdplmandresilva
authored andcommitted
Set the request index to that of the current request (#8683)
* Set the request index to that of the current request When setting up the chain of (two) requests to look up a block by hash, the second need to refer to the first. This fixes an issue where the back ref was set to the subsequent request, not the current one. When the requests are executed we loop through them in order and ensure the requests that should produce headers all match up. We do this by index so they better be right. In other words: off by one.
1 parent 17f83a2 commit 92c42b6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

rpc/src/v1/helpers/light_fetch.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ impl LightFetch {
129129
}
130130
}
131131
BlockId::Hash(h) => {
132-
reqs.push(request::HeaderByHash(h.into()).into());
133-
134132
let idx = reqs.len();
133+
reqs.push(request::HeaderByHash(h.into()).into());
135134
Ok(HeaderRef::Unresolved(idx, h.into()))
136135
}
137136
_ => Err(errors::unknown_block()) // latest, earliest, and pending will have all already returned.

rpc/src/v1/tests/eth.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ fn eth_get_block() {
204204
assert_eq!(tester.handler.handle_request_sync(req_block).unwrap(), res_block);
205205
}
206206

207+
#[test]
208+
fn eth_get_block_by_hash() {
209+
let chain = extract_chain!("BlockchainTests/bcGasPricerTest/RPC_API_Test");
210+
let tester = EthTester::from_chain(&chain);
211+
212+
// We're looking for block number 4 from "RPC_API_Test_Frontier"
213+
let req_block = r#"{"method":"eth_getBlockByHash","params":["0x9c9bdab4cb53fd834e790b13545597f026494d42112e84c0aca9dd6bcc545295",false],"id":1,"jsonrpc":"2.0"}"#;
214+
215+
let res_block = r#"{"jsonrpc":"2.0","result":{"author":"0x8888f1f195afa192cfee860698584c030f4c9db1","difficulty":"0x200c0","extraData":"0x","gasLimit":"0x1dd8112","gasUsed":"0x5458","hash":"0x9c9bdab4cb53fd834e790b13545597f026494d42112e84c0aca9dd6bcc545295","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x8888f1f195afa192cfee860698584c030f4c9db1","mixHash":"0xaddea8d25bb0f955fa6c1d58d74ab8a3fec99d37943e2a261e3b12f97d6bff7c","nonce":"0x8e18bed16d5a88da","number":"0x4","parentHash":"0x2cbf4fc930c5b4c87598f43fc8eb26dccdab2f58a7d0d3ca92ec60a5444a330e","receiptsRoot":"0x7ed8026cf72ed0e98e6fd53ab406e51ffd34397d9da0052494ff41376fda7b5f","sealFields":["0xa0addea8d25bb0f955fa6c1d58d74ab8a3fec99d37943e2a261e3b12f97d6bff7c","0x888e18bed16d5a88da"],"sha3Uncles":"0x75cc08a7cb2cf8081446659fecb2633fb6b922d26edd59bd2272b1f5cae1c78b","size":"0x661","stateRoot":"0x68805721294e365020aca15ed56c360d9dc2cf03cbeff84c9b84b8aed023bfb5","timestamp":"0x59d662ff","totalDifficulty":"0xa0180","transactions":["0xb094b9dc356dbb8b256402c6d5709288066ad6a372c90c9c516f14277545fd58"],"transactionsRoot":"0x97a593d8d7e15b57f5c6bb25bc6c325463ef99f874bc08a78656c3ab5cb23262","uncles":["0xa1e9c9ecd2af999e0723aae1dc55dd9789ca618e0b34badcc8ac7d9a3dad3af2","0x81d429b6b6635214a2b0f976cc4b2ed49808140d6bede50129bc10d22ac9249e"]},"id":1}"#;
216+
assert_eq!(tester.handler.handle_request_sync(req_block).unwrap(), res_block);
217+
}
218+
207219
// a frontier-like test with an expanded gas limit and balance on known account.
208220
const TRANSACTION_COUNT_SPEC: &'static [u8] = br#"{
209221
"name": "Frontier (Test)",

0 commit comments

Comments
 (0)