From 1929e68baa9f3cd1d7e6b5bf9ca21acfa494f2ce Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Sun, 4 Dec 2011 14:20:54 -0500 Subject: [PATCH] renamed new* to * --- p2pool/data.py | 64 ++++++++++++++++++++++++++++---------------------------- p2pool/main.py | 15 ++++++------- p2pool/p2p.py | 10 ++++---- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/p2pool/data.py b/p2pool/data.py index 917ddcc..125fd37 100644 --- a/p2pool/data.py +++ b/p2pool/data.py @@ -13,7 +13,7 @@ from p2pool.bitcoin import data as bitcoin_data, script from p2pool.util import memoize, expiring_dict, math, forest -new_share_data_type = bitcoin_data.ComposedType([ +share_data_type = bitcoin_data.ComposedType([ ('previous_share_hash', bitcoin_data.PossiblyNoneType(0, bitcoin_data.HashType())), ('coinbase', bitcoin_data.VarStrType()), ('nonce', bitcoin_data.VarStrType()), @@ -23,34 +23,34 @@ new_share_data_type = bitcoin_data.ComposedType([ ('stale_frac', bitcoin_data.StructType(' res.header['target']): raise ValueError('invalid share type') return res elif share['type'] == 1: - res = cls.from_share1b(new_share1b_type.unpack(share['contents']), net) + res = cls.from_share1b(share1b_type.unpack(share['contents']), net) if not (res.pow_hash <= res.header['target']): raise ValueError('invalid share type') return res @@ -89,10 +89,10 @@ class NewShare(object): raise ValueError('unknown share type: %r' % (share['type'],)) def as_share(self): - if self.pow_hash > self.header['target']: # new_share1a - return dict(type=0, contents=new_share1a_type.pack(self.as_share1a())) - elif self.pow_hash <= self.header['target']: # new_share1b - return dict(type=1, contents=new_share1b_type.pack(self.as_share1b())) + if self.pow_hash > self.header['target']: # share1a + return dict(type=0, contents=share1a_type.pack(self.as_share1a())) + elif self.pow_hash <= self.header['target']: # share1b + return dict(type=1, contents=share1b_type.pack(self.as_share1b())) else: raise AssertionError() @@ -115,7 +115,7 @@ class NewShare(object): self.merkle_branch = merkle_branch self.other_txs = other_txs - self.share_data = self.share_info['new_share_data'] + self.share_data = self.share_info['share_data'] self.target = self.share_info['target'] self.timestamp = self.share_info['timestamp'] @@ -138,7 +138,7 @@ class NewShare(object): self.pow_hash = net.BITCOIN_POW_FUNC(header) self.header_hash = bitcoin_data.block_header_type.hash256(header) - self.hash = new_share1a_type.hash256(self.as_share1a()) + self.hash = share1a_type.hash256(self.as_share1a()) if self.pow_hash > self.target: print 'hash %x' % self.pow_hash @@ -155,7 +155,7 @@ class NewShare(object): self.peer = None def check(self, tracker, now, net): - share_info, gentx = new_generate_transaction(tracker, self.share_info['new_share_data'], self.header['target'], self.share_info['timestamp'], net) + share_info, gentx = generate_transaction(tracker, self.share_info['share_data'], self.header['target'], self.share_info['timestamp'], net) if share_info != self.share_info: raise ValueError('share difficulty invalid') @@ -166,7 +166,7 @@ class NewShare(object): if self.other_txs is None: raise ValueError('share does not contain all txs') - share_info, gentx = new_generate_transaction(tracker, self.share_info['new_share_data'], self.header['target'], self.share_info['timestamp'], net) + share_info, gentx = generate_transaction(tracker, self.share_info['share_data'], self.header['target'], self.share_info['timestamp'], net) assert share_info == self.share_info return dict(header=self.header, txs=[gentx] + self.other_txs) @@ -182,14 +182,14 @@ def get_pool_attempts_per_second(tracker, previous_share_hash, net, dist=None): time = 1 return attempts//time -def new_generate_transaction(tracker, new_share_data, block_target, desired_timestamp, net): - previous_share_hash = new_share_data['previous_share_hash'] - new_script = new_share_data['new_script'] - subsidy = new_share_data['subsidy'] - donation = new_share_data['donation'] +def generate_transaction(tracker, share_data, block_target, desired_timestamp, net): + previous_share_hash = share_data['previous_share_hash'] + new_script = share_data['new_script'] + subsidy = share_data['subsidy'] + donation = share_data['donation'] assert 0 <= donation <= 65535 - if len(new_share_data['coinbase']) > 100: + if len(share_data['coinbase']) > 100: raise ValueError('coinbase too long!') previous_share = tracker.shares[previous_share_hash] if previous_share_hash is not None else None @@ -231,7 +231,7 @@ def new_generate_transaction(tracker, new_share_data, block_target, desired_time dests = dests[-4000:] # block length limit, unlikely to ever be hit share_info = dict( - new_share_data=new_share_data, + share_data=share_data, target=target, timestamp=math.clip(desired_timestamp, (previous_share.timestamp - 60, previous_share.timestamp + 60)) if previous_share is not None else desired_timestamp, ) @@ -241,9 +241,9 @@ def new_generate_transaction(tracker, new_share_data, block_target, desired_time tx_ins=[dict( previous_output=None, sequence=None, - script=new_share_data['coinbase'].ljust(2, '\x00'), + script=share_data['coinbase'].ljust(2, '\x00'), )], - tx_outs=[dict(value=0, script='\x20' + bitcoin_data.HashType().pack(new_share_info_type.hash256(share_info)))] + [dict(value=amounts[script], script=script) for script in dests if amounts[script]], + tx_outs=[dict(value=0, script='\x20' + bitcoin_data.HashType().pack(share_info_type.hash256(share_info)))] + [dict(value=amounts[script], script=script) for script in dests if amounts[script]], lock_time=0, ) @@ -450,7 +450,7 @@ class ShareStore(object): yield 'verified_hash', verified_hash verified_hashes.add(verified_hash) elif type_id == 5: - share = NewShare.from_share(new_share_type.unpack(data_hex.decode('hex')), self.net) + share = Share.from_share(share_type.unpack(data_hex.decode('hex')), self.net) yield 'share', share share_hashes.add(share.hash) else: @@ -472,7 +472,7 @@ class ShareStore(object): return filename def add_share(self, share): - type_id, data = 5, new_share_type.pack(share.as_share()) + type_id, data = 5, share_type.pack(share.as_share()) filename = self._add_line("%i %s" % (type_id, data.encode('hex'))) share_hashes, verified_hashes = self.known.setdefault(filename, (set(), set())) share_hashes.add(share.hash) diff --git a/p2pool/main.py b/p2pool/main.py index 32cf490..fd2c3de 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -433,9 +433,9 @@ def main(args, net): timestamp = current_work2.value['time'] previous_share = tracker.shares[state['best_share_hash']] if state['best_share_hash'] is not None else None - new_share_info, generate_tx = p2pool_data.new_generate_transaction( + share_info, generate_tx = p2pool_data.generate_transaction( tracker=tracker, - new_share_data=dict( + share_data=dict( previous_share_hash=state['best_share_hash'], coinbase=aux_str, nonce=run_identifier + struct.pack(' target: print 'Worker submitted share with hash > target:\nhash : %x\ntarget: %x' % (pow_hash, target) return False - share = p2pool_data.NewShare(net, header, new_share_info, other_txs=transactions[1:]) + share = p2pool_data.Share(net, header, share_info, other_txs=transactions[1:]) my_shares.add(share.hash) if share.previous_hash != current_work.value['best_share_hash']: doa_shares.add(share.hash) diff --git a/p2pool/p2p.py b/p2pool/p2p.py index 724ac5b..847c9d3 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -182,29 +182,29 @@ class Protocol(bitcoin_p2p.BaseProtocol): self.node.handle_get_shares(hashes, parents, stops, self) message_shares = bitcoin_data.ComposedType([ - ('shares', bitcoin_data.ListType(p2pool_data.new_share_type)), + ('shares', bitcoin_data.ListType(p2pool_data.share_type)), ]) def handle_shares(self, shares): res = [] for share in shares: - share_obj = p2pool_data.NewShare.from_share(share, self.node.net) + share_obj = p2pool_data.Share.from_share(share, self.node.net) share_obj.peer = self res.append(share_obj) self.node.handle_shares(res) def sendShares(self, shares, full=False): - new_shares = [] + shares = [] # XXX doesn't need to send full block when it's not urgent # eg. when getting history for share in shares: - new_shares.append(share.as_share()) + shares.append(share.as_share()) def att(f, **kwargs): try: f(**kwargs) except bitcoin_p2p.TooLong: att(f, **dict((k, v[:len(v)//2]) for k, v in kwargs.iteritems())) att(f, **dict((k, v[len(v)//2:]) for k, v in kwargs.iteritems())) - if new_shares: att(self.send_shares, shares=new_shares) + if shares: att(self.send_shares, shares=shares) def connectionLost(self, reason): if self.connected2: -- 1.7.1