Example #1
0
def consensus_trigger():
    """
    Consensus process consists of 2 stages. This function makes
    the necessary redirects according to the situation and works
    to shorten the block time.
    """

    dprint("Consensus Trigger")
    block = GetBlock()

    if block.validated:
        true_time = (block.block_time_change_time + block.block_time +
                     ((block.block_time_change_block - block.sequance_number) *
                      block.block_time))
        if block.newly:
            true_time -= 1
        if not int(time.time()) < true_time:
            block.newly = False
            block.reset_the_block()
    else:
        if block.raund_1_starting_time is None:
            block.raund_1_starting_time = int(time.time())
        if not block.raund_1:

            consensus_round_1(block)
        elif not block.raund_2:
            consensus_round_2(block)
Example #2
0
    def get_full_chain(self, data, node):

        get_ok = False

        if not os.path.exists(TEMP_BLOCK_PATH):
            get_ok = True
        else:
            system = GetBlock()
            if node.id == system.dowload_true_block:
                get_ok = True

        if get_ok:

            if str(data["byte"]) == "end":

                os.rename(LOADING_BLOCK_PATH, TEMP_BLOCK_PATH)

                from blockchain.block.block_main import apps_starter
                from consensus.consensus_main import consensus_trigger
                from lib.perpetualtimer import perpetualTimer
                from app.app_main import apps_starter
                system = GetBlock()
                system.newly = True
                system.change_transaction_fee()

                system.exclude_validators = []
                dprint(system.sequance_number)
                perpetualTimer(system.consensus_timer,
                               consensus_trigger).start()
                apps_starter()
                system.save_block()

            else:
                file = open(LOADING_BLOCK_PATH, "ab")

                file.write((data["byte"].encode(encoding='iso-8859-1')))
                file.close()