Skip to content

Commit a3f9d63

Browse files
fab-10jflo
authored andcommitted
Block transaction selector performance (besu-eth#9023)
* Improve performance of block creation Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
1 parent e6199a6 commit a3f9d63

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
- Add `WorldStateService` to the plugin API [#9024](https://github.com/hyperledger/besu/pull/9024)
5252
- Wait for peers before starting Backward Sync [#9003](https://github.com/hyperledger/besu/pull/9003)
5353
- LUKSO Mainnet Pectra Hardfork [#9070](https://github.com/hyperledger/besu/pull/9070)
54+
- More informative logs during block creation [#9020](https://github.com/hyperledger/besu/pull/9020)
55+
- Faster block creation, reducing the time spent committing world state changes [#9023](https://github.com/hyperledger/besu/pull/9023)
5456

5557
#### Dependencies
5658
- Generate distribution dependencies catalog [#8987](https://github.com/hyperledger/besu/pull/8987)

ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class BlockTransactionSelector implements BlockTransactionSelectionServic
9595
private final Supplier<Boolean> isCancelled;
9696
private final MainnetTransactionProcessor transactionProcessor;
9797
private final Blockchain blockchain;
98+
// private final WorldUpdater worldUpdater;
9899
private final MutableWorldState worldState;
99100
private final AbstractBlockProcessor.TransactionReceiptFactory transactionReceiptFactory;
100101
private final BlockSelectionContext blockSelectionContext;
@@ -339,24 +340,27 @@ public TransactionSelectionResult evaluatePendingTransaction(
339340
@Override
340341
public boolean commit() {
341342
// only add this tx to the selected set if it is not too late,
342-
// this need to be done synchronously to avoid that a concurrent timeout
343+
// this needs to be done synchronously to avoid that a concurrent timeout
343344
// could start packing a block while we are updating the state here
345+
final boolean isTooLate;
344346
synchronized (isTimeout) {
345-
if (!isTimeout.get()) {
347+
isTooLate = isTimeout.get();
348+
if (!isTooLate) {
346349
selectorsStateManager.commit();
347350
txWorldStateUpdater.commit();
348351
blockWorldStateUpdater.commit();
352+
blockWorldStateUpdater.markTransactionBoundary();
349353
for (final var pendingAction : selectedTxPendingActions) {
350354
pendingAction.run();
351355
}
352-
selectedTxPendingActions.clear();
353-
return true;
354356
}
355357
}
358+
356359
selectedTxPendingActions.clear();
357360
blockWorldStateUpdater = worldState.updater();
358361
txWorldStateUpdater = blockWorldStateUpdater.updater();
359-
return false;
362+
363+
return !isTooLate;
360364
}
361365

362366
@Override
@@ -471,7 +475,7 @@ private TransactionSelectionResult handleTransactionSelected(
471475
transaction.getGasLimit() - processingResult.getGasRemaining();
472476

473477
// queue the creation of the receipt and the update of the final results
474-
// there actions will be performed on commit if the pending tx is definitely selected
478+
// these actions will be performed on commit if the pending tx is definitely selected
475479
selectedTxPendingActions.add(
476480
() -> {
477481
final long cumulativeGasUsed =

0 commit comments

Comments
 (0)