Skip to content

Commit

Permalink
Added tx-pool-max-size command line parameter to config the max size …
Browse files Browse the repository at this point in the history
…of the tx pool. (PegaSysEng#1078)
  • Loading branch information
rojotek authored Mar 13, 2019
1 parent 3033c18 commit 4c53702
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public static TransactionPool createTransactionPool(
final ProtocolSchedule<?> protocolSchedule,
final ProtocolContext<?> protocolContext,
final EthContext ethContext,
final Clock clock) {
final Clock clock,
final int maxPendingTransactions) {
final PendingTransactions pendingTransactions =
new PendingTransactions(PendingTransactions.MAX_PENDING_TRANSACTIONS, clock);
new PendingTransactions(maxPendingTransactions, clock);

final PeerTransactionTracker transactionTracker = new PeerTransactionTracker();
final TransactionsMessageSender transactionsMessageSender =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.TransactionReceipt;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
Expand Down Expand Up @@ -1015,7 +1016,11 @@ public void transactionMessagesGoToTheCorrectExecutor() {
// Create a transaction pool. This has a side effect of registring a listener for the
// transactions message.
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethManager.ethContext(), TestClock.fixed());
protocolSchedule,
protocolContext,
ethManager.ethContext(),
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);

// Send just a transaction message.
final PeerConnection peer = setupPeer(ethManager, (cap, msg, connection) -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tech.pegasys.pantheon.ethereum.chain.GenesisState;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
Expand Down Expand Up @@ -133,7 +134,11 @@ public TestNode(
final EthContext ethContext = ethProtocolManager.ethContext();
transactionPool =
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethContext, TestClock.fixed());
protocolSchedule,
protocolContext,
ethContext,
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);
networkRunner.start();

selfPeer = new DefaultPeer(id(), endpoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
Expand Down Expand Up @@ -458,6 +459,14 @@ protected KeyLoader getKeyLoader() {
"The address to which the privacy pre-compiled contract will be mapped to (default: ${DEFAULT-VALUE})")
private final Integer privacyPrecompiledAddress = Address.PRIVACY;

@Option(
names = {"--tx-pool-max-size"},
paramLabel = MANDATORY_INTEGER_FORMAT_HELP,
description =
"Maximum number of pending transactions that will be kept in the transaction pool (default: ${DEFAULT-VALUE})",
arity = "1")
private final Integer txPoolMaxSize = PendingTransactions.MAX_PENDING_TRANSACTIONS;

// Inner class so we can get to loggingLevel.
public class PantheonExceptionHandler
extends CommandLine.AbstractHandler<List<Object>, PantheonExceptionHandler>
Expand Down Expand Up @@ -643,6 +652,7 @@ PantheonController<?> buildController() {
.miningParameters(
new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled))
.devMode(NetworkName.DEV.equals(getNetwork()))
.maxPendingTransactions(txPoolMaxSize)
.nodePrivateKeyFile(nodePrivateKeyFile())
.metricsSystem(metricsSystem.get())
.privacyParameters(privacyParameters())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PantheonControllerBuilder {
private File nodePrivateKeyFile;
private MetricsSystem metricsSystem;
private PrivacyParameters privacyParameters;
private Integer maxPendingTransactions;

public PantheonControllerBuilder synchronizerConfiguration(
final SynchronizerConfiguration synchronizerConfiguration) {
Expand Down Expand Up @@ -77,6 +78,11 @@ public PantheonControllerBuilder metricsSystem(final MetricsSystem metricsSystem
return this;
}

public PantheonControllerBuilder maxPendingTransactions(final Integer maxPendingTransactions) {
this.maxPendingTransactions = maxPendingTransactions;
return this;
}

public PantheonControllerBuilder privacyParameters(final PrivacyParameters privacyParameters) {
this.privacyParameters = privacyParameters;
return this;
Expand Down Expand Up @@ -108,6 +114,7 @@ public PantheonController<?> build() throws IOException {
metricsSystem,
privacyParameters,
homePath,
clock);
clock,
maxPendingTransactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ static PantheonController<CliqueContext> init(
final KeyPair nodeKeys,
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock) {
final Clock clock,
final int maxPendingTransactions) {
final Address localAddress = Util.publicKeyToAddress(nodeKeys.getPublicKey());
final CliqueConfigOptions cliqueConfig =
genesisConfig.getConfigOptions().getCliqueConfigOptions();
Expand Down Expand Up @@ -166,7 +167,11 @@ static PantheonController<CliqueContext> init(

final TransactionPool transactionPool =
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethProtocolManager.ethContext(), clock);
protocolSchedule,
protocolContext,
ethProtocolManager.ethContext(),
clock,
maxPendingTransactions);

final ExecutorService minerThreadPool = Executors.newCachedThreadPool();
final CliqueMinerExecutor miningExecutor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ static PantheonController<IbftContext> init(
final KeyPair nodeKeys,
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock) {
final Clock clock,
final int maxPendingTransactions) {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
Expand Down Expand Up @@ -168,7 +169,11 @@ static PantheonController<IbftContext> init(

final TransactionPool transactionPool =
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, istanbul64ProtocolManager.ethContext(), clock);
protocolSchedule,
protocolContext,
istanbul64ProtocolManager.ethContext(),
clock,
maxPendingTransactions);

return new IbftLegacyPantheonController(
protocolSchedule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ static PantheonController<IbftContext> init(
final KeyPair nodeKeys,
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock) {
final Clock clock,
final int maxPendingTransactions) {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
Expand Down Expand Up @@ -196,7 +197,7 @@ static PantheonController<IbftContext> init(

final TransactionPool transactionPool =
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethContext, clock);
protocolSchedule, protocolContext, ethContext, clock, maxPendingTransactions);

final IbftEventQueue ibftEventQueue = new IbftEventQueue(ibftConfig.getMessageQueueLimit());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public static PantheonController<Void> init(
final PrivacyParameters privacyParameters,
final Path dataDirectory,
final MetricsSystem metricsSystem,
final Clock clock) {
final Clock clock,
final int maxPendingTransactions) {

final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final ProtocolContext<Void> protocolContext =
Expand Down Expand Up @@ -148,7 +149,11 @@ public static PantheonController<Void> init(

final TransactionPool transactionPool =
TransactionPoolFactory.createTransactionPool(
protocolSchedule, protocolContext, ethProtocolManager.ethContext(), clock);
protocolSchedule,
protocolContext,
ethProtocolManager.ethContext(),
clock,
maxPendingTransactions);

final ExecutorService minerThreadPool = Executors.newCachedThreadPool();
final EthHashMinerExecutor executor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static PantheonController<?> fromConfig(
final MetricsSystem metricsSystem,
final PrivacyParameters privacyParameters,
final Path dataDirectory,
final Clock clock) {
final Clock clock,
final int maxPendingTransactions) {

final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();

Expand All @@ -68,7 +69,8 @@ static PantheonController<?> fromConfig(
privacyParameters,
dataDirectory,
metricsSystem,
clock);
clock,
maxPendingTransactions);
} else if (configOptions.isIbft2()) {
return IbftPantheonController.init(
storageProvider,
Expand All @@ -79,7 +81,8 @@ static PantheonController<?> fromConfig(
nodeKeys,
dataDirectory,
metricsSystem,
clock);
clock,
maxPendingTransactions);
} else if (configOptions.isIbftLegacy()) {
return IbftLegacyPantheonController.init(
storageProvider,
Expand All @@ -89,7 +92,8 @@ static PantheonController<?> fromConfig(
nodeKeys,
dataDirectory,
metricsSystem,
clock);
clock,
maxPendingTransactions);
} else if (configOptions.isClique()) {
return CliquePantheonController.init(
storageProvider,
Expand All @@ -100,7 +104,8 @@ static PantheonController<?> fromConfig(
nodeKeys,
dataDirectory,
metricsSystem,
clock);
clock,
maxPendingTransactions);
} else {
throw new IllegalArgumentException("Unknown consensus mechanism defined");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.mainnet.PrecompiledContract;
Expand Down Expand Up @@ -58,7 +59,8 @@ public void privacyPrecompiled() throws IOException {
new NoOpMetricsSystem(),
privacyParameters,
dataDir,
TestClock.fixed());
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);

Address privacyContractAddress = Address.privacyPrecompiled(ADDRESS);
PrecompiledContract precompiledContract =
Expand Down
10 changes: 7 additions & 3 deletions pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import tech.pegasys.pantheon.ethereum.core.BlockSyncTestUtils;
import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
Expand Down Expand Up @@ -111,7 +112,8 @@ private void syncFromGenesis(final SyncMode mode) throws Exception {
PrivacyParameters.noPrivacy(),
dataDirAhead,
noOpMetricsSystem,
TestClock.fixed())) {
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS)) {
setupState(blockCount, controller.getProtocolSchedule(), controller.getProtocolContext());
}

Expand All @@ -128,7 +130,8 @@ private void syncFromGenesis(final SyncMode mode) throws Exception {
PrivacyParameters.noPrivacy(),
dataDirAhead,
noOpMetricsSystem,
TestClock.fixed());
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);
final String listenHost = InetAddress.getLoopbackAddress().getHostAddress();
final JsonRpcConfiguration aheadJsonRpcConfiguration = jsonRpcConfiguration();
final WebSocketConfiguration aheadWebSocketConfiguration = wsRpcConfiguration();
Expand Down Expand Up @@ -184,7 +187,8 @@ private void syncFromGenesis(final SyncMode mode) throws Exception {
PrivacyParameters.noPrivacy(),
dataDirBehind,
noOpMetricsSystem,
TestClock.fixed());
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);
final Peer advertisedPeer = runnerAhead.getAdvertisedPeer().get();
final EthNetworkConfig behindEthNetworkConfiguration =
new EthNetworkConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void initMocks() throws Exception {
when(mockControllerBuilder.ethNetworkConfig(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.miningParameters(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.devMode(anyBoolean())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.maxPendingTransactions(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.nodePrivateKeyFile(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.metricsSystem(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.privacyParameters(any())).thenReturn(mockControllerBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
Expand Down Expand Up @@ -444,6 +445,8 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce
verify(mockRunnerBuilder).build();

verify(mockControllerBuilder).devMode(eq(false));
verify(mockControllerBuilder)
.maxPendingTransactions(eq(PendingTransactions.MAX_PENDING_TRANSACTIONS));
verify(mockControllerBuilder).build();

// TODO: Re-enable as per NC-1057/NC-1681
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
Expand Down Expand Up @@ -60,7 +61,8 @@ public void blockImport() throws IOException {
new NoOpMetricsSystem(),
PrivacyParameters.noPrivacy(),
dataDir,
TestClock.fixed());
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);
final BlockImporter.ImportResult result =
blockImporter.importBlockchain(source, targetController);
// Don't count the Genesis block
Expand Down Expand Up @@ -96,7 +98,8 @@ public void ibftImport() throws IOException {
new NoOpMetricsSystem(),
PrivacyParameters.noPrivacy(),
dataDir,
TestClock.fixed());
TestClock.fixed(),
PendingTransactions.MAX_PENDING_TRANSACTIONS);
final BlockImporter.ImportResult result = blockImporter.importBlockchain(source, controller);

// Don't count the Genesis block
Expand Down
4 changes: 3 additions & 1 deletion pantheon/src/test/resources/everything_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ permissions-config-file="./permissions_config.toml"
privacy-url="http://127.0.0.1:8888"
privacy-public-key-file="./pubKey.pub"
privacy-enabled=false
privacy-precompiled-address=9
privacy-precompiled-address=9

tx-pool-max-size=1234

0 comments on commit 4c53702

Please sign in to comment.