kaspanet / rusty-kaspa

Kaspa full-node and related libraries in the Rust programming language. This is a Beta version at the final testing phases.
ISC License
350 stars 105 forks source link

Support determining return addresses for a given UTXO #435

Open coderofstuff opened 2 months ago

coderofstuff commented 2 months ago

Given a new UTXO, support a way to determine the UTXOs that were spent in order to create that UTXO. This is relevant for instance for determining return addresses for a UTXO.

Scenario

Challenge

The utxo outpoint id can be used to get the recent tx which created it (pending txindex pr #401), but that tx only holds the outpoints of the utxos it spent (which do not include the script-public-key/address info). The full utxo was recently known by the node, but this info seems supposedly lost. Note that the original tx might be old and thus pruned.

Solution

In order to be able to reorg the virtual chain, the node saves a full utxo diff from each chain block to its selected parent block. This means that daa score of the new utxo entry can be used to binary search chain blocks in that area and find the spent utxos contained in their persisted utxo diff structure

coderofstuff commented 2 months ago

As discussed with @aspect this needs to return only a single return address - the first one in the inputs. So response can just be Option<Address>