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