Skip to content

Commit

Permalink
Automatically update MINIMUM_PROTOCOL_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
veqtrus committed Jun 30, 2016
1 parent 517064e commit bcccb91
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
16 changes: 12 additions & 4 deletions p2pool/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,16 @@ def iter_transaction_hash_refs(self):

def check(self, tracker):
from p2pool import p2p
counts = None
if self.share_data['previous_share_hash'] is not None:
previous_share = tracker.items[self.share_data['previous_share_hash']]
counts = get_desired_version_counts(tracker, tracker.get_nth_parent_hash(previous_share.hash, self.net.CHAIN_LENGTH*9//10), self.net.CHAIN_LENGTH//10)
if type(self) is type(previous_share):
pass
elif type(self) is type(previous_share).SUCCESSOR:
if tracker.get_height(previous_share.hash) < self.net.CHAIN_LENGTH:
from p2pool import p2p
raise p2p.PeerMisbehavingError('switch without enough history')

# switch only valid if 60% of hashes in [self.net.CHAIN_LENGTH*9//10, self.net.CHAIN_LENGTH] for new version
counts = get_desired_version_counts(tracker,
tracker.get_nth_parent_hash(previous_share.hash, self.net.CHAIN_LENGTH*9//10), self.net.CHAIN_LENGTH//10)
if counts.get(self.VERSION, 0) < sum(counts.itervalues())*60//100:
raise p2p.PeerMisbehavingError('switch without enough hash power upgraded')
else:
Expand All @@ -333,6 +331,8 @@ def check(self, tracker):
if bitcoin_data.calculate_merkle_link([None] + other_tx_hashes, 0) != self.merkle_link:
raise ValueError('merkle_link and other_tx_hashes do not match')

update_min_protocol_version(counts, self)

return gentx # only used by as_block

def get_other_tx_hashes(self, tracker):
Expand Down Expand Up @@ -568,6 +568,14 @@ def score(self, share_hash, block_rel_height_func):

return self.net.CHAIN_LENGTH, self.verified.get_delta(share_hash, end_point).work/((0 - block_height + 1)*self.net.PARENT.BLOCK_PERIOD)

def update_min_protocol_version(counts, share):
minpver = getattr(share.net, 'MINIMUM_PROTOCOL_VERSION', 1400)
newminpver = getattr(share.net, 'NEW_MINIMUM_PROTOCOL_VERSION', minpver)
if (counts is not None) and (type(share) is NewShare) and (minpver < newminpver):
if counts.get(share.VERSION, 0) >= sum(counts.itervalues())*95//100:
share.net.MINIMUM_PROTOCOL_VERSION = newminpver # Reject peers running obsolete nodes
print 'Setting MINIMUM_PROTOCOL_VERSION = %d' % (newminpver)

def get_pool_attempts_per_second(tracker, previous_share_hash, dist, min_work=False, integer=False):
assert dist >= 2
near = tracker.items[previous_share_hash]
Expand Down
6 changes: 6 additions & 0 deletions p2pool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ def save_shares():
if share.hash in node.tracker.verified.items:
ss.add_verified_hash(share.hash)
deferral.RobustLoopingCall(save_shares).start(60)

if len(shares) > net.CHAIN_LENGTH:
best_share = shares[node.best_share_var.value]
previous_share = shares[best_share.share_data['previous_share_hash']]
counts = p2pool_data.get_desired_version_counts(node.tracker, node.tracker.get_nth_parent_hash(previous_share.hash, net.CHAIN_LENGTH*9//10), net.CHAIN_LENGTH//10)
p2pool_data.update_min_protocol_version(counts, best_share)

print ' ...success!'
print
Expand Down
3 changes: 2 additions & 1 deletion p2pool/networks/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
VERSION_CHECK = lambda v: None if 100000 <= v else 'Bitcoin version too old. Upgrade to 0.11.2 or newer!' # not a bug. BIP65 support is ensured by SOFTFORKS_REQUIRED
VERSION_WARNING = lambda v: None
SOFTFORKS_REQUIRED = set(['bip65', 'csv'])
MINIMUM_PROTOCOL_VERSION = 1600
MINIMUM_PROTOCOL_VERSION = 1500
NEW_MINIMUM_PROTOCOL_VERSION = 1600
6 changes: 5 additions & 1 deletion p2pool/networks/bitcoin_testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
WORKER_PORT = 19332
BOOTSTRAP_ADDRS = 'forre.st vps.forre.st liteco.in'.split(' ')
ANNOUNCE_CHANNEL = '#p2pool-alt'
VERSION_CHECK = lambda v: 50700 <= v < 60000 or 60010 <= v < 60100 or 60400 <= v
VERSION_CHECK = lambda v: None if 100000 <= v else 'Bitcoin version too old. Upgrade to 0.11.2 or newer!' # not a bug. BIP65 support is ensured by SOFTFORKS_REQUIRED
VERSION_WARNING = lambda v: None
SOFTFORKS_REQUIRED = set(['bip65', 'csv'])
MINIMUM_PROTOCOL_VERSION = 1500
NEW_MINIMUM_PROTOCOL_VERSION = 1600

0 comments on commit bcccb91

Please sign in to comment.