forked from LBRYCommunity/lbry-sdk
faster spend_utxo
This commit is contained in:
parent
c81c0d9480
commit
085ce1ff16
1 changed files with 9 additions and 14 deletions
|
@ -1327,27 +1327,22 @@ class BlockProcessor:
|
||||||
if cache_value:
|
if cache_value:
|
||||||
return cache_value
|
return cache_value
|
||||||
|
|
||||||
prefix = Prefixes.hashX_utxo.pack_partial_key(tx_hash[:4])
|
txin_num = self.db.transaction_num_mapping[tx_hash]
|
||||||
candidates = {db_key: hashX for db_key, hashX in self.db.db.iterator(prefix=prefix)}
|
hdb_key = Prefixes.hashX_utxo.pack_key(tx_hash[:4], txin_num, nout)
|
||||||
for hdb_key, hashX in candidates.items():
|
hashX = self.db.db.get(hdb_key)
|
||||||
key = Prefixes.hashX_utxo.unpack_key(hdb_key)
|
if hashX:
|
||||||
if len(candidates) > 1:
|
udb_key = Prefixes.utxo.pack_key(hashX, txin_num, nout)
|
||||||
hash = self.db.total_transactions[key.tx_num]
|
|
||||||
if hash != tx_hash:
|
|
||||||
assert hash is not None # Should always be found
|
|
||||||
continue
|
|
||||||
if key.nout != nout:
|
|
||||||
continue
|
|
||||||
udb_key = Prefixes.utxo.pack_key(hashX, key.tx_num, nout)
|
|
||||||
utxo_value_packed = self.db.db.get(udb_key)
|
utxo_value_packed = self.db.db.get(udb_key)
|
||||||
if utxo_value_packed is None:
|
if utxo_value_packed is None:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"%s:%s is not found in UTXO db for %s", hash_to_hex_str(tx_hash), nout, hash_to_hex_str(hashX)
|
"%s:%s is not found in UTXO db for %s", hash_to_hex_str(tx_hash), nout, hash_to_hex_str(hashX)
|
||||||
)
|
)
|
||||||
raise ChainError(f"{hash_to_hex_str(tx_hash)}:{nout} is not found in UTXO db for {hash_to_hex_str(hashX)}")
|
raise ChainError(
|
||||||
|
f"{hash_to_hex_str(tx_hash)}:{nout} is not found in UTXO db for {hash_to_hex_str(hashX)}"
|
||||||
|
)
|
||||||
# Remove both entries for this UTXO
|
# Remove both entries for this UTXO
|
||||||
self.touched_hashXs.add(hashX)
|
self.touched_hashXs.add(hashX)
|
||||||
self.db_op_stack.extend([
|
self.db_op_stack.extend_ops([
|
||||||
RevertableDelete(hdb_key, hashX),
|
RevertableDelete(hdb_key, hashX),
|
||||||
RevertableDelete(udb_key, utxo_value_packed)
|
RevertableDelete(udb_key, utxo_value_packed)
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in a new issue