Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time limited block creation #6044

Merged
merged 55 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c57c2ac
Refactor mining options
fab-10 Oct 10, 2023
b408b64
Fix null pointer exception
fab-10 Oct 10, 2023
da79e09
fix another null pointer exception
fab-10 Oct 10, 2023
7684d7e
uncomment code
fab-10 Oct 10, 2023
78741da
Move miner options tests
fab-10 Oct 11, 2023
18bcce3
Unit test fixes
fab-10 Oct 12, 2023
59fbe8e
Removed the commented code
fab-10 Oct 12, 2023
8f14dd3
WIP
fab-10 Oct 13, 2023
2280e02
Merge branch 'main' into mining-options-refactor
fab-10 Oct 13, 2023
65bdabd
WIP
fab-10 Oct 13, 2023
e89a244
Remove not relevant for this feature
fab-10 Oct 16, 2023
46e0dc4
Revert "Remove not relevant for this feature"
fab-10 Oct 16, 2023
20e498b
Merge branch 'main' into mining-options-refactor
fab-10 Oct 16, 2023
0ea8553
Time limited transaction selection during block creation
fab-10 Oct 16, 2023
86b9a6e
Merge branch 'main' into mining-options-refactor
fab-10 Oct 17, 2023
2267bc7
Fix javadoc
fab-10 Oct 17, 2023
c6b56d2
Remove code not belonging to this PR
fab-10 Oct 17, 2023
477acf9
coinbase is an updatable parameter
fab-10 Oct 17, 2023
4626230
Move MiningOptions to upper package
fab-10 Oct 17, 2023
25b1522
Fix coinbase for *bft
fab-10 Oct 17, 2023
28a32af
Merge branch 'mining-options-refactor' into time-limited-block-creation
fab-10 Oct 17, 2023
ae775ae
Merge branch 'main' into mining-options-refactor
fab-10 Oct 18, 2023
ca5095d
Merge branch 'mining-options-refactor' into time-limited-block-creation
fab-10 Oct 18, 2023
06a7145
Fix test
fab-10 Oct 18, 2023
bc655bf
Introduce a block level and a tx level world state updater
fab-10 Oct 18, 2023
16315a4
Merge branch 'main' into mining-options-refactor
macfarla Oct 20, 2023
2700930
Merge branch 'mining-options-refactor' of github.com:fab-10/besu into…
fab-10 Oct 23, 2023
bf8eba4
Merge branch 'mining-options-refactor' into time-limited-block-creation
fab-10 Oct 23, 2023
4716d89
Fix test
fab-10 Oct 23, 2023
e55392b
Apply suggestions from code review
fab-10 Oct 23, 2023
fa534ba
Merge branch 'mining-options-refactor' into time-limited-block-creation
fab-10 Oct 23, 2023
8aef8ad
Option remaning and tests
fab-10 Oct 23, 2023
bc8137f
Better handling of tx on timeout
fab-10 Oct 23, 2023
d710e5c
Merge branch 'main' into mining-options-refactor
fab-10 Oct 24, 2023
639af82
Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
fab-10 Oct 24, 2023
232caa6
Merge branch 'mining-options-refactor' of github.com:fab-10/besu into…
fab-10 Oct 24, 2023
878969d
Merge branch 'main' into mining-options-refactor
fab-10 Oct 24, 2023
700a06a
Merge branch 'mining-options-refactor' into time-limited-block-creation
fab-10 Oct 24, 2023
f3c4c3c
Better handling of not selected tx due to timeout
fab-10 Oct 24, 2023
2050178
[skip ci] Update CHANGELOG
fab-10 Oct 24, 2023
0de5b5a
Merge branch 'main' into time-limited-block-creation
fab-10 Oct 25, 2023
90b05ea
Merge branch 'main' into time-limited-block-creation
fab-10 Oct 25, 2023
415adcf
Merge branch 'main' into time-limited-block-creation
fab-10 Oct 26, 2023
0e6b2bf
Merge branch 'main' into time-limited-block-creation
fab-10 Oct 31, 2023
5c5c954
Merge branch 'main' into time-limited-block-creation
fab-10 Nov 2, 2023
a8b859f
Apply suggestion from code review and javadoc
fab-10 Nov 2, 2023
cf8b239
Introduce a specific configuration for PoA networks
fab-10 Nov 2, 2023
5ce9aaa
Merge branch 'main' into time-limited-block-creation
fab-10 Nov 2, 2023
42548a0
javadoc
fab-10 Nov 2, 2023
f7650c9
More option tests
fab-10 Nov 2, 2023
8247a26
Merge branch 'main' into time-limited-block-creation
fab-10 Nov 3, 2023
1cbd1e8
Update CHANGELOG
fab-10 Nov 3, 2023
08e0be2
Merge branch 'main' into time-limited-block-creation
fab-10 Nov 6, 2023
a2d1ad7
Merge branch 'main' into time-limited-block-creation
fab-10 Nov 7, 2023
2fa5b03
Merge branch 'main' into time-limited-block-creation
fab-10 Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Remove not relevant for this feature"
This reverts commit e89a244.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Oct 16, 2023
commit 46e0dc41ece66c7cfe769575e5360ada2711df7c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;

import org.slf4j.Logger;
Expand Down Expand Up @@ -87,6 +92,7 @@ public class BlockTransactionSelector {
private final List<AbstractTransactionSelector> transactionSelectors;
private final PluginTransactionSelector pluginTransactionSelector;
private final OperationTracer pluginOperationTracer;
private final AtomicBoolean isTimeout = new AtomicBoolean(false);

public BlockTransactionSelector(
final MiningParameters miningParameters,
Expand Down Expand Up @@ -149,14 +155,37 @@ public TransactionSelectionResults buildTransactionListForBlock() {
.setMessage("Transaction pool stats {}")
.addArgument(blockSelectionContext.transactionPool().logStats())
.log();
blockSelectionContext.transactionPool().selectTransactions(this::evaluateTransaction);
timeLimitedSelection();
LOG.atTrace()
.setMessage("Transaction selection result {}")
.addArgument(transactionSelectionResults::toTraceLog)
.log();
return transactionSelectionResults;
}

private void timeLimitedSelection() {
final var txSelection =
CompletableFuture.runAsync(
() ->
blockSelectionContext
.transactionPool()
.selectTransactions(this::evaluateTransaction));

try {
txSelection.get(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException e) {
if (isCancelled.get()) {
throw new CancellationException("Cancelled during transaction selection.");
}
LOG.warn("Error during block transaction selection", e);
} catch (TimeoutException e) {
synchronized (isTimeout) {
isTimeout.set(true);
}
LOG.warn("Timeout during block transaction selection, interrupting transaction selection", e);
}
}

/**
* Evaluates a list of transactions and updates the selection results accordingly. If a
* transaction is not selected during the evaluation, it is updated as not selected in the
Expand Down Expand Up @@ -201,7 +230,14 @@ private TransactionSelectionResult evaluateTransaction(
return handleTransactionNotSelected(pendingTransaction, postProcessingSelectionResult);
}

return handleTransactionSelected(pendingTransaction, processingResult, worldStateUpdater);
synchronized (isTimeout) {
if (!isTimeout.get()) {
return handleTransactionSelected(pendingTransaction, processingResult, worldStateUpdater);
} else {
return handleTransactionNotSelected(
pendingTransaction, TransactionSelectionResult.BLOCK_SELECTION_TIMEOUT);
}
}
}

/**
Expand Down