aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-07-13 21:19:05 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-07-13 21:38:34 +0100
commitd7b681cd6518834ce9b76676980561cb8e235cff (patch)
tree51ff9d28bb4be6e929fd3440613932dbb039900c /src/blockchain_db
parentMerge pull request #889 (diff)
downloadmonero-d7b681cd6518834ce9b76676980561cb8e235cff.tar.xz
remove hf_starting_height db
It's not really needed, it used to be an optimization for when that code was not using the db and needed to recalculate things fast on startup.
Diffstat (limited to 'src/blockchain_db')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp28
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h2
-rw-r--r--src/blockchain_db/blockchain_db.h21
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp76
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h2
5 files changed, 2 insertions, 127 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index b11570e37..4d759d157 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -2186,34 +2186,6 @@ std::map<uint64_t, uint64_t>::BlockchainBDB::get_output_histogram(const std::vec
throw1(DB_ERROR("Not implemented."));
}
-void BlockchainBDB::set_hard_fork_starting_height(uint8_t version, uint64_t height)
-{
- LOG_PRINT_L3("BlockchainBDB::" << __func__);
- check_open();
-
- Dbt_copy<uint32_t> val_key(version + 1);
- Dbt_copy<uint64_t> val(height);
- if (m_hf_starting_heights->put(DB_DEFAULT_TX, &val_key, &val, 0))
- throw1(DB_ERROR("Error adding hard fork starting height to db transaction."));
-}
-
-uint64_t BlockchainBDB::get_hard_fork_starting_height(uint8_t version) const
-{
- LOG_PRINT_L3("BlockchainBDB::" << __func__);
- check_open();
-
- Dbt_copy<uint32_t> key(version + 1);
- Dbt_copy<uint64_t> result;
-
- auto get_result = m_hf_starting_heights->get(DB_DEFAULT_TX, &key, &result, 0);
- if (get_result == DB_NOTFOUND || get_result == DB_KEYEMPTY)
- return std::numeric_limits<uint64_t>::max();
- else if (get_result)
- throw0(DB_ERROR("Error attempting to retrieve hard fork starting height from the db"));
-
- return result;
-}
-
void BlockchainBDB::check_hard_fork_info()
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index 5c6bda4eb..6bc26ed3d 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -385,8 +385,6 @@ private:
virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const;
// Hard fork related storage
- virtual void set_hard_fork_starting_height(uint8_t version, uint64_t height);
- virtual uint64_t get_hard_fork_starting_height(uint8_t version) const;
virtual void set_hard_fork_version(uint64_t height, uint8_t version);
virtual uint8_t get_hard_fork_version(uint64_t height) const;
virtual void check_hard_fork_info();
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 1445dd13c..ab5d2d44c 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -1274,27 +1274,6 @@ public:
// Hard fork related storage
//
- // FIXME: verify that this is all correct
- // - TW
- /**
- * @brief sets the height at which a hard fork has been voted to happen
- *
- *
- * @param version the version voted to fork to
- * @param height the height of the first block on the new fork
- */
- virtual void set_hard_fork_starting_height(uint8_t version, uint64_t height) = 0;
-
- /**
- * @brief gets the height at which a hard fork has been voted to happen
- *
- * @param version the version to check
- *
- * @return the height at which the hard fork was accepted, if it has been,
- * otherwise max(uint64_t)
- */
- virtual uint64_t get_hard_fork_starting_height(uint8_t version) const = 0;
-
/**
* @brief sets which hardfork version a height is on
*
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 8c51c09b1..9824d7376 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -117,13 +117,6 @@ int compare_uint64(const MDB_val *a, const MDB_val *b)
return (va < vb) ? -1 : va > vb;
}
-int compare_uint8(const MDB_val *a, const MDB_val *b)
-{
- const uint8_t va = *(const uint8_t*)a->mv_data;
- const uint8_t vb = *(const uint8_t*)b->mv_data;
- return va - vb;
-};
-
int compare_hash32(const MDB_val *a, const MDB_val *b)
{
uint32_t *va = (uint32_t*) a->mv_data;
@@ -1103,9 +1096,10 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
mdb_set_dupsort(txn, m_output_txs, compare_uint64);
mdb_set_dupsort(txn, m_block_info, compare_uint64);
- mdb_set_compare(txn, m_hf_starting_heights, compare_uint8);
mdb_set_compare(txn, m_properties, compare_string);
+ mdb_drop(txn, m_hf_starting_heights, 1);
+
// get and keep current height
MDB_stat db_stats;
if ((result = mdb_stat(txn, m_blocks, &db_stats)))
@@ -2638,29 +2632,6 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
void BlockchainLMDB::check_hard_fork_info()
{
- LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- check_open();
-
- TXN_PREFIX(0);
-
- MDB_stat db_stat1, db_stat2;
- if (mdb_stat(*txn_ptr, m_blocks, &db_stat1))
- throw0(DB_ERROR("Failed to query m_blocks"));
- if (mdb_stat(*txn_ptr, m_hf_versions, &db_stat2))
- throw0(DB_ERROR("Failed to query m_hf_starting_heights"));
- if (db_stat1.ms_entries != db_stat2.ms_entries)
- {
- // Empty, but don't delete. This allows this function to be called after
- // startup, after the subdbs have already been created, and rest of startup
- // can proceed. If these don't exist, hard fork's init() will fail.
- //
- // If these are empty, hard fork's init() will repopulate the hard fork
- // data.
- mdb_drop(*txn_ptr, m_hf_starting_heights, 0);
- mdb_drop(*txn_ptr, m_hf_versions, 0);
- }
-
- TXN_POSTFIX_SUCCESS();
}
void BlockchainLMDB::drop_hard_fork_info()
@@ -2676,49 +2647,6 @@ void BlockchainLMDB::drop_hard_fork_info()
TXN_POSTFIX_SUCCESS();
}
-void BlockchainLMDB::set_hard_fork_starting_height(uint8_t version, uint64_t height)
-{
- LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- check_open();
-
- TXN_BLOCK_PREFIX(0);
-
- MDB_val_copy<uint8_t> val_key(version);
- MDB_val_copy<uint64_t> val_value(height);
- if (auto result = mdb_put(*txn_ptr, m_hf_starting_heights, &val_key, &val_value, MDB_APPEND))
- throw1(DB_ERROR(lmdb_error("Error adding hard fork starting height to db transaction: ", result).c_str()));
-
- TXN_BLOCK_POSTFIX_SUCCESS();
-}
-
-uint64_t BlockchainLMDB::get_hard_fork_starting_height(uint8_t version) const
-{
- LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- check_open();
-
- TXN_PREFIX_RDONLY();
-
- MDB_val_copy<uint8_t> val_key(version);
- MDB_val val_ret;
- uint64_t ret = 0;
- auto result = mdb_get(m_txn, m_hf_starting_heights, &val_key, &val_ret);
- if (result == MDB_SUCCESS)
- {
-#ifdef MISALIGNED_OK
- ret = *(const uint64_t*)val_ret.mv_data;
-#else
- memcpy(&ret, val_ret.mv_data, sizeof(uint64_t));
-#endif
- } else if (result == MDB_NOTFOUND)
- {
- ret = std::numeric_limits<uint64_t>::max();
- } else if (result)
- throw0(DB_ERROR(lmdb_error("Error attempting to retrieve a hard fork starting height from the db", result).c_str()));
-
- TXN_POSTFIX_RDONLY();
- return ret;
-}
-
void BlockchainLMDB::set_hard_fork_version(uint64_t height, uint8_t version)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index c7121bf63..d7a78617e 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -307,8 +307,6 @@ private:
virtual void remove_spent_key(const crypto::key_image& k_image);
// Hard fork
- virtual void set_hard_fork_starting_height(uint8_t version, uint64_t height);
- virtual uint64_t get_hard_fork_starting_height(uint8_t version) const;
virtual void set_hard_fork_version(uint64_t height, uint8_t version);
virtual uint8_t get_hard_fork_version(uint64_t height) const;
virtual void check_hard_fork_info();