Search in sources :

Example 1 with TransactionsMessage

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());
    }
}
Also used : DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Transaction(org.hyperledger.besu.ethereum.core.Transaction) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) TransactionsMessage(org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) RawMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage) Test(org.junit.Test)

Example 2 with TransactionsMessage

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));
}
Also used : TransactionsMessage(org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage) Instant(java.time.Instant)

Aggregations

TransactionsMessage (org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage)2 Instant (java.time.Instant)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)1 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)1 Transaction (org.hyperledger.besu.ethereum.core.Transaction)1 SyncState (org.hyperledger.besu.ethereum.eth.sync.state.SyncState)1 PeerConnection (org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection)1 DefaultMessage (org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage)1 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)1 RawMessage (org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage)1 Test (org.junit.Test)1