Hot answers tagged

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 ...
17 votes
Accepted

How does Bitcoin read from/write to LevelDB

In the specific example you asked, it does so by querying the LevelDB located in ./bitcoin/chainstate (there is where the UTXO set is stored). UTXOs are identified by its txid (Little Endian ...
  • 2,722
12 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 ...
9 votes
Accepted

mysql instead of leveldb for bitcoin core

There is no code for that, and it would be either very slow or nearly useless. Bitcoin Core assumes it has exclusive access to the -database, and caches data very aggresively. It may take hours ...
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) ...
6 votes

How to access Bitcoin's transaction database?

The best way to write a parser of your own for the blockchain is to find the source code of one that already exists and from that deduce the precise underlying data structure and how to parse and ...
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 ...
  • 63.3k
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 ...
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 ...
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 ...
  • 63.3k
4 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 ...
  • 63.3k
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 ...
  • 63.3k
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 ...
  • 15.2k
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 ...
  • 173
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 ...
  • 1,573
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 ...
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 ...
3 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 ...
  • 63.3k
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 ...
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 ...
  • 11.5k
2 votes

Trying to understand how bitcore-node stores the data in the DB

Bitpay's bitcore-node project uses the same datadirectory as Bitcoin Core. You can see this in their sample configuration in their README: var configuration = { datadir: '~/.bitcoin', network:...
  • 13.8k
2 votes
Accepted

How does serializing in coins.h work?

(note: I'll be using a different bit numbering from the comment which goes from 0..B instead of 1..2^B, as I find that easier to read myself) The binary representation of 0x9 separated in functional ...
  • 311
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 ...
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 ...
  • 986
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: ...
  • 1,313
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 (!...
  • 28.9k
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 ...
  • 70
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.
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 ...
  • 17.5k
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 ...

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