Author

Topic: LevelDB and blockchain. (Read 180 times)

hero member
Activity: 1302
Merit: 561
Leading Crypto Sports Betting & Casino Platform
August 12, 2022, 01:46:58 AM
#4
Level DB is a database that works with no SQL which can be used to store data not only for Bitcoin any project can make use of it, as the database is leveled on choosing what key and value you want to store in the program or get from the database. A running Bitcoin node saves Bitcoin related data on block or chainstate directories, then the leveldb can be used to call those files saved in the directory. For instance we can retrieve a bunch of key values from the blocks index using one operation.  

Code:
const level = require('level')
const db = level('my-db')

const ops = [
  { type: 'get', key: 'block' },
  { type: 'get', key: 'b'+32, value: 'byte block hash' },
  { type: 'get', key: 'F+4', value: 'byte file number' },
  { type: 'get', key: 'I-4', value: 'byte file number' },
  { type: 'get', key: 't+32', value: 'byte transaction hash' }
]

db.batch(ops, function (err) {
  if (err){
     return console.log(err)
  }
  console.log('Great success')
})
We have an ops array with a bunch of objects to define the operations.

The type is the type of the operation we want to do. They are the same as the method names.

The key is needed for getting the items to delete.

And the value is what we insert as the value of the key

Other additional functions include;

Get- get a key from the database
Put- put a value from the database
Del - delete a key in the current range
L.S- get all the keys in the current range
Start - defines the start of the current range
End - denfine the end of the current range


This will help you get to know leveldb better

https://bitcoindev.network/understanding-the-data/amp/

https://thewebdev.info/2020/09/21/node-js-basics%E2%80%8A-%E2%80%8Alevel-db/

https://imil.net/blog/posts/2020/bitcoin-leveldb-debugging/
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
August 10, 2022, 04:32:06 AM
#3
LevelDB itself is not in blockchain. If not so, feel free to shoot it down in flames.

While the database itself isn't serialized inside the blockchain, we know that the blockchain consists of blocks, the data of which is stored inside levelDB databases.

So the entirety of all the blocks is stored in the blockchain, but as @pooya87 said, a storage medium is needed for all those blocks, and so that's where LevelDB comes in.
legendary
Activity: 3472
Merit: 10611
August 10, 2022, 03:38:14 AM
#2
it is  solely the responsibility of every node to hold up levelDB of bitcoin feeding it up and  renewing with  the data obtained from other nodes.
The responsibility of a full node is to download and verify all the blocks from the start until the last one while enforcing consensus rules. What database that node uses to store the blockchain and the related data is not important at all. In other words LevelDB is just one of many possible key-value stores that could be used to store the bitcoin related data such as the chainstate.
hero member
Activity: 714
Merit: 1298
August 10, 2022, 03:27:41 AM
#1
Hi to all. I'm relatively new to bitcoin technicalities and in my understanding it is  solely the responsibility of every node to hold up levelDB of bitcoin feeding it up and  renewing with  the data obtained from other nodes. LevelDB itself is not in blockchain. If not so, feel free to shoot it down in flames.
Jump to: