Skip to content

Commit 41a0647

Browse files
authored
Improve Conflict Detection in Parallelization by Considering Slots to Reduce False Positives (#7923)
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
1 parent efcefad commit 41a0647

20 files changed

+507
-158
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Add TLS/mTLS options and configure the GraphQL HTTP service[#7910](https://github.com/hyperledger/besu/pull/7910)
2222
- Allow plugins to propose transactions during block creation [#8268](https://github.com/hyperledger/besu/pull/8268)
2323
- Update `eth_getLogs` to return a `Block not found` error when the requested block is not found. [#8290](https://github.com/hyperledger/besu/pull/8290)
24+
- Improve Conflict Detection in Parallelization by Considering Slots to Reduce False Positives. [#7923](https://github.com/hyperledger/besu/pull/7923)
2425
### Bug fixes
2526
- Upgrade Netty to version 4.1.118 to fix CVE-2025-24970 [#8275](https://github.com/hyperledger/besu/pull/8275)
2627
- Add missing RPC method `debug_accountRange` to `RpcMethod.java` and implemented its handler. [#8153](https://github.com/hyperledger/besu/issues/8153)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private void handleFailedBlockProcessing(
248248
protected BlockProcessingResult processBlock(
249249
final ProtocolContext context, final MutableWorldState worldState, final Block block) {
250250

251-
return blockProcessor.processBlock(context.getBlockchain(), worldState, block);
251+
return blockProcessor.processBlock(context, context.getBlockchain(), worldState, block);
252252
}
253253

254254
@Override

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.hyperledger.besu.datatypes.Wei;
2323
import org.hyperledger.besu.ethereum.BlockProcessingOutputs;
2424
import org.hyperledger.besu.ethereum.BlockProcessingResult;
25+
import org.hyperledger.besu.ethereum.ProtocolContext;
2526
import org.hyperledger.besu.ethereum.chain.Blockchain;
2627
import org.hyperledger.besu.ethereum.core.BlockHeader;
2728
import org.hyperledger.besu.ethereum.core.MutableWorldState;
@@ -95,6 +96,7 @@ protected AbstractBlockProcessor(
9596

9697
@Override
9798
public BlockProcessingResult processBlock(
99+
final ProtocolContext protocolContext,
98100
final Blockchain blockchain,
99101
final MutableWorldState worldState,
100102
final BlockHeader blockHeader,
@@ -103,6 +105,7 @@ public BlockProcessingResult processBlock(
103105
final Optional<List<Withdrawal>> maybeWithdrawals,
104106
final PrivateMetadataUpdater privateMetadataUpdater) {
105107
return processBlock(
108+
protocolContext,
106109
blockchain,
107110
worldState,
108111
blockHeader,
@@ -114,6 +117,7 @@ public BlockProcessingResult processBlock(
114117
}
115118

116119
protected BlockProcessingResult processBlock(
120+
final ProtocolContext protocolContext,
117121
final Blockchain blockchain,
118122
final MutableWorldState worldState,
119123
final BlockHeader blockHeader,
@@ -151,7 +155,7 @@ protected BlockProcessingResult processBlock(
151155

152156
final Optional<PreprocessingContext> preProcessingContext =
153157
preprocessingBlockFunction.run(
154-
worldState,
158+
protocolContext,
155159
privateMetadataUpdater,
156160
blockHeader,
157161
transactions,
@@ -342,7 +346,7 @@ public interface PreprocessingContext {}
342346

343347
public interface PreprocessingFunction {
344348
Optional<PreprocessingContext> run(
345-
final MutableWorldState worldState,
349+
final ProtocolContext protocolContext,
346350
final PrivateMetadataUpdater privateMetadataUpdater,
347351
final BlockHeader blockHeader,
348352
final List<Transaction> transactions,
@@ -354,7 +358,7 @@ class NoPreprocessing implements PreprocessingFunction {
354358

355359
@Override
356360
public Optional<PreprocessingContext> run(
357-
final MutableWorldState worldState,
361+
final ProtocolContext protocolContext,
358362
final PrivateMetadataUpdater privateMetadataUpdater,
359363
final BlockHeader blockHeader,
360364
final List<Transaction> transactions,

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockProcessor.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.hyperledger.besu.datatypes.Wei;
1818
import org.hyperledger.besu.ethereum.BlockProcessingResult;
19+
import org.hyperledger.besu.ethereum.ProtocolContext;
1920
import org.hyperledger.besu.ethereum.chain.Blockchain;
2021
import org.hyperledger.besu.ethereum.core.Block;
2122
import org.hyperledger.besu.ethereum.core.BlockHeader;
@@ -68,14 +69,19 @@ default boolean isFailed() {
6869
/**
6970
* Processes the block.
7071
*
72+
* @param protocolContext the current context of the protocol
7173
* @param blockchain the blockchain to append the block to
7274
* @param worldState the world state to apply changes to
7375
* @param block the block to process
7476
* @return the block processing result
7577
*/
7678
default BlockProcessingResult processBlock(
77-
final Blockchain blockchain, final MutableWorldState worldState, final Block block) {
79+
final ProtocolContext protocolContext,
80+
final Blockchain blockchain,
81+
final MutableWorldState worldState,
82+
final Block block) {
7883
return processBlock(
84+
protocolContext,
7985
blockchain,
8086
worldState,
8187
block.getHeader(),
@@ -88,6 +94,7 @@ default BlockProcessingResult processBlock(
8894
/**
8995
* Processes the block.
9096
*
97+
* @param protocolContext the current context of the protocol
9198
* @param blockchain the blockchain to append the block to
9299
* @param worldState the world state to apply changes to
93100
* @param blockHeader the block header for the block
@@ -96,18 +103,27 @@ default BlockProcessingResult processBlock(
96103
* @return the block processing result
97104
*/
98105
default BlockProcessingResult processBlock(
106+
final ProtocolContext protocolContext,
99107
final Blockchain blockchain,
100108
final MutableWorldState worldState,
101109
final BlockHeader blockHeader,
102110
final List<Transaction> transactions,
103111
final List<BlockHeader> ommers) {
104112
return processBlock(
105-
blockchain, worldState, blockHeader, transactions, ommers, Optional.empty(), null);
113+
protocolContext,
114+
blockchain,
115+
worldState,
116+
blockHeader,
117+
transactions,
118+
ommers,
119+
Optional.empty(),
120+
null);
106121
}
107122

108123
/**
109124
* Processes the block.
110125
*
126+
* @param protocolContext the current context of the protocol
111127
* @param blockchain the blockchain to append the block to
112128
* @param worldState the world state to apply changes to
113129
* @param blockHeader the block header for the block
@@ -118,6 +134,7 @@ default BlockProcessingResult processBlock(
118134
* @return the block processing result
119135
*/
120136
BlockProcessingResult processBlock(
137+
ProtocolContext protocolContext,
121138
Blockchain blockchain,
122139
MutableWorldState worldState,
123140
BlockHeader blockHeader,
@@ -129,13 +146,15 @@ BlockProcessingResult processBlock(
129146
/**
130147
* Processes the block when running Besu in GoQuorum-compatible mode
131148
*
149+
* @param protocolContext the current context of the protocol
132150
* @param blockchain the blockchain to append the block to
133151
* @param worldState the world state to apply public transactions to
134152
* @param privateWorldState the private world state to apply private transaction to
135153
* @param block the block to process
136154
* @return the block processing result
137155
*/
138156
default BlockProcessingResult processBlock(
157+
final ProtocolContext protocolContext,
139158
final Blockchain blockchain,
140159
final MutableWorldState worldState,
141160
final MutableWorldState privateWorldState,

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.hyperledger.besu.datatypes.Wei;
2727
import org.hyperledger.besu.ethereum.BlockProcessingResult;
2828
import org.hyperledger.besu.ethereum.MainnetBlockValidator;
29+
import org.hyperledger.besu.ethereum.ProtocolContext;
2930
import org.hyperledger.besu.ethereum.chain.Blockchain;
3031
import org.hyperledger.besu.ethereum.core.BlockHeader;
3132
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
@@ -1101,6 +1102,7 @@ private record DaoBlockProcessor(BlockProcessor wrapped) implements BlockProcess
11011102

11021103
@Override
11031104
public BlockProcessingResult processBlock(
1105+
final ProtocolContext protocolContext,
11041106
final Blockchain blockchain,
11051107
final MutableWorldState worldState,
11061108
final BlockHeader blockHeader,
@@ -1110,6 +1112,7 @@ public BlockProcessingResult processBlock(
11101112
final PrivateMetadataUpdater privateMetadataUpdater) {
11111113
updateWorldStateForDao(worldState);
11121114
return wrapped.processBlock(
1115+
protocolContext,
11131116
blockchain,
11141117
worldState,
11151118
blockHeader,

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PrivacyBlockProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hyperledger.besu.enclave.EnclaveClientException;
2222
import org.hyperledger.besu.enclave.types.ReceiveResponse;
2323
import org.hyperledger.besu.ethereum.BlockProcessingResult;
24+
import org.hyperledger.besu.ethereum.ProtocolContext;
2425
import org.hyperledger.besu.ethereum.chain.Blockchain;
2526
import org.hyperledger.besu.ethereum.core.BlockHeader;
2627
import org.hyperledger.besu.ethereum.core.MutableWorldState;
@@ -83,6 +84,7 @@ public void setPublicWorldStateArchive(final WorldStateArchive publicWorldStateA
8384

8485
@Override
8586
public BlockProcessingResult processBlock(
87+
final ProtocolContext protocolContext,
8688
final Blockchain blockchain,
8789
final MutableWorldState worldState,
8890
final BlockHeader blockHeader,
@@ -102,6 +104,7 @@ public BlockProcessingResult processBlock(
102104

103105
final BlockProcessingResult result =
104106
blockProcessor.processBlock(
107+
protocolContext,
105108
blockchain,
106109
worldState,
107110
blockHeader,

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/parallelization/MainnetParallelBlockProcessor.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.hyperledger.besu.datatypes.Address;
1818
import org.hyperledger.besu.datatypes.Wei;
1919
import org.hyperledger.besu.ethereum.BlockProcessingResult;
20+
import org.hyperledger.besu.ethereum.ProtocolContext;
2021
import org.hyperledger.besu.ethereum.chain.Blockchain;
2122
import org.hyperledger.besu.ethereum.core.BlockHeader;
2223
import org.hyperledger.besu.ethereum.core.MutableWorldState;
@@ -31,7 +32,7 @@
3132
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;
3233
import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater;
3334
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
34-
import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.DiffBasedWorldState;
35+
import org.hyperledger.besu.ethereum.trie.diffbased.common.provider.DiffBasedWorldStateProvider;
3536
import org.hyperledger.besu.evm.blockhash.BlockHashLookup;
3637
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
3738
import org.hyperledger.besu.metrics.BesuMetricCategory;
@@ -137,6 +138,7 @@ protected TransactionProcessingResult getTransactionProcessingResult(
137138

138139
@Override
139140
public BlockProcessingResult processBlock(
141+
final ProtocolContext protocolContext,
140142
final Blockchain blockchain,
141143
final MutableWorldState worldState,
142144
final BlockHeader blockHeader,
@@ -146,6 +148,7 @@ public BlockProcessingResult processBlock(
146148
final PrivateMetadataUpdater privateMetadataUpdater) {
147149
final BlockProcessingResult blockProcessingResult =
148150
super.processBlock(
151+
protocolContext,
149152
blockchain,
150153
worldState,
151154
blockHeader,
@@ -154,13 +157,15 @@ public BlockProcessingResult processBlock(
154157
maybeWithdrawals,
155158
privateMetadataUpdater,
156159
new ParallelTransactionPreprocessing());
160+
157161
if (blockProcessingResult.isFailed()) {
158162
// Fallback to non-parallel processing if there is a block processing exception .
159163
LOG.info(
160164
"Parallel transaction processing failure. Falling back to non-parallel processing for block #{} ({})",
161165
blockHeader.getNumber(),
162166
blockHeader.getBlockHash());
163167
return super.processBlock(
168+
protocolContext,
164169
blockchain,
165170
worldState,
166171
blockHeader,
@@ -209,20 +214,20 @@ class ParallelTransactionPreprocessing implements PreprocessingFunction {
209214

210215
@Override
211216
public Optional<PreprocessingContext> run(
212-
final MutableWorldState worldState,
217+
final ProtocolContext protocolContext,
213218
final PrivateMetadataUpdater privateMetadataUpdater,
214219
final BlockHeader blockHeader,
215220
final List<Transaction> transactions,
216221
final Address miningBeneficiary,
217222
final BlockHashLookup blockHashLookup,
218223
final Wei blobGasPrice) {
219-
if ((worldState instanceof DiffBasedWorldState)) {
224+
if ((protocolContext.getWorldStateArchive() instanceof DiffBasedWorldStateProvider)) {
220225
ParallelizedConcurrentTransactionProcessor parallelizedConcurrentTransactionProcessor =
221226
new ParallelizedConcurrentTransactionProcessor(transactionProcessor);
222-
// When enabled, runAsyncBlock performs non-conflicting parallel execution of transactions
223-
// in the background using an optimistic approach.
227+
// runAsyncBlock, if activated, facilitates the non-blocking parallel execution of
228+
// transactions in the background through an optimistic strategy.
224229
parallelizedConcurrentTransactionProcessor.runAsyncBlock(
225-
worldState,
230+
protocolContext,
226231
blockHeader,
227232
transactions,
228233
miningBeneficiary,

0 commit comments

Comments
 (0)