Skip to content

Commit

Permalink
Namecoin / AuxPoW: optimize transaction deserialization in deserializ…
Browse files Browse the repository at this point in the history
…e_auxpow_header.
  • Loading branch information
JeremyRand committed Jul 1, 2018
1 parent 2d78e25 commit 92da917
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/auxpow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
import electrum_nmc.blockchain
from .bitcoin import hash_encode, hash_decode
from .crypto import Hash
from .transaction import BCDataStream, Transaction
from . import transaction
from .transaction import BCDataStream, Transaction, TYPE_SCRIPT
from .util import bfh, bh2u

BLOCK_VERSION_AUXPOW_BIT = 0x100
Expand Down Expand Up @@ -80,7 +81,7 @@ def deserialize_auxpow_header(base_header, s, expect_trailing_data=False):
# The parent coinbase transaction is first.
# Deserialize it and save the trailing data.
parent_coinbase_tx = Transaction(bh2u(s), expect_trailing_data=True)
parent_coinbase_tx_dict, s_hex = parent_coinbase_tx.deserialize()
parent_coinbase_tx_dict, s_hex = fast_tx_deserialize(parent_coinbase_tx)
auxpow_header['parent_coinbase_tx'] = parent_coinbase_tx
s = bfh(s_hex)

Expand Down Expand Up @@ -305,3 +306,18 @@ def hex_to_int(s):
def fast_txid(tx):
return bh2u(Hash(bfh(tx.raw))[::-1])

def fast_tx_deserialize(tx):
def stub(_bytes, *, net=None):
return TYPE_SCRIPT, bh2u(b'')

# Monkeypatch output address parsing with a stub, since we only care about
# inputs.
real_get_address_from_output_script = transaction.get_address_from_output_script
transaction.get_address_from_output_script = stub

result = tx.deserialize()

# Restore the real output address parser.
transaction.get_address_from_output_script = real_get_address_from_output_script

return result

0 comments on commit 92da917

Please sign in to comment.