Skip to content

Commit

Permalink
Change default public rpc node (tezos-reward-distributor-organization…
Browse files Browse the repository at this point in the history
…#164)

* Change default public rpc node
* Fix unit tests
  • Loading branch information
amzid authored and jdsika committed Dec 30, 2019
1 parent cd80e2d commit d1cfad3
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 33 deletions.
6 changes: 5 additions & 1 deletion src/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ def is_processed(self):
return self.value > 0

def __str__(self):
return self.name
return self.name

PUBLIC_NODE_URL = { "MAINNET": ["https://api.tezos.org.ua/", "https://teznode.letzbake.com/"],
"ALPHANET": ["https://tezos-dev.cryptonomic-infra.tech/"],
"ZERONET": ["https://rpczero.tzbeta.net/"]}
11 changes: 4 additions & 7 deletions src/api/provider_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
from rpc.rpc_reward_api import RpcRewardApiImpl
from tzstats.tzstats_block_api import TzStatsBlockApiImpl
from tzstats.tzstats_reward_api import TzStatsRewardApiImpl
from Constants import PUBLIC_NODE_URL

class ProviderFactory:
URL = "https://{}.tezrpc.me"
url_prefixes = {"MAINNET": "mainnet", "ALPHANET": "alphanet", "ZERONET": "zeronet"}

def __init__(self, provider, verbose=False):
self.provider = provider
self.verbose = verbose
Expand All @@ -18,17 +16,16 @@ def newRewardApi(self, network_config, baking_address, node_url, node_url_public
return RpcRewardApiImpl(network_config, baking_address, node_url, verbose=self.verbose)
elif self.provider == 'prpc':
if node_url_public == '':
url_prefix = self.url_prefixes[network_config['NAME']]
node_url_public = self.URL.format(url_prefix)
node_url_public = PUBLIC_NODE_URL[network_config['NAME']][0]
return RpcRewardApiImpl(network_config, baking_address, node_url_public, verbose=self.verbose)
elif self.provider == 'tzstats':
return TzStatsRewardApiImpl(network_config, baking_address, verbose=self.verbose)

raise Exception("No supported reward data provider : {}".format(self.provider))

def newBlockApi(self, network_config, wllt_clnt_mngr, node_url):
def newBlockApi(self, network_config, node_url):
if self.provider == 'rpc' or self.provider == 'prpc':
return RpcBlockApiImpl(network_config, wllt_clnt_mngr, node_url)
return RpcBlockApiImpl(network_config, node_url)
elif self.provider == 'tzstats':
return TzStatsBlockApiImpl(network_config)
raise Exception("No supported reward data provider : {}".format(self.provider))
6 changes: 3 additions & 3 deletions src/config/test_BakingYamlConfParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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)

block_api = RpcBlockApiImpl(network, wallet_client_manager, mainnet_public_node_url)
block_api = RpcBlockApiImpl(network, 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 @@ -69,7 +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)

block_api = RpcBlockApiImpl(network, wallet_client_manager, mainnet_public_node_url)
block_api = RpcBlockApiImpl(network, 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 @@ -111,7 +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)

block_api = RpcBlockApiImpl(network, wallet_client_manager, mainnet_public_node_url)
block_api = RpcBlockApiImpl(network, 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
2 changes: 1 addition & 1 deletion src/config/yaml_baking_conf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, yaml_text, wllt_clnt_mngr, provider_factory, network_config,
self.wllt_clnt_mngr = wllt_clnt_mngr
self.network_config = network_config
if block_api is None:
block_api = provider_factory.newBlockApi(network_config, wllt_clnt_mngr, node_url)
block_api = provider_factory.newBlockApi(network_config, node_url)
self.block_api = block_api

def parse(self):
Expand Down
2 changes: 1 addition & 1 deletion src/launch_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def add_argument_provider(parser):


def add_argument_node_addr_public(parser):
parser.add_argument("-Ap", "--node_addr_public", help="Public node base url pair with protocol prefix. i.e. https://rpc.letzbake.com. This argument will only be used in case the provider is set to prpc. This node will only be used to query reward data and delegator list. It must be an ARCHIVE node. (default is https://mainnet.tezrpc.me)", default='https://mainnet.tezrpc.me')
parser.add_argument("-Ap", "--node_addr_public", help="Public node base url pair with protocol prefix. i.e. https://rpc.letzbake.com. This argument will only be used in case the provider is set to prpc. This node will only be used to query reward data and delegator list. It must be an ARCHIVE node. (default is https://mainnet.tezrpc.me)", default='')


def add_argument_reports_base(parser):
Expand Down
2 changes: 1 addition & 1 deletion src/pay/payment_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, name, initial_payment_cycle, network_config, payments_dir, ca
self.name = name

self.reward_api = provider_factory.newRewardApi(network_config, self.baking_address, node_url, node_url_public)
self.block_api = provider_factory.newBlockApi(network_config, wllt_clnt_mngr, node_url)
self.block_api = provider_factory.newBlockApi(network_config, node_url)

self.fee_calc = service_fee_calc
self.initial_payment_cycle = initial_payment_cycle
Expand Down
26 changes: 10 additions & 16 deletions src/rpc/rpc_block_api.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
from api.block_api import BlockApi
from util.rpc_utils import parse_json_response
import requests

from api.block_api import BlockApi
from log_config import main_logger

logger = main_logger

COMM_HEAD = " rpc get http://{}/chains/main/blocks/head"
COMM_REVELATION = " rpc get http://{}/chains/main/blocks/head/context/contracts/{}/manager_key"
COMM_HEAD = "http://{}/chains/main/blocks/head"
COMM_REVELATION = "http://{}/chains/main/blocks/head/context/contracts/{}/manager_key"

class RpcBlockApiImpl(BlockApi):

def __init__(self, nw, wllt_clnt_mngr, node_url):
def __init__(self, nw, node_url):
super(RpcBlockApiImpl, self).__init__(nw)

self.wllt_clnt_mngr = wllt_clnt_mngr
self.node_url = node_url

def get_current_level(self, verbose=False):
_, response = self.wllt_clnt_mngr.send_request(COMM_HEAD.format(self.node_url))
head = parse_json_response(response)
response = requests.get(COMM_HEAD.format(self.node_url), timeout=5)
head = response.json()
current_level = int(head["metadata"]["level"]["level"])
return current_level

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)
response = requests.get(COMM_REVELATION.format(self.node_url, pkh), timeout=5)
manager_key = response.json()
logger.debug("Manager key is '{}'".format(manager_key))
bool_revelation = manager_key and manager_key!='null'
return bool_revelation



from cli.wallet_client_manager import WalletClientManager

def test_get_revelation():

wllt_clnt_mngr = WalletClientManager("~/tezos-alpha/tezos-client", "", "", "", True)

address_api = RpcBlockApiImpl({"NAME":"ALPHANET"}, wllt_clnt_mngr, "127.0.0.1:8732")
address_api = RpcBlockApiImpl({"NAME":"ALPHANET"}, "127.0.0.1:8732")
print(address_api.get_revelation("tz1N5cvoGZFNYWBp2NbCWhaRXuLQf6e1gZrv"))
print(address_api.get_revelation("KT1FXQjnbdqDdKNpjeM6o8PF1w8Rn2j8BmmG"))
print(address_api.get_revelation("tz1YVxe7FFisREKXWNxdrrwqvw3o2jeXzaNb"))
2 changes: 1 addition & 1 deletion src/rpc/rpc_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __get_delegators_and_delgators_balance(self, cycle, current_level):
try:
response = self.do_rpc_request(request, time_out=5)
except:
logger.error("Fetching delegator info failed {}, will retry", delegator)
logger.debug("Fetching delegator info failed {}, will retry", delegator)

delegators[delegator] = int(response["balance"])

Expand Down
2 changes: 1 addition & 1 deletion src/tzstats/tzstats_block_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

PREFIX_API = {'MAINNET': {'HEAD_API_URL': 'https://api.tzstats.com'},
'ZERONET': {'HEAD_API_URL': 'https://api.zeronet.tzstats.com'},
'BABYLONNET': {'HEAD_API_URL': 'https://api.babylonnet.tzstats.com'}
'ALPHANET': {'HEAD_API_URL': 'https://api.babylonnet.tzstats.com'}
}

class TzStatsBlockApiImpl(BlockApi):
Expand Down
2 changes: 1 addition & 1 deletion src/tzstats/tzstats_reward_provider_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

PREFIX_API = {'MAINNET': {'API_URL': 'http://api.tzstats.com'},
'ZERONET': {'API_URL': 'http://api.zeronet.tzstats.com'},
'BABYLONNET': {'API_URL': 'http://api.babylonnet.tzstats.com'}
'ALPHANET': {'API_URL': 'http://api.babylonnet.tzstats.com'}
}


Expand Down

0 comments on commit d1cfad3

Please sign in to comment.