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));
}
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);
}
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]));
}
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));
}
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);
}
Aggregations