Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit a9fae5564f6c1ff9909c112a58df3c019b837377 1 parent 0988632
@forrestv authored
Showing with 11 additions and 5 deletions.
  1. +3 −0  p2pool/main.py
  2. +8 −5 p2pool/work.py
View
3  p2pool/main.py
@@ -37,6 +37,8 @@ def getwork(bitcoind):
raise deferral.RetrySilentlyException()
raise
packed_transactions = [x.decode('hex') for x in work['transactions']]
+ if 'height' not in work:
+ work['height'] = (yield bitcoind.rpc_getblock(work['previousblockhash']))['height'] + 1
defer.returnValue(dict(
previous_block=int(work['previousblockhash'], 16),
transactions=map(bitcoin_data.tx_type.unpack, packed_transactions),
@@ -45,6 +47,7 @@ def getwork(bitcoind):
time=work['time'],
bits=bitcoin_data.FloatingIntegerType().unpack(work['bits'].decode('hex')[::-1]) if isinstance(work['bits'], (str, unicode)) else bitcoin_data.FloatingInteger(work['bits']),
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 '',
+ height=work['height'],
clock_offset=time.time() - work['time'],
last_update=time.time(),
))
View
13 p2pool/work.py
@@ -9,7 +9,7 @@
from twisted.python import log
import bitcoin.getwork as bitcoin_getwork, bitcoin.data as bitcoin_data
-from bitcoin import worker_interface
+from bitcoin import script, worker_interface
from util import jsonrpc, variable, deferral, math, pack
import p2pool, p2pool.data as p2pool_data
@@ -79,8 +79,7 @@ def _(new_merged_work):
self.current_work = variable.Variable(None)
def compute_work():
- t = dict(self.bitcoind_work.value)
-
+ t = self.bitcoind_work.value
bb = self.best_block_header.value
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:
print 'Skipping from block %x to block %x!' % (bb['previous_block'],
@@ -89,6 +88,7 @@ def compute_work():
previous_block=bitcoin_data.hash256(bitcoin_data.block_header_type.pack(bb)),
bits=bb['bits'], # not always true
coinbaseflags='',
+ height=t['height'] + 1,
time=bb['timestamp'] + 600, # better way?
transactions=[],
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
tracker=self.tracker,
share_data=dict(
previous_share_hash=self.best_share_var.value,
- coinbase=(mm_data + self.current_work.value['coinbaseflags'])[:100],
+ coinbase=(script.create_push_script([
+ self.current_work.value['height'],
+ mm_data,
+ ]) + self.current_work.value['coinbaseflags'])[:100],
nonce=random.randrange(2**32),
pubkey_hash=pubkey_hash,
subsidy=self.current_work.value['subsidy'],
@@ -237,7 +240,7 @@ def get_work(self, pubkey_hash, desired_share_target, desired_pseudoshare_target
bits = self.current_work.value['bits']
previous_block = self.current_work.value['previous_block']
ba = bitcoin_getwork.BlockAttempt(
- version=1,
+ version=2,
previous_block=self.current_work.value['previous_block'],
merkle_root=merkle_root,
timestamp=self.current_work.value['time'],
Please sign in to comment.
Something went wrong with that request. Please try again.