Search in sources :

Example 1 with GasPricePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter in project besu by hyperledger.

the class AbstractJsonRpcHttpServiceTest method getRpcMethods.

protected Map<String, JsonRpcMethod> getRpcMethods(final JsonRpcConfiguration config, final BlockchainSetupUtil blockchainSetupUtil) {
    final ProtocolContext protocolContext = mock(ProtocolContext.class);
    final Synchronizer synchronizerMock = mock(Synchronizer.class);
    final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class);
    final TransactionPool transactionPoolMock = mock(TransactionPool.class);
    final PoWMiningCoordinator miningCoordinatorMock = mock(PoWMiningCoordinator.class);
    when(transactionPoolMock.addLocalTransaction(any(Transaction.class))).thenReturn(ValidationResult.valid());
    // nonce too low tests uses a tx with nonce=16
    when(transactionPoolMock.addLocalTransaction(argThat(tx -> tx.getNonce() == 16))).thenReturn(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_LOW));
    final GasPricePendingTransactionsSorter pendingTransactionsMock = mock(GasPricePendingTransactionsSorter.class);
    when(transactionPoolMock.getPendingTransactions()).thenReturn(pendingTransactionsMock);
    final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
    final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchainSetupUtil.getBlockchain(), blockchainSetupUtil.getWorldArchive());
    final FilterIdGenerator filterIdGenerator = mock(FilterIdGenerator.class);
    final FilterRepository filterRepository = new FilterRepository();
    when(filterIdGenerator.nextId()).thenReturn("0x1");
    filterManager = new FilterManagerBuilder().blockchainQueries(blockchainQueries).transactionPool(transactionPoolMock).filterIdGenerator(filterIdGenerator).filterRepository(filterRepository).build();
    final Set<Capability> supportedCapabilities = new HashSet<>();
    supportedCapabilities.add(EthProtocol.ETH62);
    supportedCapabilities.add(EthProtocol.ETH63);
    final NatService natService = new NatService(Optional.empty());
    return new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), peerDiscoveryMock, blockchainQueries, synchronizerMock, blockchainSetupUtil.getProtocolSchedule(), protocolContext, filterManager, transactionPoolMock, miningCoordinatorMock, new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), Optional.empty(), JSON_RPC_APIS, privacyParameters, config, mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class));
}
Also used : ValidationResult(org.hyperledger.besu.ethereum.mainnet.ValidationResult) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) URL(java.net.URL) FilterRepository(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) Map(java.util.Map) After(org.junit.After) BigInteger(java.math.BigInteger) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) ClassRule(org.junit.ClassRule) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) MediaType(okhttp3.MediaType) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Collection(java.util.Collection) Set(java.util.Set) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) Optional(java.util.Optional) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ChainResources(org.hyperledger.besu.testutil.BlockTestUtil.ChainResources) HashMap(java.util.HashMap) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) HashSet(java.util.HashSet) FilterManager(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager) HealthService(org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Before(org.junit.Before) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Vertx(io.vertx.core.Vertx) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) Mockito.when(org.mockito.Mockito.when) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) OkHttpClient(okhttp3.OkHttpClient) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) FilterIdGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator) Transaction(org.hyperledger.besu.ethereum.core.Transaction) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) NatService(org.hyperledger.besu.nat.NatService) TemporaryFolder(org.junit.rules.TemporaryFolder) Synchronizer(org.hyperledger.besu.ethereum.core.Synchronizer) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) NatService(org.hyperledger.besu.nat.NatService) P2PNetwork(org.hyperledger.besu.ethereum.p2p.network.P2PNetwork) FilterManagerBuilder(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) JsonRpcMethodsFactory(org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory) Transaction(org.hyperledger.besu.ethereum.core.Transaction) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) FilterRepository(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository) FilterIdGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) PoWMiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) HashSet(java.util.HashSet)

Example 2 with GasPricePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter in project besu by hyperledger.

the class CliqueBlockCreatorTest method proposerAddressCanBeExtractFromAConstructedBlock.

@Test
public void proposerAddressCanBeExtractFromAConstructedBlock() {
    final Bytes extraData = CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);
    final Address coinbase = AddressHelpers.ofValue(1);
    final CliqueBlockCreator blockCreator = new CliqueBlockCreator(coinbase, () -> Optional.of(10_000_000L), parent -> extraData, new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem, blockchain::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), protocolContext, protocolSchedule, proposerNodeKey, Wei.ZERO, 0.8, blockchain.getChainHeadHeader(), epochManager);
    final Block createdBlock = blockCreator.createBlock(5L);
    Java6Assertions.assertThat(CliqueHelpers.getProposerOfBlock(createdBlock.getHeader())).isEqualTo(proposerAddress);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Block(org.hyperledger.besu.ethereum.core.Block) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Test(org.junit.Test)

Example 3 with GasPricePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter in project besu by hyperledger.

the class CliqueMinerExecutorTest method extraDataCreatedOnEpochBlocksContainsValidators.

@Test
public void extraDataCreatedOnEpochBlocksContainsValidators() {
    final Bytes vanityData = generateRandomVanityData();
    final CliqueMinerExecutor executor = new CliqueMinerExecutor(cliqueProtocolContext, CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT), new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, CliqueMinerExecutorTest::mockBlockHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), proposerNodeKey, new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(vanityData).miningEnabled(false).build(), mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH));
    // NOTE: Passing in the *parent* block, so must be 1 less than EPOCH
    final BlockHeader header = blockHeaderBuilder.number(EPOCH_LENGTH - 1).buildHeader();
    final Bytes extraDataBytes = executor.calculateExtraData(header);
    final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeaderBuilder.number(EPOCH_LENGTH).extraData(extraDataBytes).blockHeaderFunctions(new CliqueBlockHeaderFunctions()).buildHeader());
    assertThat(cliqueExtraData.getVanityData()).isEqualTo(vanityData);
    assertThat(cliqueExtraData.getValidators()).containsExactly(validatorList.toArray(new Address[0]));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) CliqueBlockHeaderFunctions(org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) CliqueExtraData(org.hyperledger.besu.consensus.clique.CliqueExtraData) Test(org.junit.Test)

Example 4 with GasPricePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter in project besu by hyperledger.

the class TransactionPoolTest method setUp.

@Before
public void setUp() {
    blockchain = executionContext.getBlockchain();
    transactions = new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, MAX_TRANSACTIONS, TestClock.fixed(), metricsSystem, blockchain::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
    when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
    when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator);
    when(protocolSpec.getFeeMarket()).thenReturn(FeeMarket.legacy());
    genesisBlockGasLimit = executionContext.getGenesis().getHeader().getGasLimit();
    ethContext = mock(EthContext.class);
    final EthScheduler ethScheduler = mock(EthScheduler.class);
    syncTaskCapture = ArgumentCaptor.forClass(Runnable.class);
    doNothing().when(ethScheduler).scheduleSyncWorkerTask(syncTaskCapture.capture());
    when(ethContext.getScheduler()).thenReturn(ethScheduler);
    ethPeers = mock(EthPeers.class);
    when(ethContext.getEthPeers()).thenReturn(ethPeers);
    peerTransactionTracker = new PeerTransactionTracker();
    transactionBroadcaster = spy(new TransactionBroadcaster(ethContext, transactions, peerTransactionTracker, transactionsMessageSender, newPooledTransactionHashesMessageSender));
    transactionPool = createTransactionPool();
    blockchain.observeBlockAdded(transactionPool);
    when(miningParameters.getMinTransactionGasPrice()).thenReturn(Wei.of(2));
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Before(org.junit.Before)

Example 5 with GasPricePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter in project besu by hyperledger.

the class TransactionPoolTest method shouldDiscardRemoteTransactionThatAlreadyExistsBeforeValidation.

@Test
public void shouldDiscardRemoteTransactionThatAlreadyExistsBeforeValidation() {
    final GasPricePendingTransactionsSorter pendingTransactions = mock(GasPricePendingTransactionsSorter.class);
    final TransactionPool transactionPool = new TransactionPool(pendingTransactions, protocolSchedule, protocolContext, transactionBroadcaster, ethContext, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, TransactionPoolConfiguration.DEFAULT);
    when(pendingTransactions.containsTransaction(transaction1.getHash())).thenReturn(true);
    transactionPool.addRemoteTransactions(singletonList(transaction1));
    verify(pendingTransactions).containsTransaction(transaction1.getHash());
    verifyNoInteractions(transactionValidator);
    verifyNoMoreInteractions(pendingTransactions);
}
Also used : MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Test(org.junit.Test)

Aggregations

GasPricePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter)21 Test (org.junit.Test)15 Address (org.hyperledger.besu.datatypes.Address)8 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)8 Bytes (org.apache.tuweni.bytes.Bytes)6 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)6 Block (org.hyperledger.besu.ethereum.core.Block)6 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)6 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)6 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)5 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)4 EthPeers (org.hyperledger.besu.ethereum.eth.manager.EthPeers)4 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)4 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)3 CliqueBlockHeaderFunctions (org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions)3 CliqueExtraData (org.hyperledger.besu.consensus.clique.CliqueExtraData)3 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)3 Vertx (io.vertx.core.Vertx)2 URL (java.net.URL)2 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)2