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

4

11

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

Hersh answered 13/8, 2020 at 9:7 Comment(0)
B
13

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.

Burdock answered 14/8, 2020 at 22:51 Comment(0)
K
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.

Koren answered 13/8, 2020 at 9:33 Comment(5)
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 ??Hersh
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.Koren
Please do not forget to mark correct answer and the question closedHinds
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.Woodard
yes, it is really interesting. What about newcomers such as Solana how do they store blockchain data?Tryptophan
S
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
Sanskritic answered 14/8, 2020 at 4:20 Comment(0)
T
-2

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

Tripalmitin answered 14/8, 2020 at 16:28 Comment(2)
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 ..Hersh
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!Tripalmitin

© 2022 - 2024 — McMap. All rights reserved.