Пример #1
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":
                Transaction.create_transactions_light(
                )  # generate pending transactions
            elif p.Ttechnique == "Full":
                Transaction.create_transactions_full(
                )  # generate pending transactions

        Node.generate_gensis_block(
        )  # generate the gensis block for all miners
        Scheduler.initial_events()  # initiate initial events 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
            Event.run_event(next_event)
            Queue.remove_event(next_event)

        Consensus.freshness_preferred(
        )  # apply the longest chain to resolve the forks
        Results.calculate(
        )  # calculate the simulation results (e.g., block statstics and miners' rewards)

        ########## reset all global variable before the next run #############
        Results.reset()  # reset all variables used to calculate the results
        Node.resetState(
        )  # reset all the states (blockchains) for all nodes in the network

    print("Percentage of blocks mined by the attacker: ",
          (p.attacker_blocks / float(p.Runs)))