From d9346f7acae9c946006bb616c486692543ab975c Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Fri, 20 Jan 2012 16:11:20 -0500 Subject: [PATCH] rewrote chain scoring function for better performance and more obvious behavior --- p2pool/bitcoin/p2p.py | 2 +- p2pool/data.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/p2pool/bitcoin/p2p.py b/p2pool/bitcoin/p2p.py index e2dca75..6692f2b 100644 --- a/p2pool/bitcoin/p2p.py +++ b/p2pool/bitcoin/p2p.py @@ -365,7 +365,7 @@ class HeightTracker(object): # callers: highest height can change during yields! height, last = self._tracker.get_height_and_last(block_hash) if last not in self._tracker.tails: - return -1e300 + return -1000000000 # XXX hack return height - max(self._tracker.get_height(head_hash) for head_hash in self._tracker.tails[last]) def stop(self): diff --git a/p2pool/data.py b/p2pool/data.py index 7d760a0..6c695f6 100644 --- a/p2pool/data.py +++ b/p2pool/data.py @@ -418,16 +418,16 @@ class OkayTracker(forest.Tracker): return best, desired def score(self, share_hash, ht): - head_height, last = self.verified.get_height_and_last(share_hash) - score2 = 0 - block_height = -1000000 - max_height = min(self.net.CHAIN_LENGTH, head_height) - for share in math.reversed(self.verified.get_chain(self.verified.get_nth_parent_hash(share_hash, max_height//2), max_height//2)): - block_height = max(block_height, ht.get_height_rel_highest(share.header['previous_block'])) - this_score = (self.verified.get_work(share_hash) - self.verified.get_work(share.hash))//(0 - block_height + 1) - if this_score > score2: - score2 = this_score - return min(head_height, self.net.CHAIN_LENGTH), score2 + head_height = self.verified.get_height(share_hash) + if head_height < self.net.CHAIN_LENGTH: + return head_height, None + + end_point = self.verified.get_nth_parent_hash(share_hash, self.net.CHAIN_LENGTH*15//16) + + block_height = max(ht.get_height_rel_highest(share.header['previous_block']) for share in + self.verified.get_chain(end_point, self.net.CHAIN_LENGTH//16)) + + return self.net.CHAIN_LENGTH, (self.verified.get_work(share_hash) - self.verified.get_work(end_point))//(0 - block_height + 1) def format_hash(x): if x is None: -- 1.7.1