Skip to content

Commit 39b2c6e

Browse files
authored
EIP-2930: Access List Transactions (#1712)
https://eips.ethereum.org/EIPS/eip-2930 Signed-off-by: Ratan Rai Sur <[email protected]>
1 parent 9934403 commit 39b2c6e

File tree

28 files changed

+717
-157
lines changed

28 files changed

+717
-157
lines changed

besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
import org.junit.rules.TemporaryFolder;
8181

8282
@SuppressWarnings("rawtypes")
83-
// todo request lucas look at this pr
8483
public class PrivacyReorgTest {
8584
@Rule public final TemporaryFolder folder = new TemporaryFolder();
8685

@@ -93,9 +92,9 @@ public class PrivacyReorgTest {
9392
Bytes.fromBase64String("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
9493

9594
private static final String FIRST_BLOCK_WITH_NO_TRANSACTIONS_STATE_ROOT =
96-
"0xc9dcaffbebc7edc20839c80e706430a8fa885e8f703bb89f6e95633cc2b05d4d";
95+
"0xe368938a01d983e331eb0e4ea61224726d06075c1ad525569b369f664067ff26";
9796
private static final String FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT =
98-
"0x66fbc6ad12ef1da78740093ea2b3362e773e510e27d8f88b68c27bfc1f4d58c8";
97+
"0x9c88988f9602184efc538cf1c2f482a6b8757ff918d234602884dc8e3b983edd";
9998
private static final String BLOCK_WITH_SINGLE_TRANSACTION_RECEIPTS_ROOT =
10099
"0xc8267b3f9ed36df3ff8adb51a6d030716f23eeb50270e7fce8d9822ffa7f0461";
101100
private static final String STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE =
@@ -338,7 +337,7 @@ public void reorgToLongerChain() {
338337
privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
339338

340339
final String secondForkBlockStateRoot =
341-
"0x57ccc80f4e50d2e669d82aefa7d3bbe763cf47df27665af14c90b2f8641953f5";
340+
"0x2c37a360a700c614b10c980138f64be9ad66fc4a14cd5145199cd0d8ec43d51d";
342341
final Block secondForkBlock =
343342
gen.block(
344343
getBlockOptionsNoTransactionWithDifficulty(
@@ -368,8 +367,7 @@ public void reorgToLongerChain() {
368367
appendBlock(besuController, blockchain, protocolContext, thirdForkBlock);
369368

370369
// Check that the private state did change after reorg
371-
assertPrivateStateRoot(
372-
privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
370+
assertPrivateStateRoot(privateStateRootResolver, blockchain, EMPTY_ROOT_HASH);
373371
}
374372

375373
@SuppressWarnings("unchecked")

besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,22 @@ public void reorgedBlockEventFiresAfterSubscribe() {
299299
blockchain.appendBlock(block, gen.receipts(block));
300300
assertThat(result.get()).isNull();
301301

302-
final var reorgBlock =
302+
final var forkBlock =
303303
gen.block(
304304
new BlockDataGenerator.BlockOptions()
305305
.setParentHash(blockchain.getGenesisBlock().getHash())
306-
.setBlockNumber(blockchain.getGenesisBlock().getHeader().getNumber() + 2));
306+
.setDifficulty(block.getHeader().getDifficulty().subtract(1))
307+
.setBlockNumber(blockchain.getGenesisBlock().getHeader().getNumber() + 1));
308+
blockchain.appendBlock(forkBlock, gen.receipts(forkBlock));
309+
assertThat(result.get()).isNull();
310+
311+
final var reorgBlock =
312+
gen.block(
313+
new BlockDataGenerator.BlockOptions()
314+
.setParentHash(forkBlock.getHash())
315+
.setDifficulty(Difficulty.of(10000000))
316+
.setBlockNumber(forkBlock.getHeader().getNumber() + 1));
317+
307318
List<TransactionReceipt> transactionReceipts = gen.receipts(reorgBlock);
308319
blockchain.appendBlock(reorgBlock, transactionReceipts);
309320
assertThat(result.get()).isNotNull();

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public void getOmmerByBlockHashAndIndexShouldReturnEmptyWhenIndexIsOutOfRange()
400400

401401
@Test
402402
public void getOmmerByBlockHashAndIndexShouldReturnExpectedOmmerHeader() {
403-
final BlockchainWithData data = setupBlockchain(3);
403+
final BlockchainWithData data = setupBlockchain(4);
404404
final BlockchainQueries queries = data.blockchainQueries;
405405
final Block targetBlock = data.blockData.get(data.blockData.size() - 1).block;
406406
final BlockHeader ommerBlockHeader = targetBlock.getBody().getOmmers().get(0);
@@ -448,7 +448,7 @@ public void getOmmerByBlockNumberAndIndexShouldReturnEmptyWhenIndexIsOutOfRange(
448448

449449
@Test
450450
public void getOmmerByBlockNumberAndIndexShouldReturnExpectedOmmerHeader() {
451-
final BlockchainWithData data = setupBlockchain(3);
451+
final BlockchainWithData data = setupBlockchain(4);
452452
final BlockchainQueries queries = data.blockchainQueries;
453453
final Block targetBlock = data.blockData.get(data.blockData.size() - 1).block;
454454
final List<BlockHeader> ommers = targetBlock.getBody().getOmmers();
@@ -485,7 +485,7 @@ public void getLatestBlockOmmerByIndexShouldReturnEmptyWhenIndexIsOutOfRange() {
485485

486486
@Test
487487
public void getLatestBlockOmmerByIndexShouldReturnExpectedOmmerHeader() {
488-
final BlockchainWithData data = setupBlockchain(3);
488+
final BlockchainWithData data = setupBlockchain(4);
489489
final BlockchainQueries queries = data.blockchainQueries;
490490
final Block targetBlock = data.blockData.get(data.blockData.size() - 1).block;
491491
final BlockHeader ommerBlockHeader = targetBlock.getBody().getOmmers().get(0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* * Copyright ConsenSys AG.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6+
* * the License. You may obtain a copy of the License at
7+
* *
8+
* * http://www.apache.org/licenses/LICENSE-2.0
9+
* *
10+
* * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11+
* * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* * specific language governing permissions and limitations under the License.
13+
* *
14+
* * SPDX-License-Identifier: Apache-2.0
15+
*
16+
*/
17+
18+
package org.hyperledger.besu.ethereum.core;
19+
20+
import static java.util.Collections.emptyList;
21+
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
import org.apache.tuweni.bytes.Bytes32;
27+
28+
public class AccessList extends ArrayList<Map.Entry<Address, List<Bytes32>>> {
29+
30+
public AccessList(final List<Map.Entry<Address, List<Bytes32>>> accessList) {
31+
super(accessList);
32+
}
33+
34+
public static final AccessList EMPTY = new AccessList(emptyList());
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright ConsenSys AG.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
16+
package org.hyperledger.besu.ethereum.core;
17+
18+
import static java.util.Collections.emptySet;
19+
20+
import java.util.Set;
21+
22+
import com.google.common.collect.HashMultimap;
23+
import com.google.common.collect.Multimap;
24+
import org.apache.tuweni.bytes.Bytes32;
25+
26+
public class GasAndAccessedState {
27+
final Gas gas;
28+
final Set<Address> accessListAddressSet;
29+
final Multimap<Address, Bytes32> accessListStorageByAddress;
30+
31+
public GasAndAccessedState(
32+
final Gas gas,
33+
final Set<Address> accessListAddressSet,
34+
final Multimap<Address, Bytes32> accessedStorage) {
35+
this.gas = gas;
36+
this.accessListAddressSet = accessListAddressSet;
37+
this.accessListStorageByAddress = accessedStorage;
38+
}
39+
40+
public GasAndAccessedState(final Gas gas) {
41+
this.gas = gas;
42+
this.accessListAddressSet = emptySet();
43+
this.accessListStorageByAddress = HashMultimap.create();
44+
}
45+
46+
public Gas getGas() {
47+
return gas;
48+
}
49+
50+
public Set<Address> getAccessListAddressSet() {
51+
return accessListAddressSet;
52+
}
53+
54+
public Multimap<Address, Bytes32> getAccessListStorageByAddress() {
55+
return accessListStorageByAddress;
56+
}
57+
}

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/LogsBloomFilter.java

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public LogsBloomFilter(final Bytes data) {
5959
data.size());
6060
}
6161

62+
public LogsBloomFilter(final String logsBloomHexString) {
63+
this(Bytes.fromHexString(logsBloomHexString));
64+
}
65+
6266
public static LogsBloomFilter fromHexString(final String hexString) {
6367
return new LogsBloomFilter(Bytes.fromHexString(hexString));
6468
}

0 commit comments

Comments
 (0)