async def test_does_not_propagate_invalid_tx(event_bus, chain_with_block_validation, tx_validator): initial_two_peers = TEST_NODES[:2] node_one = initial_two_peers[0] node_two = initial_two_peers[1] async with run_proxy_peer_pool(event_bus) as peer_pool: outgoing_tx = observe_outgoing_transactions(event_bus) tx_pool = TxPool(event_bus, peer_pool, tx_validator) asyncio.ensure_future(tx_pool.run()) run_mock_request_response(GetConnectedPeersRequest, GetConnectedPeersResponse(initial_two_peers), event_bus) await asyncio.sleep(0.01) txs_broadcasted_by_peer1 = [ create_random_tx(chain_with_block_validation, is_valid=False), create_random_tx(chain_with_block_validation) ] # Peer1 sends some txs await event_bus.broadcast( TransactionsEvent(session=node_one, msg=txs_broadcasted_by_peer1, cmd=Transactions)) await asyncio.sleep(0.01) # Check that Peer2 received only the second tx which is valid assert outgoing_tx == [ (node_two, (txs_broadcasted_by_peer1[1], )), ]
class TxComponent(AsyncioIsolatedComponent): tx_pool: TxPool = None @property def name(self) -> str: return "TxComponent" @classmethod def configure_parser(cls, arg_parser: ArgumentParser, subparser: _SubParsersAction) -> None: arg_parser.add_argument( "--disable-tx-pool", action="store_true", help="Disables the Transaction Pool", ) def on_ready(self, manager_eventbus: EndpointAPI) -> None: light_mode = self.boot_info.args.sync_mode == SYNC_LIGHT is_disable = self.boot_info.args.disable_tx_pool is_supported = not light_mode is_enabled = not is_disable and is_supported if is_disable: self.logger.debug("Transaction pool disabled") elif not is_supported: self.logger.warning( "Transaction pool disabled. Not supported in light mode.") elif is_enabled: self.start() else: raise Exception("This code path should be unreachable") def do_start(self) -> None: trinity_config = self.boot_info.trinity_config db = DBClient.connect(trinity_config.database_ipc_path) app_config = trinity_config.get_app_config(Eth1AppConfig) chain_config = app_config.get_chain_config() chain = chain_config.full_chain_class(db) if self.boot_info.trinity_config.network_id == MAINNET_NETWORK_ID: validator = DefaultTransactionValidator(chain, BYZANTIUM_MAINNET_BLOCK) elif self.boot_info.trinity_config.network_id == ROPSTEN_NETWORK_ID: validator = DefaultTransactionValidator(chain, BYZANTIUM_ROPSTEN_BLOCK) else: raise ValueError( "The TxPool component only supports MainnetChain or RopstenChain" ) proxy_peer_pool = ETHProxyPeerPool(self.event_bus, TO_NETWORKING_BROADCAST_CONFIG) self.tx_pool = TxPool(self.event_bus, proxy_peer_pool, validator) asyncio.ensure_future( exit_with_services(self.tx_pool, self._event_bus_service)) asyncio.ensure_future(self.tx_pool.run()) async def do_stop(self) -> None: # This isn't really needed for the standard shutdown case as the TxPool will automatically # shutdown whenever the `CancelToken` it was chained with is triggered. It may still be # useful to stop the TxPool component individually though. if self.tx_pool.is_operational: await self.tx_pool.cancel() self.logger.info("Successfully stopped TxPool")