Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where actual blockchain state data stored : in memory , in file or in database?

I have a query, where do blockchain data saved in every node. After a long search in google, StackOverflow, and some blogs, like got many answers: like: it saved in a database like level-DB or rocks-DB, some said it saves in memory in a variable, some said it saved in a file (from hyperledger-fabric).

I want to know, is there a particular method of storing blocks which are followed by most blockchain framework?

Or all those frameworks choose different methods (like file, memory, or DB).

I know there is a current state/world state of blockchain which is saved in a database. This current state/world state is totally different from actual blockchain. In the current state or world state, the data can be modified, but in actual blockchain block/data is immutable.

So to be concise, my question is:

How the data (immutable blocks) stored on the ledger of every full nodes in a Blockchain ? is it in Memory, in a file (like JSON, CSV file ), or in DB

like image 776
subhadip pahari Avatar asked Aug 13 '20 09:08

subhadip pahari


People also ask

Where is blockchain data actually stored?

Blockchain does not store any of its information in a central location. Instead, the blockchain is copied and spread across a network of computers. Whenever a new block is added to the blockchain, every computer on the network updates its blockchain to reflect the change.

How can blockchain be used as a database to store data?

Blockchains are used as a digital ledger to store transactional information. The data is stored as signed blocks, which link to each other, creating a chain of immutable interconnected data entries. To sign a new block, a node needs to find an SHA-256 signature that matches specific criteria.

What is actually stored on blockchain?

When an NFT is purchased, a record (code) is created, pointing to the location the NFT is stored on the blockchain. That record or code is then stored within a digital wallet. The most common digital wallet is MetaMask and NFTexplained.info has a full guide for setting this popular wallet up; that can be found here.


3 Answers

Bitcoin nodes keep raw block data on disk in files .bitcoin/blocks/blk*.dat. Size of each blknnnnnn.dat is 128MB, with the total size of data as of today ~300GB. Metadata about all known blocks is kept in Level DB files in .bitcoin/blocks/index/nnnnnn.ldb files.

like image 140
Yuri Ginsburg Avatar answered Oct 23 '22 17:10

Yuri Ginsburg


Blockchain is a distributed database. This means that data is scattered around the nodes (participating computers). Each node can decide how to store data (and if to store it at all).

When you are accessing the data, you are in fact sending messages to nodes on the network. In principle, you don't have to store any part of the blockchain on your computer if you only want to send transactions. The blockchain protocol guarantees that you can reconstruct the data from pieces of received information correctly and trustfully.

As for every node, the storage depends entirely on how the software was written and configured to run. For large blockchains such as Ethereum and Bitcoin, the entire blockchain data is in order of hundreds of gigabytes, so if you configure your software to store it locally the software will typically download a number of large files from other computers and store it on your disk. For some programs, authors might prefer to use a database over files. And in most cases, parts of the data will be kept in memory temporarily by OS cache and program's own data structures.

like image 30
jurez Avatar answered Oct 23 '22 18:10

jurez


It depends on the implementation of node client. Almost all of them use key-value storage for efficiency. To name a few specifically:

  • Bitcoin Core uses LevelDB
  • GoEthereum (a.k.a geth) uses LevelDB
  • Rippled (XRP client) can be configured to use either RocksDB or NuDB
like image 5
Atu Avatar answered Oct 23 '22 17:10

Atu