Search in sources :

Example 1 with EthProtocolManager

use of org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager in project besu by hyperledger.

the class TransitionBesuControllerBuilder method createEthProtocolManager.

@Override
protected EthProtocolManager createEthProtocolManager(final ProtocolContext protocolContext, final boolean fastSyncEnabled, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration, final EthPeers ethPeers, final EthContext ethContext, final EthMessages ethMessages, final EthScheduler scheduler, final List<PeerValidator> peerValidators) {
    EthProtocolManager ethProtocolManager = super.createEthProtocolManager(protocolContext, fastSyncEnabled, transactionPool, ethereumWireProtocolConfiguration, ethPeers, ethContext, ethMessages, scheduler, peerValidators);
    ConsensusContext cc = protocolContext.getConsensusContext(ConsensusContext.class);
    if (cc instanceof MergeContext) {
        protocolContext.getConsensusContext(MergeContext.class).observeNewIsPostMergeState(ethProtocolManager);
        protocolContext.getConsensusContext(MergeContext.class).addNewForkchoiceMessageListener(ethProtocolManager);
    }
    return ethProtocolManager;
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) PostMergeContext(org.hyperledger.besu.consensus.merge.PostMergeContext)

Example 2 with EthProtocolManager

use of org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager in project besu by hyperledger.

the class Istanbul99ProtocolManagerTest method respondToEth65GetHeadersUsingIstanbul99.

@Test
public void respondToEth65GetHeadersUsingIstanbul99() throws ExecutionException, InterruptedException, TimeoutException {
    final CompletableFuture<Void> done = new CompletableFuture<>();
    final EthScheduler ethScheduler = new DeterministicEthScheduler(() -> false);
    EthPeers peers = new EthPeers(Istanbul99Protocol.NAME, TestClock.fixed(), new NoOpMetricsSystem(), 25);
    EthMessages messages = new EthMessages();
    final BigInteger networkId = BigInteger.ONE;
    try (final EthProtocolManager ethManager = new Istanbul99ProtocolManager(blockchain, networkId, protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig(), peers, messages, new EthContext(peers, messages, ethScheduler), Collections.emptyList(), false, ethScheduler)) {
        final long startBlock = blockchain.getChainHeadBlockNumber() + 1;
        final int blockCount = 5;
        final MessageData messageData = GetBlockHeadersMessage.create(startBlock, blockCount, 0, false);
        final PeerSendHandler onSend = (cap, message, conn) -> {
            if (message.getCode() == EthPV62.STATUS) {
                // Ignore status message
                return;
            }
            assertThat(message.getCode()).isEqualTo(EthPV62.BLOCK_HEADERS);
            final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message);
            final List<BlockHeader> headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule));
            assertThat(headers.size()).isEqualTo(0);
            done.complete(null);
        };
        final PeerConnection peer = setupPeer(ethManager, onSend);
        ethManager.processMessage(Istanbul99Protocol.ISTANBUL99, new DefaultMessage(peer, messageData));
        done.get(10, TimeUnit.SECONDS);
    }
}
Also used : MockPeerConnection(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection) StatusMessage(org.hyperledger.besu.ethereum.eth.messages.StatusMessage) EthPV62(org.hyperledger.besu.ethereum.eth.messages.EthPV62) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) HashSet(java.util.HashSet) GetBlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) Lists(com.google.common.collect.Lists) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) BigInteger(java.math.BigInteger) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) Set(java.util.Set) Test(org.junit.Test) BlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) List(java.util.List) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) DeterministicEthScheduler(org.hyperledger.besu.ethereum.eth.manager.DeterministicEthScheduler) EthMessages(org.hyperledger.besu.ethereum.eth.manager.EthMessages) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) EthMessages(org.hyperledger.besu.ethereum.eth.manager.EthMessages) MockPeerConnection(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) DeterministicEthScheduler(org.hyperledger.besu.ethereum.eth.manager.DeterministicEthScheduler) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) CompletableFuture(java.util.concurrent.CompletableFuture) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) DeterministicEthScheduler(org.hyperledger.besu.ethereum.eth.manager.DeterministicEthScheduler) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BigInteger(java.math.BigInteger) List(java.util.List) GetBlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage) BlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) Test(org.junit.Test)

Example 3 with EthProtocolManager

use of org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager in project besu by hyperledger.

the class TransactionPoolTest method shouldRejectGoQuorumTransactionWithNonZeroValue.

@Test
public void shouldRejectGoQuorumTransactionWithNonZeroValue() {
    when(transactionValidator.getGoQuorumCompatibilityMode()).thenReturn(true);
    final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
    final EthContext ethContext = ethProtocolManager.ethContext();
    final Wei twoEthers = Wei.fromEth(2);
    final TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, transactionBroadcaster, ethContext, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, ImmutableTransactionPoolConfiguration.builder().txFeeCap(twoEthers).build());
    final Transaction transaction37 = Transaction.builder().v(BigInteger.valueOf(37)).value(Wei.ONE).build();
    final Transaction transaction38 = Transaction.builder().v(BigInteger.valueOf(38)).value(Wei.ONE).build();
    final ValidationResult<TransactionInvalidReason> result37 = transactionPool.addLocalTransaction(transaction37);
    final ValidationResult<TransactionInvalidReason> result38 = transactionPool.addLocalTransaction(transaction38);
    assertThat(result37.getInvalidReason()).isEqualTo(TransactionInvalidReason.ETHER_VALUE_NOT_SUPPORTED);
    assertThat(result38.getInvalidReason()).isEqualTo(TransactionInvalidReason.ETHER_VALUE_NOT_SUPPORTED);
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Transaction(org.hyperledger.besu.ethereum.core.Transaction) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Wei(org.hyperledger.besu.datatypes.Wei) Test(org.junit.Test)

Example 4 with EthProtocolManager

use of org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager in project besu by hyperledger.

the class TransactionPoolTest method shouldIgnoreEIP1559TransactionWhenNotAllowed.

@Test
public void shouldIgnoreEIP1559TransactionWhenNotAllowed() {
    final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
    final EthContext ethContext = ethProtocolManager.ethContext();
    final TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, transactionBroadcaster, ethContext, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, ImmutableTransactionPoolConfiguration.builder().txFeeCap(Wei.ONE).build());
    when(transactionValidator.validate(any(Transaction.class), any(Optional.class), any())).thenReturn(valid());
    final Transaction transaction = new TransactionTestFixture().nonce(1).type(TransactionType.EIP1559).maxFeePerGas(Optional.of(Wei.ONE)).maxPriorityFeePerGas(Optional.of(Wei.ONE)).gasLimit(10).gasPrice(null).createTransaction(KEY_PAIR1);
    final ValidationResult<TransactionInvalidReason> result = transactionPool.addLocalTransaction(transaction);
    assertThat(result.getInvalidReason()).isEqualTo(TransactionInvalidReason.INVALID_TRANSACTION_FORMAT);
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Optional(java.util.Optional) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Test(org.junit.Test)

Example 5 with EthProtocolManager

use of org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager in project besu by hyperledger.

the class TransactionPoolTest method shouldSendFullTransactionPoolToNewlyConnectedPeer.

@Test
public void shouldSendFullTransactionPoolToNewlyConnectedPeer() {
    EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
    EthContext ethContext = ethProtocolManager.ethContext();
    TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, transactionBroadcaster, ethContext, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, TransactionPoolConfiguration.DEFAULT);
    final TransactionTestFixture builder = new TransactionTestFixture();
    final Transaction transactionLocal = builder.nonce(1).createTransaction(KEY_PAIR1);
    final Transaction transactionRemote = builder.nonce(2).createTransaction(KEY_PAIR1);
    when(transactionValidator.validate(any(Transaction.class), any(Optional.class), any())).thenReturn(valid());
    when(transactionValidator.validateForSender(any(Transaction.class), nullable(Account.class), any(TransactionValidationParams.class))).thenReturn(valid());
    transactionPool.addLocalTransaction(transactionLocal);
    transactionPool.addRemoteTransactions(Collections.singletonList(transactionRemote));
    RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
    Set<Transaction> transactionsToSendToPeer = peerTransactionTracker.claimTransactionsToSendToPeer(peer.getEthPeer());
    assertThat(transactionsToSendToPeer).contains(transactionLocal, transactionRemote);
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Account(org.hyperledger.besu.evm.account.Account) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Optional(java.util.Optional) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) TransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams) Test(org.junit.Test)

Aggregations

EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)39 Test (org.junit.Test)30 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)21 RespondingEthPeer (org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)21 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)16 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)14 Optional (java.util.Optional)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)11 Block (org.hyperledger.besu.ethereum.core.Block)11 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)10 EthScheduler (org.hyperledger.besu.ethereum.eth.manager.EthScheduler)10 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)10 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)10 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)9 Account (org.hyperledger.besu.evm.account.Account)9 InMemoryKeyValueStorage (org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage)9 Before (org.junit.Before)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)8