def main():
    for i in range (p.Runs):
        clock =0 # set clock to 0 at the start of the simulation
        if p.hasTrans:
            if p.Ttechnique == "Light": LT.create_transactions() # generate pending transactions
            elif p.Ttechnique == "Full": FT.create_transactions() # generate pending transactions

        Node.generate_gensis_block() # generate the gensis block for all miners
        BlockCommit.generate_initial_events() # initiate initial events >= 1 to start with

        while  not Queue.isEmpty() and clock <= p.simTime:
            next_event = Queue.get_next_event()
            clock = next_event.time # move clock to the time of the event
            BlockCommit.handle_event(next_event)
            Queue.remove_event(next_event)

        Consensus.fork_resolution() # apply the longest chain to resolve the forks
        Incentives.distribute_rewards()# distribute the rewards between the particiapting nodes
        Statistics.calculate() # calculate the simulation results (e.g., block statstics and miners' rewards)

		########## reset all global variable before the next run #############
        Statistics.reset() # reset all variables used to calculate the results
        Node.resetState() # reset all the states (blockchains) for all nodes in the network
    fname = os.getenv('OUTPUT', "(Allverify)1day_{0}M_{1}K".format(
    	p.Bsize/1000000, p.Tn/1000))+".xlsx"
    Statistics.print_to_excel(fname) # print all the simulation results in an excel file
    Statistics.reset2() # reset profit results
Exemple #2
0
def main():
    for i in range(p.Runs):
        clock = 0  # set clock to 0 at the start of the simulation
        if p.hasTrans:
            if p.Ttechnique == "Light":
                LT.create_transactions()  # generate pending transactions
            elif p.Ttechnique == "Full":
                FT.create_transactions()  # generate pending transactions

        Node.generate_gensis_block(
        )  # generate the gensis block for all miners
        # initiate initial events >= 1 to start with
        BlockCommit.generate_initial_events()

        while not Queue.isEmpty() and clock <= p.simTime:
            next_event = Queue.get_next_event()
            clock = next_event.time  # move clock to the time of the event
            BlockCommit.handle_event(next_event)
            Queue.remove_event(next_event)

        # for the AppendableBlock process transactions and
        # optionally verify the model implementation
        if p.model == 3:
            BlockCommit.process_gateway_transaction_pools()

            if i == 0 and p.VerifyImplemetation:
                Verification.perform_checks()

        Consensus.fork_resolution(
        )  # apply the longest chain to resolve the forks
        # distribute the rewards between the particiapting nodes
        Incentives.distribute_rewards()
        # calculate the simulation results (e.g., block statstics and miners' rewards)
        Statistics.calculate()

        if p.model == 3:
            Statistics.print_to_excel(i, True)
            Statistics.reset()
        else:
            ########## reset all global variable before the next run #############
            Statistics.reset(
            )  # reset all variables used to calculate the results
            Node.resetState(
            )  # reset all the states (blockchains) for all nodes in the network
            fname = "(Allverify)1day_{0}M_{1}K.xlsx".format(
                p.Bsize / 1000000, p.Tn / 1000)
            # print all the simulation results in an excel file
            Statistics.print_to_excel(fname)
            fname = "(Allverify)1day_{0}M_{1}K.xlsx".format(
                p.Bsize / 1000000, p.Tn / 1000)
            # print all the simulation results in an excel file
            Statistics.print_to_excel(fname)
            Statistics.reset2()  # reset profit results
Exemple #3
0
 def process_queue():
     while not Queue.isEmpty():
         next_event = Queue.get_next_event()
         BlockCommit.handle_event(next_event)
         Queue.remove_event(next_event)
Exemple #4
0
def main():
    for i in range(p.Runs):
        print('-' * 10, f'Run: {i+1}', '-' * 10)
        print(p.sim_type)
        print('No. of Miners:', len(p.NODES))

        hash_power = 0
        # Giving every pool a reference to the nodes it contains. Also, update the total hashrate of a pool.
        print('SOLO Nodes: ', end='')
        for node in p.NODES:
            hash_power += node.hashPower
            if node.pool:
                node.pool.nodes.append(node)
                node.pool.hash_power += node.hashPower
            else:
                print(node.id, end=', ')
        print()

        print('Pools:')
        for pool in p.POOLS:
            print(' -', pool.id, pool.strategy, 'Fee Rate:', pool.fee_rate,
                  'Nodes:', [node.id for node in pool.nodes], 'Hash power:',
                  pool.hash_power)
        print('Total hash power:', hash_power, '\n')

        clock = 0  # set clock to 0 at the start of the simulation
        if p.hasTrans:
            if p.Ttechnique == "Light":
                LT.create_transactions()  # generate pending transactions
            elif p.Ttechnique == "Full":
                FT.create_transactions()  # generate pending transactions

        Node.generate_gensis_block(
        )  # generate the gensis block for all miners
        # initiate initial events >= 1 to start with
        BlockCommit.generate_initial_events()

        while not Queue.isEmpty() and clock <= p.simTime:
            next_event = Queue.get_next_event()
            clock = next_event.time  # move clock to the time of the event
            BlockCommit.handle_event(next_event)
            Queue.remove_event(next_event)

        # for the AppendableBlock process transactions and
        # optionally verify the model implementation
        if p.model == 3:
            BlockCommit.process_gateway_transaction_pools()

            if i == 0 and p.VerifyImplemetation:
                Verification.perform_checks()

        Consensus.fork_resolution(
        )  # apply the longest chain to resolve the forks
        # distribute the rewards between the particiapting nodes
        Incentives.distribute_rewards()
        # calculate the simulation results (e.g., block statstics and miners' rewards)
        Statistics.calculate(i)

        if p.model == 3:
            Statistics.print_to_excel(i, True)
            Statistics.reset()
        else:
            ########## reset all global variable before the next run #############
            Statistics.reset(
            )  # reset all variables used to calculate the results
            Node.resetState(
            )  # reset all the states (blockchains) for all nodes in the network
            Pool.resetState()  # reset all pools in the network

    # set file name for results
    fname = f"{p.sim_type}_{int(p.simTime/(24*60*60))}days_{datetime.now()}.xlsx".replace(
        ':', '_')
    # fname = f"(Allverify)1day_{p.Bsize/1000000}M_{p.Tn/1000}K-{i}-{datetime.now()}.xlsx".replace(':', '_')
    # print all the simulation results in an excel file
    Statistics.print_to_excel(fname)