From eda00aef88c9a71b2e24f3334c0a39c51531d3c3 Mon Sep 17 00:00:00 2001 From: sbwdlihao Date: Mon, 27 Oct 2014 20:22:46 +0800 Subject: [PATCH] Update scheduler.py the result of keys command is unsorted, this makes no difference in pplns but in prop there maybe a block credited before a block which solve_time is older than it ant will trigger error in chain calc_shares, so i think we should sort unproc_blocks by solve_time --- simplecoin/scheduler.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/simplecoin/scheduler.py b/simplecoin/scheduler.py index 64ba2b07..7e5a7d25 100644 --- a/simplecoin/scheduler.py +++ b/simplecoin/scheduler.py @@ -418,11 +418,18 @@ def generate_credits(dont_simulate=True): attempts to process them """ simulate = not dont_simulate unproc_blocks = redis_conn.keys("unproc_block*") + datas = [] for key in unproc_blocks: - hash = key[13:] + data = redis_conn.hgetall(key) + data['redis_key'] = key + datas.append(data) + datas = sorted(datas, key=itemgetter('solve_time')) + + for data in datas: + hash = data['hash'] current_app.logger.info("==== Attempting to process block hash {}".format(hash)) try: - credit_block(key, simulate=simulate) + credit_block(data, simulate=simulate) except Exception: db.session.rollback() current_app.logger.error("Unable to payout block {}".format(hash), exc_info=True) @@ -506,7 +513,7 @@ def _distributor(amount, splits, scale=None, addtl_prec=0): return splits -def credit_block(redis_key, simulate=False): +def credit_block(data, simulate=False): """ Calculates credits for users from share records for the latest found block. """ @@ -517,7 +524,7 @@ def credit_block(redis_key, simulate=False): current_app.logger.warn("Running in simulate mode, no commit will be performed") current_app.logger.setLevel(logging.DEBUG) - data = redis_conn.hgetall(redis_key) + redis_key = data['redis_key'] current_app.logger.debug("Processing block with details {}".format(data)) merged = bool(int(data.get('merged', False))) # If start_time isn't listed explicitly do our best to derive from