Skip to content

Commit 2412379

Browse files
fab-10garyschulte
authored andcommitted
Layered txpool by default and txpool options hoverhaul (besu-eth#5772)
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net> Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent d4ae08f commit 2412379

File tree

46 files changed

+1184
-691
lines changed

Some content is hidden

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

46 files changed

+1184
-691
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55

66
### Breaking Changes
77
- Removed support for Kotti network (ETC) [#5816](https://github.com/hyperledger/besu/pull/5816)
8+
- Layered transaction pool implementation is now stable and enabled by default, so the following changes to experimental options have been done [#5772](https://github.com/hyperledger/besu):
9+
- `--Xlayered-tx-pool` is gone, to select the implementation use the new `--tx-pool` option with values `layered` (default) or `legacy`
10+
- `--Xlayered-tx-pool-layer-max-capacity`, `--Xlayered-tx-pool-max-prioritized` and `--Xlayered-tx-pool-max-future-by-sender` just drop the `X` and keep the same behavior
811

912
### Additions and Improvements
13+
- Layered transaction pool implementation is now stable and enabled by default. If you want still to use the legacy implementation, use `--tx-pool=legacy` [#5772](https://github.com/hyperledger/besu)
1014

1115
### Bug Fixes
12-
- do not create ignorable storage on revert storage-variables subcommand [#5830](https://github.com/hyperledger/besu/pull/5830)
16+
- do not create ignorable storage on revert storage-variables subcommand [#5830](https://github.com/hyperledger/besu/pull/5830)
1317

1418
### Download Links
1519

besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Lines changed: 22 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.hyperledger.besu.chainimport.RlpBlockImporter;
4747
import org.hyperledger.besu.cli.config.EthNetworkConfig;
4848
import org.hyperledger.besu.cli.config.NetworkName;
49-
import org.hyperledger.besu.cli.converter.FractionConverter;
5049
import org.hyperledger.besu.cli.converter.MetricCategoryConverter;
5150
import org.hyperledger.besu.cli.converter.PercentageConverter;
5251
import org.hyperledger.besu.cli.custom.CorsAllowedOriginsProperty;
@@ -59,6 +58,7 @@
5958
import org.hyperledger.besu.cli.options.stable.LoggingLevelOption;
6059
import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption;
6160
import org.hyperledger.besu.cli.options.stable.P2PTLSConfigOptions;
61+
import org.hyperledger.besu.cli.options.stable.TransactionPoolOptions;
6262
import org.hyperledger.besu.cli.options.unstable.ChainPruningOptions;
6363
import org.hyperledger.besu.cli.options.unstable.DnsOptions;
6464
import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions;
@@ -73,7 +73,6 @@
7373
import org.hyperledger.besu.cli.options.unstable.PrivacyPluginOptions;
7474
import org.hyperledger.besu.cli.options.unstable.RPCOptions;
7575
import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions;
76-
import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions;
7776
import org.hyperledger.besu.cli.presynctasks.PreSynchronizationTaskRunner;
7877
import org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask;
7978
import org.hyperledger.besu.cli.subcommands.PasswordSubCommand;
@@ -127,6 +126,7 @@
127126
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
128127
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
129128
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
129+
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
130130
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
131131
import org.hyperledger.besu.ethereum.mainnet.FrontierTargetingGasLimitCalculator;
132132
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
@@ -280,7 +280,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
280280
final SynchronizerOptions unstableSynchronizerOptions = SynchronizerOptions.create();
281281
final EthProtocolOptions unstableEthProtocolOptions = EthProtocolOptions.create();
282282
final MetricsCLIOptions unstableMetricsCLIOptions = MetricsCLIOptions.create();
283-
final TransactionPoolOptions unstableTransactionPoolOptions = TransactionPoolOptions.create();
283+
final org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions
284+
unstableTransactionPoolOptions =
285+
org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions.create();
284286
private final DnsOptions unstableDnsOptions = DnsOptions.create();
285287
private final MiningOptions unstableMiningOptions = MiningOptions.create();
286288
private final NatOptions unstableNatOptions = NatOptions.create();
@@ -298,6 +300,10 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
298300
NodePrivateKeyFileOption.create();
299301
private final LoggingLevelOption loggingLevelOption = LoggingLevelOption.create();
300302

303+
@CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Common Options|@%n")
304+
final org.hyperledger.besu.cli.options.stable.TransactionPoolOptions
305+
stableTransactionPoolOptions = TransactionPoolOptions.create();
306+
301307
private final RunnerBuilder runnerBuilder;
302308
private final BesuController.Builder controllerBuilderFactory;
303309
private final BesuPluginContextImpl besuPluginContext;
@@ -454,10 +460,8 @@ static class P2PDiscoveryOptionGroup {
454460
"The maximum percentage of P2P connections that can be initiated remotely. Must be between 0 and 100 inclusive. (default: ${DEFAULT-VALUE})",
455461
arity = "1",
456462
converter = PercentageConverter.class)
457-
private final Integer maxRemoteConnectionsPercentage =
458-
Fraction.fromFloat(DEFAULT_FRACTION_REMOTE_WIRE_CONNECTIONS_ALLOWED)
459-
.toPercentage()
460-
.getValue();
463+
private final Percentage maxRemoteConnectionsPercentage =
464+
Fraction.fromFloat(DEFAULT_FRACTION_REMOTE_WIRE_CONNECTIONS_ALLOWED).toPercentage();
461465

462466
@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
463467
@CommandLine.Option(
@@ -1111,13 +1115,6 @@ static class MinerOptionGroup {
11111115
arity = "1")
11121116
private final Wei minTransactionGasPrice = DEFAULT_MIN_TRANSACTION_GAS_PRICE;
11131117

1114-
@Option(
1115-
names = {"--rpc-tx-feecap"},
1116-
description =
1117-
"Maximum transaction fees (in Wei) accepted for transaction submitted through RPC (default: ${DEFAULT-VALUE})",
1118-
arity = "1")
1119-
private final Wei txFeeCap = DEFAULT_RPC_TX_FEE_CAP;
1120-
11211118
@Option(
11221119
names = {"--min-block-occupancy-ratio"},
11231120
description = "Minimum occupancy ratio for a mined block (default: ${DEFAULT-VALUE})",
@@ -1209,75 +1206,6 @@ static class PermissionsOptionGroup {
12091206
"Sets target gas limit per block. If set, each block's gas limit will approach this setting over time if the current gas limit is different.")
12101207
private final Long targetGasLimit = null;
12111208

1212-
// Tx Pool Option Group
1213-
@CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Options|@%n")
1214-
TxPoolOptionGroup txPoolOptionGroup = new TxPoolOptionGroup();
1215-
1216-
static class TxPoolOptionGroup {
1217-
@CommandLine.Option(
1218-
names = {"--tx-pool-disable-locals"},
1219-
paramLabel = "<Boolean>",
1220-
description =
1221-
"Set to true if transactions sent via RPC should have the same checks and not be prioritized over remote ones (default: ${DEFAULT-VALUE})",
1222-
fallbackValue = "true",
1223-
arity = "0..1")
1224-
private Boolean disableLocalTxs = TransactionPoolConfiguration.DEFAULT_DISABLE_LOCAL_TXS;
1225-
1226-
@CommandLine.Option(
1227-
names = {"--tx-pool-enable-save-restore"},
1228-
paramLabel = "<Boolean>",
1229-
description =
1230-
"Set to true to enable saving the txpool content to file on shutdown and reloading it on startup (default: ${DEFAULT-VALUE})",
1231-
fallbackValue = "true",
1232-
arity = "0..1")
1233-
private Boolean saveRestoreEnabled = TransactionPoolConfiguration.DEFAULT_ENABLE_SAVE_RESTORE;
1234-
1235-
@CommandLine.Option(
1236-
names = {"--tx-pool-limit-by-account-percentage"},
1237-
paramLabel = "<DOUBLE>",
1238-
converter = FractionConverter.class,
1239-
description =
1240-
"Maximum portion of the transaction pool which a single account may occupy with future transactions (default: ${DEFAULT-VALUE})",
1241-
arity = "1")
1242-
private Float txPoolLimitByAccountPercentage =
1243-
TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE;
1244-
1245-
@CommandLine.Option(
1246-
names = {"--tx-pool-save-file"},
1247-
paramLabel = "<STRING>",
1248-
description =
1249-
"If saving the txpool content is enabled, define a custom path for the save file (default: ${DEFAULT-VALUE} in the data-dir)",
1250-
arity = "1")
1251-
private File saveFile = TransactionPoolConfiguration.DEFAULT_SAVE_FILE;
1252-
1253-
@Option(
1254-
names = {"--tx-pool-max-size"},
1255-
paramLabel = MANDATORY_INTEGER_FORMAT_HELP,
1256-
description =
1257-
"Maximum number of pending transactions that will be kept in the transaction pool (default: ${DEFAULT-VALUE})",
1258-
arity = "1")
1259-
private final Integer txPoolMaxSize =
1260-
TransactionPoolConfiguration.DEFAULT_MAX_PENDING_TRANSACTIONS;
1261-
1262-
@Option(
1263-
names = {"--tx-pool-retention-hours"},
1264-
paramLabel = MANDATORY_INTEGER_FORMAT_HELP,
1265-
description =
1266-
"Maximum retention period of pending transactions in hours (default: ${DEFAULT-VALUE})",
1267-
arity = "1")
1268-
private final Integer pendingTxRetentionPeriod =
1269-
TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS;
1270-
1271-
@Option(
1272-
names = {"--tx-pool-price-bump"},
1273-
paramLabel = MANDATORY_INTEGER_FORMAT_HELP,
1274-
converter = PercentageConverter.class,
1275-
description =
1276-
"Price bump percentage to replace an already existing transaction (default: ${DEFAULT-VALUE})",
1277-
arity = "1")
1278-
private final Integer priceBump = TransactionPoolConfiguration.DEFAULT_PRICE_BUMP.getValue();
1279-
}
1280-
12811209
@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
12821210
@Option(
12831211
names = {"--key-value-storage"},
@@ -1906,10 +1834,15 @@ private void validateOptions() {
19061834
validateRpcOptionsParams();
19071835
validateChainDataPruningParams();
19081836
validatePostMergeCheckpointBlockRequirements();
1837+
validateTransactionPoolOptions();
19091838
p2pTLSConfigOptions.checkP2PTLSOptionsDependencies(logger, commandLine);
19101839
pkiBlockCreationOptions.checkPkiBlockCreationOptionsDependencies(logger, commandLine);
19111840
}
19121841

1842+
private void validateTransactionPoolOptions() {
1843+
stableTransactionPoolOptions.validate(commandLine);
1844+
}
1845+
19131846
private void validateRequiredOptions() {
19141847
commandLine
19151848
.getCommandSpec()
@@ -2987,28 +2920,14 @@ private SynchronizerConfiguration buildSyncConfig() {
29872920
}
29882921

29892922
private TransactionPoolConfiguration buildTransactionPoolConfiguration() {
2990-
return unstableTransactionPoolOptions
2991-
.toDomainObject()
2992-
.enableSaveRestore(txPoolOptionGroup.saveRestoreEnabled)
2993-
.disableLocalTransactions(txPoolOptionGroup.disableLocalTxs)
2994-
.txPoolLimitByAccountPercentage(txPoolOptionGroup.txPoolLimitByAccountPercentage)
2995-
.txPoolMaxSize(txPoolOptionGroup.txPoolMaxSize)
2996-
.pendingTxRetentionPeriod(txPoolOptionGroup.pendingTxRetentionPeriod)
2997-
.priceBump(Percentage.fromInt(txPoolOptionGroup.priceBump))
2998-
.txFeeCap(txFeeCap)
2999-
.saveFile(dataPath.resolve(txPoolOptionGroup.saveFile.getPath()).toFile())
2923+
final var stableTxPoolOption = stableTransactionPoolOptions.toDomainObject();
2924+
return ImmutableTransactionPoolConfiguration.builder()
2925+
.from(stableTxPoolOption)
2926+
.unstable(unstableTransactionPoolOptions.toDomainObject())
2927+
.saveFile((dataPath.resolve(stableTxPoolOption.getSaveFile().getPath()).toFile()))
30002928
.build();
30012929
}
30022930

3003-
/**
3004-
* Return the file where to save txpool content if the relative option is enabled.
3005-
*
3006-
* @return the save file
3007-
*/
3008-
public File getSaveFile() {
3009-
return txPoolOptionGroup.saveFile;
3010-
}
3011-
30122931
private boolean isPruningEnabled() {
30132932
return pruningEnabled;
30142933
}
@@ -3613,9 +3532,7 @@ private String generateConfigurationOverview() {
36133532
builder.setHighSpecEnabled();
36143533
}
36153534

3616-
if (buildTransactionPoolConfiguration().getLayeredTxPoolEnabled()) {
3617-
builder.setLayeredTxPoolEnabled();
3618-
}
3535+
builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation());
36193536

36203537
return builder.build();
36213538
}

besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.hyperledger.besu.cli;
1616

1717
import org.hyperledger.besu.BesuInfo;
18+
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
1819
import org.hyperledger.besu.util.log.FramedLogMessage;
1920
import org.hyperledger.besu.util.platform.PlatformDetector;
2021

@@ -47,7 +48,7 @@ public class ConfigurationOverviewBuilder {
4748
private Collection<String> engineApis;
4849
private String engineJwtFilePath;
4950
private boolean isHighSpec = false;
50-
private boolean isLayeredTxPool = false;
51+
private TransactionPoolConfiguration.Implementation txPoolImplementation;
5152
private Map<String, String> environment;
5253

5354
/**
@@ -167,12 +168,14 @@ public ConfigurationOverviewBuilder setHighSpecEnabled() {
167168
}
168169

169170
/**
170-
* Sets experimental layered txpool enabled.
171+
* Sets the txpool implementation in use.
171172
*
173+
* @param implementation the txpool implementation
172174
* @return the builder
173175
*/
174-
public ConfigurationOverviewBuilder setLayeredTxPoolEnabled() {
175-
isLayeredTxPool = true;
176+
public ConfigurationOverviewBuilder setTxPoolImplementation(
177+
final TransactionPoolConfiguration.Implementation implementation) {
178+
txPoolImplementation = implementation;
176179
return this;
177180
}
178181

@@ -251,9 +254,7 @@ public String build() {
251254
lines.add("Experimental high spec configuration enabled");
252255
}
253256

254-
if (isLayeredTxPool) {
255-
lines.add("Experimental layered transaction pool configuration enabled");
256-
}
257+
lines.add("Using " + txPoolImplementation + " transaction pool implementation");
257258

258259
lines.add("");
259260
lines.add("Host:");

besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java

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

1717
import org.hyperledger.besu.datatypes.Wei;
1818
import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.JwtAlgorithm;
19-
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
2019
import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration;
2120
import org.hyperledger.besu.nat.NatMethod;
2221

@@ -61,9 +60,6 @@ public interface DefaultCommandValues {
6160
String MANDATORY_NODE_ID_FORMAT_HELP = "<NODEID>";
6261
/** The constant DEFAULT_MIN_TRANSACTION_GAS_PRICE. */
6362
Wei DEFAULT_MIN_TRANSACTION_GAS_PRICE = Wei.of(1000);
64-
/** The constant DEFAULT_RPC_TX_FEE_CAP. */
65-
Wei DEFAULT_RPC_TX_FEE_CAP = TransactionPoolConfiguration.DEFAULT_RPC_TX_FEE_CAP;
66-
6763
/** The constant DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO. */
6864
Double DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO = 0.8;
6965
/** The constant DEFAULT_EXTRA_DATA. */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Hyperledger Besu Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
package org.hyperledger.besu.cli.converter;
16+
17+
import org.hyperledger.besu.cli.converter.exception.DurationConversionException;
18+
19+
import java.time.Duration;
20+
21+
import picocli.CommandLine;
22+
23+
/** The Duration (milliseconds) Cli type converter. */
24+
public class DurationMillisConverter
25+
implements CommandLine.ITypeConverter<Duration>, TypeFormatter<Duration> {
26+
27+
@Override
28+
public Duration convert(final String value) throws DurationConversionException {
29+
try {
30+
final long millis = Long.parseLong(value);
31+
if (millis < 0) {
32+
throw new DurationConversionException(millis);
33+
}
34+
return Duration.ofMillis(Long.parseLong(value));
35+
} catch (NullPointerException | IllegalArgumentException e) {
36+
throw new DurationConversionException(value);
37+
}
38+
}
39+
40+
@Override
41+
public String format(final Duration value) {
42+
return Long.toString(value.toMillis());
43+
}
44+
}

besu/src/main/java/org/hyperledger/besu/cli/converter/FractionConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import picocli.CommandLine;
2121

2222
/** The Fraction converter to convert floats in CLI. */
23-
public class FractionConverter implements CommandLine.ITypeConverter<Float> {
23+
public class FractionConverter implements CommandLine.ITypeConverter<Fraction> {
2424

2525
@Override
26-
public Float convert(final String value) throws FractionConversionException {
26+
public Fraction convert(final String value) throws FractionConversionException {
2727
try {
28-
return Fraction.fromString(value).getValue();
28+
return Fraction.fromString(value);
2929
} catch (final NullPointerException | IllegalArgumentException e) {
3030
throw new FractionConversionException(value);
3131
}

besu/src/main/java/org/hyperledger/besu/cli/converter/PercentageConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import picocli.CommandLine;
2121

2222
/** The Percentage Cli type converter. */
23-
public class PercentageConverter implements CommandLine.ITypeConverter<Integer> {
23+
public class PercentageConverter implements CommandLine.ITypeConverter<Percentage> {
2424

2525
@Override
26-
public Integer convert(final String value) throws PercentageConversionException {
26+
public Percentage convert(final String value) throws PercentageConversionException {
2727
try {
28-
return Percentage.fromString(value).getValue();
28+
return Percentage.fromString(value);
2929
} catch (NullPointerException | IllegalArgumentException e) {
3030
throw new PercentageConversionException(value);
3131
}

0 commit comments

Comments
 (0)