aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
Diffstat (limited to 'src/blockchain_db')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp2
-rw-r--r--src/blockchain_db/blockchain_db.h5
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp46
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h1
4 files changed, 35 insertions, 19 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index f540ce133..3a66ecb93 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -770,13 +770,13 @@ BlockchainBDB::~BlockchainBDB()
}
BlockchainBDB::BlockchainBDB(bool batch_transactions) :
+ BlockchainDB(),
m_buffer(DB_BUFFER_COUNT, DB_BUFFER_LENGTH)
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
// initialize folder to something "safe" just in case
// someone accidentally misuses this class...
m_folder = "thishsouldnotexistbecauseitisgibberish";
- m_open = false;
m_run_checkpoint = 0;
m_batch_transactions = batch_transactions;
m_write_txn = nullptr;
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 227169614..cce288793 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -538,6 +538,11 @@ protected:
public:
/**
+ * @brief An empty constructor.
+ */
+ BlockchainDB(): m_open(false) { }
+
+ /**
* @brief An empty destructor.
*/
virtual ~BlockchainDB() { };
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 6b81a4c90..bdec846d1 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -338,6 +338,12 @@ mdb_txn_safe::~mdb_txn_safe()
num_active_txns--;
}
+void mdb_txn_safe::uncheck()
+{
+ num_active_txns--;
+ m_check = false;
+}
+
void mdb_txn_safe::commit(std::string message)
{
if (message.size() == 0)
@@ -1074,13 +1080,12 @@ BlockchainLMDB::~BlockchainLMDB()
close();
}
-BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
+BlockchainLMDB::BlockchainLMDB(bool batch_transactions): BlockchainDB()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// initialize folder to something "safe" just in case
// someone accidentally misuses this class...
m_folder = "thishsouldnotexistbecauseitisgibberish";
- m_open = false;
m_batch_transactions = batch_transactions;
m_write_txn = nullptr;
@@ -1439,9 +1444,10 @@ void BlockchainLMDB::unlock()
#define TXN_PREFIX_RDONLY() \
MDB_txn *m_txn; \
mdb_txn_cursors *m_cursors; \
+ mdb_txn_safe auto_txn; \
bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors); \
- mdb_txn_safe auto_txn(my_rtxn); \
- if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get()
+ if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get(); \
+ else auto_txn.uncheck()
#define TXN_POSTFIX_RDONLY()
#define TXN_POSTFIX_SUCCESS() \
@@ -2434,7 +2440,7 @@ bool BlockchainLMDB::for_all_key_images(std::function<bool(const crypto::key_ima
RCURSOR(spent_keys);
MDB_val k, v;
- bool ret = true;
+ bool fret = true;
k = zerokval;
MDB_cursor_op op = MDB_FIRST;
@@ -2448,14 +2454,14 @@ bool BlockchainLMDB::for_all_key_images(std::function<bool(const crypto::key_ima
throw0(DB_ERROR("Failed to enumerate key images"));
const crypto::key_image k_image = *(const crypto::key_image*)v.mv_data;
if (!f(k_image)) {
- ret = false;
+ fret = false;
break;
}
}
TXN_POSTFIX_RDONLY();
- return ret;
+ return fret;
}
bool BlockchainLMDB::for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)> f) const
@@ -2468,7 +2474,7 @@ bool BlockchainLMDB::for_blocks_range(const uint64_t& h1, const uint64_t& h2, st
MDB_val k;
MDB_val v;
- bool ret = true;
+ bool fret = true;
MDB_cursor_op op;
if (h1)
@@ -2497,7 +2503,7 @@ bool BlockchainLMDB::for_blocks_range(const uint64_t& h1, const uint64_t& h2, st
if (!get_block_hash(b, hash))
throw0(DB_ERROR("Failed to get block hash from blob retrieved from the db"));
if (!f(height, hash, b)) {
- ret = false;
+ fret = false;
break;
}
if (height >= h2)
@@ -2506,7 +2512,7 @@ bool BlockchainLMDB::for_blocks_range(const uint64_t& h1, const uint64_t& h2, st
TXN_POSTFIX_RDONLY();
- return ret;
+ return fret;
}
bool BlockchainLMDB::for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)> f) const
@@ -2520,7 +2526,7 @@ bool BlockchainLMDB::for_all_transactions(std::function<bool(const crypto::hash&
MDB_val k;
MDB_val v;
- bool ret = true;
+ bool fret = true;
MDB_cursor_op op = MDB_FIRST;
while (1)
@@ -2547,14 +2553,14 @@ bool BlockchainLMDB::for_all_transactions(std::function<bool(const crypto::hash&
if (!parse_and_validate_tx_from_blob(bd, tx))
throw0(DB_ERROR("Failed to parse tx from blob retrieved from the db"));
if (!f(hash, tx)) {
- ret = false;
+ fret = false;
break;
}
}
TXN_POSTFIX_RDONLY();
- return ret;
+ return fret;
}
bool BlockchainLMDB::for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const
@@ -2567,7 +2573,7 @@ bool BlockchainLMDB::for_all_outputs(std::function<bool(uint64_t amount, const c
MDB_val k;
MDB_val v;
- bool ret = true;
+ bool fret = true;
MDB_cursor_op op = MDB_FIRST;
while (1)
@@ -2582,14 +2588,14 @@ bool BlockchainLMDB::for_all_outputs(std::function<bool(uint64_t amount, const c
outkey *ok = (outkey *)v.mv_data;
tx_out_index toi = get_output_tx_and_index_from_global(ok->output_id);
if (!f(amount, toi.first, toi.second)) {
- ret = false;
+ fret = false;
break;
}
}
TXN_POSTFIX_RDONLY();
- return ret;
+ return fret;
}
// batch_num_blocks: (optional) Used to check if resize needed before batch transaction starts.
@@ -3140,8 +3146,12 @@ void BlockchainLMDB::drop_hard_fork_info()
TXN_PREFIX(0);
- mdb_drop(*txn_ptr, m_hf_starting_heights, 1);
- mdb_drop(*txn_ptr, m_hf_versions, 1);
+ auto result = mdb_drop(*txn_ptr, m_hf_starting_heights, 1);
+ if (result)
+ throw1(DB_ERROR(lmdb_error("Error dropping hard fork starting heights db: ", result).c_str()));
+ result = mdb_drop(*txn_ptr, m_hf_versions, 1);
+ if (result)
+ throw1(DB_ERROR(lmdb_error("Error dropping hard fork versions db: ", result).c_str()));
TXN_POSTFIX_SUCCESS();
}
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index ceae2f084..1b76abf35 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -112,6 +112,7 @@ struct mdb_txn_safe
// BlockchainLMDB destructor to call mdb_txn_safe destructor, as that's too late
// to properly abort, since mdb_env_close would have been called earlier.
void abort();
+ void uncheck();
operator MDB_txn*()
{