Skip to content

Commit 59b4b1d

Browse files
mirgeematkt
authored andcommitted
Separate BAL from block body (besu-eth#9629)
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com> Co-authored-by: Karim Taam <karim.t2am@gmail.com>
1 parent cae4b66 commit 59b4b1d

File tree

100 files changed

+1280
-423
lines changed

Some content is hidden

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

100 files changed

+1280
-423
lines changed

app/src/main/java/org/hyperledger/besu/cli/subcommands/storage/PrunePreMergeBlockDataSubCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ private void deleteBlockRange(
141141
}
142142
final Hash h = maybeBlockHash.get();
143143
updater.removeTransactionReceipts(h);
144+
updater.removeBlockAccessList(h);
144145
updater.removeBlockBody(h);
145146
} while (++headerNumber < endBlockNumber);
146147
updater.commit();

consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ void doesNotMineBlockIfNoTransactionsWhenEmptyBlocksNotAllowed() throws Interrup
9494
when(blockCreator.createBlock(anyLong(), any()))
9595
.thenReturn(
9696
new BlockCreator.BlockCreationResult(
97-
blockToCreate, new TransactionSelectionResults(), new BlockCreationTiming()));
97+
blockToCreate,
98+
new TransactionSelectionResults(),
99+
new BlockCreationTiming(),
100+
Optional.empty()));
98101

99102
final BlockImporter blockImporter = mock(BlockImporter.class);
100103
final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
101104
when(protocolSpec.getHardforkId()).thenReturn(FRONTIER);
102105
final ProtocolSchedule protocolSchedule = singleSpecSchedule(protocolSpec);
103106

104107
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
105-
when(blockImporter.importBlock(any(), any(), any())).thenReturn(new BlockImportResult(true));
108+
when(blockImporter.importBlock(any(), any(), any(), any(), any()))
109+
.thenReturn(new BlockImportResult(true));
106110

107111
final MinedBlockObserver observer = mock(MinedBlockObserver.class);
108112
final DefaultBlockScheduler scheduler = mock(DefaultBlockScheduler.class);
@@ -121,7 +125,12 @@ void doesNotMineBlockIfNoTransactionsWhenEmptyBlocksNotAllowed() throws Interrup
121125
final boolean result = miner.mineBlock();
122126
assertThat(result).isFalse();
123127
verify(blockImporter, never())
124-
.importBlock(protocolContext, blockToCreate, HeaderValidationMode.FULL);
128+
.importBlock(
129+
protocolContext,
130+
blockToCreate,
131+
HeaderValidationMode.FULL,
132+
HeaderValidationMode.FULL,
133+
Optional.empty());
125134
verify(observer, never()).blockMined(blockToCreate);
126135
}
127136

@@ -150,15 +159,19 @@ void minesBlockIfHasTransactionsWhenEmptyBlocksNotAllowed() throws InterruptedEx
150159
when(blockCreator.createBlock(anyLong(), any()))
151160
.thenReturn(
152161
new BlockCreator.BlockCreationResult(
153-
blockToCreate, new TransactionSelectionResults(), new BlockCreationTiming()));
162+
blockToCreate,
163+
new TransactionSelectionResults(),
164+
new BlockCreationTiming(),
165+
Optional.empty()));
154166

155167
final BlockImporter blockImporter = mock(BlockImporter.class);
156168
final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
157169
when(protocolSpec.getHardforkId()).thenReturn(FRONTIER);
158170
final ProtocolSchedule protocolSchedule = singleSpecSchedule(protocolSpec);
159171

160172
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
161-
when(blockImporter.importBlock(any(), any(), any())).thenReturn(new BlockImportResult(true));
173+
when(blockImporter.importBlock(any(), any(), any(), any(), any()))
174+
.thenReturn(new BlockImportResult(true));
162175

163176
final MinedBlockObserver observer = mock(MinedBlockObserver.class);
164177
final DefaultBlockScheduler scheduler = mock(DefaultBlockScheduler.class);
@@ -176,7 +189,13 @@ void minesBlockIfHasTransactionsWhenEmptyBlocksNotAllowed() throws InterruptedEx
176189

177190
final boolean result = miner.mineBlock();
178191
assertThat(result).isTrue();
179-
verify(blockImporter).importBlock(protocolContext, blockToCreate, HeaderValidationMode.FULL);
192+
verify(blockImporter)
193+
.importBlock(
194+
protocolContext,
195+
blockToCreate,
196+
HeaderValidationMode.FULL,
197+
HeaderValidationMode.FULL,
198+
Optional.empty());
180199
verify(observer).blockMined(blockToCreate);
181200
}
182201

consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
3131
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
3232
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;
33-
import org.hyperledger.besu.ethereum.mainnet.WithdrawalsValidator;
3433
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
3534
import org.hyperledger.besu.evm.internal.EvmConfiguration;
3635
import org.hyperledger.besu.plugin.services.MetricsSystem;
@@ -139,7 +138,6 @@ private ProtocolSpecBuilder applyBftChanges(
139138
.skipZeroBlockRewards(true)
140139
.blockHeaderFunctions(BftBlockHeaderFunctions.forOnchainBlock(bftExtraDataCodec))
141140
.blockReward(Wei.of(configOptions.getBlockRewardWei()))
142-
.withdrawalsValidator(new WithdrawalsValidator.NotApplicableWithdrawals())
143141
.miningBeneficiaryCalculator(
144142
header -> configOptions.getMiningBeneficiary().orElseGet(header::getCoinbase));
145143
}

consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public void setup() {
120120
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
121121
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
122122

123-
when(blockImporter.importBlock(any(), any(), any())).thenReturn(new BlockImportResult(true));
123+
when(blockImporter.importBlock(any(), any(), any(), any(), any()))
124+
.thenReturn(new BlockImportResult(true));
124125

125126
protocolContext =
126127
new ProtocolContext.Builder()
@@ -202,6 +203,6 @@ public void failuresToSignStillAllowBlockToBeImported() {
202203
assertThat(roundState.isCommitted()).isTrue();
203204
verifyNoInteractions(multicaster);
204205

205-
verify(blockImporter).importBlock(any(), any(), any());
206+
verify(blockImporter).importBlock(any(), any(), any(), any(), any());
206207
}
207208
}

consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/Proposal.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate;
2424
import org.hyperledger.besu.datatypes.Hash;
2525
import org.hyperledger.besu.ethereum.core.Block;
26+
import org.hyperledger.besu.ethereum.core.encoding.BlockAccessListDecoder;
27+
import org.hyperledger.besu.ethereum.mainnet.block.access.list.BlockAccessList;
2628
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
2729
import org.hyperledger.besu.ethereum.rlp.RLP;
2830
import org.hyperledger.besu.ethereum.rlp.RLPInput;
@@ -36,6 +38,7 @@ public class Proposal extends BftMessage<ProposalPayload> {
3638

3739
private static final IbftExtraDataCodec BFT_EXTRA_DATA_ENCODER = new IbftExtraDataCodec();
3840
private final Block proposedBlock;
41+
private final Optional<BlockAccessList> blockAccessList;
3942

4043
private final Optional<RoundChangeCertificate> roundChangeCertificate;
4144

@@ -44,14 +47,17 @@ public class Proposal extends BftMessage<ProposalPayload> {
4447
*
4548
* @param payload the payload
4649
* @param proposedBlock the proposed block
50+
* @param blockAccessList the block access list
4751
* @param certificate the certificate
4852
*/
4953
public Proposal(
5054
final SignedData<ProposalPayload> payload,
5155
final Block proposedBlock,
56+
final Optional<BlockAccessList> blockAccessList,
5257
final Optional<RoundChangeCertificate> certificate) {
5358
super(payload);
5459
this.proposedBlock = proposedBlock;
60+
this.blockAccessList = blockAccessList;
5561
this.roundChangeCertificate = certificate;
5662
}
5763

@@ -64,6 +70,15 @@ public Block getBlock() {
6470
return proposedBlock;
6571
}
6672

73+
/**
74+
* Gets block access list.
75+
*
76+
* @return the block access list
77+
*/
78+
public Optional<BlockAccessList> getBlockAccessList() {
79+
return blockAccessList;
80+
}
81+
6782
/**
6883
* Gets digest.
6984
*
@@ -93,6 +108,7 @@ public Bytes encode() {
93108
} else {
94109
rlpOut.writeNull();
95110
}
111+
blockAccessList.ifPresentOrElse((bal) -> bal.writeTo(rlpOut), rlpOut::writeNull);
96112
rlpOut.endList();
97113
return rlpOut.encoded();
98114
}
@@ -113,9 +129,10 @@ public static Proposal decode(final Bytes data) {
113129

114130
final Optional<RoundChangeCertificate> roundChangeCertificate =
115131
readRoundChangeCertificate(rlpIn);
132+
final Optional<BlockAccessList> blockAccessList = readBlockAccessList(rlpIn);
116133

117134
rlpIn.leaveList();
118-
return new Proposal(payload, proposedBlock, roundChangeCertificate);
135+
return new Proposal(payload, proposedBlock, blockAccessList, roundChangeCertificate);
119136
}
120137

121138
private static Optional<RoundChangeCertificate> readRoundChangeCertificate(final RLPInput rlpIn) {
@@ -128,4 +145,12 @@ private static Optional<RoundChangeCertificate> readRoundChangeCertificate(final
128145

129146
return Optional.ofNullable(roundChangeCertificate);
130147
}
148+
149+
private static Optional<BlockAccessList> readBlockAccessList(final RLPInput rlpIn) {
150+
if (!rlpIn.nextIsNull()) {
151+
return Optional.of(BlockAccessListDecoder.decode(rlpIn));
152+
}
153+
rlpIn.skipNext();
154+
return Optional.empty();
155+
}
131156
}

consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/RoundChange.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate;
2424
import org.hyperledger.besu.consensus.ibft.payload.RoundChangePayload;
2525
import org.hyperledger.besu.ethereum.core.Block;
26+
import org.hyperledger.besu.ethereum.core.encoding.BlockAccessListDecoder;
27+
import org.hyperledger.besu.ethereum.mainnet.block.access.list.BlockAccessList;
2628
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
2729
import org.hyperledger.besu.ethereum.rlp.RLP;
2830
import org.hyperledger.besu.ethereum.rlp.RLPInput;
@@ -36,17 +38,22 @@ public class RoundChange extends BftMessage<RoundChangePayload> {
3638

3739
private static final IbftExtraDataCodec BFT_EXTRA_DATA_ENCODER = new IbftExtraDataCodec();
3840
private final Optional<Block> proposedBlock;
41+
private final Optional<BlockAccessList> blockAccessList;
3942

4043
/**
4144
* Instantiates a new Round change.
4245
*
4346
* @param payload the payload
4447
* @param proposedBlock the proposed block
48+
* @param blockAccessList the block access list
4549
*/
4650
public RoundChange(
47-
final SignedData<RoundChangePayload> payload, final Optional<Block> proposedBlock) {
51+
final SignedData<RoundChangePayload> payload,
52+
final Optional<Block> proposedBlock,
53+
final Optional<BlockAccessList> blockAccessList) {
4854
super(payload);
4955
this.proposedBlock = proposedBlock;
56+
this.blockAccessList = blockAccessList;
5057
}
5158

5259
/**
@@ -58,6 +65,15 @@ public Optional<Block> getProposedBlock() {
5865
return proposedBlock;
5966
}
6067

68+
/**
69+
* Gets block access list.
70+
*
71+
* @return the block access list
72+
*/
73+
public Optional<BlockAccessList> getBlockAccessList() {
74+
return blockAccessList;
75+
}
76+
6177
/**
6278
* Gets prepared certificate.
6379
*
@@ -87,6 +103,7 @@ public Bytes encode() {
87103
} else {
88104
rlpOut.writeNull();
89105
}
106+
blockAccessList.ifPresentOrElse((bal) -> bal.writeTo(rlpOut), rlpOut::writeNull);
90107
rlpOut.endList();
91108
return rlpOut.encoded();
92109
}
@@ -112,8 +129,17 @@ public static RoundChange decode(final Bytes data) {
112129
} else {
113130
rlpIn.skipNext();
114131
}
132+
final Optional<BlockAccessList> blockAccessList = readBlockAccessList(rlpIn);
115133
rlpIn.leaveList();
116134

117-
return new RoundChange(payload, block);
135+
return new RoundChange(payload, block, blockAccessList);
136+
}
137+
138+
private static Optional<BlockAccessList> readBlockAccessList(final RLPInput rlpIn) {
139+
if (!rlpIn.nextIsNull()) {
140+
return Optional.of(BlockAccessListDecoder.decode(rlpIn));
141+
}
142+
rlpIn.skipNext();
143+
return Optional.empty();
118144
}
119145
}

consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/network/IbftMessageTransmitter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.hyperledger.besu.crypto.SECPSignature;
3131
import org.hyperledger.besu.datatypes.Hash;
3232
import org.hyperledger.besu.ethereum.core.Block;
33+
import org.hyperledger.besu.ethereum.mainnet.block.access.list.BlockAccessList;
3334
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException;
3435

3536
import java.util.Optional;
@@ -62,15 +63,18 @@ public IbftMessageTransmitter(
6263
*
6364
* @param roundIdentifier the round identifier
6465
* @param block the block
66+
* @param blockAccessList the block access list
6567
* @param roundChangeCertificate the round change certificate
6668
*/
6769
public void multicastProposal(
6870
final ConsensusRoundIdentifier roundIdentifier,
6971
final Block block,
72+
final Optional<BlockAccessList> blockAccessList,
7073
final Optional<RoundChangeCertificate> roundChangeCertificate) {
7174
try {
7275
final Proposal data =
73-
messageFactory.createProposal(roundIdentifier, block, roundChangeCertificate);
76+
messageFactory.createProposal(
77+
roundIdentifier, block, blockAccessList, roundChangeCertificate);
7478

7579
final ProposalMessageData message = ProposalMessageData.create(data);
7680

consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/payload/MessageFactory.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.hyperledger.besu.cryptoservices.NodeKey;
2727
import org.hyperledger.besu.datatypes.Hash;
2828
import org.hyperledger.besu.ethereum.core.Block;
29+
import org.hyperledger.besu.ethereum.mainnet.block.access.list.BlockAccessList;
2930

3031
import java.util.Optional;
3132

@@ -50,17 +51,35 @@ public MessageFactory(final NodeKey nodeKey) {
5051
*
5152
* @param roundIdentifier the round identifier
5253
* @param block the block
54+
* @param blockAccessList the block access list
5355
* @param roundChangeCertificate the round change certificate
5456
* @return the proposal
5557
*/
5658
public Proposal createProposal(
5759
final ConsensusRoundIdentifier roundIdentifier,
5860
final Block block,
61+
final Optional<BlockAccessList> blockAccessList,
5962
final Optional<RoundChangeCertificate> roundChangeCertificate) {
6063

6164
final ProposalPayload payload = new ProposalPayload(roundIdentifier, block.getHash());
6265

63-
return new Proposal(createSignedMessage(payload), block, roundChangeCertificate);
66+
return new Proposal(
67+
createSignedMessage(payload), block, blockAccessList, roundChangeCertificate);
68+
}
69+
70+
/**
71+
* Create proposal.
72+
*
73+
* @param roundIdentifier the round identifier
74+
* @param block the block
75+
* @param roundChangeCertificate the round change certificate
76+
* @return the proposal
77+
*/
78+
public Proposal createProposal(
79+
final ConsensusRoundIdentifier roundIdentifier,
80+
final Block block,
81+
final Optional<RoundChangeCertificate> roundChangeCertificate) {
82+
return createProposal(roundIdentifier, block, Optional.empty(), roundChangeCertificate);
6483
}
6584

6685
/**
@@ -111,7 +130,9 @@ public RoundChange createRoundChange(
111130
roundIdentifier,
112131
preparedRoundArtifacts.map(PreparedRoundArtifacts::getPreparedCertificate));
113132
return new RoundChange(
114-
createSignedMessage(payload), preparedRoundArtifacts.map(PreparedRoundArtifacts::getBlock));
133+
createSignedMessage(payload),
134+
preparedRoundArtifacts.map(PreparedRoundArtifacts::getBlock),
135+
preparedRoundArtifacts.flatMap(PreparedRoundArtifacts::getBlockAccessList));
115136
}
116137

117138
private <M extends Payload> SignedData<M> createSignedMessage(final M payload) {

0 commit comments

Comments
 (0)