import requests


def do_gossip(known_nodes):
    """
    The gossip algorithm - pull.
    All the known nodes are checked for collecting the available chains.

    :return: True if our chain was replaced, False if not
    """
    collected_chains = []
    # Pull: Collect the blockchains from the neighbours
    for node in known_nodes:
        try:
            response = requests.get(f'http://{node}/chain')

            if response.status_code == 200:
                chain = response.json()['chain']
                collected_chains.append(chain)
        except Exception as e:
            print(f'Exception on node {node}: {e}')
    return collected_chains