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

Expose price bump to a CLI flag. #930

Merged
merged 4 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Expose price bump to a CLI flag.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
  • Loading branch information
AbdelStark committed May 15, 2020
commit ed08b7e599b8d479d862b8dc5636136436307d50
11 changes: 11 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,16 @@ void setBannedNodeIds(final List<String> values) {
private final Integer pendingTxRetentionPeriod =
TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS;

@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final.
RatanRSur marked this conversation as resolved.
Show resolved Hide resolved
@Option(
names = {"--tx-pool-price-bump"},
matkt marked this conversation as resolved.
Show resolved Hide resolved
paramLabel = MANDATORY_INTEGER_FORMAT_HELP,
converter = PercentageConverter.class,
description =
"Price bump percentage to replace an already existing transaction (default: ${DEFAULT-VALUE})",
arity = "1")
private Integer priceBump = TransactionPoolConfiguration.DEFAULT_PRICE_BUMP.getValue();

@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
@Option(
names = {"--key-value-storage"},
Expand Down Expand Up @@ -1856,6 +1866,7 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() {
.txPoolMaxSize(txPoolMaxSize)
.pooledTransactionHashesSize(pooledTransactionHashesSize)
.pendingTxRetentionPeriod(pendingTxRetentionPeriod)
.priceBump(priceBump)
.build();
}

Expand Down
11 changes: 11 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,17 @@ public void pendingTransactionRetentionPeriod() {
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void transactionPoolPriceBump() {
final Percentage priceBump = Percentage.fromInt(13);
parseCommand("--tx-pool-price-bump", priceBump.toString());
verify(mockControllerBuilder)
.transactionPoolConfiguration(transactionPoolConfigCaptor.capture());
assertThat(transactionPoolConfigCaptor.getValue().getPriceBump()).isEqualTo(priceBump);
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void txMessageKeepAliveSecondsWithInvalidInputShouldFail() {
parseCommand("--Xincoming-tx-messages-keep-alive-seconds", "acbd");
Expand Down
2 changes: 1 addition & 1 deletion besu/src/test/resources/everything_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ privacy-onchain-groups-enabled=false

# Transaction Pool
tx-pool-retention-hours=999

tx-pool-price-bump=13
tx-pool-max-size=1234
tx-pool-hashes-max-size=10000
Xincoming-tx-messages-keep-alive-seconds=60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.util.Subscribers;
import org.hyperledger.besu.util.number.Percentage;

import java.time.Clock;
import java.time.Instant;
Expand Down Expand Up @@ -98,13 +99,14 @@ public PendingTransactions(
final Clock clock,
final MetricsSystem metricsSystem,
final Supplier<BlockHeader> chainHeadHeaderSupplier,
final Optional<EIP1559> eip1559) {
final Optional<EIP1559> eip1559,
final Percentage priceBump) {
this.maxTransactionRetentionHours = maxTransactionRetentionHours;
this.maxPendingTransactions = maxPendingTransactions;
this.clock = clock;
this.newPooledHashes = EvictingQueue.create(maxPooledTransactionHashes);
this.chainHeadHeaderSupplier = chainHeadHeaderSupplier;
this.transactionReplacementHandler = new TransactionPoolReplacementHandler(eip1559);
this.transactionReplacementHandler = new TransactionPoolReplacementHandler(eip1559, priceBump);
final LabelledMetric<Counter> transactionAddedCounter =
metricsSystem.createLabelledCounter(
BesuMetricCategory.TRANSACTION_POOL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,35 @@
*/
package org.hyperledger.besu.ethereum.eth.transactions;

import org.hyperledger.besu.util.number.Percentage;

import java.util.Objects;

public class TransactionPoolConfiguration {
public static final int DEFAULT_TX_MSG_KEEP_ALIVE = 60;
public static final int MAX_PENDING_TRANSACTIONS = 4096;
public static final int MAX_PENDING_TRANSACTIONS_HASHES = 4096;
public static final int DEFAULT_TX_RETENTION_HOURS = 13;
public static final int DEFAULT_PRICE_BUMP = 10;
public static final Percentage DEFAULT_PRICE_BUMP = Percentage.fromInt(10);

private final int txPoolMaxSize;
private final int pooledTransactionHashesSize;
private final int pendingTxRetentionPeriod;
private final int txMessageKeepAliveSeconds;

private final Percentage priceBump;

public TransactionPoolConfiguration(
final int txPoolMaxSize,
final int pooledTransactionHashesSize,
final int pendingTxRetentionPeriod,
final int txMessageKeepAliveSeconds) {
final int txMessageKeepAliveSeconds,
final Percentage priceBump) {
this.txPoolMaxSize = txPoolMaxSize;
this.pooledTransactionHashesSize = pooledTransactionHashesSize;
this.pendingTxRetentionPeriod = pendingTxRetentionPeriod;
this.txMessageKeepAliveSeconds = txMessageKeepAliveSeconds;
this.priceBump = priceBump;
}

public int getTxPoolMaxSize() {
Expand All @@ -55,6 +61,10 @@ public int getTxMessageKeepAliveSeconds() {
return txMessageKeepAliveSeconds;
}

public Percentage getPriceBump() {
return priceBump;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -66,12 +76,14 @@ public boolean equals(final Object o) {
final TransactionPoolConfiguration that = (TransactionPoolConfiguration) o;
return txPoolMaxSize == that.txPoolMaxSize
&& Objects.equals(pendingTxRetentionPeriod, that.pendingTxRetentionPeriod)
&& Objects.equals(txMessageKeepAliveSeconds, that.txMessageKeepAliveSeconds);
&& Objects.equals(txMessageKeepAliveSeconds, that.txMessageKeepAliveSeconds)
&& Objects.equals(priceBump, that.priceBump);
}

@Override
public int hashCode() {
return Objects.hash(txPoolMaxSize, pendingTxRetentionPeriod, txMessageKeepAliveSeconds);
return Objects.hash(
txPoolMaxSize, pendingTxRetentionPeriod, txMessageKeepAliveSeconds, priceBump);
}

@Override
Expand All @@ -83,6 +95,8 @@ public String toString() {
+ pendingTxRetentionPeriod
+ ", txMessageKeepAliveSeconds="
+ txMessageKeepAliveSeconds
+ ", priceBump="
+ priceBump
+ '}';
}

Expand All @@ -95,6 +109,7 @@ public static class Builder {
private int pendingTxRetentionPeriod = DEFAULT_TX_RETENTION_HOURS;
private Integer txMessageKeepAliveSeconds = DEFAULT_TX_MSG_KEEP_ALIVE;
private int pooledTransactionHashesSize = MAX_PENDING_TRANSACTIONS_HASHES;
private Percentage priceBump = DEFAULT_PRICE_BUMP;

public Builder txPoolMaxSize(final int txPoolMaxSize) {
this.txPoolMaxSize = txPoolMaxSize;
Expand All @@ -116,12 +131,22 @@ public Builder txMessageKeepAliveSeconds(final int txMessageKeepAliveSeconds) {
return this;
}

public Builder priceBump(final Percentage priceBump) {
this.priceBump = priceBump;
return this;
}

public Builder priceBump(final int priceBump) {
return priceBump(Percentage.fromInt(priceBump));
}

public TransactionPoolConfiguration build() {
return new TransactionPoolConfiguration(
txPoolMaxSize,
pooledTransactionHashesSize,
pendingTxRetentionPeriod,
txMessageKeepAliveSeconds);
txMessageKeepAliveSeconds,
priceBump);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public static TransactionPool createTransactionPool(
clock,
metricsSystem,
protocolContext.getBlockchain()::getChainHeadHeader,
eip1559);
eip1559,
transactionPoolConfiguration.getPriceBump());

final PeerTransactionTracker transactionTracker = new PeerTransactionTracker();
final TransactionsMessageSender transactionsMessageSender =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ public class TransactionPoolReplacementHandler {
private final List<TransactionPoolReplacementRule> rules;
private final Optional<EIP1559> eip1559;

public TransactionPoolReplacementHandler(final Optional<EIP1559> eip1559) {
this(
asList(
new TransactionReplacementByPriceRule(
Percentage.fromInt(TransactionPoolConfiguration.DEFAULT_PRICE_BUMP))),
eip1559);
public TransactionPoolReplacementHandler(
final Optional<EIP1559> eip1559, final Percentage priceBump) {
this(asList(new TransactionReplacementByPriceRule(priceBump)), eip1559);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void testDisconnect() {
new NoOpMetricsSystem(),
state,
Wei.of(1),
new TransactionPoolConfiguration(1, 1, 1, 1),
new TransactionPoolConfiguration(
1, 1, 1, 1, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP),
pendingTransactions,
peerTransactionTracker,
transactionsMessageSender,
Expand Down Expand Up @@ -167,7 +168,8 @@ public <C> void testNoEth65() {
new NoOpMetricsSystem(),
state,
Wei.of(1),
new TransactionPoolConfiguration(1, 1, 1, 1),
new TransactionPoolConfiguration(
1, 1, 1, 1, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP),
pendingTransactions,
peerTransactionTracker,
transactionsMessageSender,
Expand Down