Let's say I am a new node.
I try to synch with the full node to grab the whole blockchain. Now, I synced with it .It's time for my node to create UTXO database ..
How does it do this exactly so that it knows which one to put in UTXO database ? since it will need to know which one is unspent. By looking at the blockchain, it can't quickly figure out which one is unspent for the following Reason: 1st height block contains output which has 5btc sent to me. I only spend this in the 400,000th block. This kind of thing happens for every other output. So how does bitcoin build UTXO in an effective way ?
It would also be great if there could be any code from bitcoind or something so i can take a look. Couldn't find it myself.