10

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

subhadip pahari
  • 799
  • 1
  • 7
  • 16

4 Answers4

12

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.

Yuri Ginsburg
  • 2,302
  • 2
  • 13
  • 16
6

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jurez
  • 4,436
  • 2
  • 12
  • 20
  • 1
    Part of your comment "For large blockchains such as Ethereum and Bitcoin, the entire blockchain data is in order of hundreds of gigabytes" , then each full node (not lightweight nodes) saved the whole data locally . So where they save the enormous data ,in memory , db or file ?? – subhadip pahari Aug 13 '20 at 12:21
  • 1
    It's a design choice and up to the authors to decide. Some programs use plain files, some use databases, some use a mix. Memory is not persistent so in almost any case the disk is used for storing permanent data. – jurez Aug 13 '20 at 13:23
  • Please do not forget to mark correct answer and the question closed – Mikko Ohtamaa Aug 14 '20 at 13:21
  • Typically, Is all the data stored on all the nodes for, says, Bitcoin? Or parts of it on a bunch of nodes which can be strung together later to reconstruct the whole ? I ask because, as the blockchain keeps increasing in size, how are the nodes supposed to store all of it? It could run into multiple terabytes and beyond. – anotherDev Feb 05 '21 at 03:24
  • yes, it is really interesting. What about newcomers such as Solana how do they store blockchain data? – Pavel Fedotov Nov 23 '21 at 01:50
5

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
Atu
  • 917
  • 1
  • 11
  • 20
-2

It is stored in Ledgers. Now that ledger can adopt any NO-SQL tech-stack.

Spagar
  • 30
  • 1
  • as you state: "ledger can adopt any NO-SQL tech-stack.", do you know well-known blockchain applications uses which tech, like for bitcoin ? or ethereum ? or hyperledger-fabric? it will be helpful. I searched a lot but did not find the answer .. – subhadip pahari Aug 14 '20 at 18:54
  • okay so most of them use (key, value) pairs to store data. There is no restriction to the kind of data that can be stored. Generally the actual data is not directly stored in Blockchain but the computed hash values of it. Read about Merkle trees, it will clear a lot of things up! – Spagar Aug 15 '20 at 19:10