示例#1
0
 def handle_header(new_header):
     # check that header matches current target
     if not (self.net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(new_header)) <= self.bitcoind_work.value['bits'].target):
         return
     bitcoind_best_block = self.bitcoind_work.value['previous_block']
     if (self.best_block_header.value is None
         or (
             new_header['previous_block'] == bitcoind_best_block and
             bitcoin_data.grshash256(bitcoin_data.block_header_type.pack(self.best_block_header.value)) == bitcoind_best_block
         ) # new is child of current and previous is current
         or (
             bitcoin_data.grshash256(bitcoin_data.block_header_type.pack(new_header)) == bitcoind_best_block and
             self.best_block_header.value['previous_block'] != bitcoind_best_block
         )): # new is current and previous is not a child of current
         self.best_block_header.set(new_header)
示例#2
0
 def __init__(self, net, peer_addr, contents):
     self.net = net
     self.peer_addr = peer_addr
     self.contents = contents
     
     self.min_header = contents['min_header']
     self.share_info = contents['share_info']
     self.hash_link = contents['hash_link']
     self.merkle_link = contents['merkle_link']
     
     if not (2 <= len(self.share_info['share_data']['coinbase']) <= 100):
         raise ValueError('''bad coinbase size! %i bytes''' % (len(self.share_info['share_data']['coinbase']),))
     
     if len(self.merkle_link['branch']) > 16:
         raise ValueError('merkle branch too long!')
     
     assert not self.hash_link['extra_data'], repr(self.hash_link['extra_data'])
     
     self.share_data = self.share_info['share_data']
     self.max_target = self.share_info['max_bits'].target
     self.target = self.share_info['bits'].target
     self.timestamp = self.share_info['timestamp']
     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():
         assert share_count < 110
         if share_count == 0:
             n.add(tx_count)
     assert n == set(range(len(self.share_info['new_transaction_hashes'])))
     
     self.gentx_hash = check_hash_link(
         self.hash_link,
         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)
     self.header = dict(self.min_header, merkle_root=merkle_root)
     self.pow_hash = net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(self.header))
     self.hash = self.header_hash = bitcoin_data.grshash256(bitcoin_data.block_header_type.pack(self.header))
     
     if self.target > net.MAX_TARGET:
         from p2pool import p2p
         raise p2p.PeerMisbehavingError('share target invalid')
     
     if self.pow_hash > self.target:
         from p2pool import p2p
         raise p2p.PeerMisbehavingError('share PoW invalid')
     
     self.new_transaction_hashes = self.share_info['new_transaction_hashes']
     
     # XXX eww
     self.time_seen = time.time()
示例#3
0
 def handle_header(new_header):
     # check that header matches current target
     if not (self.net.PARENT.POW_FUNC(
             bitcoin_data.block_header_type.pack(new_header)) <=
             self.bitcoind_work.value['bits'].target):
         return
     bitcoind_best_block = self.bitcoind_work.value['previous_block']
     if (self.best_block_header.value is None or
         (new_header['previous_block'] == bitcoind_best_block
          and bitcoin_data.grshash256(
              bitcoin_data.block_header_type.pack(
                  self.best_block_header.value)) == bitcoind_best_block
          )  # new is child of current and previous is current
             or (bitcoin_data.grshash256(
                 bitcoin_data.block_header_type.pack(new_header))
                 == bitcoind_best_block
                 and self.best_block_header.value['previous_block'] !=
                 bitcoind_best_block)
         ):  # new is current and previous is not a child of current
         self.best_block_header.set(new_header)
示例#4
0
    def __init__(self, net, peer_addr, contents):
        self.net = net
        self.peer_addr = peer_addr
        self.contents = contents

        self.min_header = contents['min_header']
        self.share_info = contents['share_info']
        self.hash_link = contents['hash_link']
        self.merkle_link = contents['merkle_link']

        if not (2 <= len(self.share_info['share_data']['coinbase']) <= 100):
            raise ValueError(
                '''bad coinbase size! %i bytes''' %
                (len(self.share_info['share_data']['coinbase']), ))

        if len(self.merkle_link['branch']) > 16:
            raise ValueError('merkle branch too long!')

        assert not self.hash_link['extra_data'], repr(
            self.hash_link['extra_data'])

        self.share_data = self.share_info['share_data']
        self.max_target = self.share_info['max_bits'].target
        self.target = self.share_info['bits'].target
        self.timestamp = self.share_info['timestamp']
        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():
            assert share_count < 110
            if share_count == 0:
                n.add(tx_count)
        assert n == set(range(len(self.share_info['new_transaction_hashes'])))

        self.gentx_hash = check_hash_link(
            self.hash_link,
            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)
        self.header = dict(self.min_header, merkle_root=merkle_root)
        self.pow_hash = net.PARENT.POW_FUNC(
            bitcoin_data.block_header_type.pack(self.header))
        self.hash = self.header_hash = bitcoin_data.grshash256(
            bitcoin_data.block_header_type.pack(self.header))

        if self.target > net.MAX_TARGET:
            from p2pool import p2p
            raise p2p.PeerMisbehavingError('share target invalid')

        if self.pow_hash > self.target:
            from p2pool import p2p
            raise p2p.PeerMisbehavingError('share PoW invalid')

        self.new_transaction_hashes = self.share_info['new_transaction_hashes']

        # XXX eww
        self.time_seen = time.time()