From f7b6a091107d6ffc38ec18e88b35a3e50c82005d Mon Sep 17 00:00:00 2001 From: hackrush Date: Fri, 7 Jul 2017 00:23:16 +0530 Subject: [PATCH] Updated max_key_fee_setting Added an option to disable max key fee check. Did the required docs changes. --- CHANGELOG.md | 2 ++ docs/cli.md | 1 + docs/index.md | 1 + lbrynet/conf.py | 1 + lbrynet/daemon/Daemon.py | 6 ++++++ lbrynet/daemon/Downloader.py | 5 +++-- tests/unit/lbrynet_daemon/test_Downloader.py | 4 ++-- 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47d2cb356..b5d832653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ at anytime. ### Added * Add link to instructions on how to change the default peer port * Add `peer_port` to settings configurable using `settings_set` + * Added an option to disable max key fee check. + * ### Changed * diff --git a/docs/cli.md b/docs/cli.md index 3c89d1d57..a838c683d 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -751,6 +751,7 @@ Args: 'run_on_startup': (bool) currently not supported 'data_rate': (float) data rate, 'max_key_fee': (float) maximum key fee, + 'disable_max_key_fee': (bool) true to disable max_key_fee check, 'download_directory': (str) path of where files are downloaded, 'peer_port': (int) port through which daemon should connect, 'max_upload': (float), currently not supported diff --git a/docs/index.md b/docs/index.md index 4a7fff3c6..2c36273b7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -603,6 +603,7 @@ Args: 'run_on_startup': (bool) currently not supported 'data_rate': (float) data rate, 'max_key_fee': (float) maximum key fee, + 'disable_max_key_fee': (bool) true to disable max_key_fee check, 'download_directory': (str) path of where files are downloaded, 'peer_port': (int) port through which daemon should connect, 'max_upload': (float), currently not supported diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 8efeaa87e..ad6f710e5 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -187,6 +187,7 @@ ADJUSTABLE_SETTINGS = { # TODO: writing json on the cmd line is a pain, come up with a nicer # parser for this data structure. maybe 'USD:25' 'max_key_fee': (json.loads, {'currency': 'USD', 'amount': 50.0}), + 'disable_max_key_fee': (bool, False), 'min_info_rate': (float, .02), # points/1000 infos 'min_valuable_hash_rate': (float, .05), # points/1000 infos 'min_valuable_info_rate': (float, .05), # points/1000 infos diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 87c94c7c5..797def182 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -179,6 +179,7 @@ class Daemon(AuthJSONRPCServer): self.blobfile_dir = conf.settings['BLOBFILES_DIR'] self.data_rate = conf.settings['data_rate'] self.max_key_fee = conf.settings['max_key_fee'] + self.disable_max_key_fee = conf.settings['disable_max_key_fee'] self.download_timeout = conf.settings['download_timeout'] self.run_reflector_server = conf.settings['run_reflector_server'] self.wallet_type = conf.settings['wallet'] @@ -429,6 +430,7 @@ class Daemon(AuthJSONRPCServer): 'cache_time': int, 'reflect_uploads': bool, 'share_usage_data': bool, + 'disable_max_key_fee': bool, 'peer_search_timeout': int, 'sd_download_timeout': int, } @@ -455,6 +457,7 @@ class Daemon(AuthJSONRPCServer): self.data_rate = conf.settings['data_rate'] self.max_key_fee = conf.settings['max_key_fee'] + self.disable_max_key_fee = conf.settings['disable_max_key_fee'] self.download_directory = conf.settings['download_directory'] self.download_timeout = conf.settings['download_timeout'] @@ -628,6 +631,7 @@ class Daemon(AuthJSONRPCServer): self.streams[claim_id] = GetStream(self.sd_identifier, self.session, self.exchange_rate_manager, self.max_key_fee, + self.disable_max_key_fee, conf.settings['data_rate'], timeout, file_name) try: @@ -1115,6 +1119,7 @@ class Daemon(AuthJSONRPCServer): [ | --download_timeout=] [ | --peer_port=] [ | --max_key_fee=] + [ | --disable_max_key_fee=] [ | --use_upnp=] [ | --run_reflector_server=] [ | --cache_time=] @@ -1138,6 +1143,7 @@ class Daemon(AuthJSONRPCServer): LBC BTC USD + , --disable_max_key_fee= : (bool), False , --use_upnp= : (bool), True , --run_reflector_server= : (bool), False , --cache_time= : (int), 150 diff --git a/lbrynet/daemon/Downloader.py b/lbrynet/daemon/Downloader.py index 03a201d67..14f570ffc 100644 --- a/lbrynet/daemon/Downloader.py +++ b/lbrynet/daemon/Downloader.py @@ -31,12 +31,13 @@ log = logging.getLogger(__name__) class GetStream(object): def __init__(self, sd_identifier, session, exchange_rate_manager, - max_key_fee, data_rate=None, timeout=None, + max_key_fee, disable_max_key_fee, data_rate=None, timeout=None, file_name=None): self.timeout = timeout or conf.settings['download_timeout'] self.data_rate = data_rate or conf.settings['data_rate'] self.max_key_fee = max_key_fee or conf.settings['max_key_fee'][1] + self.disable_max_key_fee = disable_max_key_fee or conf.settings['disable_max_key_fee'] self.download_directory = conf.settings['download_directory'] self.file_name = file_name self.timeout_counter = 0 @@ -97,7 +98,7 @@ class GetStream(object): fee.amount) if converted_fee_amount > self.wallet.get_balance(): raise InsufficientFundsError('Unable to pay the key fee of %s' % converted_fee_amount) - if converted_fee_amount > max_key_fee_amount: + if converted_fee_amount > max_key_fee_amount and not self.disable_max_key_fee: raise KeyFeeAboveMaxAllowed('Key fee %s above max allowed %s' % (converted_fee_amount, max_key_fee_amount)) converted_fee = { diff --git a/tests/unit/lbrynet_daemon/test_Downloader.py b/tests/unit/lbrynet_daemon/test_Downloader.py index 0795dc047..df3e4315c 100644 --- a/tests/unit/lbrynet_daemon/test_Downloader.py +++ b/tests/unit/lbrynet_daemon/test_Downloader.py @@ -73,10 +73,11 @@ class GetStreamTests(unittest.TestCase): exchange_rate_manager = DummyExchangeRateManager(market_feeds, rates) exchange_rate_manager = mock.Mock(spec=ExchangeRateManager) max_key_fee = {'currency':"LBC", 'amount':10, 'address':''} + disable_max_key_fee = False data_rate = {'currency':"LBC", 'amount':0, 'address':''} getstream = Downloader.GetStream(sd_identifier, session, - exchange_rate_manager, max_key_fee, timeout=3, data_rate=data_rate) + exchange_rate_manager, max_key_fee, disable_max_key_fee, timeout=3, data_rate=data_rate) getstream.pay_key_fee_called = False self.clock = task.Clock() @@ -180,4 +181,3 @@ class GetStreamTests(unittest.TestCase): getstream.downloader.running_status = ManagedEncryptedFileDownloader.STATUS_STOPPED self.clock.advance(1) downloader, f_deferred = yield start -