aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-10-25 10:36:12 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-10-25 12:35:52 +0000
commit572780e335bdfc08b4f788826fc20c6c8aca4433 (patch)
tree83d723a6f1abec9a081a231b806f67b77ad6c657
parentMerge pull request #437 (diff)
downloadmonero-572780e335bdfc08b4f788826fc20c6c8aca4433.tar.xz
blockchain_db: use the DNE exceptions where appropriate
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp18
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp18
2 files changed, 19 insertions, 17 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index bd579ed38..06a87c39b 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -385,7 +385,7 @@ void BlockchainBDB::remove_tx_outputs(const crypto::hash& tx_hash, const transac
auto result = cur->get(&k, &v, DB_SET);
if (result == DB_NOTFOUND)
{
- throw0(DB_ERROR("Attempting to remove a tx's outputs, but none found."));
+ throw0(OUTPUT_DNE("Attempting to remove a tx's outputs, but none found."));
}
else if (result)
{
@@ -977,7 +977,7 @@ block BlockchainBDB::get_block_from_height(const uint64_t& height) const
auto get_result = m_blocks->get(DB_DEFAULT_TX, &key, &result, 0);
if (get_result == DB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get block from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get block from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a block from the db"));
@@ -1002,7 +1002,7 @@ uint64_t BlockchainBDB::get_block_timestamp(const uint64_t& height) const
auto get_result = m_block_timestamps->get(DB_DEFAULT_TX, &key, &result, 0);
if (get_result == DB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get timestamp from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- timestamp not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get timestamp from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- timestamp not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a timestamp from the db"));
@@ -1034,7 +1034,7 @@ size_t BlockchainBDB::get_block_size(const uint64_t& height) const
auto get_result = m_block_sizes->get(DB_DEFAULT_TX, &key, &result, 0);
if (get_result == DB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get block size from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get block size from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a block size from the db"));
@@ -1052,7 +1052,7 @@ difficulty_type BlockchainBDB::get_block_cumulative_difficulty(const uint64_t& h
auto get_result = m_block_diffs->get(DB_DEFAULT_TX, &key, &result, 0);
if (get_result == DB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get cumulative difficulty from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- difficulty not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get cumulative difficulty from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- difficulty not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a cumulative difficulty from the db"));
@@ -1087,7 +1087,7 @@ uint64_t BlockchainBDB::get_block_already_generated_coins(const uint64_t& height
auto get_result = m_block_coins->get(DB_DEFAULT_TX, &key, &result, 0);
if (get_result == DB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get generated coins from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get generated coins from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a total generated coins from the db"));
@@ -1319,7 +1319,7 @@ output_data_t BlockchainBDB::get_output_key(const uint64_t& global_index) const
Dbt_copy<output_data_t> v;
auto get_result = m_output_keys->get(DB_DEFAULT_TX, &k, &v, 0);
if (get_result == DB_NOTFOUND)
- throw0(DB_ERROR("Attempting to get output pubkey by global index, but key does not exist"));
+ throw1(OUTPUT_DNE("Attempting to get output pubkey by global index, but key does not exist"));
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve an output pubkey from the db"));
@@ -1908,7 +1908,9 @@ uint8_t BlockchainBDB::get_hard_fork_version(uint64_t height) const
Dbt_copy<uint8_t> result;
auto get_result = m_hf_versions->get(DB_DEFAULT_TX, &key, &result, 0);
- if (get_result == DB_NOTFOUND || get_result)
+ if (get_result == DB_NOTFOUND)
+ throw0(OUTPUT_DNE("Error attempting to retrieve hard fork version from the db"));
+ else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve hard fork version from the db"));
return result;
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 2695d83f8..fb853a7f4 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -747,7 +747,7 @@ void BlockchainLMDB::remove_output(const uint64_t& out_index, const uint64_t amo
auto result = mdb_del(*m_write_txn, m_output_gindices, &k, NULL);
if (result != 0 && result != MDB_NOTFOUND)
- throw1(DB_ERROR("Error adding removal of output global index to db transaction"));
+ throw1(OUTPUT_DNE("Error adding removal of output global index to db transaction"));
result = mdb_del(*m_write_txn, m_outputs, &v, NULL);
if (result != 0 && result != MDB_NOTFOUND)
@@ -1242,7 +1242,7 @@ block BlockchainLMDB::get_block_from_height(const uint64_t& height) const
auto get_result = mdb_get(txn, m_blocks, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get block from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get block from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a block from the db"));
@@ -1278,7 +1278,7 @@ uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height) const
auto get_result = mdb_get(*txn_ptr, m_block_timestamps, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get timestamp from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- timestamp not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get timestamp from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- timestamp not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a timestamp from the db"));
@@ -1322,7 +1322,7 @@ size_t BlockchainLMDB::get_block_size(const uint64_t& height) const
auto get_result = mdb_get(*txn_ptr, m_block_sizes, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get block size from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get block size from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a block size from the db"));
@@ -1351,7 +1351,7 @@ difficulty_type BlockchainLMDB::get_block_cumulative_difficulty(const uint64_t&
auto get_result = mdb_get(*txn_ptr, m_block_diffs, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get cumulative difficulty from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- difficulty not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get cumulative difficulty from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- difficulty not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a cumulative difficulty from the db"));
@@ -1398,7 +1398,7 @@ uint64_t BlockchainLMDB::get_block_already_generated_coins(const uint64_t& heigh
auto get_result = mdb_get(*txn_ptr, m_block_coins, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- throw0(DB_ERROR(std::string("Attempt to get generated coins from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
+ throw0(BLOCK_DNE(std::string("Attempt to get generated coins from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block size not in db").c_str()));
}
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve a total generated coins from the db"));
@@ -1696,7 +1696,7 @@ output_data_t BlockchainLMDB::get_output_key(const uint64_t &global_index) const
MDB_val v;
auto get_result = mdb_get(txn, m_output_keys, &k, &v);
if (get_result == MDB_NOTFOUND)
- throw0(DB_ERROR("Attempting to get output pubkey by global index, but key does not exist"));
+ throw1(OUTPUT_DNE("Attempting to get output pubkey by global index, but key does not exist"));
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve an output pubkey from the db"));
txn.commit();
@@ -2329,8 +2329,8 @@ void BlockchainLMDB::get_output_key(const uint64_t &amount, const std::vector<ui
MDB_val v;
auto get_result = mdb_get(*txn_ptr, m_output_keys, &k, &v);
- if (get_result != 0)
- throw0(DB_ERROR("Attempting to get output pubkey by global index, but key does not exist"));
+ if (get_result == MDB_NOTFOUND)
+ throw1(OUTPUT_DNE("Attempting to get output pubkey by global index, but key does not exist"));
else if (get_result)
throw0(DB_ERROR("Error attempting to retrieve an output pubkey from the db"));