예제 #1
0
def test_superblock_size_limit(go_list_proposals):
    import polislib
    import misc
    from polisd import PolisDaemon
    polisd = PolisDaemon.from_polis_conf(config.polis_conf)
    for item in go_list_proposals:
        (go,
         subobj) = GovernanceObject.import_gobject_from_polisd(polisd, item)

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

    maxgovobjdatasize = 469
    sb = polislib.create_superblock(prop_list, 72000, max_budget, misc.now(),
                                    maxgovobjdatasize)

    # two proposals in the list, but...
    assert len(prop_list) == 2

    # only one should have been included in the SB, because the 2nd one is over the limit
    assert sb.event_block_height == 72000
    assert sb.payment_addresses == 'TXDSaTXerg68SCyLkWw2ERsqoTMWRBZiZQ'
    assert sb.payment_amounts == '25.75000000'
    assert sb.proposal_hashes == 'dfd7d63979c0b62456b63d5fc5306dbec451180adee85876cbf5b28c69d1a86c'

    assert sb.hex_hash(
    ) == 'ef6d1ad5a474bc77537c1fc6c256c4c6bd5d1e635bc6d9616b1c5e257895f9f3'
예제 #2
0
def attempt_superblock_creation(polisd):
    import polislib

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

        # now return, we're done
        return

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

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

    maxgovobjdatasize = polisd.govinfo['maxgovobjdatasize']
    sb = polislib.create_superblock(proposals, event_block_height, budget_max, sb_epoch_time, maxgovobjdatasize)
    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(polisd, 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(polisd, 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 (polisd.we_are_the_winner()):
        printdbg("we are the winner! Submit SB to network")
        sb.submit(polisd)
예제 #3
0
def test_deterministic_superblock_creation(go_list_proposals):
    import polislib
    import misc
    from polisd import PolisDaemon
    polisd = PolisDaemon.from_polis_conf(config.polis_conf)
    for item in go_list_proposals:
        (go,
         subobj) = GovernanceObject.import_gobject_from_polisd(polisd, item)

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

    # MAX_GOVERNANCE_OBJECT_DATA_SIZE defined in governance-object.h
    maxgovobjdatasize = 16 * 1024
    sb = polislib.create_superblock(prop_list, 72000, max_budget, misc.now(),
                                    maxgovobjdatasize)

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

    assert sb.hex_hash(
    ) == '93f37147fb086c1948f2d73f29e4a20f846cdaeef515c2c8701925b664bae024'
예제 #4
0
def test_deterministic_superblock_creation(go_list_proposals):
    import polislib
    import misc
    from polisd import PolisDaemon
    polisd = PolisDaemon.from_polis_conf(config.polis_conf)
    for item in go_list_proposals:
        (go,
         subobj) = GovernanceObject.import_gobject_from_polisd(polisd, item)

    max_budget = 60
    prop_list = Proposal.approved_and_ranked(
        proposal_quorum=1, next_superblock_max_budget=max_budget)
    sb = polislib.create_superblock(prop_list,
                                    72000,
                                    budget_max=max_budget,
                                    sb_epoch_time=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(
    ) == '5534e9fa4a51423820b9e19fa6d4770c12ea0a5663e8adff8223f5e8b6df641c'