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
Show file tree
Hide file tree
Changes from 44 commits
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
13 changes: 2 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# Changelog

### Breaking Changes

### Deprecations

### Additions and Improvements
- TraceService: return results for transactions in block [#6086](https://github.com/hyperledger/besu/pull/6086)

### Bug Fixes

### Download Links

## 23.10.2

### Breaking Changes
Expand All @@ -22,6 +11,8 @@
- Add a method to read from a `Memory` instance without altering its inner state [#6073](https://github.com/hyperledger/besu/pull/6073)
- Accept `input` and `data` field for the payload of transaction-related RPC methods [#6094](https://github.com/hyperledger/besu/pull/6094)
- Add APIs to set and get the min gas price a transaction must pay for being selected during block creation [#6097](https://github.com/hyperledger/besu/pull/6097)
- Introduce the possibility to limit the time spent selecting pending transactions during block creation, using the new experimental option `Xtxs-selection-max-time` (by default set to 5000ms) [#6044](https://github.com/hyperledger/besu/pull/6044)
- TraceService: return results for transactions in block [#6086](https://github.com/hyperledger/besu/pull/6086)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POW_JOB_TTL;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_TTL;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_TXS_SELECTION_MAX_TIME;

import org.hyperledger.besu.cli.util.CommandLineUtils;
import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -162,6 +163,14 @@ static class Unstable {
+ " then it waits before next repetition. Must be positive and ≤ 2000 (default: ${DEFAULT-VALUE} milliseconds)")
private Long posBlockCreationRepetitionMinDuration =
DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION;

@CommandLine.Option(
hidden = true,
names = {"--Xtxs-selection-max-time"},
description =
"Specifies the maximum time, in milliseconds, that could be spent selecting transactions to be included in the block."
+ " Must be positive and ≤ (default: ${DEFAULT-VALUE} milliseconds)")
private Long txsSelectionMaxTime = DEFAULT_TXS_SELECTION_MAX_TIME;
}

private MiningOptions() {}
Expand Down Expand Up @@ -231,14 +240,23 @@ public void validate(
if (unstableOptions.posBlockCreationMaxTime <= 0
|| unstableOptions.posBlockCreationMaxTime > DEFAULT_POS_BLOCK_CREATION_MAX_TIME) {
throw new ParameterException(
commandLine, "--Xpos-block-creation-max-time must be positive and ≤ 12000");
commandLine,
"--Xpos-block-creation-max-time must be positive and ≤ "
+ DEFAULT_POS_BLOCK_CREATION_MAX_TIME);
}

if (unstableOptions.posBlockCreationRepetitionMinDuration <= 0
|| unstableOptions.posBlockCreationRepetitionMinDuration > 2000) {
throw new ParameterException(
commandLine, "--Xpos-block-creation-repetition-min-duration must be positive and ≤ 2000");
}

if (unstableOptions.txsSelectionMaxTime <= 0
|| unstableOptions.txsSelectionMaxTime > DEFAULT_TXS_SELECTION_MAX_TIME) {
throw new ParameterException(
commandLine,
"--Xtxs-selection-max-time must be positive and ≤ " + DEFAULT_TXS_SELECTION_MAX_TIME);
}
}

static MiningOptions fromConfig(final MiningParameters miningParameters) {
Expand All @@ -265,6 +283,8 @@ static MiningOptions fromConfig(final MiningParameters miningParameters) {
miningParameters.getUnstable().getPosBlockCreationMaxTime();
miningOptions.unstableOptions.posBlockCreationRepetitionMinDuration =
miningParameters.getUnstable().getPosBlockCreationRepetitionMinDuration();
miningOptions.unstableOptions.txsSelectionMaxTime =
miningParameters.getUnstable().getTxsSelectionMaxTime();

miningParameters.getCoinbase().ifPresent(coinbase -> miningOptions.coinbase = coinbase);
miningParameters.getTargetGasLimit().ifPresent(tgl -> miningOptions.targetGasLimit = tgl);
Expand Down Expand Up @@ -304,6 +324,7 @@ public MiningParameters toDomainObject() {
.posBlockCreationMaxTime(unstableOptions.posBlockCreationMaxTime)
.posBlockCreationRepetitionMinDuration(
unstableOptions.posBlockCreationRepetitionMinDuration)
.txsSelectionMaxTime(unstableOptions.txsSelectionMaxTime)
.build());

return miningParametersBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ protected MiningCoordinator createMiningCoordinator(
protocolContext.getConsensusContext(CliqueContext.class).getValidatorProvider(),
localAddress,
secondsBetweenBlocks),
epochManager);
epochManager,
ethProtocolManager.ethContext().getScheduler());
final CliqueMiningCoordinator miningCoordinator =
new CliqueMiningCoordinator(
protocolContext.getBlockchain(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ protected MiningCoordinator createMiningCoordinator(
forksSchedule,
miningParameters,
localAddress,
bftExtraDataCodec().get());
bftExtraDataCodec().get(),
ethProtocolManager.ethContext().getScheduler());

final ValidatorProvider validatorProvider =
protocolContext.getConsensusContext(BftContext.class).getValidatorProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected MiningCoordinator createMiningCoordinator(
MainnetBlockHeaderValidator.MINIMUM_SECONDS_SINCE_PARENT,
MainnetBlockHeaderValidator.TIMESTAMP_TOLERANCE_S,
clock),
epochCalculator);
epochCalculator,
ethProtocolManager.ethContext().getScheduler());

final PoWMiningCoordinator miningCoordinator =
new PoWMiningCoordinator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.MergePeerFilter;
import org.hyperledger.besu.ethereum.eth.manager.MonitoredExecutors;
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator;
import org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
Expand All @@ -46,13 +45,10 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;

import org.slf4j.Logger;
Expand Down Expand Up @@ -85,7 +81,7 @@ protected MiningCoordinator createMiningCoordinator(
syncState,
BackwardChain.from(
storageProvider, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule))),
metricsSystem);
ethProtocolManager.ethContext().getScheduler());
}

@Override
Expand Down Expand Up @@ -146,7 +142,7 @@ protected EthProtocolManager createEthProtocolManager(
* @param miningParameters the mining parameters
* @param syncState the sync state
* @param backwardSyncContext the backward sync context
* @param metricsSystem the metrics system
* @param ethScheduler the scheduler
* @return the mining coordinator
*/
protected MiningCoordinator createTransitionMiningCoordinator(
Expand All @@ -156,24 +152,18 @@ protected MiningCoordinator createTransitionMiningCoordinator(
final MiningParameters miningParameters,
final SyncState syncState,
final BackwardSyncContext backwardSyncContext,
final MetricsSystem metricsSystem) {
final EthScheduler ethScheduler) {

this.syncState.set(syncState);

final ExecutorService blockBuilderExecutor =
MonitoredExecutors.newSingleThreadExecutor("PoS-Block-Builder", metricsSystem);

final GenesisConfigOptions genesisConfigOptions = configOptionsSupplier.get();
final Optional<Address> depositContractAddress =
genesisConfigOptions.getDepositContractAddress();

return new MergeCoordinator(
protocolContext,
protocolSchedule,
task -> {
LOG.debug("Block builder executor status {}", blockBuilderExecutor);
return CompletableFuture.runAsync(task, blockBuilderExecutor);
},
ethScheduler,
transactionPool,
miningParameters,
backwardSyncContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ protected MiningCoordinator createMiningCoordinator(
qbftForksSchedule,
miningParameters,
localAddress,
bftExtraDataCodec().get());
bftExtraDataCodec().get(),
ethProtocolManager.ethContext().getScheduler());

final ValidatorProvider validatorProvider =
protocolContext.getConsensusContext(BftContext.class).getValidatorProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected MiningCoordinator createMiningCoordinator(
transitionMiningParameters,
syncState,
transitionBackwardsSyncContext,
metricsSystem));
ethProtocolManager.ethContext().getScheduler()));
initTransitionWatcher(protocolContext, composedCoordinator);
return composedCoordinator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_TXS_SELECTION_MAX_TIME;
import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -308,6 +309,31 @@ public void posBlockCreationMaxTimeOutOfAllowedRange() {
"17000");
}

@Test
public void txsSelectionMaxTimeDefaultValue() {
internalTestSuccess(
miningParams ->
assertThat(miningParams.getUnstable().getTxsSelectionMaxTime())
.isEqualTo(DEFAULT_TXS_SELECTION_MAX_TIME));
}

@Test
public void txsSelectionMaxTimeOption() {
internalTestSuccess(
miningParams ->
assertThat(miningParams.getUnstable().getTxsSelectionMaxTime()).isEqualTo(1700L),
"--Xtxs-selection-max-time",
"1700");
}

@Test
public void txsSelectionMaxTimeOutOfAllowedRange() {
internalTestFailure(
"--Xtxs-selection-max-time must be positive and ≤ 5000",
"--Xtxs-selection-max-time",
"6000");
}

@Override
protected MiningParameters createDefaultDomainObject() {
return MiningParameters.newDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;

import java.util.Optional;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

Expand All @@ -71,7 +73,10 @@ public class TransitionControllerBuilderTest {
@Mock MutableBlockchain mockBlockchain;
@Mock TransactionPool transactionPool;
@Mock SyncState syncState;
@Mock EthProtocolManager ethProtocolManager;

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
EthProtocolManager ethProtocolManager;

@Mock PostMergeContext mergeContext;
StorageProvider storageProvider = new InMemoryKeyValueStorageProvider();

Expand Down Expand Up @@ -101,6 +106,8 @@ public void setup() {
.thenReturn(mock(CliqueContext.class));
when(protocolContext.getConsensusContext(PostMergeContext.class)).thenReturn(mergeContext);
when(protocolContext.getConsensusContext(MergeContext.class)).thenReturn(mergeContext);
when(ethProtocolManager.ethContext().getScheduler())
.thenReturn(new DeterministicEthScheduler());
miningParameters = MiningParameters.newDefault();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.SealableBlockHeader;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
Expand Down Expand Up @@ -64,7 +65,8 @@ public CliqueBlockCreator(
final ProtocolSchedule protocolSchedule,
final NodeKey nodeKey,
final BlockHeader parentHeader,
final EpochManager epochManager) {
final EpochManager epochManager,
final EthScheduler ethScheduler) {
super(
miningParameters,
__ -> Util.publicKeyToAddress(nodeKey.getPublicKey()),
Expand All @@ -73,7 +75,8 @@ public CliqueBlockCreator(
protocolContext,
protocolSchedule,
parentHeader,
Optional.empty());
Optional.empty(),
ethScheduler);
this.nodeKey = nodeKey;
this.epochManager = epochManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.util.Subscribers;
Expand Down Expand Up @@ -66,8 +67,15 @@ public CliqueMinerExecutor(
final NodeKey nodeKey,
final MiningParameters miningParams,
final AbstractBlockScheduler blockScheduler,
final EpochManager epochManager) {
super(protocolContext, protocolSchedule, transactionPool, miningParams, blockScheduler);
final EpochManager epochManager,
final EthScheduler ethScheduler) {
super(
protocolContext,
protocolSchedule,
transactionPool,
miningParams,
blockScheduler,
ethScheduler);
this.nodeKey = nodeKey;
this.localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
this.epochManager = epochManager;
Expand All @@ -89,7 +97,8 @@ public CliqueBlockMiner createMiner(
protocolSchedule,
nodeKey,
header,
epochManager);
epochManager,
ethScheduler);

return new CliqueBlockMiner(
blockCreator,
Expand Down
Loading