Fix for litecoin block sending
[p2pool.git] / p2pool / bitcoin / helper.py
index 3d5810b..85ae90e 100644 (file)
@@ -26,11 +26,15 @@ def getwork(bitcoind, use_getblocktemplate=False):
         else:
             return bitcoind.rpc_getmemorypool()
     try:
+        start = time.time()
         work = yield go()
+        end = time.time()
     except jsonrpc.Error_for_code(-32601): # Method not found
         use_getblocktemplate = not use_getblocktemplate
         try:
+            start = time.time()
             work = yield go()
+            end = time.time()
         except jsonrpc.Error_for_code(-32601): # Method not found
             print >>sys.stderr, 'Error: Bitcoin version too old! Upgrade to v0.5 or newer!'
             raise deferral.RetrySilentlyException()
@@ -44,6 +48,7 @@ def getwork(bitcoind, use_getblocktemplate=False):
         previous_block=int(work['previousblockhash'], 16),
         transactions=map(bitcoin_data.tx_type.unpack, packed_transactions),
         transaction_hashes=map(bitcoin_data.hash256, packed_transactions),
+        transaction_fees=[x.get('fee', None) if isinstance(x, dict) else None for x in work['transactions']],
         subsidy=work['coinbasevalue'],
         time=work['time'] if 'time' in work else work['curtime'],
         bits=bitcoin_data.FloatingIntegerType().unpack(work['bits'].decode('hex')[::-1]) if isinstance(work['bits'], (str, unicode)) else bitcoin_data.FloatingInteger(work['bits']),
@@ -51,6 +56,7 @@ def getwork(bitcoind, use_getblocktemplate=False):
         height=work['height'],
         last_update=time.time(),
         use_getblocktemplate=use_getblocktemplate,
+        latency=end - start,
     ))
 
 @deferral.retry('Error submitting primary block: (will retry)', 10, 10)
@@ -64,8 +70,12 @@ def submit_block_p2p(block, factory, net):
 @defer.inlineCallbacks
 def submit_block_rpc(block, ignore_failure, bitcoind, bitcoind_work, net):
     if bitcoind_work.value['use_getblocktemplate']:
-        result = yield bitcoind.rpc_submitblock(bitcoin_data.block_type.pack(block).encode('hex'))
-        success = result is None
+        if 'lite' in self.node.net.NAME:
+            result = yield bitcoind.rpc_getblocktemplate(dict(mode='submit', data=bitcoin_data.block_type.pack(block).encode('hex')))
+            success = result is None
+        else:
+            result = yield bitcoind.rpc_submitblock(bitcoin_data.block_type.pack(block).encode('hex'))
+            success = result is None
     else:
         result = yield bitcoind.rpc_getmemorypool(bitcoin_data.block_type.pack(block).encode('hex'))
         success = result