Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Edit snapshot call which was slowing down the rpc api queries (resolves tezos-reward-distributor-organization#142)
* Change condition for unfrozen rewards (resolves issue tezos-reward-distributor-organization#137)
  • Loading branch information
amzid authored and jdsika committed Dec 16, 2019
1 parent 6430e0e commit 772ced7
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/rpc/rpc_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RpcRewardApiImpl(RewardApi):
COMM_HEAD = "{}/chains/main/blocks/head"
COMM_DELEGATES = "{}/chains/main/blocks/{}/context/delegates/{}"
COMM_BLOCK = "{}/chains/main/blocks/{}"
COMM_SNAPSHOT = COMM_BLOCK + "/context/raw/json/rolls/owner/snapshot/{}/"
COMM_SNAPSHOT = COMM_BLOCK + "/context/raw/json/cycle/{}/roll_snapshot"
COMM_DELEGATE_BALANCE = "{}/chains/main/blocks/{}/context/contracts/{}"

def __init__(self, nw, baking_address, node_url, verbose=True):
Expand Down Expand Up @@ -85,7 +85,7 @@ def __get_unfrozen_rewards(self, level_of_last_block_in_unfreeze_cycle, cycle):
balance_update = balance_updates[i]
if balance_update["kind"] == "freezer":
if balance_update["delegate"] == self.baking_address:
if int(balance_update["cycle"]) == cycle or int(balance_update["change"]) < 0:
if int(balance_update["cycle"]) == cycle and int(balance_update["change"]) < 0:
if balance_update["category"] == "rewards":
unfrozen_rewards = -int(balance_update["change"])
logger.debug(
Expand Down Expand Up @@ -176,13 +176,7 @@ def __get_snapshot_block_hash(self, cycle, current_level):

if current_level - snapshot_level >= 0:
request = self.COMM_SNAPSHOT.format(self.node_url, block_level, cycle)
snapshots = self.do_rpc_request(request)

if len(snapshots) == 1:
chosen_snapshot = snapshots[0]
else:
logger.error("Too few or too many possible snapshots found!")
return ""
chosen_snapshot = self.do_rpc_request(request)

level_snapshot_block = (cycle - self.preserved_cycles - 2) * self.blocks_per_cycle + (
chosen_snapshot + 1) * self.blocks_per_roll_snapshot
Expand Down

0 comments on commit 772ced7

Please sign in to comment.