use of org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage in project besu by hyperledger.
the class EthProtocolManagerTest method transactionMessagesGoToTheCorrectExecutor.
@Test
public void transactionMessagesGoToTheCorrectExecutor() {
// Create a mock ethScheduler to hold our mock executors.
final ExecutorService worker = mock(ExecutorService.class);
final ScheduledExecutorService scheduled = mock(ScheduledExecutorService.class);
final ExecutorService transactions = mock(ExecutorService.class);
final ExecutorService services = mock(ExecutorService.class);
final ExecutorService computations = mock(ExecutorService.class);
final EthScheduler ethScheduler = new EthScheduler(worker, scheduled, transactions, services, computations);
// Create the fake TransactionMessage to feed to the EthManager.
final BlockDataGenerator gen = new BlockDataGenerator(1);
final List<Transaction> txes = Collections.singletonList(gen.transaction());
final MessageData initialMessage = TransactionsMessage.create(txes);
final MessageData raw = new RawMessage(EthPV62.TRANSACTIONS, initialMessage.getData());
final TransactionsMessage transactionMessage = TransactionsMessage.readFrom(raw);
try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create(blockchain, ethScheduler, protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig())) {
// Create a transaction pool. This has a side effect of registering a listener for the
// transactions message.
TransactionPoolFactory.createTransactionPool(protocolSchedule, protocolContext, ethManager.ethContext(), TestClock.fixed(), metricsSystem, mock(SyncState.class), new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), TransactionPoolConfiguration.DEFAULT);
// Send just a transaction message.
final PeerConnection peer = setupPeer(ethManager, (cap, msg, connection) -> {
});
ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(peer, transactionMessage));
// Verify the regular message executor and scheduled executor got nothing to execute.
verifyNoInteractions(worker, scheduled);
// Verify our transactions executor got something to execute.
verify(transactions).execute(any());
}
}
use of org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage in project besu by hyperledger.
the class TransactionsMessageHandler method exec.
@Override
public void exec(final EthMessage message) {
final TransactionsMessage transactionsMessage = TransactionsMessage.readFrom(message.getData());
final Instant startedAt = now();
scheduler.scheduleTxWorkerTask(() -> transactionsMessageProcessor.processTransactionsMessage(message.getPeer(), transactionsMessage, startedAt, txMsgKeepAlive));
}
Aggregations