How does cardano "search" the blockchain

One question I have is around how Cardano searches, and then groups together unspent transactions efficiently. Say for instance I want to send 100 ADA. And i have 2 unspent transactions each of 50 ADA. Do validators simply search through the entire blockchain starting with the most recent to find those 2 transaction addresses to validate that I do in fact have 100 ADA to spend?

Validators don’t search anything, your wallet does, before submitting the transaction to mempool. The wallet is aware of all your available utxo’s and uses an algorithm to choose necessary ones. Different wallets may have slightly different algorithms. The concept is described here: Self Organisation in Coin Selection - IOHK Blog
Validators then pick the transaction from the mempool, check that it’s valid (utxo’s with such value exist and signed properly), and add it to a block.


Those coin selection algorithms, since native-tokens, do not apply anymore (though IOG has implemented some RandomImprove RoundRobin in Daedalus). Those algs were to eliminate dusts, which is not the case now as we have minUTxOADA (min ~1 ADA) for every transaction outputs, meaning we won’t have any (ADA) dust, but can have the theoretical max. 45bn UTxOs. But, for native tokens it’s quite complex. I had some idea for easily rewriting the original RandomImprove coin selection for native tokens for emurgo’s serialisation lib, but could not spare some time to implement it and make a PR for that.

To do the same with the LargestFirst is surprisingly much harder, un-intuitively, than the RI one.