Ejemplo n.º 1
0
        def get_share(header, last_txout_nonce=last_txout_nonce):
            min_header = dict(header)
            del min_header['merkle_root']

            packed_gentx = axe_data.tx_type.pack(gentx)

            coinbase_payload_data_size = 0
            coinbase_payload_data = None
            if share_data['coinbase_payload'] is not None and len(
                    share_data['coinbase_payload']) != 0:
                coinbase_payload_data = pack.VarStrType().pack(
                    share_data['coinbase_payload'])
                coinbase_payload_data_size = len(coinbase_payload_data)
            prefix = packed_gentx[:-coinbase_payload_data_size - 32 - 8 - 4]

            share = cls(
                net, None,
                dict(
                    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(prefix,
                                                  cls.gentx_before_refhash),
                    merkle_link=axe_data.calculate_merkle_link(
                        [None] + other_transaction_hashes, 0),
                    coinbase_payload=coinbase_payload_data,
                ))
            assert share.header == header  # checks merkle_root
            return share
Ejemplo n.º 2
0
    def check(self, tracker):
        from p2pool import p2p
        if self.share_data['previous_share_hash'] is not None:
            previous_share = tracker.items[
                self.share_data['previous_share_hash']]
            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 85% 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()) * 85 // 100:
                    raise p2p.PeerMisbehavingError(
                        'switch without enough hash power upgraded')
            else:
                raise p2p.PeerMisbehavingError(
                    '''%s can't follow %s''' %
                    (type(self).__name__, type(previous_share).__name__))

        other_tx_hashes = [
            tracker.items[tracker.get_nth_parent_hash(
                self.hash,
                share_count)].share_info['new_transaction_hashes'][tx_count]
            for share_count, tx_count in self.iter_transaction_hash_refs()
        ]

        share_info, gentx, other_tx_hashes2, get_share = self.generate_transaction(
            tracker,
            self.share_info['share_data'],
            self.header['bits'].target,
            self.share_info['timestamp'],
            self.share_info['bits'].target,
            self.contents['ref_merkle_link'],
            [(h, None) for h in other_tx_hashes],
            self.net,
            last_txout_nonce=self.contents['last_txout_nonce'])
        assert other_tx_hashes2 == other_tx_hashes
        if share_info != self.share_info:
            raise ValueError('share_info invalid')
        if axe_data.hash256(axe_data.tx_type.pack(gentx)) != self.gentx_hash:
            raise ValueError('''gentx doesn't match hash_link''')

        if axe_data.calculate_merkle_link([None] + other_tx_hashes,
                                          0) != self.merkle_link:
            raise ValueError('merkle_link and other_tx_hashes do not match')

        return gentx  # only used by as_block
Ejemplo n.º 3
0
 def get_share(header, last_txout_nonce=last_txout_nonce):
     min_header = dict(header)
     del min_header['merkle_root']
     share = cls(
         net, None,
         dict(
             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(
                 axe_data.tx_type.pack(gentx)[:-32 - 8 - 4],
                 cls.gentx_before_refhash),
             merkle_link=axe_data.calculate_merkle_link(
                 [None] + other_transaction_hashes, 0),
         ))
     assert share.header == header  # checks merkle_root
     return share