Bitcoin Forum
November 13, 2024, 03:58:22 AM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Are Blocks in blockchain are indexed ?  (Read 380 times)
r1s2g3 (OP)
Sr. Member
****
Offline Offline

Activity: 742
Merit: 395


I am alive but in hibernation.


View Profile
September 18, 2018, 02:54:45 AM
Merited by dbshck (2), NeuroticFish (1), ABCbits (1)
 #1

When we do a transaction then it is made sure that whatever we are going to send to receiver are unspent outputs (UTXO). It means it need to be scanned in entire blockchain that it is not spent.
But I see that transaction are validated within a seconds (or few seconds). Since blockchain size is now is 170 GB plus so it look to me quite a fast speed to traverse all blocks in blockchain.

I understand each block has address of the previous block  so do it have kind of index to reach that last block and we traverse all block one by one?

I am alive
ABCbits
Legendary
*
Offline Offline

Activity: 3052
Merit: 8081


Crypto Swap Exchange


View Profile
September 18, 2018, 04:04:30 AM
Last edit: September 18, 2018, 04:24:24 AM by ETFbitcoin
Merited by dbshck (5), NeuroticFish (1)
 #2

Bitcoin core (other client might do things differently) build and use UTXO database which stored on storage (not RAM) which makes transaction verification is faster. The UTXO database updated every time node receive transaction/block or create and broadcast transaction.
Besides, AFAIK most transaction can be verified in hundred millisecond.

There's no way any developer would think scan entire database just to get a data. Indexing, database balancing, sorting or/and separate database for linking obviously used in here.

If you're curious with UTXO size/count, you can check https://statoshi.info/dashboard/db/unspent-transaction-output-set

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
nc50lc
Legendary
*
Offline Offline

Activity: 2590
Merit: 6372


Self-proclaimed Genius


View Profile
September 18, 2018, 06:30:03 AM
Merited by dbshck (5), Welsh (2), ABCbits (1), LeGaulois (1)
 #3

-snip-
By saying "indexed" was it meant like index in books and file storage systems?
Then, by comparing the speed between (ex. not indexed Window Explorer) and Bitcoin's Blockchain, this question pops in to your mind?

Clients have a blockchain_headers which contains something similar (for indexing) that enables it to easily find the transaction hashes which have the accurate "links" to where the UTXOs are stored:
Code:
"inputs": [
        {
            "addresses": [
                "39EK***********************"
            ],
            "age": 513486,
            "output_index": 82,
            "output_value": 10000,
            "prev_hash": "24dc16f626085e7c75e6fbdbd2533f27d98d884fe73f58fed46a3e319157****",
            "script": "160014d0ef607e4dc338d4dd67df92e2090b770a781***",
            "script_type": "pay-to-script-hash",
            "sequence": 4294967293,
            "witness":
  • prev_hash: the previous transaction where it belongs.
  • output_index: where it sits between all of the other outputs of the particular transaction.

File explorers and Blockchain works differently, this is just "in-relation".

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Thirdspace
Hero Member
*****
Offline Offline

Activity: 1232
Merit: 738


Mixing reinvented for your privacy | chipmixer.com


View Profile
September 18, 2018, 10:36:25 PM
Merited by dbshck (5), r1s2g3 (1)
 #4

It means it need to be scanned in entire blockchain that it is not spent.
chainstate/*: this is a LevelDB database with a compact representation of all currently unspent transaction outputs and some metadata about the transactions they are from. The data here is necessary for validating new incoming blocks and transactions.
no it doesn't have to (re)scan the entire blockchain everytime,
wallet/node keeps track of current unspent transaction outputs in chainstate

I understand each block has address of the previous block  so do it have kind of index to reach that last block and we traverse all block one by one?
all databases always have indexes to make searching specific data faster
for bitcoin, metadata for blocks are stored under blocks/index/* directory
you can read more in details on bitcoin wiki Bitcoin Core 0.11 (ch 2): Data Storage

r1s2g3 (OP)
Sr. Member
****
Offline Offline

Activity: 742
Merit: 395


I am alive but in hibernation.


View Profile
September 19, 2018, 01:33:29 AM
 #5

There's no way any developer would think scan entire database just to get a data.


Then, by comparing the speed between (ex. not indexed Window Explorer) and Bitcoin's Blockchain, this question pops in to your mind?

I am a Performance DBA, I know even if the table size in a couple of GB and you have to do Full table scan to fetch the data ,required data cannot be fetched within the seconds . (Debarring parallel query operations).

you can read more in details on bitcoin wiki Bitcoin Core 0.11 (ch 2): Data Storage

That link perfectly satisfy my query.


Thanks  to you all. Slightly off topic question, I already gone through all the chapters of "Mastering Bitcoin" book and I do not remember if I have read anything about it.  Did I missed in reading or there are some other source/book from which I should start.

I am alive
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!