Monero
Classes | Namespaces | Macros | Typedefs | Functions | Variables
db_lmdb.cpp File Reference
#include "db_lmdb.h"
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/current_function.hpp>
#include <memory>
#include <cstring>
#include <random>
#include "string_tools.h"
#include "file_io_utils.h"
#include "common/util.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_old
 
struct  cryptonote::mdb_block_info
 
struct  cryptonote::blk_height
 
struct  cryptonote::txindex
 
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 MONERO_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"
 
#define VERSION   3
 
#define MDB_val_set(var, val)   MDB_val var = {sizeof(val), (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_old cryptonote::mdb_block_info_old
 
typedef struct cryptonote::mdb_block_info cryptonote::mdb_block_info
 
typedef struct cryptonote::blk_height cryptonote::blk_height
 
typedef struct cryptonote::txindex cryptonote::txindex
 
typedef struct cryptonote::pre_rct_outkey cryptonote::pre_rct_outkey
 
typedef struct cryptonote::outkey cryptonote::outkey
 
typedef struct cryptonote::outtx cryptonote::outtx
 

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)
 
int anonymous_namespace{db_lmdb.cpp}::compare_uint64 (const MDB_val *a, const MDB_val *b)
 
int anonymous_namespace{db_lmdb.cpp}::compare_hash32 (const MDB_val *a, const MDB_val *b)
 
int anonymous_namespace{db_lmdb.cpp}::compare_string (const MDB_val *a, const MDB_val *b)
 
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)
 

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_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_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:215
const char * name
Definition: simplewallet.cpp:319

◆ 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)
const std::string lmdb_error(const std::string &error_string, int mdb_res)
Definition: db_lmdb.cpp:215

◆ 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}

◆ MONERO_DEFAULT_LOG_CATEGORY

#define MONERO_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"

◆ 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; \
}
const std::string lmdb_error(const std::string &error_string, int mdb_res)
Definition: db_lmdb.cpp:215
const char * name
Definition: simplewallet.cpp:319

◆ RENAME_DB

#define RENAME_DB (   name)
Value:
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]++
const std::string lmdb_error(const std::string &error_string, int mdb_res)
Definition: db_lmdb.cpp:215
const char * name
Definition: simplewallet.cpp:319

◆ 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:437
const std::string lmdb_error(const std::string &error_string, int mdb_res)
Definition: db_lmdb.cpp:215

◆ 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())); \
} \
int lmdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Definition: db_lmdb.cpp:437
const std::string lmdb_error(const std::string &error_string, int mdb_res)
Definition: db_lmdb.cpp:215

◆ 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   3