X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=p2pool%2Fdata.py;h=6df3e89303a6d3a366436bc8cf03e97fb63ae39c;hb=94b87f6c9c04c292bca9565961f83198438f0f76;hp=3101f348f84afe02c8a8dae093d102326c45c04b;hpb=8f591b6caaf3ed6cbc5aea28f3e30b028ed1274a;p=p2pool.git diff --git a/p2pool/data.py b/p2pool/data.py index 3101f34..6df3e89 100644 --- a/p2pool/data.py +++ b/p2pool/data.py @@ -83,6 +83,8 @@ class NewShare(object): ('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([ @@ -105,7 +107,7 @@ class NewShare(object): ('share_info', share_info_type), ]) - gentx_before_refhash = pack.VarStrType().pack(DONATION_SCRIPT) + pack.IntType(64).pack(0) + pack.VarStrType().pack('\x28' + pack.IntType(256).pack(0) + pack.IntType(64).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): @@ -117,11 +119,11 @@ class NewShare(object): 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) - bits = bitcoin_data.FloatingInteger.from_target_upper_bound(math.clip(desired_target, (pre_target3//10, pre_target3))) + bits = bitcoin_data.FloatingInteger.from_target_upper_bound(math.clip(desired_target, (pre_target3//30, pre_target3))) new_transaction_hashes = [] new_transaction_size = 0 @@ -159,7 +161,7 @@ class NewShare(object): 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.SPREAD*bitcoin_data.target_to_average_attempts(block_target), + 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) @@ -179,11 +181,13 @@ class NewShare(object): 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( @@ -195,7 +199,7 @@ class NewShare(object): )], tx_outs=[dict(value=amounts[script], script=script) for script in dests if amounts[script] or script == DONATION_SCRIPT] + [dict( value=0, - script='\x28' + cls.get_ref_hash(net, share_info, ref_merkle_link) + pack.IntType(64).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, ) @@ -222,7 +226,7 @@ class NewShare(object): 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 @@ -249,6 +253,8 @@ class NewShare(object): 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(): @@ -349,8 +355,7 @@ class NewShare(object): other_txs = self._get_other_txs(tracker, known_txs) if other_txs is None: - if self.time_seen != 0: # ignore if loaded from ShareStore - return True, 'not all txs present' + pass else: all_txs_size = sum(bitcoin_data.tx_type.packed_size(tx) for tx in other_txs) if all_txs_size > 1000000: @@ -373,6 +378,8 @@ class Share(object): VOTING_VERSION = 11 SUCCESSOR = NewShare + absheight = abswork = 0 + small_block_header_type = pack.ComposedType([ ('version', pack.VarIntType()), ('previous_block', pack.PossiblyNoneType(0, pack.IntType(256))),