From e4e60ebe9b40c0f311de99181806892707bff729 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Tue, 28 Nov 2017 13:47:44 -0500 Subject: [PATCH] add auto_renew_claim_height_delta to configuration and auto renew after startup if necessary --- lbrynet/conf.py | 4 ++++ lbrynet/daemon/Daemon.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lbrynet/conf.py b/lbrynet/conf.py index cc290a3bf..9c016a98c 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -242,6 +242,10 @@ ADJUSTABLE_SETTINGS = { # all of your credits. 'api_host': (str, 'localhost'), 'api_port': (int, 5279), + # claims set to expire within this many blocks will be + # automatically renewed after startup (if set to 0, renews + # will not be made automatically) + 'auto_renew_claim_height_delta': (int, 0), 'cache_time': (int, 150), 'data_dir': (str, default_data_dir), 'data_rate': (float, .0001), # points/megabyte diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 55630c6ad..048065c71 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -188,6 +188,8 @@ class Daemon(AuthJSONRPCServer): self.reflector_port = conf.settings['reflector_port'] self.dht_node_port = conf.settings['dht_node_port'] self.use_upnp = conf.settings['use_upnp'] + self.auto_renew_claim_height_delta = conf.settings['auto_renew_claim_height_delta'] + self.startup_status = STARTUP_STAGES[0] self.connected_to_internet = True @@ -255,6 +257,7 @@ class Daemon(AuthJSONRPCServer): yield self._setup_server() log.info("Starting balance: " + str(self.session.wallet.get_balance())) yield _announce_startup() + self._auto_renew() def _get_platform(self): if self.platform is None: @@ -290,6 +293,23 @@ class Daemon(AuthJSONRPCServer): if not self.connected_to_internet: self.connection_status_code = CONNECTION_STATUS_NETWORK + @defer.inlineCallbacks + def _auto_renew(self): + # automatically renew claims + # auto renew is turned off if 0 or some negative number + if self.auto_renew_claim_height_delta < 1: + return + log.debug("Renewing claim") + h = self.session.wallet.network.get_local_height() + self.auto_renew_claim_height_delta + results = yield self.session.wallet.claim_renew_all_before_expiration(h) + for outpoint, result in results.iteritems(): + if result['success']: + log.info("Renewed claim at outpoint:%s claim ID:%s, paid fee:%s", + outpoint, result['claim_id'], result['fee']) + else: + log.info("Failed to renew claim at outpoint:%s, reason:%s", + outpoint, result['reason']) + def _start_server(self): if self.peer_port is not None: server_factory = ServerProtocolFactory(self.session.rate_limiter,