Skip to content

Commit f8eade3

Browse files
shemnonGabriel-Trintinalia
authored andcommitted
EIP-2935: Serve historical block hashes from state (besu-eth#7080)
* EIP-2935: Serve historical block hashes from state Refactor the BlockHashOperation to move hash lookup into the ProtocolSpec, and combine logic with beacon root storage. Update t8n test to use block hash list in new format Signed-off-by: Danno Ferrin <danno@numisight.com> Author: Gabriel-Trintinalia gabriel.trintinalia@consensys.net Co-authored-by: Danno Ferrin danno@numisight.com Co-authored-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net> Signed-off-by: Justin Florentine <justin+github@florentine.us>
1 parent 086ca99 commit f8eade3

File tree

78 files changed

+987
-253
lines changed

Some content is hidden

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

78 files changed

+987
-253
lines changed

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/06_prague_getPayloadV4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"executionPayload": {
1515
"parentHash": "0x2b0ef8ec0a5f8b3bd5e64cde3f1ed7f61c472b79bea9e44598921c3c37890a6a",
1616
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
17-
"stateRoot": "0x9d7467981e875b5b81ec6b9ab44300fa390d253b5d83da24fe58700f66a3925e",
17+
"stateRoot": "0xc809e88f0456bc45340fa03cedd1c1d658c1b947a7f23e6a17ed108af60d3afc",
1818
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1919
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
2020
"gasLimit": "0x1c9c380",
@@ -35,7 +35,7 @@
3535
}
3636
],
3737
"blockNumber": "0x2",
38-
"blockHash": "0xb4be7cd1193f86d725c93275f9f9fe902c5fc34e1758b9ebcac371de370a1bdd",
38+
"blockHash": "0x41d9ad8707752c4e6c46eecc956e79fc1fafc44fc0cc5fd7a5b981b02e216932",
3939
"blobGasUsed": "0x0",
4040
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
4141
},

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/09_prague_newPayloadV4.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"parentHash": "0x2b0ef8ec0a5f8b3bd5e64cde3f1ed7f61c472b79bea9e44598921c3c37890a6a",
88
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
9-
"stateRoot": "0xdcd8284a4904f95448a522e4c47d9c2f1b4541c5f6f711b42692fb26e1e0d986",
9+
"stateRoot": "0xb25de115723e262bb1d5da7e3576dea47c3fe7e8ca52c430e6f9def712de830d",
1010
"logsBloom": "0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000",
1111
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
1212
"gasLimit": "0x1c9c380",
@@ -36,7 +36,7 @@
3636
}
3737
],
3838
"blockNumber": "0x2",
39-
"blockHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
39+
"blockHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
4040
"receiptsRoot": "0x79ee3424eb720a3ad4b1c5a372bb8160580cbe4d893778660f34213c685627a9",
4141
"blobGasUsed": "0x0"
4242
},
@@ -50,7 +50,7 @@
5050
"id": 67,
5151
"result": {
5252
"status": "VALID",
53-
"latestValidHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
53+
"latestValidHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
5454
"validationError": null
5555
}
5656
},

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/10_prague_forkchoiceUpdatedV3.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"method": "engine_forkchoiceUpdatedV3",
55
"params": [
66
{
7-
"headBlockHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
8-
"safeBlockHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
9-
"finalizedBlockHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c"
7+
"headBlockHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
8+
"safeBlockHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
9+
"finalizedBlockHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e"
1010
},
1111
{
1212
"timestamp": "0x30",
@@ -24,10 +24,10 @@
2424
"result": {
2525
"payloadStatus": {
2626
"status": "VALID",
27-
"latestValidHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
27+
"latestValidHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
2828
"validationError": null
2929
},
30-
"payloadId": "0x282643832633dccf"
30+
"payloadId": "0x28264390264496cf"
3131
}
3232
},
3333
"statusCode" : 200

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/11_prague_getPayloadV4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"jsonrpc": "2.0",
44
"method": "engine_getPayloadV4",
55
"params": [
6-
"0x282643832633dccf"
6+
"0x28264390264496cf"
77
],
88
"id": 67
99
},
@@ -12,9 +12,9 @@
1212
"id": 67,
1313
"result": {
1414
"executionPayload": {
15-
"parentHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
15+
"parentHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
1616
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
17-
"stateRoot": "0xdcd8284a4904f95448a522e4c47d9c2f1b4541c5f6f711b42692fb26e1e0d986",
17+
"stateRoot": "0xf786274a52a498c61961f6faa82c8f2df6c65bf6f0cbdd53216821bc981494a4",
1818
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1919
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
2020
"gasLimit": "0x1c9c380",
@@ -29,7 +29,7 @@
2929
"depositReceipts": [],
3030
"withdrawalRequests": [],
3131
"blockNumber": "0x3",
32-
"blockHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
32+
"blockHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
3333
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
3434
"blobGasUsed": "0x0"
3535
},

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/12_cancun_newPayloadV4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"method": "engine_newPayloadV3",
55
"params": [
66
{
7-
"parentHash": "0x57291a8c6fd912648046cae66dcae8b3f3d00b49e679c69566cd11286490458c",
7+
"parentHash": "0xcf161dd8d9811f119f7377aa7cccd933955d1a6deb538200785191fb938fec5e",
88
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
9-
"stateRoot": "0xdcd8284a4904f95448a522e4c47d9c2f1b4541c5f6f711b42692fb26e1e0d986",
9+
"stateRoot": "0xf786274a52a498c61961f6faa82c8f2df6c65bf6f0cbdd53216821bc981494a4",
1010
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1111
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
1212
"gasLimit": "0x1c9c380",
@@ -19,7 +19,7 @@
1919
"depositReceipts": [],
2020
"withdrawalRequests": [],
2121
"blockNumber": "0x3",
22-
"blockHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
22+
"blockHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
2323
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
2424
"excessBlobGas": "0x0",
2525
"blobGasUsed": "0x0"
@@ -34,7 +34,7 @@
3434
"id": 67,
3535
"result": {
3636
"status": "VALID",
37-
"latestValidHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
37+
"latestValidHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
3838
"validationError": null
3939
}
4040
},

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/14_prague_forkchoiceUpdatedV3.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"method": "engine_forkchoiceUpdatedV3",
55
"params": [
66
{
7-
"headBlockHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
8-
"safeBlockHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
9-
"finalizedBlockHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b"
7+
"headBlockHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
8+
"safeBlockHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
9+
"finalizedBlockHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98"
1010
},
1111
{
1212
"timestamp": "0x40",
@@ -24,10 +24,10 @@
2424
"result": {
2525
"payloadStatus": {
2626
"status": "VALID",
27-
"latestValidHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
27+
"latestValidHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
2828
"validationError": null
2929
},
30-
"payloadId": "0x282643f22efc45bf"
30+
"payloadId": "0x282643d998c41241"
3131
}
3232
},
3333
"statusCode" : 200

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/15_prague_getPayloadV4.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"jsonrpc": "2.0",
44
"method": "engine_getPayloadV4",
55
"params": [
6-
"0x282643f22efc45bf"
6+
"0x282643d998c41241"
77
],
88
"id": 67
99
},
@@ -12,9 +12,9 @@
1212
"id": 67,
1313
"result": {
1414
"executionPayload": {
15-
"parentHash": "0xbac2080fec3fecfb46b4fa1ce20767021f0e53e85b017d5b6a5f4ec43bdbf18b",
15+
"parentHash": "0xf1626764177578f1bf1f0fcce3f5ecab4bf7e4c8c7754d1d30e7c0b98334ad98",
1616
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
17-
"stateRoot": "0x4a387af05417b5767993052457ca85b2a5a172b3f809eb5cbcf17f070f398c3f",
17+
"stateRoot": "0x4021e9832c7d9945cb681d670c238c6178bd2184e957a474a7989d06f7171349",
1818
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1919
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
2020
"gasLimit": "0x1c9c380",
@@ -36,10 +36,10 @@
3636
"validatorPubKey": "0x8706d19a62f28a6a6549f96c5adaebac9124a61d44868ec94f6d2d707c6a2f82c9162071231dfeb40e24bfde4ffdf243"
3737
}
3838
],
39-
"receiptsRoot": "0x765bd9d63cc10fa47117d6cc0958f15e55a3bde540d4ed15d220f573fbb82cba",
39+
"blockNumber": "0x4",
4040
"blobGasUsed": "0x0",
41-
"blockHash": "0xe589c7673025f6844ffbaeddcf38d77d652669c60412e8506a2ae62ac80e9de4",
42-
"blockNumber": "0x4"
41+
"receiptsRoot": "0x765bd9d63cc10fa47117d6cc0958f15e55a3bde540d4ed15d220f573fbb82cba",
42+
"blockHash": "0xc5c15f6a88d3576927b16de1c635cabf46bb9419a3bbb3be156ddbe229de5e64"
4343
},
4444
"blockValue": "0x12855dcd153473b",
4545
"blobsBundle": {

besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
3232
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
3333
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
34-
import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup;
3534
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
3635
import org.hyperledger.besu.plugin.Unstable;
3736
import org.hyperledger.besu.plugin.data.BlockTraceResult;
@@ -217,7 +216,7 @@ private List<TransactionProcessingResult> trace(
217216
transaction,
218217
protocolSpec.getMiningBeneficiaryCalculator().calculateBeneficiary(header),
219218
tracer,
220-
new CachingBlockHashLookup(header, blockchain),
219+
protocolSpec.getBlockHashProcessor().getBlockHashLookup(header, blockchain),
221220
false,
222221
blobGasPrice);
223222

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/ExecuteTransactionStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
1616

1717
import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalculator.calculateExcessBlobGasForParent;
18+
import static org.hyperledger.besu.evm.operation.BlockHashOperation.BlockHashLookup;
1819

1920
import org.hyperledger.besu.datatypes.BlobGas;
2021
import org.hyperledger.besu.datatypes.Wei;
@@ -26,8 +27,6 @@
2627
import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor;
2728
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
2829
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
29-
import org.hyperledger.besu.ethereum.vm.BlockHashLookup;
30-
import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup;
3130
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
3231

3332
import java.util.List;
@@ -95,7 +94,8 @@ public TransactionTrace apply(final TransactionTrace transactionTrace) {
9594
maybeParentHeader
9695
.map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent))
9796
.orElse(BlobGas.ZERO));
98-
final BlockHashLookup blockHashLookup = new CachingBlockHashLookup(header, blockchain);
97+
final BlockHashLookup blockHashLookup =
98+
protocolSpec.getBlockHashProcessor().getBlockHashLookup(header, blockchain);
9999
result =
100100
transactionProcessor.processTransaction(
101101
chainUpdater.getNextUpdater(),

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/BlockReplay.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor;
1616

1717
import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalculator.calculateExcessBlobGasForParent;
18+
import static org.hyperledger.besu.evm.operation.BlockHashOperation.BlockHashLookup;
1819

1920
import org.hyperledger.besu.datatypes.BlobGas;
2021
import org.hyperledger.besu.datatypes.Hash;
@@ -30,8 +31,6 @@
3031
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
3132
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
3233
import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams;
33-
import org.hyperledger.besu.ethereum.vm.BlockHashLookup;
34-
import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup;
3534

3635
import java.util.List;
3736
import java.util.Optional;
@@ -90,7 +89,8 @@ public <T> Optional<T> beforeTransactionInBlock(
9089
return performActionWithBlock(
9190
blockHash,
9291
(body, header, blockchain, transactionProcessor, protocolSpec) -> {
93-
final BlockHashLookup blockHashLookup = new CachingBlockHashLookup(header, blockchain);
92+
final BlockHashLookup blockHashLookup =
93+
protocolSpec.getBlockHashProcessor().getBlockHashLookup(header, blockchain);
9494
final Wei blobGasPrice =
9595
protocolSpec
9696
.getFeeMarket()
@@ -137,7 +137,7 @@ public <T> Optional<T> afterTransactionInBlock(
137137
blockHeader,
138138
transaction,
139139
spec.getMiningBeneficiaryCalculator().calculateBeneficiary(blockHeader),
140-
new CachingBlockHashLookup(blockHeader, blockchain),
140+
spec.getBlockHashProcessor().getBlockHashLookup(blockHeader, blockchain),
141141
false,
142142
TransactionValidationParams.blockReplay(),
143143
blobGasPrice);
@@ -180,6 +180,10 @@ private Optional<Block> getBlock(final Hash blockHash) {
180180
return Optional.empty();
181181
}
182182

183+
public ProtocolSpec getProtocolSpec(final BlockHeader header) {
184+
return protocolSchedule.getByBlockHeader(header);
185+
}
186+
183187
@FunctionalInterface
184188
public interface BlockAction<T> {
185189
Optional<T> perform(

0 commit comments

Comments
 (0)