示例#1
0
 def _getwork(self, request, data, long_poll):
     request.setHeader('X-Long-Polling', '/long-polling')
     request.setHeader('X-Roll-NTime', 'expire=100')
     request.setHeader('X-Is-P2Pool', 'true')
     if request.getHeader('Host') is not None:
         request.setHeader('X-Stratum', 'stratum+tcp://' + request.getHeader('Host'))
     
     if data is not None:
         header = getwork.decode_data(data)
         if header['merkle_root'] not in self.merkle_root_to_handler:
             print >>sys.stderr, '''Couldn't link returned work's merkle root with its handler. This should only happen if this process was recently restarted!'''
             defer.returnValue(False)
         defer.returnValue(self.merkle_root_to_handler[header['merkle_root']](header, request.getUser() if request.getUser() is not None else '', '\0'*self.worker_bridge.COINBASE_NONCE_LENGTH))
     
     if p2pool.DEBUG:
         id = random.randrange(1000, 10000)
         print 'POLL %i START is_long_poll=%r user_agent=%r user=%r' % (id, long_poll, request.getHeader('User-Agent'), request.getUser())
     
     if long_poll:
         request_id = request.getClientIP(), request.getHeader('Authorization')
         if self.worker_views.get(request_id, self.worker_bridge.new_work_event.times) != self.worker_bridge.new_work_event.times:
             if p2pool.DEBUG:
                 print 'POLL %i PUSH' % (id,)
         else:
             if p2pool.DEBUG:
                 print 'POLL %i WAITING' % (id,)
             yield self.worker_bridge.new_work_event.get_deferred()
         self.worker_views[request_id] = self.worker_bridge.new_work_event.times
     
     x, handler = self.worker_bridge.get_work(*self.worker_bridge.preprocess_request(request.getUser() if request.getUser() is not None else ''))
     res = getwork.BlockAttempt(
         version=x['version'],
         previous_block=x['previous_block'],
         merkle_root=bitcoin_data.check_merkle_link(bitcoin_data.hash256(x['coinb1'] + '\0'*self.worker_bridge.COINBASE_NONCE_LENGTH + x['coinb2']), x['merkle_link']),
         timestamp=x['timestamp'],
         bits=x['bits'],
         share_target=x['share_target'],
     )
     assert res.merkle_root not in self.merkle_root_to_handler
     
     self.merkle_root_to_handler[res.merkle_root] = handler
     
     if p2pool.DEBUG:
         print 'POLL %i END identifier=%i' % (id, self.worker_bridge.new_work_event.times)
     
     extra_params = {}
     if request.getHeader('User-Agent') == 'Jephis PIC Miner':
         # ASICMINER BE Blades apparently have a buffer overflow bug and
         # can't handle much extra in the getwork response
         extra_params = {}
     else:
         extra_params = dict(identifier=str(self.worker_bridge.new_work_event.times), submitold=True)
     defer.returnValue(res.getwork(**extra_params))
示例#2
0
    def test_all(self):
        cases = [
            {
                'target':
                '0000000000000000000000000000000000000000000000f2b944000000000000',
                'midstate':
                '5982f893102dec03e374b472647c4f19b1b6d21ae4b2ac624f3d2f41b9719404',
                'hash1':
                '00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000',
                'data':
                '0000000163930d52a5ffca79b29b95a659a302cd4e1654194780499000002274000000002e133d9e51f45bc0886d05252038e421e82bff18b67dc14b90d9c3c2f422cd5c4dd4598e1a44b9f200000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000'
            },
            {
                'midstate':
                'f4a9b048c0cb9791bc94b13ee0eec21e713963d524fd140b58bb754dd7b0955f',
                'data':
                '000000019a1d7342fb62090bda686b22d90f9f73d0f5c418b9c980cd0000011a00000000680b07c8a2f97ecd831f951806857e09f98a3b81cdef1fa71982934fef8dc3444e18585d1a0abbcf00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000',
                'hash1':
                '00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000',
                'target':
                '0000000000000000000000000000000000000000000000cfbb0a000000000000',
                'extrathing': 'hi!',
            },
            {
                'data':
                '000000019a1d7342fb62090bda686b22d90f9f73d0f5c418b9c980cd0000011a00000000680b07c8a2f97ecd831f951806857e09f98a3b81cdef1fa71982934fef8dc3444e18585d1a0abbcf00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000',
                'hash1':
                '00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000',
                'target':
                '0000000000000000000000000000000000000000000000cfbb0a000000000000',
                'extrathing': 'hi!',
            },
        ]
        for case in cases:
            ba = getwork.BlockAttempt.from_getwork(case)

            extra = dict(case)
            del extra['data'], extra['hash1'], extra['target']
            extra.pop('midstate', None)

            getwork_check = ba.getwork(**extra)
            assert getwork_check == case or dict(
                (k, v) for k, v in getwork_check.iteritems()
                if k != 'midstate') == case

        case2s = [
            getwork.BlockAttempt(
                1,
                0x148135e10208db85abb62754341a392eab1f186aab077a831cf7,
                0x534ea08be1ab529f484369344b6d5423ef5a0767db9b3ebb4e182bbb67962520,
                1305759879,
                bitcoin_data.FloatingInteger.from_target_upper_bound(
                    0x44b9f20000000000000000000000000000000000000000000000),
                0x44b9f20000000000000000000000000000000000000000000000,
            ),
            getwork.BlockAttempt(
                1,
                0x148135e10208db85abb62754341a392eab1f186aab077a831cf7,
                0x534ea08be1ab529f484369344b6d5423ef5a0767db9b3ebb4e182bbb67962520,
                1305759879,
                bitcoin_data.FloatingInteger.from_target_upper_bound(
                    0x44b9f20000000000000000000000000000000000000000000000),
                432 * 2**230,
            ),
            getwork.BlockAttempt(
                1,
                0x148135e10208db85abb62754341a392eab1f186aab077a831cf7,
                0x534ea08be1ab529f484369344b6d5423ef5a0767db9b3ebb4e182bbb67962520,
                1305759879,
                bitcoin_data.FloatingInteger.from_target_upper_bound(
                    0x44b9f20000000000000000000000000000000000000000000000),
                7 * 2**240,
            )
        ]
        for case2 in case2s:
            assert getwork.BlockAttempt.from_getwork(case2.getwork()) == case2
            assert getwork.BlockAttempt.from_getwork(
                case2.getwork(ident='hi')) == case2
            case2 = case2.update(previous_block=case2.previous_block - 10)
            assert getwork.BlockAttempt.from_getwork(case2.getwork()) == case2
            assert getwork.BlockAttempt.from_getwork(
                case2.getwork(ident='hi')) == case2
示例#3
0
 def test_all(self):
     getwork.BlockAttempt.from_getwork(
         {
             'target':
             '0000000000000000000000000000000000000000000000f2b944000000000000',
             'midstate':
             '5982f893102dec03e374b472647c4f19b1b6d21ae4b2ac624f3d2f41b9719404',
             'hash1':
             '00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000',
             'data':
             '0000000163930d52a5ffca79b29b95a659a302cd4e1654194780499000002274000000002e133d9e51f45bc0886d05252038e421e82bff18b67dc14b90d9c3c2f422cd5c4dd4598e1a44b9f200000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000'
         },
         _check=100)
     getwork.BlockAttempt.from_getwork({
         'midstate':
         'f4a9b048c0cb9791bc94b13ee0eec21e713963d524fd140b58bb754dd7b0955f',
         'data':
         '000000019a1d7342fb62090bda686b22d90f9f73d0f5c418b9c980cd0000011a00000000680b07c8a2f97ecd831f951806857e09f98a3b81cdef1fa71982934fef8dc3444e18585d1a0abbcf00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000',
         'hash1':
         '00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000',
         'target':
         '0000000000000000000000000000000000000000000000cfbb0a000000000000',
         'extrathing': 'hi!',
     })
     getwork.BlockAttempt.from_getwork({
         'data':
         '000000019a1d7342fb62090bda686b22d90f9f73d0f5c418b9c980cd0000011a00000000680b07c8a2f97ecd831f951806857e09f98a3b81cdef1fa71982934fef8dc3444e18585d1a0abbcf00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000',
         'hash1':
         '00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000',
         'target':
         '0000000000000000000000000000000000000000000000cfbb0a000000000000',
         'extrathing': 'hi!',
     })
     ba = getwork.BlockAttempt(
         1,
         0x148135e10208db85abb62754341a392eab1f186aab077a831cf7,
         0x534ea08be1ab529f484369344b6d5423ef5a0767db9b3ebb4e182bbb67962520,
         1305759879,
         bitcoin_data.FloatingInteger.from_target_upper_bound(
             0x44b9f20000000000000000000000000000000000000000000000),
         0x44b9f20000000000000000000000000000000000000000000000,
     )
     ba.getwork(100)
     ba = getwork.BlockAttempt(
         1,
         0x148135e10208db85abb62754341a392eab1f186aab077a831cf7,
         0x534ea08be1ab529f484369344b6d5423ef5a0767db9b3ebb4e182bbb67962520,
         1305759879,
         bitcoin_data.FloatingInteger.from_target_upper_bound(
             0x44b9f20000000000000000000000000000000000000000000000),
         432 * 2**230,
     )
     ba.getwork(100)
     ba = getwork.BlockAttempt(
         1,
         0x148135e10208db85abb62754341a392eab1f186aab077a831cf7,
         0x534ea08be1ab529f484369344b6d5423ef5a0767db9b3ebb4e182bbb67962520,
         1305759879,
         bitcoin_data.FloatingInteger.from_target_upper_bound(
             0x44b9f20000000000000000000000000000000000000000000000),
         7 * 2**240,
     )
     ba.getwork(100)
     ba.getwork()
     ba.getwork(_check=100)
     ba.update(previous_block=ba.previous_block - 10).getwork(_check=100,
                                                              ident="hi")