Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Hot answers tagged

54 votes
Accepted

What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?

Bitcoind since 0.8 maintains two databases, the block index (in $DATADIR/blocks/index) and the chainstate (in $DATADIR/chainstate). The block index maintains information for every block, and where it ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 2,692
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 ...
user avatar
8 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 ...
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) ...
user avatar
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 ...
user avatar
4 votes

What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?

OK I know I shouldn't really answer my own question but... in the absence of a response to this question, I did a bit of hunting. Github provided the answer in a file found in the bitcoin-leveldb ...
user avatar
  • 1,314
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 ...
user avatar
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 ...
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 ...
user avatar
  • 60.6k
4 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 ...
user avatar
  • 60.6k
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 ...
user avatar
  • 60.6k
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 ...
user avatar
  • 15k
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 ...
user avatar
  • 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 ...
user avatar
  • 1,583
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 60.6k
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 ...
user avatar
  • 11.3k
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:...
user avatar
  • 13.7k
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 ...
user avatar
  • 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 ...
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 ...
user avatar
  • 966
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: ...
user avatar
  • 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 (!...
user avatar
  • 28.6k
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 ...
user avatar
  • 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.
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 ...
user avatar
  • 17.2k
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 ...
user avatar

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