Ejemplo n.º 1
0
 async def _handle_new_collation_hashes(self, peer: ShardingPeer, msg: Dict[str, Any]) -> None:
     """Request those collations."""
     # Request all collations for now, no matter if we now about them or not, as there's no way
     # to header existence at the moment. In the future we won't transfer collations anyway but
     # only collation bodies (headers are retrieved from the main chain), so there's no need to
     # add this at the moment.
     collation_hashes = set(
         collation_hash for collation_hash, _ in msg["collation_hashes_and_periods"]
     )
     if collation_hashes:
         peer.sub_proto = cast(ShardingProtocol, peer.sub_proto)
         peer.sub_proto.send_get_collations(gen_request_id(), list(collation_hashes))
Ejemplo n.º 2
0
    async def _handle_get_collations(self, peer: ShardingPeer,
                                     msg: Dict[str, Any]) -> None:
        """Respond with all requested collations that we know about."""
        collation_hashes = set(msg["collation_hashes"])
        self.collation_hashes_at_peer[peer] |= collation_hashes

        get_collation_or_none = excepts(
            (CollationHeaderNotFound, CollationBodyNotFound),
            self.shard.get_collation_by_hash)
        collations = [
            collation for collation in [
                get_collation_or_none(collation_hash)
                for collation_hash in collation_hashes
            ] if collation is not None
        ]
        self.logger.info(
            "Responding to peer %s with %d collations",
            peer.remote,
            len(collations),
        )
        peer.sub_proto = cast(ShardingProtocol, peer.sub_proto)
        peer.sub_proto.send_collations(msg["request_id"], collations)