From 34d81316546a243857c17b29f9fb8b554737aa99 Mon Sep 17 00:00:00 2001 From: amzid <33556352+amzid@users.noreply.github.com> Date: Fri, 18 Oct 2019 15:53:33 +0200 Subject: [PATCH] Fix bugs and perform changes after testing with local archive node (#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 --- .gitignore | 5 +++++ src/NetworkConfiguration.py | 8 ++++---- src/calc/test_calculatePhase0.py | 14 ++++++-------- src/config/test_BakingYamlConfParser.py | 15 ++++----------- src/config/yaml_baking_conf_parser.py | 18 +++++++++--------- src/rpc/lrpc_reward_api.py | 4 ++-- src/rpc/prpc_reward_api.py | 2 +- src/rpc/rpc_block_api.py | 2 -- src/tzscan/tzscan_reward_api.py | 4 +++- 9 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..71e2c152 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +logs/ +reports/ +*/*/__pycache__/ +*/__pycache__/ +email.ini \ No newline at end of file diff --git a/src/NetworkConfiguration.py b/src/NetworkConfiguration.py index 38ebe47f..133c8085 100644 --- a/src/NetworkConfiguration.py +++ b/src/NetworkConfiguration.py @@ -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}, } @@ -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 diff --git a/src/calc/test_calculatePhase0.py b/src/calc/test_calculatePhase0.py index 69bb09e8..eb0e8635 100644 --- a/src/calc/test_calculatePhase0.py +++ b/src/calc/test_calculatePhase0.py @@ -2,9 +2,7 @@ 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" @@ -12,12 +10,12 @@ 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() diff --git a/src/config/test_BakingYamlConfParser.py b/src/config/test_BakingYamlConfParser.py index 7ce437e4..a5f1e64b 100644 --- a/src/config/test_BakingYamlConfParser.py +++ b/src/config/test_BakingYamlConfParser.py @@ -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/" @@ -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) @@ -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) @@ -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() diff --git a/src/config/yaml_baking_conf_parser.py b/src/config/yaml_baking_conf_parser.py index af995fa7..df9430d7 100644 --- a/src/config/yaml_baking_conf_parser.py +++ b/src/config/yaml_baking_conf_parser.py @@ -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 ' 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 ' 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" diff --git a/src/rpc/lrpc_reward_api.py b/src/rpc/lrpc_reward_api.py index 1a27d339..eb43a542 100644 --- a/src/rpc/lrpc_reward_api.py +++ b/src/rpc/lrpc_reward_api.py @@ -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'] @@ -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: diff --git a/src/rpc/prpc_reward_api.py b/src/rpc/prpc_reward_api.py index 789cd074..71853d5d 100644 --- a/src/rpc/prpc_reward_api.py +++ b/src/rpc/prpc_reward_api.py @@ -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'] diff --git a/src/rpc/rpc_block_api.py b/src/rpc/rpc_block_api.py index 2cc82cc9..561f8efc 100644 --- a/src/rpc/rpc_block_api.py +++ b/src/rpc/rpc_block_api.py @@ -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 diff --git a/src/tzscan/tzscan_reward_api.py b/src/tzscan/tzscan_reward_api.py index 45f6ed90..6658234b 100644 --- a/src/tzscan/tzscan_reward_api.py +++ b/src/tzscan/tzscan_reward_api.py @@ -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"]