Skip to content
This repository
Browse code

support for BIP 34 - version 2 blocks with height included in coinbase

  • Loading branch information...
commit a9fae5564f6c1ff9909c112a58df3c019b837377 1 parent 0988632
Forrest Voight authored August 08, 2012
3  p2pool/main.py
@@ -37,6 +37,8 @@ def getwork(bitcoind):
37 37
             raise deferral.RetrySilentlyException()
38 38
         raise
39 39
     packed_transactions = [x.decode('hex') for x in work['transactions']]
  40
+    if 'height' not in work:
  41
+        work['height'] = (yield bitcoind.rpc_getblock(work['previousblockhash']))['height'] + 1
40 42
     defer.returnValue(dict(
41 43
         previous_block=int(work['previousblockhash'], 16),
42 44
         transactions=map(bitcoin_data.tx_type.unpack, packed_transactions),
@@ -45,6 +47,7 @@ def getwork(bitcoind):
45 47
         time=work['time'],
46 48
         bits=bitcoin_data.FloatingIntegerType().unpack(work['bits'].decode('hex')[::-1]) if isinstance(work['bits'], (str, unicode)) else bitcoin_data.FloatingInteger(work['bits']),
47 49
         coinbaseflags=work['coinbaseflags'].decode('hex') if 'coinbaseflags' in work else ''.join(x.decode('hex') for x in work['coinbaseaux'].itervalues()) if 'coinbaseaux' in work else '',
  50
+        height=work['height'],
48 51
         clock_offset=time.time() - work['time'],
49 52
         last_update=time.time(),
50 53
     ))
13  p2pool/work.py
@@ -9,7 +9,7 @@
9 9
 from twisted.python import log
10 10
 
11 11
 import bitcoin.getwork as bitcoin_getwork, bitcoin.data as bitcoin_data
12  
-from bitcoin import worker_interface
  12
+from bitcoin import script, worker_interface
13 13
 from util import jsonrpc, variable, deferral, math, pack
14 14
 import p2pool, p2pool.data as p2pool_data
15 15
 
@@ -79,8 +79,7 @@ def _(new_merged_work):
79 79
         
80 80
         self.current_work = variable.Variable(None)
81 81
         def compute_work():
82  
-            t = dict(self.bitcoind_work.value)
83  
-            
  82
+            t = self.bitcoind_work.value
84 83
             bb = self.best_block_header.value
85 84
             if bb is not None and bb['previous_block'] == t['previous_block'] and net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(bb)) <= t['bits'].target:
86 85
                 print 'Skipping from block %x to block %x!' % (bb['previous_block'],
@@ -89,6 +88,7 @@ def compute_work():
89 88
                     previous_block=bitcoin_data.hash256(bitcoin_data.block_header_type.pack(bb)),
90 89
                     bits=bb['bits'], # not always true
91 90
                     coinbaseflags='',
  91
+                    height=t['height'] + 1,
92 92
                     time=bb['timestamp'] + 600, # better way?
93 93
                     transactions=[],
94 94
                     merkle_link=bitcoin_data.calculate_merkle_link([None], 0),
@@ -185,7 +185,10 @@ def get_work(self, pubkey_hash, desired_share_target, desired_pseudoshare_target
185 185
                 tracker=self.tracker,
186 186
                 share_data=dict(
187 187
                     previous_share_hash=self.best_share_var.value,
188  
-                    coinbase=(mm_data + self.current_work.value['coinbaseflags'])[:100],
  188
+                    coinbase=(script.create_push_script([
  189
+                        self.current_work.value['height'],
  190
+                        mm_data,
  191
+                    ]) + self.current_work.value['coinbaseflags'])[:100],
189 192
                     nonce=random.randrange(2**32),
190 193
                     pubkey_hash=pubkey_hash,
191 194
                     subsidy=self.current_work.value['subsidy'],
@@ -237,7 +240,7 @@ def get_work(self, pubkey_hash, desired_share_target, desired_pseudoshare_target
237 240
         bits = self.current_work.value['bits']
238 241
         previous_block = self.current_work.value['previous_block']
239 242
         ba = bitcoin_getwork.BlockAttempt(
240  
-            version=1,
  243
+            version=2,
241 244
             previous_block=self.current_work.value['previous_block'],
242 245
             merkle_root=merkle_root,
243 246
             timestamp=self.current_work.value['time'],

0 notes on commit a9fae55

Please sign in to comment.
Something went wrong with that request. Please try again.