def delegate_history(cycle):
    """Populates delegate_history table with data for each baker at a given
    cycle"""

    print("Acquiring delegate history for cycle %s..." % cycle)
    bakers = tezos.all_bakers()
    data = []
    for baker in bakers:

        # See README.md for a description on these values
        snapshot_index = tezos.snapshot_index(cycle)
        snapshot_block = tezos.snapshot_index_to_block(snapshot_index, cycle)
        snapshot_level = snapshot_block - 1

        # if the rpc comes back with an unexpected response
        response = tezos.baker_info_at_level(baker, snapshot_level)
        if "delegated_contracts" not in response:
            continue
        for delegator in response["delegated_contracts"]:
            data.append(
                DelegateHistory(cycle=cycle,
                                snapshot_block_level=snapshot_block,
                                delegator=delegator,
                                baker=baker))
    return data
def populate_baker_performance(cycle, after=populate_grades):
    """Populates general columns of the baker_performance table, followed by the
    grades, in each cycle"""

    print("Acquiring baker performance data for cycle %s..." % cycle)
    start_cycle = cycle - SAMPLE_RANGE
    bakers = tezos.all_bakers()
    data = []
    for baker in bakers:
        data.append(get_baker_performance(baker, cycle))
    return data
Exemplo n.º 3
0
def populate_grades(cycle):
    """Populates all the grade column for every baker in the baking_performance
    table for a particular cycle"""

    stats = get_grading_stats_for_cycle(cycle)
    baking_grades = calculate_partial_grades(stats, "num_baked", "num_missed")
    endorsing_grades = calculate_partial_grades(stats,
                                                "high_priority_endorsements",
                                                "missed_endorsements")
    grades = {}
    bakers = tezos.all_bakers()

    for baker in bakers:
        grades[baker] = average_grade_for(baker, baking_grades,
                                          endorsing_grades)
    return grades
Exemplo n.º 4
0
def get_snapshot_data(cycle):
    """Populates snapshot_info table with data for each baker at given cycle"""

    print("Acquiring snapshot data for cycle %s..." % cycle)
    snapshot_index = tezos.snapshot_index(cycle)

    # snapshot_block is the actual block level of the snapshot. However,
    # snapshot data such as roll balances are taken before operations in the
    # snapshot block have settled. The correct balances are those after the
    # block before the snapshot block has been baked (snapshot_level)

    snapshot_block = tezos.snapshot_index_to_block(snapshot_index, cycle)
    snapshot_level = snapshot_block - 1
    end_of_cycle = tezos.cycle_to_level(cycle + 1) + 1

    bakers = tezos.all_bakers()
    data = []
    for baker in bakers:
        response = tezos.baker_info_at_level(baker, snapshot_level)

        # if the rpc comes back with an unexpected response
        if not ("delegated_contracts" in response):
            continue

        delegated_balance = int(response["delegated_balance"])
        staking_balance = int(response["staking_balance"])

        response = tezos.baker_info_at_level(baker, end_of_cycle)

        rewards = response["frozen_balance_by_cycle"]
        reward = 0
        for entry in rewards:
            if entry["cycle"] == cycle:
                reward = int(entry["fees"]) + int(entry["rewards"])

        data.append(
            SnapshotInfo(cycle=cycle,
                         baker=baker,
                         snapshot_index=snapshot_index,
                         snapshot_block_level=snapshot_block,
                         staking_balance=staking_balance,
                         delegated_balance=delegated_balance,
                         rewards=reward))

    return data
Exemplo n.º 5
0
def populate_baker_payouts(cycle):
    """Populates baker_payouts table with data for each baker at given cycle"""

    print("Acquiring payout accounts for cycle %s..." % cycle)

    bakers = tezos.all_bakers()
    data = []
    for baker in bakers:
        payout_delay = get_payout_delay(baker)
        snapshot_index = tezos.snapshot_index(cycle)
        snapshot_level = tezos.snapshot_index_to_block(snapshot_index,
                                                       cycle) - 1
        baker_info = tezos.baker_info_at_level(baker, snapshot_level)
        if "delegated_contracts" not in baker_info:
            continue
        source_count = count_sources(baker_info["delegated_contracts"],
                                     cycle - payout_delay)
        data.append(
            BakerPayouts(cycle=cycle,
                         baker=baker,
                         payout=max_source(source_count)))
    return data