Пример #1
0
def attempt_superblock_creation(gobyted):
    import gobytelib

    if not gobyted.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 = gobyted.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(gobyted, VoteSignals.funding, VoteOutcomes.no)

        # now return, we're done
        return

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

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

    sb = gobytelib.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(gobyted, 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(gobyted, 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 (gobyted.we_are_the_winner()):
        printdbg("we are the winner! Submit SB to network")
        sb.submit(gobyted)
Пример #2
0
def test_deterministic_superblock_creation(go_list_proposals):
    import gobytelib
    import misc
    from gobyted import GoByteDaemon
    gobyted = GoByteDaemon.from_gobyte_conf(config.gobyte_conf)
    for item in go_list_proposals:
        (go, subobj) = GovernanceObject.import_gobject_from_gobyted(gobyted, item)

    max_budget = 60
    prop_list = Proposal.approved_and_ranked(proposal_quorum=1, next_superblock_max_budget=max_budget)
    sb = gobytelib.create_superblock(prop_list, 72000, budget_max=max_budget, sb_epoch_time=misc.now())

    assert sb.event_block_height == 72000
    assert sb.payment_addresses == 'nLLGSuauCV21NBpHJpLHKevWpwE3t6CHGc|nLLGSuauCV21NBpHJpLHKevWpwE3t6CHGc'
    assert sb.payment_amounts == '25.75000000|32.01000000'
    assert sb.proposal_hashes == 'e966911624df92b90582ef9cdd2b3d8c1ed5c06ee2847aadc68ad0442c22ea6a|2b6b4aee7bea18b38a928ef8c50aa74dac58787e850d990881daf5c1341c9bf8'

    assert sb.hex_hash() == '5534e9fa4a51423820b9e19fa6d4770c12ea0a5663e8adff8223f5e8b6df641c'
Пример #3
0
def test_deterministic_superblock_creation(go_list_proposals):
    import gobytelib
    import misc
    from gobyted import GoByteDaemon
    gobyted = GoByteDaemon.from_gobyte_conf(config.gobyte_conf)
    for item in go_list_proposals:
        (go,
         subobj) = GovernanceObject.import_gobject_from_gobyted(gobyted, item)

    max_budget = 60
    prop_list = Proposal.approved_and_ranked(
        proposal_quorum=1, next_superblock_max_budget=max_budget)

    sb = gobytelib.create_superblock(prop_list, 72000, max_budget, misc.now())

    assert sb.event_block_height == 72000
    assert sb.payment_addresses == 'yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui|yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV'
    assert sb.payment_amounts == '25.75000000|32.01000000'
    assert sb.proposal_hashes == 'dfd7d63979c0b62456b63d5fc5306dbec451180adee85876cbf5b28c69d1a86c|0523445762025b2e01a2cd34f1d10f4816cf26ee1796167e5b029901e5873630'

    assert sb.hex_hash(
    ) == 'bb3f33ccf95415c396bd09d35325dbcbc7b067010d51c7ccf772a9e839c1e414'