EIP-2481: Added testcases (#3228)

* EIP-2481: add testcases

* EIP-2481: propose unpacking of GetHeadersPacket

* EIP-2481: revert spec changes
This commit is contained in:
Martin Holst Swende 2021-02-08 10:14:28 +01:00 committed by GitHub
parent 3ec9510e81
commit de2fbc8527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,14 +43,7 @@ Let's consider a client making many simultaneous requests for `GetBlockHeaders`
This can be particular tricky for responses that are ambiguous such as empty responses. This can be particular tricky for responses that are ambiguous such as empty responses.
This EIP proposes to change the `GetBlockHeaders` and the `BlockHeaders` command to include a `request_id` as shown below. This EIP proposes to change the `GetBlockHeaders` and the `BlockHeaders` command to include a `request_id`.
* `GetBlockHeaders (0x03)`
* **Current (eth/65):** `[block: {P, B_32}, maxHeaders: P, skip: P, reverse: P in {0, 1}]`
* **Then (eth/66)**: `[request_id: P, [block: {P, B_32}, maxHeaders: P, skip: P, reverse: P in {0, 1}]]`
* `BlockHeaders (0x04)`
* **Current (eth/65):** `[blockHeader_0, blockHeader_1, ...]`
* **Then (eth/66)**: `[request_id: P, [blockHeader_0, blockHeader_1, ...]]`
The `request_id` is a 64-bit integer set by the client when it makes the request. On the responding side, the exact same `request_id` from the incoming request is put back into the response object. The `request_id` is a 64-bit integer set by the client when it makes the request. On the responding side, the exact same `request_id` from the incoming request is put back into the response object.
@ -103,8 +96,6 @@ To elaborate, each command is altered in the following way:
1. Create a list with the `request_id` being the first element. 1. Create a list with the `request_id` being the first element.
2. Make the second element the list that defines the whole command in the current scheme. 2. Make the second element the list that defines the whole command in the current scheme.
This is consistent with the request / response pairs in the `les` protocol.
The ``request_id`` has the following characteristics: The ``request_id`` has the following characteristics:
* 64 bit integer * 64 bit integer
@ -151,10 +142,279 @@ This EIP does not change the consensus engine, thus does *not* require a hard fo
## Implementation ## Implementation
Trinity has a [draft PR](https://github.com/ethereum/trinity/pull/1672) with an implementation. Trinity has a [draft PR](https://github.com/ethereum/trinity/pull/1672) with an implementation.
Geth [PR](https://github.com/ethereum/go-ethereum/pull/22241).
## Security Considerations ## Security Considerations
None None
## Test cases
These testcases cover RLP-encoding of all the redefined messages types, where the `rlp` portion is the rlp-encoding of the message defined in the `data` portion.
```json
{
"type": "GetBlockHeadersPacket66",
"rlp": "0xe8820457e4a000000000000000000000000000000000000000000000000000000000deadc0de050580",
"data": {
"RequestId": 1111,
"Origin": {
"Hash": "0x00000000000000000000000000000000000000000000000000000000deadc0de",
"Number": 0
},
"Amount": 5,
"Skip": 5,
"Reverse": false
}
}
```
```json
{
"type": "GetBlockHeadersPacket66",
"rlp": "0xca820457c682270f050580",
"data": {
"RequestId": 1111,
"Origin": {
"Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"Number": 9999
},
"Amount": 5,
"Skip": 5,
"Reverse": false
}
}
```
```json
{
"type": "BlockHeadersPacket66",
"rlp": "0xf90202820457f901fcf901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000",
"data": {
"RequestId": 1111,
"BlockHeadersPacket": [
{
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"sha3Uncles": "0x0000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x8ae",
"number": "0xd05",
"gasLimit": "0x115c",
"gasUsed": "0x15b3",
"timestamp": "0x1a0a",
"extraData": "0x7788",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"hash": "0x8c2f2af15b7b563b6ab1e09bed0e9caade7ed730aec98b70a993597a797579a9"
}
]
}
}
```
```json
{
"type": "GetBlockBodiesPacket66",
"rlp": "0xf847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef",
"data": {
"RequestId": 1111,
"GetBlockBodiesPacket": [
"0x00000000000000000000000000000000000000000000000000000000deadc0de",
"0x00000000000000000000000000000000000000000000000000000000feedbeef"
]
}
}
```
```json
{
"type": "BlockBodiesPacket66",
"rlp": "0xf902dc820457f902d6f902d3f8d2f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afbf901fcf901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000",
"data": {
"RequestId": 1111,
"BlockBodiesPacket": [
{
"Transactions": [
{
"nonce": "0x8",
"gasPrice": "0x4a817c808",
"gas": "0x2e248",
"to": "0x3535353535353535353535353535353535353535",
"value": "0x200",
"input": "0x",
"v": "0x25",
"r": "0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
"s": "0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
"hash": "0x588df025c4c2d757d3e314bd3dfbfe352687324e6b8557ad1731585e96928aed"
},
{
"nonce": "0x9",
"gasPrice": "0x4a817c809",
"gas": "0x33450",
"to": "0x3535353535353535353535353535353535353535",
"value": "0x2d9",
"input": "0x",
"v": "0x25",
"r": "0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
"s": "0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
"hash": "0xf39c7dac06a9f3abf09faf5e30439a349d3717611b3ed337cd52b0d192bc72da"
}
],
"Uncles": [
{
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"sha3Uncles": "0x0000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x8ae",
"number": "0xd05",
"gasLimit": "0x115c",
"gasUsed": "0x15b3",
"timestamp": "0x1a0a",
"extraData": "0x7788",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"hash": "0x8c2f2af15b7b563b6ab1e09bed0e9caade7ed730aec98b70a993597a797579a9"
}
]
}
]
}
}
```
```json
{
"type": "GetNodeDataPacket66",
"rlp": "0xf847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef",
"data": {
"RequestId": 1111,
"GetNodeDataPacket": [
"0x00000000000000000000000000000000000000000000000000000000deadc0de",
"0x00000000000000000000000000000000000000000000000000000000feedbeef"
]
}
}
```
```json
{
"type": "NodeDataPacket66",
"rlp": "0xce820457ca84deadc0de84feedbeef",
"data": {
"RequestId": 1111,
"NodeDataPacket": [
"0xdeadcode",
"0xfeedbeef"
]
}
}
```
```json
{
"type": "GetReceiptsPacket66",
"rlp": "0xf847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef",
"data": {
"RequestId": 1111,
"GetReceiptsPacket": [
"0x00000000000000000000000000000000000000000000000000000000deadc0de",
"0x00000000000000000000000000000000000000000000000000000000feedbeef"
]
}
}
```
```json
{
"type": "ReceiptsPacket66",
"rlp": "0xf90172820457f9016cf90169f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff",
"data": {
"RequestId": 1111,
"ReceiptsPacket": [
[
{
"root": "0x",
"status": "0x0",
"cumulativeGasUsed": "0x1",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"logs": [
{
"address": "0x0000000000000000000000000000000000000011",
"topics": [
"0x000000000000000000000000000000000000000000000000000000000000dead",
"0x000000000000000000000000000000000000000000000000000000000000beef"
],
"data": "0x0100ff",
"blockNumber": "0x0",
"transactionHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionIndex": "0x0",
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logIndex": "0x0",
"removed": false
}
],
"transactionHash": "0x00000000000000000000000000000000000000000000000000000000deadc0de",
"contractAddress": "0x0000000000000000000000000000000000011111",
"gasUsed": "0x1b207",
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionIndex": "0x0"
}
]
]
}
}
```
```json
{
"type": "GetPooledTransactionsPacket66",
"rlp": "0xf847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef",
"data": {
"RequestId": 1111,
"GetPooledTransactionsPacket": [
"0x00000000000000000000000000000000000000000000000000000000deadc0de",
"0x00000000000000000000000000000000000000000000000000000000feedbeef"
]
}
}
```
```json
{
"type": "PooledTransactionsPacket66",
"rlp": "0xf8d7820457f8d2f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
"data": {
"RequestId": 1111,
"PooledTransactionsPacket": [
{
"nonce": "0x8",
"gasPrice": "0x4a817c808",
"gas": "0x2e248",
"to": "0x3535353535353535353535353535353535353535",
"value": "0x200",
"input": "0x",
"v": "0x25",
"r": "0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
"s": "0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
"hash": "0x588df025c4c2d757d3e314bd3dfbfe352687324e6b8557ad1731585e96928aed"
},
{
"nonce": "0x9",
"gasPrice": "0x4a817c809",
"gas": "0x33450",
"to": "0x3535353535353535353535353535353535353535",
"value": "0x2d9",
"input": "0x",
"v": "0x25",
"r": "0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
"s": "0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
"hash": "0xf39c7dac06a9f3abf09faf5e30439a349d3717611b3ed337cd52b0d192bc72da"
}
]
}
}
```
## Copyright ## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).