Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: schnuber on April 29, 2016, 09:45:29 PM



Title: How are referenced output scriptPubKey found in a very large blockchain
Post by: schnuber on April 29, 2016, 09:45:29 PM
Hi all

Imagine you made a tx that moves bitcoins that had been lying a very long time on the same address (let's say 10 years).
So in this tx, you have to reference this old transaction, which is done by declaring the hash of that tx (you can read that on the bitcoin wiki, topic: transaction).
To validate whether you have the right to claim those funds, the validating node has to retrieve the scriptPubKey of the referenced tx.
But how is this done? I wonder.
In 10 years the blockchain will have grown by over 1000GB (2MB Blocks assumed). So how does the validating node search for the referenced tx? Does it simply go backwards, searches every block? But how long would that take with 1000GB?

Sincerely


Title: Re: How are referenced output scriptPubKey found in a very large blockchain
Post by: shorena on April 29, 2016, 09:47:54 PM
Hi all

Imagine you made a tx that moves bitcoins that had been lying a very long time on the same address (let's say 10 years).
So in this tx, you have to reference this old transaction, which is done by declaring the hash of that tx (you can read that on the bitcoin wiki, topic: transaction).
To validate whether you have the right to claim those funds, the validating node has to retrieve the scriptPubKey of the referenced tx.
But how is this done? I wonder.
In 10 years the blockchain will have grown by over 1000GB (2MB Blocks assumed). So how does the validating node search for the referenced tx? Does it simply go backwards, searches every block? But how long would that take with 1000GB?

Sincerely

It keeps a record of all unspend transaction outputs (aka UTXO set).


Title: Re: How are referenced output scriptPubKey found in a very large blockchain
Post by: achow101 on April 29, 2016, 09:50:28 PM
It depends on the software implementation. A poorly written software will crawl though the entire blockchain and that will waste time and energy. Well written software keep their own databases of every single Unspent Transaction Output. This is much smaller and easier to search through. Once a UTXO is spent, it is removed from this database. This database is built from scanning all of the blocks as it receives them and updating this database when transactions are confirmed.


Title: Re: How are referenced output scriptPubKey found in a very large blockchain
Post by: schnuber on April 29, 2016, 09:52:23 PM
Ah, I recap just to make sure I understand correctly:
Every node has a local database where it indexes all unspent tx, correct?

greets


Title: Re: How are referenced output scriptPubKey found in a very large blockchain
Post by: achow101 on April 29, 2016, 09:54:45 PM
Ah, I recap just to make sure I understand correctly:
Every node has a local database where it indexes all unspent tx, correct?

greets
yes.


Title: Re: How are referenced output scriptPubKey found in a very large blockchain
Post by: danda on April 30, 2016, 08:03:16 PM
10 years?  satoshi is that you?  Getting ready to move some coins in 2019?   :-P