Electroneum
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
db_lmdb.cpp File Reference
#include "db_lmdb.h"
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <memory>
#include <cstring>
#include "string_tools.h"
#include "file_io_utils.h"
#include "common/util.h"
#include "common/pruning.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "crypto/crypto.h"
#include "profile_tools.h"
#include "ringct/rctOps.h"
Include dependency graph for db_lmdb.cpp:

Classes

struct  anonymous_namespace{db_lmdb.cpp}::pre_rct_output_data_t
 
struct  anonymous_namespace{db_lmdb.cpp}::MDB_val_copy< T >
 
struct  anonymous_namespace{db_lmdb.cpp}::MDB_val_copy< cryptonote::blobdata >
 
struct  anonymous_namespace{db_lmdb.cpp}::MDB_val_copy< const char * >
 
struct  cryptonote::mdb_block_info_1
 
struct  cryptonote::mdb_block_info_2
 
struct  cryptonote::mdb_block_info_3
 
struct  cryptonote::mdb_block_info_4
 
struct  cryptonote::blk_height
 
struct  cryptonote::pre_rct_outkey
 
struct  cryptonote::outkey
 
struct  cryptonote::outtx
 

Namespaces

 anonymous_namespace{db_lmdb.cpp}
 
 cryptonote
 Holds cryptonote related classes and helpers.
 

Macros

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"
 
#define VERSION   5
 
#define MDB_val_set(var, val)   MDB_val var = {sizeof(val), (void *)&val}
 
#define MDB_val_sized(var, val)   MDB_val var = {val.size(), (void *)val.data()}
 
#define MDB_val_str(var, val)   MDB_val var = {strlen(val) + 1, (void *)val}
 
#define CURSOR(name)
 
#define RCURSOR(name)
 
#define TXN_PREFIX(flags)
 
#define TXN_PREFIX_RDONLY()
 
#define TXN_POSTFIX_RDONLY()
 
#define TXN_POSTFIX_SUCCESS()
 
#define TXN_BLOCK_PREFIX(flags)
 
#define TXN_BLOCK_POSTFIX_SUCCESS()
 
#define RENAME_DB(name)
 
#define LOGIF(y)   if (ELPP->vRegistry()->allowed(y, "global"))
 
#define DELETE_DB(x)
 

Typedefs

typedef struct cryptonote::mdb_block_info_1 cryptonote::mdb_block_info_1
 
typedef struct cryptonote::mdb_block_info_2 cryptonote::mdb_block_info_2
 
typedef struct cryptonote::mdb_block_info_3 cryptonote::mdb_block_info_3
 
typedef struct cryptonote::mdb_block_info_4 cryptonote::mdb_block_info_4
 
typedef mdb_block_info_4 cryptonote::mdb_block_info
 
typedef struct cryptonote::blk_height cryptonote::blk_height
 
typedef struct cryptonote::pre_rct_outkey cryptonote::pre_rct_outkey
 
typedef struct cryptonote::outkey cryptonote::outkey
 
typedef struct cryptonote::outtx cryptonote::outtx
 

Enumerations

enum  { cryptonote::prune_mode_prune , cryptonote::prune_mode_update , cryptonote::prune_mode_check }
 

Functions

template<typename T >
void anonymous_namespace{db_lmdb.cpp}::throw0 (const T &e)
 
template<typename T >
void anonymous_namespace{db_lmdb.cpp}::throw1 (const T &e)
 
const std::string anonymous_namespace{db_lmdb.cpp}::lmdb_error (const std::string &error_string, int mdb_res)
 
void anonymous_namespace{db_lmdb.cpp}::lmdb_db_open (MDB_txn *txn, const char *name, int flags, MDB_dbi &dbi, const std::string &error_string)
 
void cryptonote::lmdb_resized (MDB_env *env)
 
int cryptonote::lmdb_txn_begin (MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
 
int cryptonote::lmdb_txn_renew (MDB_txn *txn)
 
static bool cryptonote::is_v1_tx (MDB_cursor *c_txs_pruned, MDB_val *tx_id)
 

Variables

const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_BLOCKS = "blocks"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_BLOCK_HEIGHTS = "block_heights"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_BLOCK_INFO = "block_info"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXS = "txs"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXS_PRUNED = "txs_pruned"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXS_PRUNABLE = "txs_prunable"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXS_PRUNABLE_HASH = "txs_prunable_hash"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXS_PRUNABLE_TIP = "txs_prunable_tip"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TX_INDICES = "tx_indices"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TX_OUTPUTS = "tx_outputs"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_OUTPUT_TXS = "output_txs"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_OUTPUT_AMOUNTS = "output_amounts"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_SPENT_KEYS = "spent_keys"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXPOOL_META = "txpool_meta"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_TXPOOL_BLOB = "txpool_blob"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_HF_STARTING_HEIGHTS = "hf_starting_heights"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_HF_VERSIONS = "hf_versions"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_VALIDATORS = "validators"
 
const char *const anonymous_namespace{db_lmdb.cpp}::LMDB_PROPERTIES = "properties"
 
const char anonymous_namespace{db_lmdb.cpp}::zerokey [8] = {0}
 
const MDB_val anonymous_namespace{db_lmdb.cpp}::zerokval = { sizeof(zerokey), (void *)zerokey }
 

Macro Definition Documentation

◆ CURSOR

#define CURSOR (   name)
Value:
if (!m_cur_ ## name) { \
int result = mdb_cursor_open(*m_write_txn, m_ ## name, &m_cur_ ## name); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to open cursor: ", result).c_str())); \
}
const std::string lmdb_error(const std::string &error_string, int mdb_res)
Definition: db_lmdb.cpp:237
const char * name
Definition: simplewallet.cpp:400

◆ DELETE_DB

#define DELETE_DB (   x)
Value:
do { \
LOG_PRINT_L1(" " x ":"); \
result = mdb_txn_begin(m_env, NULL, 0, txn); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str())); \
result = mdb_dbi_open(txn, x, 0, &dbi); \
if (!result) { \
result = mdb_drop(txn, dbi, 1); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to delete " x ": ", result).c_str())); \
txn.commit(); \
} } while(0)

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"

◆ LOGIF

#define LOGIF (   y)    if (ELPP->vRegistry()->allowed(y, "global"))

◆ MDB_val_set

#define MDB_val_set (   var,
  val 
)    MDB_val var = {sizeof(val), (void *)&val}

◆ MDB_val_sized

#define MDB_val_sized (   var,
  val 
)    MDB_val var = {val.size(), (void *)val.data()}

◆ MDB_val_str

#define MDB_val_str (   var,
  val 
)    MDB_val var = {strlen(val) + 1, (void *)val}

◆ RCURSOR

#define RCURSOR (   name)
Value:
if (!m_cur_ ## name) { \
int result = mdb_cursor_open(m_txn, m_ ## name, (MDB_cursor **)&m_cur_ ## name); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to open cursor: ", result).c_str())); \
if (m_cursors != &m_wcursors) \
m_tinfo->m_ti_rflags.m_rf_ ## name = true; \
} else if (m_cursors != &m_wcursors && !m_tinfo->m_ti_rflags.m_rf_ ## name) { \
int result = mdb_cursor_renew(m_txn, m_cur_ ## name); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to renew cursor: ", result).c_str())); \
m_tinfo->m_ti_rflags.m_rf_ ## name = true; \
}

◆ RENAME_DB

#define RENAME_DB (   name)
Value:
do { \
char n2[] = name; \
MDB_dbi tdbi; \
n2[sizeof(n2)-2]--; \
/* play some games to put (name) on a writable page */ \
result = mdb_dbi_open(txn, n2, MDB_CREATE, &tdbi); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to create " + std::string(n2) + ": ", result).c_str())); \
result = mdb_drop(txn, tdbi, 1); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to delete " + std::string(n2) + ": ", result).c_str())); \
k.mv_data = (void *)name; \
k.mv_size = sizeof(name)-1; \
result = mdb_cursor_open(txn, 1, &c_cur); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for " name ": ", result).c_str())); \
result = mdb_cursor_get(c_cur, &k, NULL, MDB_SET_KEY); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to get DB record for " name ": ", result).c_str())); \
ptr = (char *)k.mv_data; \
ptr[sizeof(name)-2]++; } while(0)

◆ TXN_BLOCK_POSTFIX_SUCCESS

#define TXN_BLOCK_POSTFIX_SUCCESS ( )
Value:
do { \
if (! m_batch_active && ! m_write_txn) \
auto_txn.commit(); \
} while(0)

◆ TXN_BLOCK_PREFIX

#define TXN_BLOCK_PREFIX (   flags)
Value:
; \
mdb_txn_safe auto_txn; \
mdb_txn_safe* txn_ptr = &auto_txn; \
if (m_batch_active || m_write_txn) \
txn_ptr = m_write_txn; \
else \
{ \
if (auto mdb_res = lmdb_txn_begin(m_env, NULL, flags, auto_txn)) \
throw0(DB_ERROR(lmdb_error(std::string("Failed to create a transaction for the db in ")+__FUNCTION__+": ", mdb_res).c_str())); \
} \
int lmdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Definition: db_lmdb.cpp:481

◆ TXN_POSTFIX_RDONLY

#define TXN_POSTFIX_RDONLY ( )

◆ TXN_POSTFIX_SUCCESS

#define TXN_POSTFIX_SUCCESS ( )
Value:
do { \
if (! m_batch_active) \
auto_txn.commit(); \
} while(0)

◆ TXN_PREFIX

#define TXN_PREFIX (   flags)
Value:
; \
mdb_txn_safe auto_txn; \
mdb_txn_safe* txn_ptr = &auto_txn; \
if (m_batch_active) \
txn_ptr = m_write_txn; \
else \
{ \
if (auto mdb_res = lmdb_txn_begin(m_env, NULL, flags, auto_txn)) \
throw0(DB_ERROR(lmdb_error(std::string("Failed to create a transaction for the db in ")+__FUNCTION__+": ", mdb_res).c_str())); \
} \

◆ TXN_PREFIX_RDONLY

#define TXN_PREFIX_RDONLY ( )
Value:
MDB_txn *m_txn; \
mdb_txn_cursors *m_cursors; \
mdb_txn_safe auto_txn; \
bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors); \
if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get(); \
else auto_txn.uncheck()

◆ VERSION

#define VERSION   5