Skip to content

Commit

Permalink
Namecoin / AuxPoW: Avoid some copy operations in blockchain.deseriali…
Browse files Browse the repository at this point in the history
…ze_header.
  • Loading branch information
JeremyRand committed Jul 2, 2018
1 parent ae28d43 commit 80578e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/auxpow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ def auxpow_active(base_header):
def get_chain_id(base_header):
return base_header['version'] >> 16

def deserialize_auxpow_header(base_header, s, expect_trailing_data=False):
if len(s) == 0 and not expect_trailing_data:
def deserialize_auxpow_header(base_header, s, expect_trailing_data=False, start_position=0):
if len(s) - start_position == 0 and not expect_trailing_data:
return None

auxpow_header = {}

# Chain ID is the top 16 bits of the 32-bit version.
auxpow_header['chain_id'] = get_chain_id(base_header)

s = s[start_position:]

# The parent coinbase transaction is first.
# Deserialize it and save the trailing data.
parent_coinbase_tx = Transaction(None, expect_trailing_data=True, raw_bytes=s, expect_trailing_bytes=True, copy_input=False)
Expand Down
4 changes: 2 additions & 2 deletions lib/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def deserialize_header(s, height, expect_trailing_data=False, start_position=0):

if auxpow.auxpow_active(h):
if expect_trailing_data:
h['auxpow'], trailing_data = auxpow.deserialize_auxpow_header(h, s[start_position+80:], expect_trailing_data=True)
h['auxpow'], trailing_data = auxpow.deserialize_auxpow_header(h, s, expect_trailing_data=True, start_position=start_position+80)
else:
h['auxpow'] = auxpow.deserialize_auxpow_header(h, s[start_position+80:])
h['auxpow'] = auxpow.deserialize_auxpow_header(h, s, start_position=start_position+80)
else:
if expect_trailing_data:
trailing_data = s[start_position+80:]
Expand Down

0 comments on commit 80578e3

Please sign in to comment.