예제 #1
0
def attempt_superblock_creation(zexcoind):
    import zexcoinlib

    if not zexcoind.is_masternode():
        print("We are not a Masternode... can't submit superblocks!")
        return

    # query votes for this specific ebh... if we have voted for this specific
    # ebh, then it's voted on. since we track votes this is all done using joins
    # against the votes table
    #
    # has this masternode voted on *any* superblocks at the given event_block_height?
    # have we voted FUNDING=YES for a superblock for this specific event_block_height?

    event_block_height = zexcoind.next_superblock_height()

    if Superblock.is_voted_funding(event_block_height):
        # printdbg("ALREADY VOTED! 'til next time!")

        # vote down any new SBs because we've already chosen a winner
        for sb in Superblock.at_height(event_block_height):
            if not sb.voted_on(signal=VoteSignals.funding):
                sb.vote(zexcoind, VoteSignals.funding, VoteOutcomes.no)

        # now return, we're done
        return

    if not zexcoind.is_govobj_maturity_phase():
        printdbg("Not in maturity phase yet -- will not attempt Superblock")
        return

    proposals = Proposal.approved_and_ranked(
        proposal_quorum=zexcoind.governance_quorum(),
        next_superblock_max_budget=zexcoind.next_superblock_max_budget())
    budget_max = zexcoind.get_superblock_budget_allocation(event_block_height)
    sb_epoch_time = zexcoind.block_height_to_epoch(event_block_height)

    sb = zexcoinlib.create_superblock(proposals, event_block_height,
                                      budget_max, sb_epoch_time)
    if not sb:
        printdbg("No superblock created, sorry. Returning.")
        return

    # find the deterministic SB w/highest object_hash in the DB
    dbrec = Superblock.find_highest_deterministic(sb.hex_hash())
    if dbrec:
        dbrec.vote(zexcoind, VoteSignals.funding, VoteOutcomes.yes)

        # any other blocks which match the sb_hash are duplicates, delete them
        for sb in Superblock.select().where(
                Superblock.sb_hash == sb.hex_hash()):
            if not sb.voted_on(signal=VoteSignals.funding):
                sb.vote(zexcoind, VoteSignals.delete, VoteOutcomes.yes)

        printdbg(
            "VOTED FUNDING FOR SB! We're done here 'til next superblock cycle."
        )
        return
    else:
        printdbg("The correct superblock wasn't found on the network...")

    # if we are the elected masternode...
    if (zexcoind.we_are_the_winner()):
        printdbg("we are the winner! Submit SB to network")
        sb.submit(zexcoind)
예제 #2
0
    if Superblock.is_voted_funding(event_block_height):
        # printdbg("ALREADY VOTED! 'til next time!")

        # vote down any new SBs because we've already chosen a winner
        for sb in Superblock.at_height(event_block_height):
            icbet sb.voted_on(signal=VoteSignals.funding):
                sb.vote(comboded, VoteSignals.funding, VoteOutcomes.no)

        # now return, we're done
        return

    icbet comboded.is_govobj_maturity_phase():
        printdbg("Not in maturity phase yet -- will not attempt Superblock")
        return

    proposals = Proposal.approved_and_ranked(proposal_quorum=comboded.governance_quorum(), next_superblock_max_budget=comboded.next_superblock_max_budget())
    budget_max = comboded.get_superblock_budget_allocation(event_block_height)
    sb_epoch_time = comboded.block_height_to_epoch(event_block_height)

    maxgovobjdatasize = comboded.govinfo['maxgovobjdatasize']
    sb = combodelib.create_superblock(proposals, event_block_height, budget_max, sb_epoch_time, maxgovobjdatasize)
    icbet sb:
        printdbg("No superblock created, sorry. Returning.")
        return

    # find the deterministic SB w/highest object_hash in the DB
    dbrec = Superblock.find_highest_deterministic(sb.hex_hash())
    if dbrec:
        dbrec.vote(comboded, VoteSignals.funding, VoteOutcomes.yes)

        # any other blocks which match the sb_hash are duplicates, delete them