track current block height and use it to calculate block subsidy when skipping ahead...
authorForrest Voight <forrest@forre.st>
Sun, 17 Jun 2012 03:32:39 +0000 (23:32 -0400)
committerForrest Voight <forrest@forre.st>
Sun, 17 Jun 2012 04:09:35 +0000 (00:09 -0400)
p2pool/bitcoin/networks.py
p2pool/main.py

index a0f9b53..d093c12 100644 (file)
@@ -16,6 +16,7 @@ nets = dict(
             'bitcoinaddress' in (yield bitcoind.rpc_help()) and
             not (yield bitcoind.rpc_getinfo())['testnet']
         )),
+        SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
         POW_FUNC=data.hash256,
         BLOCK_PERIOD=600, # s
         SYMBOL='BTC',
@@ -33,6 +34,7 @@ nets = dict(
             'bitcoinaddress' in (yield bitcoind.rpc_help()) and
             (yield bitcoind.rpc_getinfo())['testnet']
         )),
+        SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
         POW_FUNC=data.hash256,
         BLOCK_PERIOD=600, # s
         SYMBOL='tBTC',
@@ -51,6 +53,7 @@ nets = dict(
             'namecoinaddress' in (yield bitcoind.rpc_help()) and
             not (yield bitcoind.rpc_getinfo())['testnet']
         )),
+        SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
         POW_FUNC=data.hash256,
         BLOCK_PERIOD=600, # s
         SYMBOL='NMC',
@@ -68,6 +71,7 @@ nets = dict(
             'namecoinaddress' in (yield bitcoind.rpc_help()) and
             (yield bitcoind.rpc_getinfo())['testnet']
         )),
+        SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//210000,
         POW_FUNC=data.hash256,
         BLOCK_PERIOD=600, # s
         SYMBOL='tNMC',
@@ -86,6 +90,7 @@ nets = dict(
             'litecoinaddress' in (yield bitcoind.rpc_help()) and
             not (yield bitcoind.rpc_getinfo())['testnet']
         )),
+        SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
         BLOCK_PERIOD=150, # s
         SYMBOL='LTC',
@@ -103,6 +108,7 @@ nets = dict(
             'litecoinaddress' in (yield bitcoind.rpc_help()) and
             (yield bitcoind.rpc_getinfo())['testnet']
         )),
+        SUBSIDY_FUNC=lambda height: 50*100000000 >> (height + 1)//840000,
         POW_FUNC=lambda data: pack.IntType(256).unpack(__import__('ltc_scrypt').getPoWHash(data)),
         BLOCK_PERIOD=150, # s
         SYMBOL='tLTC',
index fc7f949..6dea291 100644 (file)
@@ -71,8 +71,17 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                 raise deferral.RetrySilentlyException()
             defer.returnValue(temp_work)
         temp_work = yield check()
+        
+        block_height_var = variable.Variable(None)
+        @defer.inlineCallbacks
+        def poll_height():
+            block_height_var.set((yield deferral.retry('Error while calling getblockcount:')(bitcoind.rpc_getblockcount)()))
+        yield poll_height()
+        task.LoopingCall(poll_height).start(60*60)
+        
         print '    ...success!'
         print '    Current block hash: %x' % (temp_work['previous_block_hash'],)
+        print '    Current block height: %i' % (block_height_var.value,)
         print
         
         # connect to bitcoind over bitcoin-p2p
@@ -253,7 +262,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                     time=best_block_header.value['timestamp'] + 600, # better way?
                     transactions=[],
                     merkle_link=bitcoin_data.calculate_merkle_link([0], 0),
-                    subsidy=5000000000, # XXX fix this
+                    subsidy=net.PARENT.SUBSIDY_FUNC(block_height_var.value),
                     clock_offset=current_work.value['clock_offset'],
                     last_update=current_work.value['last_update'],
                 )