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()),
('stale_frac', bitcoin_data.StructType('<B')),
])
-new_share_info_type = bitcoin_data.ComposedType([
- ('new_share_data', new_share_data_type),
+share_info_type = bitcoin_data.ComposedType([
+ ('share_data', share_data_type),
('target', bitcoin_data.FloatingIntegerType()),
('timestamp', bitcoin_data.StructType('<I')),
])
-new_share1a_type = bitcoin_data.ComposedType([
+share1a_type = bitcoin_data.ComposedType([
('header', bitcoin_data.block_header_type),
- ('share_info', new_share_info_type),
+ ('share_info', share_info_type),
('merkle_branch', bitcoin_data.merkle_branch_type),
])
-new_share1b_type = bitcoin_data.ComposedType([
+share1b_type = bitcoin_data.ComposedType([
('header', bitcoin_data.block_header_type),
- ('share_info', new_share_info_type),
+ ('share_info', share_info_type),
('other_txs', bitcoin_data.ListType(bitcoin_data.tx_type)),
])
# type:
-# 0: new_share1a
-# 1: new_share1b
+# 0: share1a
+# 1: share1b
-new_share_type = bitcoin_data.ComposedType([
+share_type = bitcoin_data.ComposedType([
('type', bitcoin_data.VarIntType()),
('contents', bitcoin_data.VarStrType()),
])
-class NewShare(object):
+class Share(object):
@classmethod
def from_share1a(cls, share1a, net):
return cls(net, **share1a)
@classmethod
def from_share(cls, share, net):
if share['type'] == 0:
- res = cls.from_share1a(new_share1a_type.unpack(share['contents']), net)
+ res = cls.from_share1a(share1a_type.unpack(share['contents']), net)
if not (res.pow_hash > 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
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()
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']
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
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')
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)
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
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,
)
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,
)
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:
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)
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('<Q', random.randrange(2**64)),
net=net,
)
- print 'New work for worker! Difficulty: %.06f Payout if block: %.6f %s Total block value: %.6f %s including %i transactions' % (bitcoin_data.target_to_difficulty(new_share_info['target']), (sum(t['value'] for t in generate_tx['tx_outs'] if t['script'] == payout_script) -subsidy//200)*1e-8, net.BITCOIN_SYMBOL, subsidy*1e-8, net.BITCOIN_SYMBOL, len(current_work2.value['transactions']))
+ print 'New work for worker! Difficulty: %.06f Payout if block: %.6f %s Total block value: %.6f %s including %i transactions' % (bitcoin_data.target_to_difficulty(share_info['target']), (sum(t['value'] for t in generate_tx['tx_outs'] if t['script'] == payout_script) -subsidy//200)*1e-8, net.BITCOIN_SYMBOL, subsidy*1e-8, net.BITCOIN_SYMBOL, len(current_work2.value['transactions']))
#print 'Target: %x' % (p2pool_data.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['target'],)
#, have', shares.count(my_script) - 2, 'share(s) in the current chain. Fee:', sum(tx.value_in - tx.value_out for tx in extra_txs)/100000000
transactions = [generate_tx] + list(current_work2.value['transactions'])
merkle_root = bitcoin_data.merkle_hash(transactions)
- merkle_root_to_transactions[merkle_root] = new_share_info, transactions
+ merkle_root_to_transactions[merkle_root] = share_info, transactions
- target2 = new_share_info['target']
+ target2 = share_info['target']
times[merkle_root] = time.time()
#print 'SENT', 2**256//p2pool_data.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['target']
return bitcoin_getwork.BlockAttempt(state['version'], state['previous_block'], merkle_root, timestamp, state['target'], target2), state['best_share_hash']
print '''Couldn't link returned work's merkle root with its transactions - should only happen if you recently restarted p2pool'''
return False
share_info, transactions = xxx
- new_share_info = share_info
hash_ = bitcoin_data.block_header_type.hash256(header)
except:
log.err(None, 'Error while processing merged mining POW:')
- target = new_share_info['target']
+ target = share_info['target']
if pow_hash > 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)