Electroneum
Loading...
Searching...
No Matches
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:

Go to the source code of this file.

Classes

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
struct  cryptonote::acc_outs_t
struct  cryptonote::acc_addr_tx_t

Namespaces

namespace  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)
#define MDB_val_sized(var, val)
#define MDB_val_str(var, 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)
#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
typedef struct cryptonote::acc_outs_t cryptonote::acc_outs_t
typedef struct cryptonote::acc_addr_tx_t cryptonote::acc_addr_tx_t

Enumerations

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

Functions

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)
template<class t_pod_type>
std::string pod_to_hex (const t_pod_type &s)

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())); \
}
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.

Definition at line 285 of file db_lmdb.cpp.

285#define CURSOR(name) \
286 if (!m_cur_ ## name) { \
287 int result = mdb_cursor_open(*m_write_txn, m_ ## name, &m_cur_ ## name); \
288 if (result) \
289 throw0(DB_ERROR(lmdb_error("Failed to open cursor: ", result).c_str())); \
290 }

◆ 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)
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"

Definition at line 49 of file db_lmdb.cpp.

◆ LOGIF

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

Definition at line 4954 of file db_lmdb.cpp.

◆ MDB_val_set

#define MDB_val_set ( var,
val )
Value:
MDB_val var = {sizeof(val), (void *)&val}
Generic structure used for passing keys and data in and out of the database.
Definition lmdb.h:286

Definition at line 89 of file db_lmdb.cpp.

◆ MDB_val_sized

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

Definition at line 91 of file db_lmdb.cpp.

◆ MDB_val_str

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

Definition at line 93 of file db_lmdb.cpp.

◆ 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; \
}
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
struct MDB_cursor MDB_cursor
Opaque structure for navigating through a database.
Definition lmdb.h:273

Definition at line 292 of file db_lmdb.cpp.

292#define RCURSOR(name) \
293 if (!m_cur_ ## name) { \
294 int result = mdb_cursor_open(m_txn, m_ ## name, (MDB_cursor **)&m_cur_ ## name); \
295 if (result) \
296 throw0(DB_ERROR(lmdb_error("Failed to open cursor: ", result).c_str())); \
297 if (m_cursors != &m_wcursors) \
298 m_tinfo->m_ti_rflags.m_rf_ ## name = true; \
299 } else if (m_cursors != &m_wcursors && !m_tinfo->m_ti_rflags.m_rf_ ## name) { \
300 int result = mdb_cursor_renew(m_txn, m_cur_ ## name); \
301 if (result) \
302 throw0(DB_ERROR(lmdb_error("Failed to renew cursor: ", result).c_str())); \
303 m_tinfo->m_ti_rflags.m_rf_ ## name = true; \
304 }

◆ 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)
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
@ MDB_SET_KEY
Definition lmdb.h:423
#define MDB_CREATE
Definition lmdb.h:357
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition lmdb.h:270

Definition at line 4932 of file db_lmdb.cpp.

4932#define RENAME_DB(name) do { \
4933 char n2[] = name; \
4934 MDB_dbi tdbi; \
4935 n2[sizeof(n2)-2]--; \
4936 /* play some games to put (name) on a writable page */ \
4937 result = mdb_dbi_open(txn, n2, MDB_CREATE, &tdbi); \
4938 if (result) \
4939 throw0(DB_ERROR(lmdb_error("Failed to create " + std::string(n2) + ": ", result).c_str())); \
4940 result = mdb_drop(txn, tdbi, 1); \
4941 if (result) \
4942 throw0(DB_ERROR(lmdb_error("Failed to delete " + std::string(n2) + ": ", result).c_str())); \
4943 k.mv_data = (void *)name; \
4944 k.mv_size = sizeof(name)-1; \
4945 result = mdb_cursor_open(txn, 1, &c_cur); \
4946 if (result) \
4947 throw0(DB_ERROR(lmdb_error("Failed to open a cursor for " name ": ", result).c_str())); \
4948 result = mdb_cursor_get(c_cur, &k, NULL, MDB_SET_KEY); \
4949 if (result) \
4950 throw0(DB_ERROR(lmdb_error("Failed to get DB record for " name ": ", result).c_str())); \
4951 ptr = (char *)k.mv_data; \
4952 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)

Definition at line 1823 of file db_lmdb.cpp.

1823#define TXN_BLOCK_POSTFIX_SUCCESS() \
1824 do { \
1825 if (! m_batch_active && ! m_write_txn) \
1826 auto_txn.commit(); \
1827 } 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())); \
} \

Definition at line 1812 of file db_lmdb.cpp.

1812#define TXN_BLOCK_PREFIX(flags); \
1813 mdb_txn_safe auto_txn; \
1814 mdb_txn_safe* txn_ptr = &auto_txn; \
1815 if (m_batch_active || m_write_txn) \
1816 txn_ptr = m_write_txn; \
1817 else \
1818 { \
1819 if (auto mdb_res = lmdb_txn_begin(m_env, NULL, flags, auto_txn)) \
1820 throw0(DB_ERROR(lmdb_error(std::string("Failed to create a transaction for the db in ")+__FUNCTION__+": ", mdb_res).c_str())); \
1821 } \
1822

◆ TXN_POSTFIX_RDONLY

#define TXN_POSTFIX_RDONLY ( )

Definition at line 1795 of file db_lmdb.cpp.

◆ TXN_POSTFIX_SUCCESS

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

Definition at line 1797 of file db_lmdb.cpp.

1797#define TXN_POSTFIX_SUCCESS() \
1798 do { \
1799 if (! m_batch_active) \
1800 auto_txn.commit(); \
1801 } 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())); \
} \

Definition at line 1777 of file db_lmdb.cpp.

1777#define TXN_PREFIX(flags); \
1778 mdb_txn_safe auto_txn; \
1779 mdb_txn_safe* txn_ptr = &auto_txn; \
1780 if (m_batch_active) \
1781 txn_ptr = m_write_txn; \
1782 else \
1783 { \
1784 if (auto mdb_res = lmdb_txn_begin(m_env, NULL, flags, auto_txn)) \
1785 throw0(DB_ERROR(lmdb_error(std::string("Failed to create a transaction for the db in ")+__FUNCTION__+": ", mdb_res).c_str())); \
1786 } \
1787

◆ 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()
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
Definition lmdb.h:267

Definition at line 1788 of file db_lmdb.cpp.

1788#define TXN_PREFIX_RDONLY() \
1789 MDB_txn *m_txn; \
1790 mdb_txn_cursors *m_cursors; \
1791 mdb_txn_safe auto_txn; \
1792 bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors); \
1793 if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get(); \
1794 else auto_txn.uncheck()

◆ VERSION

#define VERSION   5

Definition at line 60 of file db_lmdb.cpp.

Function Documentation

◆ pod_to_hex()

template<class t_pod_type>
std::string epee::string_tools::pod_to_hex ( const t_pod_type & s)

Definition at line 317 of file string_tools.h.

318 {
319 static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
320 return to_hex::string(as_byte_span(s));
321 }
span< const std::uint8_t > as_byte_span(const T &src) noexcept
Definition span.h:153