Esempio n. 1
0
    def do_start(self) -> None:

        trinity_config = self.boot_info.trinity_config
        db_manager = create_db_consumer_manager(
            trinity_config.database_ipc_path)
        db = db_manager.get_db()  # type: ignore

        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:
            # TODO: We could hint the user about e.g. a --tx-pool-no-validation flag to run the
            # tx pool without tx validation in this case
            raise ValueError(
                "The TxPool plugin 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(self.tx_pool.run())
def test_tx_class_resolution(initial_block_number,
                             expected_initial_tx_class,
                             expected_outdated_tx_class,
                             expected_future_tx_class):
    chain = api.build(
        MiningChain,
        api.frontier_at(0),
        api.homestead_at(5),
        api.spurious_dragon_at(10),
        api.disable_pow_check,
        api.genesis
    )
    validator = DefaultTransactionValidator(chain, initial_block_number)
    assert validator.get_appropriate_tx_class() == expected_initial_tx_class

    if expected_outdated_tx_class is not None:
        assert validator.is_outdated_tx_class(expected_outdated_tx_class)

    # The `get_appropriate_tx_class` method has a cache decorator applied
    # To test it properly, we need to clear the cache
    validator.get_appropriate_tx_class.cache_clear()

    # Check that the validator uses the correct tx class when we have reached the tip of the chain
    for n in range(10):
        chain.mine_block()

    assert validator.get_appropriate_tx_class() == expected_future_tx_class
Esempio n. 3
0
    def do_start(self) -> None:
        if self.boot_info.trinity_config.network_id == MAINNET_NETWORK_ID:
            validator = DefaultTransactionValidator(self.chain, BYZANTIUM_MAINNET_BLOCK)
        elif self.boot_info.trinity_config.network_id == ROPSTEN_NETWORK_ID:
            validator = DefaultTransactionValidator(self.chain, BYZANTIUM_ROPSTEN_BLOCK)
        else:
            # TODO: We could hint the user about e.g. a --tx-pool-no-validation flag to run the
            # tx pool without tx validation in this case
            raise ValueError("The TxPool plugin only supports MainnetChain or RopstenChain")

        self.tx_pool = TxPool(self.peer_pool, validator, self.cancel_token)
        asyncio.ensure_future(self.tx_pool.run())
Esempio n. 4
0
    def start(self, context: PluginContext) -> None:
        if isinstance(self.chain, BaseMainnetChain):
            validator = DefaultTransactionValidator(self.chain, BYZANTIUM_MAINNET_BLOCK)
        elif isinstance(self.chain, BaseRopstenChain):
            validator = DefaultTransactionValidator(self.chain, BYZANTIUM_ROPSTEN_BLOCK)
        else:
            # TODO: We could hint the user about e.g. a --tx-pool-no-validation flag to run the
            # tx pool without tx validation in this case
            raise ValueError("The TxPool plugin only supports MainnetChain or RopstenChain")

        tx_pool = TxPool(self.peer_pool, validator, self.cancel_token)
        asyncio.ensure_future(tx_pool.run())
Esempio n. 5
0
def tx_validator(chain_with_block_validation):
    return DefaultTransactionValidator(chain_with_block_validation, 0)