Skip to content

Commit

Permalink
[PAN-1062] Evict old transactions (1 of 2) (PegaSysEng#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish authored and notlesh committed May 14, 2019
1 parent 062ea7a commit c0bf672
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.util.List;
import java.util.concurrent.TimeUnit;

import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;

public class CliqueBlockCreatorTest {
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);

private final KeyPair proposerKeyPair = KeyPair.generate();
private final Address proposerAddress = Util.publicKeyToAddress(proposerKeyPair.getPublicKey());
Expand Down Expand Up @@ -113,7 +115,8 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand All @@ -140,7 +143,8 @@ public void insertsValidVoteIntoConstructedBlock() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand All @@ -166,7 +170,8 @@ public void insertsNoVoteWhenAuthInValidators() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand Down Expand Up @@ -195,7 +200,8 @@ public void insertsNoVoteWhenAtEpoch() {
new CliqueBlockCreator(
coinbase,
parent -> extraData.encode(),
new PendingTransactions(5, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem),
protocolContext,
protocolSchedule,
gasLimit -> gasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import com.google.common.collect.Lists;
import io.vertx.core.json.JsonObject;
Expand All @@ -54,6 +55,7 @@ public class CliqueMinerExecutorTest {

private static final GenesisConfigOptions GENESIS_CONFIG_OPTIONS =
GenesisConfigFile.fromConfig(new JsonObject()).getConfigOptions();
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private final KeyPair proposerKeyPair = KeyPair.generate();
private Address localAddress;
private final List<Address> validatorList = Lists.newArrayList();
Expand Down Expand Up @@ -90,7 +92,8 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() {
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
mock(CliqueBlockScheduler.class),
Expand Down Expand Up @@ -120,7 +123,8 @@ public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
mock(CliqueBlockScheduler.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import com.google.common.collect.Iterables;

public class TestContextBuilder {

private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private static MetricsSystem metricsSystem = new NoOpMetricsSystem();

private static class ControllerAndState {
Expand Down Expand Up @@ -282,10 +285,13 @@ private static ControllerAndState createControllerAndFinalState(
new ProtocolContext<>(
blockChain, worldStateArchive, new IbftContext(voteTallyCache, voteProposer));

final PendingTransactions pendingTransactions =
new PendingTransactions(TRANSACTION_EVICTION_INTERVAL_MS, 1, clock, metricsSystem);

final IbftBlockCreatorFactory blockCreatorFactory =
new IbftBlockCreatorFactory(
(gasLimit) -> gasLimit,
new PendingTransactions(1, clock, metricsSystem), // changed from IbftPantheonController
pendingTransactions, // changed from IbftPantheonController
protocolContext,
protocolSchedule,
miningParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import com.google.common.collect.Lists;
import org.junit.Test;

public class IbftBlockCreatorTest {
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

@Test
Expand Down Expand Up @@ -81,6 +83,10 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() {
createInMemoryWorldStateArchive(),
setupContextWithValidators(initialValidatorList));

final PendingTransactions pendingTransactions =
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem);

final IbftBlockCreator blockCreator =
new IbftBlockCreator(
initialValidatorList.get(0),
Expand All @@ -92,7 +98,7 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() {
0,
initialValidatorList)
.encode(),
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
pendingTransactions,
protContext,
protocolSchedule,
parentGasLimit -> parentGasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import com.google.common.collect.Lists;
import org.junit.Test;

public class IbftBlockCreatorTest {
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

@Test
Expand Down Expand Up @@ -97,7 +99,8 @@ public void headerProducedPassesValidationRules() {
null,
initialValidatorList)
.encode(),
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem),
protContext,
protocolSchedule,
parentGasLimit -> parentGasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.math.BigInteger;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import com.google.common.collect.Lists;
Expand All @@ -63,6 +64,7 @@
public class BlockTransactionSelectorTest {

private static final KeyPair keyPair = KeyPair.generate();
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

@Test
Expand All @@ -75,7 +77,9 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() {
final DefaultMutableWorldState worldState = inMemoryWorldState();

final PendingTransactions pendingTransactions =
new PendingTransactions(5, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final Supplier<Boolean> isCancelled = () -> false;

final ProcessableBlockHeader blockHeader =
Expand Down Expand Up @@ -113,7 +117,8 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() {
@Test
public void failedTransactionsAreIncludedInTheBlock() {
final PendingTransactions pendingTransactions =
new PendingTransactions(5, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final Transaction transaction = createTransaction(1);
pendingTransactions.addRemoteTransaction(transaction);
Expand Down Expand Up @@ -165,7 +170,8 @@ public void failedTransactionsAreIncludedInTheBlock() {
@Test
public void invalidTransactionsTransactionProcessingAreSkippedButBlockStillFills() {
final PendingTransactions pendingTransactions =
new PendingTransactions(5, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final List<Transaction> transactionsToInject = Lists.newArrayList();
for (int i = 0; i < 5; i++) {
Expand Down Expand Up @@ -228,7 +234,8 @@ public void invalidTransactionsTransactionProcessingAreSkippedButBlockStillFills
@Test
public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() {
final PendingTransactions pendingTransactions =
new PendingTransactions(5, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final List<Transaction> transactionsToInject = Lists.newArrayList();
// Transactions are reported in reverse order.
Expand Down Expand Up @@ -294,7 +301,8 @@ public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() {
@Test
public void transactionOfferingGasPriceLessThanMinimumIsIdentifiedAndRemovedFromPending() {
final PendingTransactions pendingTransactions =
new PendingTransactions(5, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final Blockchain blockchain = new TestBlockchain();

Expand Down Expand Up @@ -339,7 +347,9 @@ public void transactionOfferingGasPriceLessThanMinimumIsIdentifiedAndRemovedFrom
@Test
public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupancyNotReached() {
final PendingTransactions pendingTransactions =
new PendingTransactions(5, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final Blockchain blockchain = new TestBlockchain();
final DefaultMutableWorldState worldState = inMemoryWorldState();
final Supplier<Boolean> isCancelled = () -> false;
Expand Down Expand Up @@ -410,7 +420,9 @@ public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupa
@Test
public void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() {
final PendingTransactions pendingTransactions =
new PendingTransactions(10, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final Blockchain blockchain = new TestBlockchain();
final DefaultMutableWorldState worldState = inMemoryWorldState();
final Supplier<Boolean> isCancelled = () -> false;
Expand Down Expand Up @@ -492,7 +504,9 @@ public void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() {
@Test
public void shouldDiscardTransactionsThatFailValidation() {
final PendingTransactions pendingTransactions =
new PendingTransactions(10, TestClock.fixed(), metricsSystem);
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 5, TestClock.fixed(), metricsSystem);

final TransactionProcessor transactionProcessor = mock(TransactionProcessor.class);
final Blockchain blockchain = new TestBlockchain();
final DefaultMutableWorldState worldState = inMemoryWorldState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.IOException;
import java.math.BigInteger;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import com.google.common.collect.Lists;
Expand All @@ -47,6 +48,7 @@ public class EthHashBlockCreatorTest {

private static final BytesValue BLOCK_1_EXTRA_DATA =
BytesValue.fromHexString("0x476574682f76312e302e302f6c696e75782f676f312e342e32");
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

private final ExecutionContextTestFixture executionContextTestFixture =
Expand All @@ -63,11 +65,16 @@ public class EthHashBlockCreatorTest {
@Test
public void createMainnetBlock1() throws IOException {
final EthHashSolver solver = new EthHashSolver(Lists.newArrayList(BLOCK_1_NONCE), new Light());

final PendingTransactions pendingTransactions =
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem);

final EthHashBlockCreator blockCreator =
new EthHashBlockCreator(
BLOCK_1_COINBASE,
parent -> BLOCK_1_EXTRA_DATA,
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
pendingTransactions,
executionContextTestFixture.getProtocolContext(),
executionContextTestFixture.getProtocolSchedule(),
gasLimit -> gasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@
import tech.pegasys.pantheon.util.Subscribers;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

public class EthHashMinerExecutorTest {
private static final long TRANSACTION_EVICTION_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

@Test
public void startingMiningWithoutCoinbaseThrowsException() {
final MiningParameters miningParameters =
new MiningParametersTestBuilder().coinbase(null).build();

final PendingTransactions pendingTransactions =
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem);

final EthHashMinerExecutor executor =
new EthHashMinerExecutor(
null,
Executors.newCachedThreadPool(),
null,
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
pendingTransactions,
miningParameters,
new DefaultBlockScheduler(1, 10, TestClock.fixed()));

Expand All @@ -52,12 +58,16 @@ public void startingMiningWithoutCoinbaseThrowsException() {
public void settingCoinbaseToNullThrowsException() {
final MiningParameters miningParameters = new MiningParametersTestBuilder().build();

final PendingTransactions pendingTransactions =
new PendingTransactions(
TRANSACTION_EVICTION_INTERVAL_MS, 1, TestClock.fixed(), metricsSystem);

final EthHashMinerExecutor executor =
new EthHashMinerExecutor(
null,
Executors.newCachedThreadPool(),
null,
new PendingTransactions(1, TestClock.fixed(), metricsSystem),
pendingTransactions,
miningParameters,
new DefaultBlockScheduler(1, 10, TestClock.fixed()));

Expand Down
Loading

0 comments on commit c0bf672

Please sign in to comment.