Skip to content

Commit

Permalink
Fix bugs and perform changes after testing with local archive node (t…
Browse files Browse the repository at this point in the history
…ezos-reward-distributor-organization#114)

* Fix missing argument
* Add .gitignore
* Fix the process of getting network constants from a local node
* Fix broken CI build
* Fix revelation query exception
* Remove tests dependency on tzscan to fix the CI build
  • Loading branch information
amzid authored and jdsika committed Oct 18, 2019
1 parent 5df4449 commit 34d8131
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
logs/
reports/
*/*/__pycache__/
*/__pycache__/
email.ini
8 changes: 4 additions & 4 deletions src/NetworkConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
logger = main_logger

default_network_config_map = {
'MAINNET': {'NAME': 'MAINNET', 'NB_FREEZE_CYCLE': 5, BLOCK_TIME_IN_SEC: 60, 'BLOCKS_PER_CYCLE': 4096,
'MAINNET': {'NAME': 'MAINNET', 'NB_FREEZE_CYCLE': 5, 'BLOCK_TIME_IN_SEC': 60, 'BLOCKS_PER_CYCLE': 4096,
'BLOCKS_PER_ROLL_SNAPSHOT': 256},
'ALPHANET': {'NAME': 'ALPHANET', 'NB_FREEZE_CYCLE': 3, BLOCK_TIME_IN_SEC: 30, 'BLOCKS_PER_CYCLE': 2048,
'ALPHANET': {'NAME': 'ALPHANET', 'NB_FREEZE_CYCLE': 3, 'BLOCK_TIME_IN_SEC': 30, 'BLOCKS_PER_CYCLE': 2048,
'BLOCKS_PER_ROLL_SNAPSHOT': 256},
'ZERONET': {'NAME': 'ZERONET', 'NB_FREEZE_CYCLE': 5, BLOCK_TIME_IN_SEC: 20, 'BLOCKS_PER_CYCLE': 128,
'ZERONET': {'NAME': 'ZERONET', 'NB_FREEZE_CYCLE': 5, 'BLOCK_TIME_IN_SEC': 20, 'BLOCKS_PER_CYCLE': 128,
'BLOCKS_PER_ROLL_SNAPSHOT': 8},
}

Expand Down Expand Up @@ -48,7 +48,7 @@ def is_mainnet(nw_name):

def get_network_config_from_local_node(config_client_manager, node_addr):
request_constants = CONSTANTS_COMM.format(node_addr)
response_constants = config_client_manager.exec(request_constants)
_,response_constants = config_client_manager.send_request(request_constants)
constants = parse_json_response(response_constants)
network_config_map = parse_constants(constants)
return network_config_map
Expand Down
14 changes: 6 additions & 8 deletions src/calc/test_calculatePhase0.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@

from calc.calculate_phase0 import CalculatePhase0
from model import reward_log
from tzscan.tzscan_mirror_selection_helper import TzScanMirrorSelector
from tzscan.tzscan_reward_api import TzScanRewardApiImpl
from tzscan.tzscan_reward_provider_helper import TzScanRewardProviderHelper
from rpc.prpc_reward_api import PRpcRewardApiImpl

BAKING_ADDRESS = "tz1Z1tMai15JWUWeN2PKL9faXXVPMuWamzJj"


class TestCalculatePhase0(TestCase):

def test_calculate(self):
nw = {"NAME": "MAINNET"}
mirror_selector = TzScanMirrorSelector(nw)
mirror_selector.initialize()

api = TzScanRewardApiImpl(nw, BAKING_ADDRESS, mirror_selector)
model = api.get_rewards_for_cycle_map(43)
nw = {'NAME': 'MAINNET', 'NB_FREEZE_CYCLE': 5, 'BLOCK_TIME_IN_SEC': 60, 'BLOCKS_PER_CYCLE': 4096,
'BLOCKS_PER_ROLL_SNAPSHOT': 256}

api = PRpcRewardApiImpl(nw, BAKING_ADDRESS, "mainnet.tezrpc.me")
model = api.get_rewards_for_cycle_map(153)

phase0 = CalculatePhase0(model)
reward_data, total_rewards = phase0.calculate()
Expand Down
15 changes: 4 additions & 11 deletions src/config/test_BakingYamlConfParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from cli.wallet_client_manager import WalletClientManager
from config.addr_type import AddrType
from config.yaml_baking_conf_parser import BakingYamlConfParser
from tzscan.tzscan_block_api import TzScanBlockApiImpl
from tzscan.tzscan_mirror_selection_helper import TzScanMirrorSelector
from rpc.rpc_block_api import RpcBlockApiImpl

network={'NAME': 'MAINNET'}
mainnet_public_node_url = "https://rpc.tzbeta.net/"
Expand Down Expand Up @@ -35,9 +34,7 @@ def test_validate(self):

wallet_client_manager = WalletClientManager(client_path=None, addr_dict_by_pkh=addr_dict_by_pkh, contr_dict_by_alias=contr_dict_by_alias, managers=managers)

mirror_selector = TzScanMirrorSelector(network)
mirror_selector.initialize()
block_api = TzScanBlockApiImpl(network, mirror_selector)
block_api = RpcBlockApiImpl(network, wallet_client_manager, mainnet_public_node_url)
cnf_prsr = BakingYamlConfParser(data_fine, wallet_client_manager, provider_factory=None, network_config=network,node_url=mainnet_public_node_url,block_api=block_api)


Expand Down Expand Up @@ -72,9 +69,7 @@ def test_validate_no_founders_map(self):
wallet_client_manager = WalletClientManager(client_path=None, addr_dict_by_pkh=addr_dict_by_pkh,
contr_dict_by_alias=contr_dict_by_alias, managers=managers_map)

mirror_selector = TzScanMirrorSelector(network)
mirror_selector.initialize()
block_api = TzScanBlockApiImpl(network, mirror_selector)
block_api = RpcBlockApiImpl(network, wallet_client_manager, mainnet_public_node_url)
cnf_prsr = BakingYamlConfParser(data_no_founders, wallet_client_manager, provider_factory=None, network_config=network,
node_url=mainnet_public_node_url, block_api=block_api)

Expand Down Expand Up @@ -116,9 +111,7 @@ def test_validate_pymnt_alias(self):

wallet_client_manager = WalletClientManager(client_path=None, addr_dict_by_pkh=addr_dict_by_pkh, contr_dict_by_alias=contr_dict_by_alias, managers=managers_map)

mirror_selector = TzScanMirrorSelector(network)
mirror_selector.initialize()
block_api = TzScanBlockApiImpl(network, mirror_selector)
block_api = RpcBlockApiImpl(network, wallet_client_manager, mainnet_public_node_url)
cnf_prsr = BakingYamlConfParser(data_no_founders, wallet_client_manager, provider_factory=None, network_config=network, node_url=mainnet_public_node_url, block_api=block_api)

cnf_prsr.parse()
Expand Down
18 changes: 9 additions & 9 deletions src/config/yaml_baking_conf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ def validate_payment_address(self, conf_obj):
# if reveal information is present, do not ask
if 'revealed' in addr_obj:
revealed = addr_obj['revealed']
else:
revealed = self.block_api.get_revelation(conf_obj[('__%s_pkh' % PAYMENT_ADDRESS)])
#else:
# revealed = self.block_api.get_revelation(conf_obj[('__%s_pkh' % PAYMENT_ADDRESS)])

# payment address needs to be revealed
if not revealed:
raise ConfigurationException("Payment Address ({}) is not eligible for payments. \n"
"Public key is not revealed.\n"
"Use command 'reveal key for <src>' to reveal your public key. \n"
"For implicit accounts, setting your account as delegate is enough.\n"
"For more information please refer to tezos command line interface."
.format(pymnt_addr))
#if not revealed:
# raise ConfigurationException("Payment Address ({}) is not eligible for payments. \n"
# "Public key is not revealed.\n"
# "Use command 'reveal key for <src>' to reveal your public key. \n"
# "For implicit accounts, setting your account as delegate is enough.\n"
# "For more information please refer to tezos command line interface."
# .format(pymnt_addr))

# if not self.block_api.get_revelation(conf_obj[('%s_manager' % PAYMENT_ADDRESS)]):
# raise ConfigurationException("Payment Address ({}) is not eligible for payments. \n"
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/lrpc_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LRpcRewardApiImpl(RewardApi):
COMM_SNAPSHOT = COMM_BLOCK + "/context/raw/json/rolls/owner/snapshot/{}/"
COMM_DELEGATE_BALANCE = "%protocol%://{}/chains/main/blocks/{}/context/contracts/{}"

def __init__(self, nw, baking_address, node_url, wllt_clnt_mngr, validate=True, verbose=True):
def __init__(self, nw, baking_address, node_url, wllt_clnt_mngr, validate=False, verbose=True):
super(LRpcRewardApiImpl, self).__init__()

self.blocks_per_cycle = nw['BLOCKS_PER_CYCLE']
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_rewards_for_cycle_map(self, cycle):
logger.debug("Cycle {}, preserved cycles {}, blocks per cycle {}, last_block_cycle {}".format(cycle, self.preserved_cycles, self.blocks_per_cycle, level_of_last_block_in_unfreeze_cycle))

if current_level - level_of_last_block_in_unfreeze_cycle >= 0:
unfrozen_rewards = self.__get_unfrozen_rewards(level_of_last_block_in_unfreeze_cycle)
unfrozen_rewards = self.__get_unfrozen_rewards(level_of_last_block_in_unfreeze_cycle, cycle)
reward_data["total_rewards"] = unfrozen_rewards

else:
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/prpc_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PRpcRewardApiImpl(RewardApi):
COMM_SNAPSHOT = COMM_BLOCK + "/context/raw/json/rolls/owner/snapshot/{}/"
COMM_DELEGATE_BALANCE = "%protocol%://{}/chains/main/blocks/{}/context/contracts/{}"

def __init__(self, nw, baking_address, node_url, validate=True, verbose=True):
def __init__(self, nw, baking_address, node_url, validate=False, verbose=True):
super(PRpcRewardApiImpl, self).__init__()

self.blocks_per_cycle = nw['BLOCKS_PER_CYCLE']
Expand Down
2 changes: 0 additions & 2 deletions src/rpc/rpc_block_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def get_current_level(self, verbose=False):
def get_revelation(self, pkh, verbose=False):
_, response = self.wllt_clnt_mngr.send_request(COMM_REVELATION.format(self.node_url, pkh))
manager_key = parse_json_response(response, verbose=verbose)

logger.debug("Manager key is '{}'".format(manager_key))

bool_revelation = manager_key and manager_key!='null'
return bool_revelation

Expand Down
4 changes: 3 additions & 1 deletion src/tzscan/tzscan_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def get_rewards_for_cycle_map(self, cycle):
lost_fees_denounciation = int(root["lost_fees_denounciation"])

fees = int(root["fees"])
revelation_net = int(root["revelation_rewards"]) - int(root["lost_revelation_rewards"]) - int(root["lost_revelation_fees"])

total_reward_amount = (blocks_rewards + endorsements_rewards + future_blocks_rewards +
future_endorsements_rewards + fees - lost_rewards_denounciation - lost_fees_denounciation)
future_endorsements_rewards + fees + revelation_net
- lost_rewards_denounciation - lost_fees_denounciation)

delegators_balance = root["delegators_balance"]

Expand Down

0 comments on commit 34d8131

Please sign in to comment.