Skip to content

Commit

Permalink
Add optional list of withdrawals to block body (#4944)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Frame <jason.frame@consensys.net>
  • Loading branch information
jframe authored Jan 17, 2023
1 parent 1889b1b commit 009508d
Show file tree
Hide file tree
Showing 54 changed files with 157 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ public void logEventDoesNotFireAfterUnsubscribe() {
}

private Block generateBlock() {
final BlockBody body = new BlockBody(Collections.emptyList(), Collections.emptyList());
final BlockBody body =
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty());
return new Block(new BlockHeaderTestFixture().buildHeader(), body);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand All @@ -54,7 +55,8 @@ public class CliqueBlockChoiceTests {
private Block createEmptyBlock(final KeyPair blockSigner) {
final BlockHeader header =
TestHelpers.createCliqueSignedBlockHeader(headerBuilder, blockSigner, addresses);
return new Block(header, new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
return new Block(
header, new BlockBody(Lists.newArrayList(), Lists.newArrayList(), Optional.empty()));
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.hyperledger.besu.ethereum.core.Util;

import java.util.List;
import java.util.Optional;

import com.google.common.collect.Lists;
import org.junit.Before;
Expand All @@ -59,7 +60,8 @@ public class NodeCanProduceNextBlockTest {
private Block createEmptyBlock(final KeyPair blockSigner) {
final BlockHeader header =
TestHelpers.createCliqueSignedBlockHeader(headerBuilder, blockSigner, validatorList);
return new Block(header, new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
return new Block(
header, new BlockBody(Lists.newArrayList(), Lists.newArrayList(), Optional.empty()));
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void setup() {
new Block(
TestHelpers.createCliqueSignedBlockHeader(
headerTestFixture, otherKeyPair, validatorList),
new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
new BlockBody(Lists.newArrayList(), Lists.newArrayList(), Optional.empty()));
blockchain.appendBlock(emptyBlock, Lists.newArrayList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private Block createEmptyBlock(
headerTestFixture.number(blockNumber).parentHash(parentHash);
final BlockHeader header =
TestHelpers.createCliqueSignedBlockHeader(headerTestFixture, signer, validators);
return new Block(header, new BlockBody(Collections.emptyList(), Collections.emptyList()));
return new Block(
header, new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.util.Lists;
Expand All @@ -43,7 +44,7 @@ protected Block createEmptyBlock(final long blockNumber, final Hash parentHash)
headerBuilder.number(blockNumber).parentHash(parentHash).coinbase(AddressHelpers.ofValue(0));
return new Block(
headerBuilder.buildHeader(),
new BlockBody(Collections.emptyList(), Collections.emptyList()));
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
}

protected MutableBlockchain blockChain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ private static Block createGenesisBlock(final Set<Address> validators) {

final BlockHeader genesisHeader = headerTestFixture.buildHeader();
return new Block(
genesisHeader, new BlockBody(Collections.emptyList(), Collections.emptyList()));
genesisHeader,
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
}

private static ControllerAndState createControllerAndFinalState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void setup() {
headerTestFixture.extraData(bftExtraDataEncoder.encode(proposedExtraData));
headerTestFixture.number(1);
final BlockHeader header = headerTestFixture.buildHeader();
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList(), Optional.empty()));

when(blockImporter.importBlock(any(), any(), any())).thenReturn(new BlockImportResult(true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void buildCreatedBlock() {

headerTestFixture.extraData(new IbftExtraDataCodec().encode(extraData));
final BlockHeader header = headerTestFixture.buildHeader();
createdBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
createdBlock = new Block(header, new BlockBody(emptyList(), emptyList(), Optional.empty()));
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void setup() {
headerTestFixture.number(1);

final BlockHeader header = headerTestFixture.buildHeader();
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList(), Optional.empty()));

when(blockCreator.createBlock(anyLong()))
.thenReturn(new BlockCreationResult(proposedBlock, new TransactionSelectionResults()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ private static Block createGenesisBlock(final Set<Address> validators) {

final BlockHeader genesisHeader = headerTestFixture.buildHeader();
return new Block(
genesisHeader, new BlockBody(Collections.emptyList(), Collections.emptyList()));
genesisHeader,
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
}

private GenesisState createGenesisBlock(final String genesisFile) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.hyperledger.besu.util.Subscribers;

import java.math.BigInteger;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void setup() {
headerTestFixture.extraData(qbftExtraDataEncoder.encode(proposedExtraData));
headerTestFixture.number(1);
final BlockHeader header = headerTestFixture.buildHeader();
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList(), Optional.empty()));

when(blockImporter.importBlock(any(), any(), any())).thenReturn(new BlockImportResult(true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.hyperledger.besu.pki.cms.CmsCreator;

import java.util.Collections;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
Expand Down Expand Up @@ -121,7 +122,7 @@ private Block createBlockBeingProposed() {
final Block block =
new Block(
blockHeaderWithExtraData,
new BlockBody(Collections.emptyList(), Collections.emptyList()));
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
when(blockCreator.createBlock(eq(1L)))
.thenReturn(new BlockCreationResult(block, new TransactionSelectionResults()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ProposalTest {
private static final Block BLOCK =
new Block(
new BlockHeaderTestFixture().extraData(bftExtraDataCodec.encode(extraData)).buildHeader(),
new BlockBody(Collections.emptyList(), Collections.emptyList()));
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));

@Test
public void canRoundTripProposalMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class RoundChangeTest {
new BlockHeaderTestFixture()
.extraData(new QbftExtraDataCodec().encode(extraData))
.buildHeader(),
new BlockBody(Collections.emptyList(), Collections.emptyList()));
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));

@Test
public void canRoundTripARoundChangeMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void buildCreatedBlock() {

headerTestFixture.extraData(bftExtraDataCodec.encode(extraData));
final BlockHeader header = headerTestFixture.buildHeader();
createdBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
createdBlock = new Block(header, new BlockBody(emptyList(), emptyList(), Optional.empty()));
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void setup() {
headerTestFixture.number(1);

final BlockHeader header = headerTestFixture.buildHeader();
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList(), Optional.empty()));

when(blockCreator.createBlock(anyLong()))
.thenReturn(new BlockCreationResult(proposedBlock, new TransactionSelectionResults()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void setup() {

private Block createEmptyBlock(final long blockNumber, final Hash parentHash) {
headerBuilder.number(blockNumber).parentHash(parentHash).coinbase(AddressHelpers.ofValue(0));
return new Block(headerBuilder.buildHeader(), new BlockBody(emptyList(), emptyList()));
return new Block(
headerBuilder.buildHeader(), new BlockBody(emptyList(), emptyList(), Optional.empty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -77,7 +78,8 @@ public void setup() {

private Block createEmptyBlock(final long blockNumber, final Hash parentHash) {
headerBuilder.number(blockNumber).parentHash(parentHash).coinbase(AddressHelpers.ofValue(0));
return new Block(headerBuilder.buildHeader(), new BlockBody(emptyList(), emptyList()));
return new Block(
headerBuilder.buildHeader(), new BlockBody(emptyList(), emptyList(), Optional.empty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private Block appendBlock(
.parentHash(parentBlock.getHash())
.number(parentBlock.getNumber() + 1)
.buildHeader(),
new BlockBody(transactionList, emptyList()));
new BlockBody(transactionList, emptyList(), Optional.empty()));
final List<TransactionReceipt> transactionReceipts =
transactionList.stream()
.map(transaction -> new TransactionReceipt(1, 1, emptyList(), Optional.empty()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private Block appendBlock(
.parentHash(parentBlock.getHash())
.number(parentBlock.getNumber() + 1)
.buildHeader(),
new BlockBody(transactionList, emptyList()));
new BlockBody(transactionList, emptyList(), Optional.empty()));
final List<TransactionReceipt> transactionReceipts =
transactionList.stream()
.map(transaction -> new TransactionReceipt(1, 1, emptyList(), Optional.empty()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
}

final var block =
new Block(newBlockHeader, new BlockBody(transactions, Collections.emptyList()));
new Block(
newBlockHeader, new BlockBody(transactions, Collections.emptyList(), Optional.empty()));

if (parentHeader.isEmpty()) {
debugLambda(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.ethereum.core.Difficulty;

import java.util.Collections;
import java.util.Optional;

public class UncleBlockResult {

Expand All @@ -30,7 +31,8 @@ public class UncleBlockResult {
* @return A BlockResult, generated from the header and empty body.
*/
public static BlockResult build(final BlockHeader header) {
final BlockBody body = new BlockBody(Collections.emptyList(), Collections.emptyList());
final BlockBody body =
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty());
final int size = new Block(header, body).calculateSize();
return new BlockResult(
header, Collections.emptyList(), Collections.emptyList(), Difficulty.ZERO, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ private Object createFakeBlock(final Long height) {
Bytes.EMPTY,
Address.ZERO,
Optional.empty())),
List.of())));
List.of(),
Optional.empty())));
}

private Object createEmptyBlock(final Long height) {
Expand All @@ -198,7 +199,7 @@ private Object createEmptyBlock(final Long height) {
Hash.EMPTY,
0,
null),
new BlockBody(List.of(), List.of())));
new BlockBody(List.of(), List.of(), Optional.empty())));
}

private JsonRpcRequestContext requestWithParams(final Object... params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ public void shouldReturnExpectedBlockResult() {

private BlockResult blockResult(final BlockHeader header) {
final Block block =
new Block(header, new BlockBody(Collections.emptyList(), Collections.emptyList()));
new Block(
header,
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
return new BlockResult(
header,
Collections.emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public void shouldReturnExpectedBlockResult() {

private BlockResult blockResult(final BlockHeader header) {
final Block block =
new Block(header, new BlockBody(Collections.emptyList(), Collections.emptyList()));
new Block(
header,
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
return new BlockResult(
header,
Collections.emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public AbstractEngineGetPayloadTest(final MethodFactory methodFactory) {
protected static final BlockHeader mockHeader =
new BlockHeaderTestFixture().prevRandao(Bytes32.random()).buildHeader();
private static final Block mockBlock =
new Block(mockHeader, new BlockBody(Collections.emptyList(), Collections.emptyList()));
new Block(
mockHeader,
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
private static final BlockWithReceipts mockBlockWithReceipts =
new BlockWithReceipts(mockBlock, Collections.emptyList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public void shouldReturnAcceptedOnLatestValidAncestorEmpty() {
public void shouldReturnSuccessOnAlreadyPresent() {
BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
Block mockBlock =
new Block(mockHeader, new BlockBody(Collections.emptyList(), Collections.emptyList()));
new Block(
mockHeader,
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));

when(blockchain.getBlockByHash(any())).thenReturn(Optional.of(mockBlock));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class RewardTraceGeneratorTest {

@Before
public void setUp() {
final BlockBody blockBody = new BlockBody(Collections.emptyList(), List.of(ommerHeader));
final BlockBody blockBody =
new BlockBody(Collections.emptyList(), List.of(ommerHeader), Optional.empty());
final BlockHeader blockHeader =
gen.header(0x0A, blockBody, new BlockDataGenerator.BlockOptions());
block = new Block(blockHeader, blockBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public void setup() {
0,
new MainnetBlockHeaderFunctions());
testHash = fakeHeader.getHash();
final BlockBody fakeBody = new BlockBody(Collections.emptyList(), Collections.emptyList());
final BlockBody fakeBody =
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty());
when(blockchain.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(testHash));
when(blockchain.getBlockHeader(any())).thenReturn(Optional.of(fakeHeader));
when(blockchain.getBlockHeader(anyLong())).thenReturn(Optional.of(fakeHeader));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void setup() {
new MainnetBlockHeaderFunctions(),
Optional.of(testLogsBloomFilter));
testHash = fakeHeader.getHash();
final BlockBody fakeBody = new BlockBody(Collections.emptyList(), Collections.emptyList());
final BlockBody fakeBody =
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty());
when(blockchain.getBlockHeader(any())).thenReturn(Optional.of(fakeHeader));
when(blockchain.getBlockHeader(anyLong())).thenReturn(Optional.of(fakeHeader));
when(blockchain.getTxReceipts(any())).thenReturn(Optional.of(Collections.emptyList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public void setup() throws IOException {
@Test
public void shouldUpdateCacheWhenBlockAdded() throws IOException {

final BlockBody fakeBody = new BlockBody(Collections.emptyList(), Collections.emptyList());
final BlockBody fakeBody =
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty());
when(blockchain.getBlockHeader(testBlockHeaderHash)).thenReturn(Optional.of(fakeHeader));
when(blockchain.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(testBlockHeaderHash));
when(blockchain.getTxReceipts(any())).thenReturn(Optional.of(Collections.emptyList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ protected BlockCreationResult createBlock(
final BlockHeader blockHeader = createFinalBlockHeader(sealableBlockHeader);

final Block block =
new Block(blockHeader, new BlockBody(transactionResults.getTransactions(), ommers));
new Block(
blockHeader,
new BlockBody(transactionResults.getTransactions(), ommers, Optional.empty()));
return new BlockCreationResult(block, transactionResults);
} catch (final SecurityModuleException ex) {
throw new IllegalStateException("Failed to create block signature", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AbstractMiningCoordinatorTest {
private static final Block BLOCK =
new Block(
new BlockHeaderTestFixture().buildHeader(),
new BlockBody(Collections.emptyList(), Collections.emptyList()));
new BlockBody(Collections.emptyList(), Collections.emptyList(), Optional.empty()));
private final Blockchain blockchain = mock(Blockchain.class);
private final PoWMinerExecutor minerExecutor = mock(PoWMinerExecutor.class);
private final SyncState syncState = mock(SyncState.class);
Expand Down
Loading

0 comments on commit 009508d

Please sign in to comment.