def load_share(share, net, peer_addr):
assert peer_addr is None or isinstance(peer_addr, tuple)
- if share['type'] in [0, 1, 2, 3, 4, 5, 6, 7, 8]:
+ if share['type'] < Share.VERSION:
from p2pool import p2p
raise p2p.PeerMisbehavingError('sent an obsolete share')
elif share['type'] == Share.VERSION:
return Share(net, peer_addr, Share.share_type.unpack(share['contents']))
+ elif share['type'] == NewShare.VERSION:
+ return NewShare(net, peer_addr, NewShare.share_type.unpack(share['contents']))
else:
raise ValueError('unknown share type: %r' % (share['type'],))
DONATION_SCRIPT = '4104ffd03de44a6e11b9917f3a29f9443283d9871c9d743ef30d5eddcd37094b64d1b3d8090496b53256786bf5c82932ec23c3b74d9f05a6f95a8b5529352656664bac'.decode('hex')
-class Share(object):
- VERSION = 9
- VOTING_VERSION = 11
+class NewShare(object):
+ VERSION = 13
+ VOTING_VERSION = 13
SUCCESSOR = None
small_block_header_type = pack.ComposedType([
('max_bits', bitcoin_data.FloatingIntegerType()),
('bits', bitcoin_data.FloatingIntegerType()),
('timestamp', pack.IntType(32)),
+ ('absheight', pack.IntType(32)),
+ ('abswork', pack.IntType(128)),
])
share_type = pack.ComposedType([
('branch', pack.ListType(pack.IntType(256))),
('index', pack.IntType(0)),
])),
- ('last_txout_nonce', pack.IntType(32)),
+ ('last_txout_nonce', pack.IntType(64)),
('hash_link', hash_link_type),
('merkle_link', pack.ComposedType([
('branch', pack.ListType(pack.IntType(256))),
('share_info', share_info_type),
])
- gentx_before_refhash = pack.VarStrType().pack(DONATION_SCRIPT) + pack.IntType(64).pack(0) + pack.VarStrType().pack('\x24' + pack.IntType(256).pack(0) + pack.IntType(32).pack(0))[:2]
+ gentx_before_refhash = pack.VarStrType().pack(DONATION_SCRIPT) + pack.IntType(64).pack(0) + pack.VarStrType().pack('\x6a\x28' + pack.IntType(256).pack(0) + pack.IntType(64).pack(0))[:3]
@classmethod
def generate_transaction(cls, tracker, share_data, block_target, desired_timestamp, desired_target, ref_merkle_link, desired_other_transaction_hashes_and_fees, net, known_txs=None, last_txout_nonce=0, base_subsidy=None):
pre_target3 = net.MAX_TARGET
else:
attempts_per_second = get_pool_attempts_per_second(tracker, share_data['previous_share_hash'], net.TARGET_LOOKBEHIND, min_work=True, integer=True)
- pre_target = 2**256//(net.SHARE_PERIOD*attempts_per_second) - 1 if attempts_per_second else 2**256-1
+ pre_target = 2**256//(net.NEW_SHARE_PERIOD*attempts_per_second) - 1 if attempts_per_second else 2**256-1
pre_target2 = math.clip(pre_target, (previous_share.max_target*9//10, previous_share.max_target*11//10))
pre_target3 = math.clip(pre_target2, (net.MIN_TARGET, net.MAX_TARGET))
max_bits = bitcoin_data.FloatingInteger.from_target_upper_bound(pre_target3)
assert base_subsidy is not None
share_data = dict(share_data, subsidy=base_subsidy + definite_fees)
- weights, total_weight, donation_weight = tracker.get_cumulative_weights(share_data['previous_share_hash'],
- min(height, net.REAL_CHAIN_LENGTH),
- 65535*net.SPREAD*bitcoin_data.target_to_average_attempts(block_target),
+ weights, total_weight, donation_weight = tracker.get_cumulative_weights(previous_share.share_data['previous_share_hash'] if previous_share is not None else None,
+ min(height, net.REAL_CHAIN_LENGTH-1),
+ 65535*net.NEW_SPREAD*bitcoin_data.target_to_average_attempts(block_target),
)
assert total_weight == sum(weights.itervalues()) + donation_weight, (total_weight, sum(weights.itervalues()) + donation_weight)
max_bits=max_bits,
bits=bits,
timestamp=math.clip(desired_timestamp, (
- (previous_share.timestamp + net.SHARE_PERIOD) - (net.SHARE_PERIOD - 1), # = previous_share.timestamp + 1
- (previous_share.timestamp + net.SHARE_PERIOD) + (net.SHARE_PERIOD - 1),
+ (previous_share.timestamp + net.NEW_SHARE_PERIOD) - (net.NEW_SHARE_PERIOD - 1), # = previous_share.timestamp + 1
+ (previous_share.timestamp + net.NEW_SHARE_PERIOD) + (net.NEW_SHARE_PERIOD - 1),
)) if previous_share is not None else desired_timestamp,
new_transaction_hashes=new_transaction_hashes,
transaction_hash_refs=transaction_hash_refs,
+ absheight=((previous_share.absheight if previous_share is not None else 0) + 1) % 2**32,
+ abswork=((previous_share.abswork if previous_share is not None else 0) + bitcoin_data.target_to_average_attempts(bits.target)) % 2**128,
)
gentx = dict(
)],
tx_outs=[dict(value=amounts[script], script=script) for script in dests if amounts[script] or script == DONATION_SCRIPT] + [dict(
value=0,
- script='\x24' + cls.get_ref_hash(net, share_info, ref_merkle_link) + pack.IntType(32).pack(last_txout_nonce),
+ script='\x6a\x28' + cls.get_ref_hash(net, share_info, ref_merkle_link) + pack.IntType(64).pack(last_txout_nonce),
)],
lock_time=0,
)
min_header=min_header,
share_info=share_info,
ref_merkle_link=dict(branch=[], index=0),
- last_txout_nonce=last_txout_nonce,
- hash_link=prefix_to_hash_link(bitcoin_data.tx_type.pack(gentx)[:-32-4-4], cls.gentx_before_refhash),
+ last_txout_nonce=last_txout_nonce*2**32,
+ hash_link=prefix_to_hash_link(bitcoin_data.tx_type.pack(gentx)[:-32-8-4], cls.gentx_before_refhash),
merkle_link=bitcoin_data.calculate_merkle_link([None] + other_transaction_hashes, 0),
))
assert share.header == header # checks merkle_root
share_info=share_info,
))), ref_merkle_link))
- __slots__ = 'net peer_addr contents min_header share_info hash_link merkle_link hash share_data max_target target timestamp previous_hash new_script desired_version gentx_hash header pow_hash header_hash new_transaction_hashes time_seen'.split(' ')
+ __slots__ = 'net peer_addr contents min_header share_info hash_link merkle_link hash share_data max_target target timestamp previous_hash new_script desired_version gentx_hash header pow_hash header_hash new_transaction_hashes time_seen absheight abswork'.split(' ')
def __init__(self, net, peer_addr, contents):
self.net = net
self.previous_hash = self.share_data['previous_share_hash']
self.new_script = bitcoin_data.pubkey_hash_to_script2(self.share_data['pubkey_hash'])
self.desired_version = self.share_data['desired_version']
+ self.absheight = self.share_info['absheight']
+ self.abswork = self.share_info['abswork']
n = set()
for share_count, tx_count in self.iter_transaction_hash_refs():
self.gentx_hash = check_hash_link(
self.hash_link,
- self.get_ref_hash(net, self.share_info, contents['ref_merkle_link']) + pack.IntType(32).pack(self.contents['last_txout_nonce']) + pack.IntType(32).pack(0),
+ self.get_ref_hash(net, self.share_info, contents['ref_merkle_link']) + pack.IntType(64).pack(self.contents['last_txout_nonce']) + pack.IntType(32).pack(0),
self.gentx_before_refhash,
)
merkle_root = bitcoin_data.check_merkle_link(self.gentx_hash, self.merkle_link)
class Share(object):
VERSION = 9
VOTING_VERSION = 11
- SUCCESSOR = None
+ SUCCESSOR = NewShare
+
+ absheight = abswork = 0
small_block_header_type = pack.ComposedType([
('version', pack.VarIntType()),