Esempio n. 1
0
def fork_analysis(list_of_miners):
    chain_versions = []
    for entity in list_of_miners:
        temp_path = "temporary/" + entity.address + "_local_chain.json"
        chain = modification.read_file(temp_path)
        h = hashlib.sha256()
        h.update(str(chain).encode(encoding='UTF-8'))
        hashed_chain = h.hexdigest()
        if hashed_chain in chain_versions:
            pass
        else:
            chain_versions.append(hashed_chain)
    output.fork_analysis(len(chain_versions))
    modification.write_file(
        'temporary/forking_log.json',
        {"Number of times a fork appeared": len(chain_versions) - 1})
Esempio n. 2
0
def initiate_miners():
    the_miners_list = []

    if blockchainPlacement == 1:
        for i in range(NumOfFogNodes):
            the_miners_list.append(
                miner.Miner(i + 1, trans_delay, gossip_activated))
    if blockchainPlacement == 2:
        for i in range(NumOfMiners):
            the_miners_list.append(
                miner.Miner(i + 1, trans_delay, gossip_activated))
    for entity in the_miners_list:
        modification.write_file(
            "temporary/" + entity.address + "_local_chain.json", {})
        miner_wallets_log_py = modification.read_file(
            "temporary/miner_wallets_log.json")
        miner_wallets_log_py[str(
            entity.address)] = data['miners_initial_wallet_value']
        modification.rewrite_file("temporary/miner_wallets_log.json",
                                  miner_wallets_log_py)
    connect_miners(the_miners_list)
    output.miners_are_up()
    return the_miners_list
Esempio n. 3
0
def prepare_necessary_files():
    if num_of_consensus in [2, 5]:
        modification.write_file('temporary/miners_stake_amounts.json', {})
    if num_of_consensus == 6:
        pass