Beispiel #1
0
async def test_fast_syncer(request, event_loop, chaindb_fresh, chaindb_20):
    client_peer, server_peer = await get_directly_linked_peers(
        request, event_loop, ETHPeer, FakeAsyncHeaderDB(chaindb_fresh.db),
        ETHPeer, FakeAsyncHeaderDB(chaindb_20.db))
    client_peer_pool = MockPeerPoolWithConnectedPeers([client_peer])
    client = FastChainSyncer(chaindb_fresh, client_peer_pool)
    server = RegularChainSyncer(FrontierTestChain(chaindb_20.db), chaindb_20,
                                MockPeerPoolWithConnectedPeers([server_peer]))
    asyncio.ensure_future(server.run())

    def finalizer():
        event_loop.run_until_complete(server.cancel())
        # Yield control so that server.run() returns, otherwise asyncio will complain.
        event_loop.run_until_complete(asyncio.sleep(0.1))

    request.addfinalizer(finalizer)

    # FastChainSyncer.run() will return as soon as it's caught up with the peer.
    await asyncio.wait_for(client.run(), timeout=2)

    head = chaindb_fresh.get_canonical_head()
    assert head == chaindb_20.get_canonical_head()

    # Now download the state for the chain's head.
    state_downloader = StateDownloader(chaindb_fresh.db, head.state_root,
                                       client_peer_pool)
    await asyncio.wait_for(state_downloader.run(), timeout=2)

    assert head.state_root in chaindb_fresh.db
Beispiel #2
0
    async def _run(self) -> None:
        head = await self.wait(self.chaindb.coro_get_canonical_head())
        # We're still too slow at block processing, so if our local head is older than
        # FAST_SYNC_CUTOFF we first do a fast-sync run to catch up with the rest of the network.
        # See https://github.com/ethereum/py-evm/issues/654 for more details
        if head.timestamp < time.time() - FAST_SYNC_CUTOFF:
            # Fast-sync chain data.
            self.logger.info("Starting fast-sync; current head: #%d",
                             head.block_number)
            chain_syncer = FastChainSyncer(self.chaindb, self.peer_pool,
                                           self.cancel_token)
            await chain_syncer.run()

        # Ensure we have the state for our current head.
        head = await self.wait(self.chaindb.coro_get_canonical_head())
        if head.state_root != BLANK_ROOT_HASH and head.state_root not in self.base_db:
            self.logger.info(
                "Missing state for current head (#%d), downloading it",
                head.block_number)
            downloader = StateDownloader(self.base_db, head.state_root,
                                         self.peer_pool, self.cancel_token)
            await downloader.run()

        # Now, loop forever, fetching missing blocks and applying them.
        self.logger.info("Starting regular sync; current head: #%d",
                         head.block_number)
        chain_syncer = RegularChainSyncer(self.chain, self.chaindb,
                                          self.peer_pool, self.cancel_token)
        await chain_syncer.run()
Beispiel #3
0
    async def _run(self) -> None:
        head = await self.chaindb.coro_get_canonical_head()
        # We're still too slow at block processing, so if our local head is older than
        # FAST_SYNC_CUTOFF we first do a fast-sync run to catch up with the rest of the network.
        # See https://github.com/ethereum/py-evm/issues/654 for more details
        if head.timestamp < time.time() - FAST_SYNC_CUTOFF:
            # Fast-sync chain data.
            self.logger.info("Starting fast-sync; current head: #%d",
                             head.block_number)
            chain_syncer = FastChainSyncer(self.chaindb, self.peer_pool,
                                           self.cancel_token)
            await chain_syncer.run()

            # Download state for our current head.
            head = await self.chaindb.coro_get_canonical_head()
            downloader = StateDownloader(self.db, head.state_root,
                                         self.peer_pool, self.cancel_token)
            await downloader.run()

        # Now, loop forever, fetching missing blocks and applying them.
        self.logger.info("Starting regular sync; current head: #%d",
                         head.block_number)
        # This is a bit of a hack, but self.chain is stuck in the past as during the fast-sync we
        # did not use it to import the blocks, so we need this to get a Chain instance with our
        # latest head so that we can start importing blocks.
        new_chain = type(self.chain)(self.chaindb)
        chain_syncer = RegularChainSyncer(new_chain, self.chaindb,
                                          self.peer_pool, self.cancel_token)
        await chain_syncer.run()
Beispiel #4
0
async def test_regular_syncer(request, event_loop, chaindb_fresh, chaindb_20):
    client_peer, server_peer = await get_directly_linked_peers(
        request, event_loop,
        ETHPeer, FakeAsyncHeaderDB(chaindb_fresh.db),
        ETHPeer, FakeAsyncHeaderDB(chaindb_20.db))
    client = RegularChainSyncer(
        FrontierTestChain(chaindb_fresh.db),
        chaindb_fresh,
        MockPeerPoolWithConnectedPeers([client_peer]))
    server = RegularChainSyncer(
        FrontierTestChain(chaindb_20.db),
        chaindb_20,
        MockPeerPoolWithConnectedPeers([server_peer]))
    asyncio.ensure_future(server.run())

    def finalizer():
        event_loop.run_until_complete(asyncio.gather(client.cancel(), server.cancel()))
        # Yield control so that client/server.run() returns, otherwise asyncio will complain.
        event_loop.run_until_complete(asyncio.sleep(0.1))
    request.addfinalizer(finalizer)

    asyncio.ensure_future(client.run())

    await wait_for_head(client.db, server.db.get_canonical_head())
    head = client.db.get_canonical_head()
    assert head.state_root in client.db.db