Skip to content

Allow transaction lookup by bare txid#79

Merged
galpHub merged 3 commits intoDiviProject:Developmentfrom
domob1812:baretxid-lookup
Apr 28, 2021
Merged

Allow transaction lookup by bare txid#79
galpHub merged 3 commits intoDiviProject:Developmentfrom
domob1812:baretxid-lookup

Conversation

@domob1812
Copy link
Copy Markdown

This extends GetTransaction (lookup of a transaction from disk) and GetWalletTx (lookup of a transaction in the wallet) to find transactions both by txid and bare txid. For this, we also extend the on-disk index created when -txindex is enabled.

This will be needed after segwit light, to look up previous transactions given a CTxIn prevout pointer. Note that this change by itself does not affect consensus. It only makes those lookups succeed in some cases that failed before, and all places that do lookups with GetTransaction in the consensus logic do that just as part of more checks (e.g. to access a previous transaction's output script) where other checks will fail accordingly before the fork.

This is #76 reopened after some changes made to the branches.

This was referenced Apr 14, 2021
This extends the two functions GetWalletTx and GetTransaction to (also)
find transactions by bare txid, not just by the normal txid.

These methods are mainly used in places where we need to look up e.g.
the previous transaction to a spend, so that we can know the address
that is being spent or the value of the input.

The change is fine to do (won't cause any extra consensus changes)
because all it does is make those methods return the correct previous
transaction (for after the fork) in cases where they would have
failed otherwise (since both are SHA-256d hashes and thus cannot have
collisions).  Also actual checks that some spent coin actually exists
are the explicitly on the consensus-level anyway.
When the transaction index is enabled (-txindex), this change also keeps
an index from bare txid to the disk position, so that lookups with the
index work on both normal txids and bare txids.

With this, the previous change made to GetTransaction will be improved
for enabled -txindex, and it will also allow us to look up any transaction
by bare txid, even if the fallbacks in GetTransaction fail.
This extends the txindex.py test, to check lookups also by bare txid
where this is possible (mempool and txindex).  Lookups by UTXO set only
work on whatever hash is used for the UTXO before/after segwit light.
@galpHub galpHub merged commit 2d26d98 into DiviProject:Development Apr 28, 2021
@domob1812 domob1812 deleted the baretxid-lookup branch April 28, 2021 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants