Hot answers tagged

23 votes
Accepted

How does Bitcoin read from/write to LevelDB

bitcoind uses leveldb to store its utxo database, which is also referred to as chainstate. This can be found in the Bitcoin data directory under chainstate/. UTXOs are identified by their txid (using ...
sr_gi's user avatar
  • 3,220
17 votes
Accepted

Migration from Berkeley DB to LevelDB

As someone who was involved in doing that migration at the time, I believe it was the right decision. LevelDB is far from perfect, but I wouldn't know what else to use. In particular: BDB is much ...
Pieter Wuille's user avatar
13 votes
Accepted

Why is Bitcoin Core using LevelDB instead of Redis or SQLite?

Redis and LevelDB solve very different problems. We tried using SQLite and its performance was abysmal. Bitcoin Core needs a database to store the set of unspent transaction outputs (UTXOs). This ...
Pieter Wuille's user avatar
7 votes
Accepted

Why does bitcoind use a fork of LevelDB for key-value storage?

The fork serves two purposes: Local modifications that are hard to bring upstream: Windows support (which is partially based on the existing Windows port, but needed changes for building in MinGW) ...
Pieter Wuille's user avatar
5 votes
Accepted

Bitcoind Node crashes after using -dbcache option

You are allocating far too much dbcache. If you allocate 4000 MB to the dbcache, you will use up all of your RAM and it will crash. Your operating system needs RAM, Bitcoin Core itself needs RAM ...
Ava Chow's user avatar
  • 70.1k
5 votes
Accepted

When the UTXO in the cache is full, what strategy is used to replace one UTXO with another in the cache?

The UTXO set cache is not a fixed size and the limit isn't a hard limit. New entries can be added to the cache without regards for the maximum cache size. In fact, the cache object itself doesn't even ...
Ava Chow's user avatar
  • 70.1k
4 votes
Accepted

How does the wallet know which outputs are available with LevelDB

The wallet is to a large extent separate from the rest of the node software. One of the reasons for this is because of the (slow) progress towards a working SPV mode. This means the wallet cannot ...
Pieter Wuille's user avatar
4 votes

Why was Bitcoin Core in need of a fork of LevelDB?

Sometimes LevelDB has bugs and those bugs sometimes are not fixed in a timely manner in the upstream LevelDB project. These bugs can be problematic for Bitcoin Core so a fork of LevelDB was created to ...
Ava Chow's user avatar
  • 70.1k
4 votes
Accepted

Format of a block key's contents in bitcoind's LevelDB?

This is the Bitcoin Core v0.15.1 source code snippet that defines the serialization of CDiskBlockIndex. The various fields are: A varint version number of the client who wrote the record (for future ...
Pieter Wuille's user avatar
4 votes
Accepted

Does the chainstate leveldb only contain "addresses" for P2PKH and P2SH?

Yes, Bitcoin Core does do some compression of standard output scripts in order to store the minimal amount of data needed. Anyway, would I be correct in assuming that you could only get an address ...
Ava Chow's user avatar
  • 70.1k
4 votes
Accepted

Number of transactions per blk.dat files

No. blk*.dat files are limited by actual size on disk, not number of transactions. Blocks are added to them until they reach a maximum size, not whether they exceed a block or transaction count. As ...
Ava Chow's user avatar
  • 70.1k
3 votes
Accepted

Why was Bitcoin Core in need of a fork of LevelDB?

There are two reasons for having the fork in the first place: Upstream LevelDB does not support Windows, and the branches that are available elsewhere don't support MinGW (which Bitcoin Core uses for ...
Pieter Wuille's user avatar
3 votes
Accepted

Chainstate LevelDB corruption after reading from the database

Plyvel has Snappy compression enabled by default. Have you tried disabling it when opening the database? # Open the LevelDB db = plyvel.DB(".bitcoin/chainstate", compression=None) With this code my ...
cpsola's user avatar
  • 1,548
3 votes
Accepted

CVarint serialization format

The CVarInt format is implemented in serialize.h As the comment is extensive, I'll just quote it here: Variable-length integers: bytes are a MSB base-128 encoding of the number. The high bit in ...
Pieter Wuille's user avatar
3 votes

Non-obfuscated chainstate data

There’s no way of easily disabling obfuscation, but you could build a version that sets the keys to zero, resulting in no change when the XOR is used. Generally it has no impact on anything, so it’s ...
Claris's user avatar
  • 15.4k
3 votes
Accepted

Bcoin - Database backend not found

This happens when your dependencies get twisted up, especially when bcoin has an update where leveldown gets upgraded. You should be good with a npm rebuild leveldown to fix the dependency tree, but ...
Bucko's user avatar
  • 183
3 votes
Accepted

What is in the Bitcoin Core LevelDB dbcache? Is it full records or metadata?

The Bitcoin Core documentation describes dbcache as the cache for the UTXO database. Wikipedia describes a cache as a: software component that stores data so that future requests for that data can be ...
Michael Folkson's user avatar
3 votes

Are the block headers kept in memory?

I think you are confusing what it means to store things "in memory". As you say, indeed, the block index DB and the chainstate DB are both levelDB databases stored on disk. However, while ...
meshcollider's user avatar
  • 11.8k
2 votes
Accepted

Resyncing bcoin brings up database version error

If you're running master, there was a recent migration that would cause this. you can run this to fix it: node migrate/chaindb2to3.js /path/to/chaindb.ldb That will take a very long time, but if ...
Thann's user avatar
  • 70
2 votes
Accepted

Trojans detected in ldb bitcoin database?

No, it's vandalism. Some virus signatures were uploaded to the blockchain as a prank: https://www.reddit.com/r/Bitcoin/comments/25otbt/someone_put_a_virus_signature_in_the_bitcoin/ It seems those are ...
Osias Jota's user avatar
2 votes

Bitcoin blockchain in mongodb

On the subject of why LevelDB is used, core developer Greg Maxwell stated the following to the ref: I think people are falling into a trap of thinking "It's a <database>, I know a <black ...
Roman Kiselenko's user avatar
2 votes
Accepted

How does bitcoind store blocks?

There is a lot of information available, just not consolidated. After searching for sometime, I found the best answer from this link. The format of each file is: 4 bytes: Magic bytes 4 bytes: ...
Jus12's user avatar
  • 1,365
2 votes
Accepted

Non-obfuscated chainstate data

To add on to eponymous's answer, to disable this, comment out this section of code: https://github.com/bitcoin/bitcoin/blob/50fae68d416b4b8ec4ca192923dfd5ae9ea42773/src/dbwrapper.cpp#L129-L139 if (!...
Nick ODell's user avatar
  • 29.4k
2 votes

EXCEPTION: 15dbwrapper_error

Your database is corrupted. This probably means the RPi overheated, or its storage is crappy. This is not unusual for RPi class hardware. To recover, you'll need to reindex.
Pieter Wuille's user avatar
2 votes
Accepted

How does Bitcoin use its communication protocol and its database model?

is it a great idea to use IPFS for blockchain communication? Bitcoin nodes form a P2P network, using TCP to communicate bitcoin-specific messages between one another. By using a self-defined ...
chytrik's user avatar
  • 18.1k
2 votes

How Does Bitcoin Core Client Keep Track of Longest Chain/Strongest PoW Chains?

You're looking for validation.h and its corresponding .cpp source file. You should start at CChainState::ActivateBestChain. This subroutine calls CChainState::ActivateBestChainStep which runs the ...
Jose Fonseca's user avatar
2 votes

Getting wrong version number of block from block index of Bitcoin Core

The version that you are deserializing is not the block version but rather the client version that wrote that entry to the database. In your case, a client version of 210000 means Bitcoin Core 0.21 ...
Ava Chow's user avatar
  • 70.1k
2 votes

When does chainstate get updated?

The chainstate gets updated every time a new block gets added to (or deleted from) the chain, so you should be seeing it changing for every new block. However, updates are only seen on disk when a ...
sr_gi's user avatar
  • 3,220
2 votes

Does Bitcoin Core write blockchain and chainstate data atomically?

Yes, yes, yes(*), and no. The blockchain-related on-disk data Bitcoin Core keeps generally fall into these three categories: The block data (flat blocks/blk?????.dat files with concatenated blocks). ...
Pieter Wuille's user avatar
1 vote

why is bitcoin leveldb separated in so many small pieces?

At the moment I try out creating my own leveldb I understand.. The chainstate folder itself is the entry point of the database; all the files within it are just the data. This is what the data looks ...
lzl124631x's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible