From 4c853dc76903954f85c9368be64a924f2d17303a Mon Sep 17 00:00:00 2001 From: Calin Culianu Date: Wed, 13 Nov 2019 12:39:03 +0200 Subject: [PATCH] Final nit on transaction.py calc_common_sighash We were taking the length of the two input/output arrays twice and all call paths used them at least once (if not twice), so why not just save the lengths to a local var for readability. --- lib/transaction.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/transaction.py b/lib/transaction.py index 0c841aada40e..2d853b1c9c5b 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -717,19 +717,20 @@ def calc_common_sighash(self, use_cache=False): afterwards, this cache will be wrong! """ inputs = self.inputs() outputs = self.outputs() + meta = (len(inputs), len(outputs)) if use_cache: try: - meta, res = self._cached_sighash_tup + cmeta, res = self._cached_sighash_tup except AttributeError: pass else: # minimal heuristic check to detect bad cached value - if meta == (len(inputs), len(outputs)): + if cmeta == meta: # cache hit and heuristic check ok return res else: - del meta, res, self._cached_sighash_tup + del cmeta, res, self._cached_sighash_tup hashPrevouts = Hash(bfh(''.join(self.serialize_outpoint(txin) for txin in inputs))) hashSequence = Hash(bfh(''.join(int_to_hex(txin.get('sequence', 0xffffffff - 1), 4) for txin in inputs))) @@ -738,7 +739,7 @@ def calc_common_sighash(self, use_cache=False): res = hashPrevouts, hashSequence, hashOutputs # cach resulting value, along with some minimal metadata to defensively # program against cache invalidation (due to class mutation). - self._cached_sighash_tup = (len(inputs), len(outputs)), res + self._cached_sighash_tup = meta, res return res def serialize_preimage(self, i, nHashType=0x00000041, use_cache = False):