Electroneum
blockchain_db.h File Reference
#include <string>
#include <exception>
#include <boost/program_options.hpp>
#include "common/command_line.h"
#include "crypto/hash.h"
#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/difficulty.h"
#include "cryptonote_basic/hardfork.h"
Include dependency graph for blockchain_db.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cryptonote::output_data_t
 a struct containing output metadata More...
 
struct  cryptonote::tx_data_t
 
struct  cryptonote::txpool_tx_meta_t
 a struct containing txpool per transaction metadata More...
 
struct  cryptonote::chainstate_key_t
 
struct  cryptonote::chainstate_value_t
 
struct  cryptonote::tx_input_t
 
class  cryptonote::DB_EXCEPTION
 A base class for BlockchainDB exceptions. More...
 
class  cryptonote::DB_ERROR
 A generic BlockchainDB exception. More...
 
class  cryptonote::DB_ERROR_TXN_START
 thrown when there is an error starting a DB transaction More...
 
class  cryptonote::DB_OPEN_FAILURE
 thrown when opening the BlockchainDB fails More...
 
class  cryptonote::DB_CREATE_FAILURE
 thrown when creating the BlockchainDB fails More...
 
class  cryptonote::DB_SYNC_FAILURE
 thrown when synchronizing the BlockchainDB to disk fails More...
 
class  cryptonote::BLOCK_DNE
 thrown when a requested block does not exist More...
 
class  cryptonote::BLOCK_PARENT_DNE
 thrown when a block's parent does not exist (and it needed to) More...
 
class  cryptonote::BLOCK_EXISTS
 thrown when a block exists, but shouldn't, namely when adding a block More...
 
class  cryptonote::BLOCK_INVALID
 thrown when something is wrong with the block to be added More...
 
class  cryptonote::TX_DNE
 thrown when a requested transaction does not exist More...
 
class  cryptonote::TX_EXISTS
 thrown when a transaction exists, but shouldn't, namely when adding a block More...
 
class  cryptonote::OUTPUT_DNE
 thrown when a requested output does not exist More...
 
class  cryptonote::OUTPUT_EXISTS
 thrown when an output exists, but shouldn't, namely when adding a block More...
 
class  cryptonote::KEY_IMAGE_EXISTS
 thrown when a spent key image exists, but shouldn't, namely when adding a block More...
 
class  cryptonote::UTXO_EXISTS
 thrown when a utxo already exists, but shouldn't, namely when adding a block More...
 
class  cryptonote::ADDR_OUTPUT_EXISTS
 thrown when an output record for an address already exists, but shouldn't, namely when adding a block More...
 
class  cryptonote::ADDR_TX_EXISTS
 
class  cryptonote::BlockchainDB
 The BlockchainDB backing store interface declaration/contract. More...
 
class  cryptonote::db_txn_guard
 
class  cryptonote::db_rtxn_guard
 
class  cryptonote::db_wtxn_guard
 

Namespaces

 cryptonote
 Holds cryptonote related classes and helpers.
 

Macros

#define DBF_SAFE   1
 
#define DBF_FAST   2
 
#define DBF_FASTEST   4
 
#define DBF_RDONLY   8
 
#define DBF_SALVAGE   0x10
 
#define DBF_ADDR_TX_SALVAGE   0x20
 

Typedefs

typedef std::pair< crypto::hash, uint64_tcryptonote::tx_out_index
 

Functions

BlockchainDB * cryptonote::new_db (const std::string &db_type)
 

Detailed Description

Cryptonote Blockchain Database Interface

The DB interface is a store for the canonical block chain. It serves as a persistent storage for the blockchain.

For the sake of efficiency, a concrete implementation may also store some blockchain data outside of the blocks, such as spent transfer key images, unspent transaction outputs, etc.

Examples are as follows:

Transactions are duplicated so that we don't have to fetch a whole block in order to fetch a transaction from that block.

Spent key images are duplicated outside of the blocks so it is quick to verify an output hasn't already been spent

Unspent transaction outputs are duplicated to quickly gather random outputs to use for mixins

Indices and Identifiers: The word "index" is used ambiguously throughout this code. It is particularly confusing when talking about the output or transaction tables since their indexing can refer to themselves or each other. I have attempted to clarify these usages here:

Blocks, transactions, and outputs are all identified by a hash. For storage efficiency, a 64-bit integer ID is used instead of the hash inside the DB. Tables exist to map between hash and ID. A block ID is also referred to as its "height". Transactions and outputs generally are not referred to by ID outside of this module, but the tx ID is returned by tx_exists() and used by get_tx_amount_output_indices(). Like their corresponding hashes, IDs are globally unique.

The remaining uses of the word "index" refer to local offsets, and are not globally unique. An "amount output index" N refers to the Nth output of a specific amount. An "output local index" N refers to the Nth output of a specific tx.

Exceptions: DB_ERROR – generic DB_OPEN_FAILURE DB_CREATE_FAILURE DB_SYNC_FAILURE BLOCK_DNE BLOCK_PARENT_DNE BLOCK_EXISTS BLOCK_INVALID – considering making this multiple errors TX_DNE TX_EXISTS OUTPUT_DNE OUTPUT_EXISTS KEY_IMAGE_EXISTS UTXO_EXISTS ADDR_OUTPUT_EXISTS ADDR_TX_EXISTS

Definition in file blockchain_db.h.

Macro Definition Documentation

◆ DBF_ADDR_TX_SALVAGE

#define DBF_ADDR_TX_SALVAGE   0x20

Definition at line 192 of file blockchain_db.h.

◆ DBF_FAST

#define DBF_FAST   2

Definition at line 188 of file blockchain_db.h.

◆ DBF_FASTEST

#define DBF_FASTEST   4

Definition at line 189 of file blockchain_db.h.

◆ DBF_RDONLY

#define DBF_RDONLY   8

Definition at line 190 of file blockchain_db.h.

◆ DBF_SAFE

#define DBF_SAFE   1

Definition at line 187 of file blockchain_db.h.

◆ DBF_SALVAGE

#define DBF_SALVAGE   0x10

Definition at line 191 of file blockchain_db.h.