mirror of
https://github.com/jwinterm/wownero.git
synced 2026-12-03 12:14:01 +01:00
Merge pull request #911
d7b681c remove hf_starting_height db (moneromooo-monero)
This commit is contained in:
@@ -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__);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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__);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -419,10 +419,6 @@ int main(int argc, char* argv[])
|
||||
for (uint64_t h = 0; h < height; ++h)
|
||||
write_pod(d, boost::lexical_cast<std::string>(h), (unsigned int)db->get_hard_fork_version(h));
|
||||
end_compound(d);
|
||||
start_struct(d, "hf_starting_heights", true);
|
||||
for (unsigned int v = 0; v <= 255; ++v)
|
||||
write_pod(d, boost::lexical_cast<std::string>(v), db->get_hard_fork_starting_height(v));
|
||||
end_compound(d);
|
||||
}
|
||||
#endif
|
||||
end_compound(d);
|
||||
|
||||
@@ -137,10 +137,6 @@ bool HardFork::add(uint8_t block_version, uint8_t voting_version, uint64_t heigh
|
||||
|
||||
uint8_t voted = get_voted_fork_index(height + 1);
|
||||
if (voted > current_fork_index) {
|
||||
for (int v = heights[current_fork_index].version + 1; v <= heights[voted].version; ++v) {
|
||||
// we reached the vote threshold with this block, next one will be forked
|
||||
db.set_hard_fork_starting_height(v, height + 1);
|
||||
}
|
||||
current_fork_index = voted;
|
||||
}
|
||||
|
||||
@@ -172,7 +168,12 @@ void HardFork::init()
|
||||
else
|
||||
height = 1;
|
||||
|
||||
bool populate = db.get_hard_fork_starting_height(original_version) == std::numeric_limits<uint64_t>::max();
|
||||
bool populate = false;
|
||||
try
|
||||
{
|
||||
db.get_hard_fork_version(0);
|
||||
}
|
||||
catch (...) { populate = true; }
|
||||
if (populate) {
|
||||
LOG_PRINT_L0("The DB has no hard fork info, reparsing from start");
|
||||
height = 1;
|
||||
@@ -182,7 +183,6 @@ void HardFork::init()
|
||||
reorganize_from_chain_height(height);
|
||||
// reorg will not touch the genesis block, use this as a flag for populating done
|
||||
db.set_hard_fork_version(0, original_version);
|
||||
db.set_hard_fork_starting_height(original_version, 0);
|
||||
}
|
||||
else {
|
||||
rescan_from_chain_height(height);
|
||||
@@ -215,7 +215,6 @@ bool HardFork::reorganize_from_block_height(uint64_t height)
|
||||
const uint64_t rescan_height = height >= (window_size - 1) ? height - (window_size -1) : 0;
|
||||
const uint8_t start_version = height == 0 ? original_version : db.get_hard_fork_version(height);
|
||||
while (current_fork_index > 0 && heights[current_fork_index].version > start_version) {
|
||||
db.set_hard_fork_starting_height(heights[current_fork_index].version, std::numeric_limits<uint64_t>::max());
|
||||
--current_fork_index;
|
||||
}
|
||||
for (uint64_t h = rescan_height; h <= height; ++h) {
|
||||
@@ -227,10 +226,6 @@ bool HardFork::reorganize_from_block_height(uint64_t height)
|
||||
|
||||
uint8_t voted = get_voted_fork_index(height + 1);
|
||||
if (voted > current_fork_index) {
|
||||
for (int v = heights[current_fork_index].version + 1; v <= heights[voted].version; ++v) {
|
||||
// we reached the vote threshold with this block, next one will be forked
|
||||
db.set_hard_fork_starting_height(v, height + 1);
|
||||
}
|
||||
current_fork_index = voted;
|
||||
}
|
||||
|
||||
@@ -337,12 +332,6 @@ uint8_t HardFork::get(uint64_t height) const
|
||||
return db.get_hard_fork_version(height);
|
||||
}
|
||||
|
||||
uint64_t HardFork::get_start_height(uint8_t version) const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(lock);
|
||||
return db.get_hard_fork_starting_height(version);
|
||||
}
|
||||
|
||||
uint8_t HardFork::get_current_version() const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(lock);
|
||||
|
||||
@@ -154,13 +154,6 @@ namespace cryptonote
|
||||
*/
|
||||
uint8_t get(uint64_t height) const;
|
||||
|
||||
/**
|
||||
* @brief returns the height of the first block on the fork with th given version
|
||||
*
|
||||
* @param version version of the fork to query the starting block for
|
||||
*/
|
||||
uint64_t get_start_height(uint8_t version) const;
|
||||
|
||||
/**
|
||||
* @brief returns the latest "ideal" version
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user