def trigger_pow_miners(the_miners_list, the_type_of_consensus): for counter in range(expected_chain_length): obj = random.choice(the_miners_list) if Parallel_PoW_mining: # parallel approach process = Process(target=obj.build_block, args=( numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, mempool.discarded_txs, expected_chain_length, )) process.start() mining_processes.append(process) else: # non-parallel approach obj.build_block(numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, mempool.discarded_txs, expected_chain_length) output.simulation_progress(counter, expected_chain_length) for process in mining_processes: process.join()
def trigger_pos_miners(the_miners_list, the_type_of_consensus, expected_chain_length, numOfTXperBlock, blockchainFunction): for counter in range(expected_chain_length): randomly_chosen_miners = [] x = int(round((len(the_miners_list) / 2), 0)) for i in range(x): randomly_chosen_miners.append(random.choice(the_miners_list)) biggest_stake = 0 final_chosen_miner = the_miners_list[0] temp_file_py = modification.read_file( 'temporary/miners_stake_amounts.json') for chosen_miner in randomly_chosen_miners: stake = temp_file_py[chosen_miner.address] if stake > biggest_stake: biggest_stake = stake final_chosen_miner = chosen_miner for entity in the_miners_list: entity.next_pos_block_from = final_chosen_miner.address if mempool.MemPool.qsize() != 0: final_chosen_miner.build_block(numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, expected_chain_length) output.simulation_progress(counter, expected_chain_length)
def trigger_dpos_miners(expected_chain_length, the_miners_list, number_of_delegates, numOfTXperBlock, the_type_of_consensus, blockchainFunction, Parallel_PoW_mining): for counter in range(expected_chain_length): votes_and_stakes = dpos_voting(the_miners_list) selected_delegates = dpos_delegates_selection(votes_and_stakes, number_of_delegates) for entity in the_miners_list: entity.delegates = selected_delegates processes = [] for entity in the_miners_list: if entity.address in entity.delegates: if Parallel_PoW_mining: process = Process(target=entity.build_block, args=( numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, expected_chain_length, )) process.start() processes.append(process) else: entity.build_block(numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, expected_chain_length) for process in processes: process.join() output.simulation_progress(counter, expected_chain_length)
def trigger_poa_miners(the_miners_list, the_type_of_consensus): for counter in range(expected_chain_length): for obj in miner_list: if mempool.MemPool.qsize() != 0: obj.build_block(numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, mempool.discarded_txs, expected_chain_length) output.simulation_progress(counter, expected_chain_length)
def trigger_dummy_miners(the_miners_list, numOfTXperBlock, the_type_of_consensus, blockchainFunction, expected_chain_length): counter = -1 while mempool.MemPool.qsize() != 0: obj = random.choice(the_miners_list) obj.build_block(numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, expected_chain_length) counter += 1 output.simulation_progress(counter, expected_chain_length)
def trigger_pos_miners(the_miners_list, the_type_of_consensus): for counter in range(expected_chain_length): randomly_chosen_miners = [] x = int(round((len(the_miners_list) / 2), 0)) for i in range(x): randomly_chosen_miners.append(random.choice(the_miners_list)) biggest_stake = 0 final_chosen_miner = the_miners_list[0] with open('temporary/miners_stake_amounts.json', 'r') as temp_file: temp_file_py = json.load(temp_file) for chosen_miner in randomly_chosen_miners: if temp_file_py[chosen_miner.address] > biggest_stake: biggest_stake = temp_file_py[chosen_miner.address] final_chosen_miner = chosen_miner for entity in the_miners_list: entity.next_pos_block_from = final_chosen_miner.address if mempool.MemPool.qsize() != 0: final_chosen_miner.build_block( numOfTXperBlock, mempool.MemPool, the_miners_list, the_type_of_consensus, blockchainFunction, mempool.discarded_txs, expected_chain_length) output.simulation_progress(counter, expected_chain_length)