コード例 #1
0
def run_fullnode_process(chain_config: ChainConfig,
                         pool_class: Type[HardCodedNodesPeerPool]) -> None:

    manager = create_dbmanager(chain_config.database_ipc_path)
    db = manager.get_db()  # type: ignore
    chaindb = manager.get_chaindb()  # type: ignore
    chain = manager.get_chain()  # type: ignore

    peer_pool = pool_class(ETHPeer, chaindb, chain_config.network_id,
                           chain_config.nodekey)
    asyncio.ensure_future(peer_pool.run())
    syncer = FullNodeSyncer(chain, chaindb, db, peer_pool)

    loop = asyncio.get_event_loop()
    # Use a ProcessPoolExecutor as the default so that we can offload cpu-intensive tasks from the
    # main thread.
    loop.set_default_executor(ProcessPoolExecutor())
    sigint_received = asyncio.Event()
    for sig in [signal.SIGINT, signal.SIGTERM]:
        loop.add_signal_handler(sig, sigint_received.set)

    async def exit_on_sigint():
        await sigint_received.wait()
        await peer_pool.cancel()
        await syncer.cancel()
        loop.stop()

    asyncio.ensure_future(exit_on_sigint())
    asyncio.ensure_future(syncer.run())
    loop.run_forever()
    loop.close()
コード例 #2
0
ファイル: server.py プロジェクト: shawnxu1111/py-evm
 def __init__(
     self,
     privkey: datatypes.PrivateKey,
     address: Address,
     chain: AsyncChain,
     chaindb: AsyncChainDB,
     headerdb: 'BaseAsyncHeaderDB',
     db: BaseDB,
     network_id: int,
     min_peers: int = DEFAULT_MIN_PEERS,
     peer_class: Type[BasePeer] = ETHPeer,
     peer_pool_class: Type[PeerPool] = PeerPool,
     bootstrap_nodes: List[str] = [],
 ) -> None:
     super().__init__(CancelToken('Server'))
     self.headerdb = headerdb
     self.privkey = privkey
     self.address = address
     self.network_id = network_id
     self.peer_class = peer_class
     if not bootstrap_nodes:
         if self.network_id == MAINNET_NETWORK_ID:
             bootstrap_nodes = MAINNET_BOOTNODES
         elif self.network_id == ROPSTEN_NETWORK_ID:
             bootstrap_nodes = ROPSTEN_BOOTNODES
         else:
             self.logger.warn(
                 "No bootstrap nodes for network id: {}".format(network_id))
             bootstrap_nodes = []
     self.discovery = DiscoveryProtocol(self.privkey,
                                        self.address,
                                        bootstrap_nodes=bootstrap_nodes)
     self.peer_pool = peer_pool_class(
         peer_class,
         self.headerdb,
         self.network_id,
         self.privkey,
         self.discovery,
         min_peers=min_peers,
     )
     self.syncer = FullNodeSyncer(chain, chaindb, db, self.peer_pool,
                                  self.cancel_token)
コード例 #3
0
ファイル: server.py プロジェクト: yuhaibao324/py-evm
 def _make_syncer(self, peer_pool: PeerPool) -> BaseService:
     # This method exists only so that ShardSyncer can provide a different implementation.
     return FullNodeSyncer(self.chain, self.chaindb, self.base_db,
                           peer_pool, self.cancel_token)