Difference between revisions of "Libbitcoin Blockchain"

From Bitcoin Wiki
Jump to: navigation, search
m (Dependencies (Version3): change libbitcoin to libbitcoin-system)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
The [https://github.com/libbitcoin/libbitcoin-blockchain libbitcoin-blockchain] library is a dependency of [[Libbitcoin_Node|libbitcoin-node]] and [[Libbitcoin_Server|libbitcoin-server]]. It was originally contained within [[Libbitcoin_Common|libbitcoin]].
+
The [https://github.com/libbitcoin/libbitcoin-blockchain libbitcoin-blockchain] library is a dependency of [[Libbitcoin_Node|libbitcoin-node]] and [[Libbitcoin_Server|libbitcoin-server]]. The library provides transaction and block validation as well as transaction (memory) and block (orphan) pools.
 
 
==Example==
 
#include <string>
 
#include <bitcoin/blockchain.hpp>
 
 
// Initialize the blockchain.
 
int main(int argc, char* argv[])
 
{
 
    std::string prefix("blockchain");
 
   
 
    if (argc > 1)
 
        prefix = argv[1];
 
       
 
    bc::chain::initialize_blockchain(prefix);
 
    bc::chain::db_paths paths(prefix);
 
   
 
    constexpr size_t history_height = 0;
 
    bc::chain::db_interface interface(paths, { history_height });
 
    interface.start();
 
    const auto genesis = bc::genesis_block();
 
    interface.push(genesis);
 
   
 
    return 0;
 
}
 
 
 
==Design==
 
The original implementation used [http://leveldb.org LevelDB]. Following a redesign in late 2014 by [[Amir_Taaki|Amir Taaki]] (genjix) the database was replaced by a memory-mapped I/O implementation. Logical queries are performed using a set of hash tables. The number of hash buckets is optimized to minimize hash collisions, though collisions are accommodated. These changes resulted in a substantial performance increase, near constant time, for queries against the blockchain. Insert performance was not materially affected.
 
 
 
[[Image:Libbitcoin-blockchain-gets.png|500px]] [[Image:Libbitcoin-blockchain-gets-normalised.png|500px]]
 
 
 
==Database==
 
The following files constitute the blockchain database non-volatile storage. As of height 350,000 the database consumes approximately 105 GB of disk space.
 
* blocks_lookup
 
* blocks_rows
 
* history_lookup
 
* history_rows
 
* spends
 
* stealth_index
 
* stealth_rows
 
* txs
 
  
 
==Consensus Validation==
 
==Consensus Validation==
By default the library depends on the [[Libbitcoin_Consensus|libbitcoin-consensus]] library. This ensures that consensus checks are identical to those implemented by [[Bitcoind|bitcoind]]. By building using the ''--without-consensus'' flag the dependency is avoided and [[Libbitcoin|libbitcoin]] native consensus checks are used instead.
+
By default the library depends on the [[Libbitcoin_Consensus|libbitcoin-consensus]] library and its use can be selected by run time configuration. This ensures that consensus checks are identical to those implemented by [[Bitcoind|bitcoind]]. By building using the ''--without-consensus'' flag the dependency is avoided and [[Libbitcoin|libbitcoin]] native consensus checks are used instead.
  
==Considerations==
+
==History==
* There is no mechanical hard drive optimization. The implementation is intended for solid state drives ([http://en.wikipedia.org/wiki/Solid-state_drive SSD]).
+
* The blockchain was originally contained within [[Libbitcoin_Common|libbitcoin]] and contained [[Libbitcoin_Database|libbitcoin-database]].
* There is a possibility of index corruption during hard shutdown. There is no means of detecting corruption aside from catastrophic fault. However given that the entire blockchain is a cache this is not considered significant. Repair can be accomplished by re-synchronizing the blockchain.
 
* Data files are append only, with logical deletions only. Therefore file size is not minimized following blockchain reorganization although the impact is typically small. Defragmentation can be accomplished by re-synchronizing the blockchain.
 
* The database is effectively locked during write operations. As these operations are anticipated on a period of approximately ten minutes this is not typically significant. However during a period of catch-up synchronizing the server can become continuously unresponsive to requests.
 
  
==Dependencies==
+
==Dependencies (Version2)==
 
* [http://www.boost.org boost]
 
* [http://www.boost.org boost]
 
* [https://github.com/bitcoin/secp256k1 secp256k1]
 
* [https://github.com/bitcoin/secp256k1 secp256k1]
 
* [[Libbitcoin_Common|libbitcoin]]
 
* [[Libbitcoin_Common|libbitcoin]]
 +
* [[Libbitcoin_Consensus|libbitcoin-consensus (optional)]]
 +
 +
==Dependencies (Version3)==
 +
* [http://www.boost.org boost]
 +
* [https://github.com/bitcoin/secp256k1 secp256k1]
 +
* [[Libbitcoin_Common|libbitcoin-system]]
 +
* [[Libbitcoin_Database|libbitcoin-database]]
 
* [[Libbitcoin_Consensus|libbitcoin-consensus (optional)]]
 
* [[Libbitcoin_Consensus|libbitcoin-consensus (optional)]]
  

Latest revision as of 01:25, 9 March 2021

The libbitcoin-blockchain library is a dependency of libbitcoin-node and libbitcoin-server. The library provides transaction and block validation as well as transaction (memory) and block (orphan) pools.

Consensus Validation

By default the library depends on the libbitcoin-consensus library and its use can be selected by run time configuration. This ensures that consensus checks are identical to those implemented by bitcoind. By building using the --without-consensus flag the dependency is avoided and libbitcoin native consensus checks are used instead.

History

Dependencies (Version2)

Dependencies (Version3)

See Also

References