Search in sources :

Example 1 with SyncState

use of org.hyperledger.besu.ethereum.eth.sync.state.SyncState in project besu by hyperledger.

the class TransactionPoolTest method shouldRejectRemoteTransactionsWhenNotInSync.

@Test
public void shouldRejectRemoteTransactionsWhenNotInSync() {
    SyncState syncState = mock(SyncState.class);
    when(syncState.isInSync(anyLong())).thenReturn(false);
    TransactionPool transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, batchAddedListener, pendingBatchAddedListener, syncState, ethContext, peerTransactionTracker, peerPendingTransactionTracker, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), metricsSystem, TransactionPoolConfiguration.DEFAULT);
    final TransactionTestFixture builder = new TransactionTestFixture();
    final Transaction transaction1 = builder.nonce(1).createTransaction(KEY_PAIR1);
    final Transaction transaction2 = builder.nonce(2).createTransaction(KEY_PAIR1);
    final Transaction transaction3 = builder.nonce(3).createTransaction(KEY_PAIR1);
    transactionPool.addRemoteTransactions(asList(transaction3, transaction1, transaction2));
    assertTransactionNotPending(transaction1);
    assertTransactionNotPending(transaction2);
    assertTransactionNotPending(transaction3);
    verifyNoInteractions(batchAddedListener);
}
Also used : MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) Test(org.junit.Test)

Example 2 with SyncState

use of org.hyperledger.besu.ethereum.eth.sync.state.SyncState in project besu by hyperledger.

the class ForestBlockPropagationManagerTest method setup.

@Before
public void setup() {
    blockchainUtil = BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST);
    blockchain = blockchainUtil.getBlockchain();
    protocolSchedule = blockchainUtil.getProtocolSchedule();
    final ProtocolContext tempProtocolContext = blockchainUtil.getProtocolContext();
    protocolContext = new ProtocolContext(blockchain, tempProtocolContext.getWorldStateArchive(), tempProtocolContext.getConsensusContext(ConsensusContext.class));
    ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain, blockchainUtil.getWorldArchive(), blockchainUtil.getTransactionPool(), EthProtocolConfiguration.defaultConfig());
    syncConfig = SynchronizerConfiguration.builder().blockPropagationRange(-3, 5).build();
    syncState = new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers());
    blockBroadcaster = mock(BlockBroadcaster.class);
    blockPropagationManager = new BlockPropagationManager(syncConfig, protocolSchedule, protocolContext, ethProtocolManager.ethContext(), syncState, pendingBlocksManager, metricsSystem, blockBroadcaster);
}
Also used : SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Before(org.junit.Before)

Example 3 with SyncState

use of org.hyperledger.besu.ethereum.eth.sync.state.SyncState in project besu by hyperledger.

the class FullSyncChainDownloaderTest method setupTest.

@Before
public void setupTest() {
    gen = new BlockDataGenerator();
    localBlockchainSetup = BlockchainSetupUtil.forTesting(storageFormat);
    localBlockchain = localBlockchainSetup.getBlockchain();
    otherBlockchainSetup = BlockchainSetupUtil.forTesting(storageFormat);
    otherBlockchain = otherBlockchainSetup.getBlockchain();
    protocolSchedule = localBlockchainSetup.getProtocolSchedule();
    protocolContext = localBlockchainSetup.getProtocolContext();
    ethProtocolManager = EthProtocolManagerTestUtil.create(localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localBlockchainSetup.getWorldArchive(), localBlockchainSetup.getTransactionPool(), EthProtocolConfiguration.defaultConfig());
    ethContext = ethProtocolManager.ethContext();
    syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
}
Also used : EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) Before(org.junit.Before)

Example 4 with SyncState

use of org.hyperledger.besu.ethereum.eth.sync.state.SyncState in project besu by hyperledger.

the class FullSyncDownloaderTest method setupTest.

@Before
public void setupTest() {
    localBlockchainSetup = BlockchainSetupUtil.forTesting(storageFormat);
    localBlockchain = localBlockchainSetup.getBlockchain();
    protocolSchedule = localBlockchainSetup.getProtocolSchedule();
    protocolContext = localBlockchainSetup.getProtocolContext();
    ethProtocolManager = EthProtocolManagerTestUtil.create(localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localBlockchainSetup.getWorldArchive(), localBlockchainSetup.getTransactionPool(), EthProtocolConfiguration.defaultConfig());
    ethContext = ethProtocolManager.ethContext();
    syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
}
Also used : EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Before(org.junit.Before)

Example 5 with SyncState

use of org.hyperledger.besu.ethereum.eth.sync.state.SyncState in project besu by hyperledger.

the class TransactionPoolFactoryTest method testDisconnect.

@Test
public void testDisconnect() {
    final ProtocolSchedule schedule = mock(ProtocolSchedule.class);
    final ProtocolContext context = mock(ProtocolContext.class);
    final MutableBlockchain blockchain = mock(MutableBlockchain.class);
    when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.of(mock(Block.class)));
    when(blockchain.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(mock(Hash.class)));
    when(context.getBlockchain()).thenReturn(blockchain);
    final EthPeers ethPeers = new EthPeers("ETH", TestClock.fixed(), new NoOpMetricsSystem(), 25);
    final EthContext ethContext = mock(EthContext.class);
    when(ethContext.getEthMessages()).thenReturn(mock(EthMessages.class));
    when(ethContext.getEthPeers()).thenReturn(ethPeers);
    final EthScheduler ethScheduler = mock(EthScheduler.class);
    when(ethContext.getScheduler()).thenReturn(ethScheduler);
    final SyncState state = mock(SyncState.class);
    final GasPricePendingTransactionsSorter pendingTransactions = mock(GasPricePendingTransactionsSorter.class);
    final PeerTransactionTracker peerTransactionTracker = mock(PeerTransactionTracker.class);
    final TransactionsMessageSender transactionsMessageSender = mock(TransactionsMessageSender.class);
    doNothing().when(transactionsMessageSender).sendTransactionsToPeer(any(EthPeer.class));
    final NewPooledTransactionHashesMessageSender newPooledTransactionHashesMessageSender = mock(NewPooledTransactionHashesMessageSender.class);
    final TransactionPool pool = TransactionPoolFactory.createTransactionPool(schedule, context, ethContext, new NoOpMetricsSystem(), state, new MiningParameters.Builder().minTransactionGasPrice(Wei.ONE).build(), ImmutableTransactionPoolConfiguration.of(1, 1, 1, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP, TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD, TransactionPoolConfiguration.DEFAULT_RPC_TX_FEE_CAP, TransactionPoolConfiguration.DEFAULT_STRICT_TX_REPLAY_PROTECTION_ENABLED), pendingTransactions, peerTransactionTracker, transactionsMessageSender, newPooledTransactionHashesMessageSender);
    final EthProtocolManager ethProtocolManager = new EthProtocolManager(blockchain, BigInteger.ONE, mock(WorldStateArchive.class), pool, new EthProtocolConfiguration(5, 5, 5, 5, 5, false), ethPeers, mock(EthMessages.class), ethContext, Collections.emptyList(), true, mock(EthScheduler.class), mock(ForkIdManager.class));
    final RespondingEthPeer ethPeer = RespondingEthPeer.builder().ethProtocolManager(ethProtocolManager).build();
    assertThat(ethPeer.getEthPeer()).isNotNull();
    assertThat(ethPeer.getEthPeer().isDisconnected()).isFalse();
    ethPeer.disconnect(DisconnectMessage.DisconnectReason.CLIENT_QUITTING);
    verify(peerTransactionTracker, times(1)).onDisconnect(ethPeer.getEthPeer());
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) EthMessages(org.hyperledger.besu.ethereum.eth.manager.EthMessages) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) ForkIdManager(org.hyperledger.besu.ethereum.eth.manager.ForkIdManager) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Test(org.junit.Test)

Aggregations

SyncState (org.hyperledger.besu.ethereum.eth.sync.state.SyncState)17 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)11 EthScheduler (org.hyperledger.besu.ethereum.eth.manager.EthScheduler)10 Before (org.junit.Before)10 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)8 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)6 EthMessages (org.hyperledger.besu.ethereum.eth.manager.EthMessages)4 EthPeers (org.hyperledger.besu.ethereum.eth.manager.EthPeers)4 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)4 GenesisState (org.hyperledger.besu.ethereum.chain.GenesisState)2 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)2 BlockchainSetupUtil (org.hyperledger.besu.ethereum.core.BlockchainSetupUtil)2 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)2 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)2 Checkpoint (org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint)2 ImmutableCheckpoint (org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.ImmutableCheckpoint)2 ImmutableTransactionPoolConfiguration (org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration)2 TransactionPoolConfiguration (org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration)2 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)2 Test (org.junit.Test)2