Skip to content

Commit

Permalink
Merge pull request Beldex-Coin#129 from Tore-tto/dev
Browse files Browse the repository at this point in the history
Added Height for HF-18 in testnet
  • Loading branch information
sanada08 authored Nov 23, 2023
2 parents eceb9b6 + ef8e229 commit d4202db
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ library archives (`.a`).
| libzmq | 4.3.0 | YES | `libzmq3-dev` | `zeromq` | `zeromq-devel` | NO | ZeroMQ library |
| sqlite3 | ? | YES | `libsqlite3-dev` | `sqlite` | `sqlite-devel` | NO | Beldex Name System |
| libsodium | 1.0.9 | YES | `libsodium-dev` | `libsodium` | `libsodium-devel` | NO | cryptography |
| libcurl | 4.0 | NO | `libcurl4-dev` | `curl` | `curl-devel` | NO | HTTP RPC |
| libcurl | 4.0 | NO | `curl` | `curl-devel` | NO | HTTP | RPC |
| libuv (Win) | any | NO | (Windows only) | -- | -- | NO | RPC event loop |
| libunwind | any | NO | `libunwind8-dev` | `libunwind` | `libunwind-devel` | YES | Stack traces |
| liblzma | any | NO | `liblzma-dev` | `xz` | `xz-devel` | YES | For libunwind |
Expand Down
1 change: 1 addition & 0 deletions src/cryptonote_basic/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static constexpr std::array testnet_hard_forks =
hard_fork{12, 0, 104832, 1629012232 }, // Sunday, August 15, 2021 7:23:52 AM
hard_fork{15, 0, 169950, 1636391396 }, // Monday, November 8, 2021 5:09:56 PM
hard_fork{17, 0, 169960, 1636391696 }, // Monday, November 8, 2021 5:14:56 PM
hard_fork{18, 0, 1251330, 1701063000 }, // Monday, November 27, 2023 5:30:00 AM
};

static constexpr std::array devnet_hard_forks =
Expand Down
24 changes: 12 additions & 12 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,22 @@ uint64_t Blockchain::get_current_blockchain_height(bool lock) const
//------------------------------------------------------------------
bool Blockchain::load_missing_blocks_into_beldex_subsystems()
{
uint64_t const snl_height = std::max(hard_fork_begins(m_nettype, network_version_9_master_nodes).value_or(0), m_master_node_list.height() + 1);
uint64_t const mnl_height = std::max(hard_fork_begins(m_nettype, network_version_9_master_nodes).value_or(0), m_master_node_list.height() + 1);
uint64_t const bns_height = std::max(hard_fork_begins(m_nettype, network_version_18_bns).value_or(0), m_bns_db.height() + 1);
uint64_t const end_height = m_db->height();
uint64_t const start_height = std::min(end_height, std::min(bns_height, snl_height));

uint64_t const start_height = std::min(end_height, std::min(bns_height, mnl_height));
int64_t const total_blocks = static_cast<int64_t>(end_height) - static_cast<int64_t>(start_height);
if (total_blocks <= 0) return true;
if (total_blocks > 1)
MGINFO("Loading blocks into beldex subsystems, scanning blockchain from height: " << start_height << " to: " << end_height << " (snl: " << snl_height << ", bns: " << bns_height << ")");
MGINFO("Loading blocks into beldex subsystems, scanning blockchain from height: " << start_height << " to: " << end_height << " (mnl: " << mnl_height << ", bns: " << bns_height << ")");

using clock = std::chrono::steady_clock;
using work_time = std::chrono::duration<float>;
int64_t constexpr BLOCK_COUNT = 1000;
auto work_start = clock::now();
auto scan_start = work_start;
work_time bns_duration{}, snl_duration{}, bns_iteration_duration{}, snl_iteration_duration{};
work_time bns_duration{}, mnl_duration{}, bns_iteration_duration{}, mnl_iteration_duration{};

std::vector<cryptonote::block> blocks;
std::vector<cryptonote::transaction> txs;
Expand All @@ -330,7 +330,7 @@ bool Blockchain::load_missing_blocks_into_beldex_subsystems()
{
m_master_node_list.store();
auto duration = work_time{clock::now() - work_start};
MGINFO("... scanning height " << start_height + (index * BLOCK_COUNT) << " (" << duration.count() << "s) (snl: " << snl_iteration_duration.count() << "s; bns: " << bns_iteration_duration.count() << "s)");
MGINFO("... scanning height " << start_height + (index * BLOCK_COUNT) << " (" << duration.count() << "s) (mnl: " << mnl_iteration_duration.count() << "s; bns: " << bns_iteration_duration.count() << "s)");
#ifdef ENABLE_SYSTEMD
// Tell systemd that we're doing something so that it should let us continue starting up
// (giving us 120s until we have to send the next notification):
Expand All @@ -339,8 +339,8 @@ bool Blockchain::load_missing_blocks_into_beldex_subsystems()
work_start = clock::now();

bns_duration += bns_iteration_duration;
snl_duration += snl_iteration_duration;
bns_iteration_duration = snl_iteration_duration = {};
mnl_duration += mnl_iteration_duration;
bns_iteration_duration = mnl_iteration_duration = {};
}

blocks.clear();
Expand All @@ -363,9 +363,9 @@ bool Blockchain::load_missing_blocks_into_beldex_subsystems()
return false;
}

if (block_height >= snl_height)
if (block_height >= mnl_height)
{
auto snl_start = clock::now();
auto mnl_start = clock::now();

checkpoint_t *checkpoint_ptr = nullptr;
checkpoint_t checkpoint;
Expand All @@ -378,7 +378,7 @@ bool Blockchain::load_missing_blocks_into_beldex_subsystems()
MFATAL("Unable to process block {} for updating master node list: " << e.what());
return false;
}
snl_iteration_duration += clock::now() - snl_start;
mnl_iteration_duration += clock::now() - mnl_start;
}

if (m_bns_db.db && (block_height >= bns_height))
Expand All @@ -397,7 +397,7 @@ bool Blockchain::load_missing_blocks_into_beldex_subsystems()
if (total_blocks > 1)
{
auto duration = work_time{clock::now() - scan_start};
MGINFO("Done recalculating beldex subsystems (" << duration.count() << "s) (snl: " << snl_duration.count() << "s; bns: " << bns_duration.count() << "s)");
MGINFO("Done recalculating beldex subsystems (" << duration.count() << "s) (mnl: " << mnl_duration.count() << "s; bns: " << bns_duration.count() << "s)");
}

if (total_blocks > 0)
Expand Down
12 changes: 6 additions & 6 deletions src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ namespace cryptonote
// Returns the master nodes info
std::shared_ptr<const master_nodes::master_node_info> core::get_my_mn_info() const
{
auto& snl = get_master_node_list();
auto& mnl = get_master_node_list();
const auto& pubkey = get_master_keys().pub;
auto states = snl.get_master_node_list_state({ pubkey });
auto states = mnl.get_master_node_list_state({ pubkey });
if (states.empty())
return nullptr;
else
Expand All @@ -523,9 +523,9 @@ namespace cryptonote
s += "no";
else
{
auto& snl = get_master_node_list();
auto& mnl = get_master_node_list();
const auto& pubkey = get_master_keys().pub;
auto states = snl.get_master_node_list_state({ pubkey });
auto states = mnl.get_master_node_list_state({ pubkey });
if (states.empty())
s += "not registered";
else
Expand All @@ -539,7 +539,7 @@ namespace cryptonote
s += "decomm.";

uint64_t last_proof = 0;
snl.access_proof(pubkey, [&](auto& proof) { last_proof = proof.timestamp; });
mnl.access_proof(pubkey, [&](auto& proof) { last_proof = proof.timestamp; });
s += ", proof: ";
time_t now = std::time(nullptr);
s += time_ago_str(now, last_proof);
Expand Down Expand Up @@ -2393,7 +2393,7 @@ namespace cryptonote
m_master_node_vote_relayer.do_call([this] { return relay_master_node_votes(); });
m_check_disk_space_interval.do_call([this] { return check_disk_space(); });
m_block_rate_interval.do_call([this] { return check_block_rate(); });
m_mn_proof_cleanup_interval.do_call([&snl=m_master_node_list] { snl.cleanup_proofs(); return true; });
m_mn_proof_cleanup_interval.do_call([&mnl=m_master_node_list] { mnl.cleanup_proofs(); return true; });

std::chrono::seconds lifetime{time(nullptr) - get_start_time()};
if (m_master_node && lifetime > get_net_config().UPTIME_PROOF_STARTUP_DELAY) // Give us some time to connect to peers before sending uptimes
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/master_node_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3308,12 +3308,12 @@ namespace master_nodes
return result;
}

master_node_list::state_t::state_t(master_node_list* snl, state_serialized &&state)
master_node_list::state_t::state_t(master_node_list* mnl, state_serialized &&state)
: height{state.height}
, key_image_blacklist{std::move(state.key_image_blacklist)}
, only_loaded_quorums{state.only_stored_quorums}
, block_hash{state.block_hash}
, mn_list{snl}
, mn_list{mnl}
{
if (!mn_list)
throw std::logic_error("Cannot deserialize a state_t without a master_node_list");
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/master_node_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ namespace master_nodes
mutable quorum_manager quorums; // Mutable because we are allowed to (and need to) change it via std::set iterator
master_node_list* mn_list;

state_t(master_node_list* snl) : mn_list{snl} {}
state_t(master_node_list* snl, state_serialized &&state);
state_t(master_node_list* mnl) : mn_list{mnl} {}
state_t(master_node_list* mnl, state_serialized &&state);

friend bool operator<(const state_t &a, const state_t &b) { return a.height < b.height; }
friend bool operator<(const state_t &s, block_height h) { return s.height < h; }
Expand Down
8 changes: 4 additions & 4 deletions src/cryptonote_core/tx_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ static void check_args(flash_tx::subquorum q, int position, const char *func_nam
throw std::invalid_argument("Invalid voter position passed to " + std::string(func_name));
}

crypto::public_key flash_tx::get_mn_pubkey(subquorum q, int position, const master_node_list &snl) const {
crypto::public_key flash_tx::get_mn_pubkey(subquorum q, int position, const master_node_list &mnl) const {
check_args(q, position, __func__);
uint64_t qheight = quorum_height(q);
auto flash_quorum = snl.get_quorum(quorum_type::flash, qheight);
auto flash_quorum = mnl.get_quorum(quorum_type::flash, qheight);
if (!flash_quorum) {
// TODO FIXME XXX - we don't want a failure here; if this happens we need to go back into state
// history to retrieve the state info. (Or maybe this can't happen?)
Expand Down Expand Up @@ -86,8 +86,8 @@ bool flash_tx::add_signature(subquorum q, int position, bool approved, const cry
}


bool flash_tx::add_signature(subquorum q, int position, bool approved, const crypto::signature &sig, const master_node_list &snl) {
return add_signature(q, position, approved, sig, get_mn_pubkey(q, position, snl));
bool flash_tx::add_signature(subquorum q, int position, bool approved, const crypto::signature &sig, const master_node_list &mnl) {
return add_signature(q, position, approved, sig, get_mn_pubkey(q, position, mnl));
}

bool flash_tx::add_prechecked_signature(subquorum q, int position, bool approved, const crypto::signature &sig) {
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/tx_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class flash_tx {
* present; true if the signature was accepted and stored; and throws a
* `flash_tx::signature_verification_error` if the signature fails validation.
*/
bool add_signature(subquorum q, int position, bool approved, const crypto::signature &sig, const master_nodes::master_node_list &snl);
bool add_signature(subquorum q, int position, bool approved, const crypto::signature &sig, const master_nodes::master_node_list &mnl);

/**
* Adds a signature for the given quorum and position without checking it for validity (i.e.
Expand Down Expand Up @@ -162,7 +162,7 @@ class flash_tx {
uint64_t quorum_height(subquorum q) const { return quorum_height(height, q); }

/// Returns the pubkey of the referenced master node, or null if there is no such master node.
crypto::public_key get_mn_pubkey(subquorum q, int position, const master_nodes::master_node_list &snl) const;
crypto::public_key get_mn_pubkey(subquorum q, int position, const master_nodes::master_node_list &mnl) const;

/// Returns the hashed signing value for this flash TX for a tx with status `approved`. The
/// result is a fast hash of the height + tx hash + approval value. Lock not required.
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_protocol/quorumnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ std::enable_if_t<std::is_integral<I>::value, I> get_or(bt_dict &d, const std::st
// input quorum checksum matches the computed checksum for the quorums (if provided), otherwise sets
// the given output checksum (if provided) to the calculated value. Throws std::runtime_error on
// failure.
quorum_array get_flash_quorums(uint64_t flash_height, const master_node_list &snl, const uint64_t *input_checksum, uint64_t *output_checksum = nullptr) {
quorum_array get_flash_quorums(uint64_t flash_height, const master_node_list &mnl, const uint64_t *input_checksum, uint64_t *output_checksum = nullptr) {
// We currently just use two quorums, Q and Q' in the whitepaper, but this code is designed to
// work fine with more quorums (but don't use a single subquorum; that could only be secure or
// reliable but not both).
Expand All @@ -604,7 +604,7 @@ quorum_array get_flash_quorums(uint64_t flash_height, const master_node_list &sn
auto height = flash_tx::quorum_height(flash_height, static_cast<flash_tx::subquorum>(qi));
if (!height)
throw std::runtime_error("too early in blockchain to create a quorum");
result[qi] = snl.get_quorum(quorum_type::flash, height);
result[qi] = mnl.get_quorum(quorum_type::flash, height);
if (!result[qi])
throw std::runtime_error("failed to obtain a flash quorum");
auto &v = result[qi]->validators;
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8865,6 +8865,11 @@ std::vector<wallet2::pending_tx> wallet2::bns_create_buy_mapping_tx(bns::mapping
return {};
}

if (hf_version <= cryptonote::network_version_17_POS)
{
if (reason) *reason = ERR_MSG_BNS_HF_VERSION;
return {};
}
beldex_construct_tx_params tx_params = wallet2::construct_params(*hf_version, txtype::beldex_name_system, priority, 0, mapping_years);
auto result = create_transactions_2({} /*dests*/,
CRYPTONOTE_DEFAULT_TX_MIXIN,
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace tools
static const char *ERR_MSG_MASTER_NODE_LIST_QUERY_FAILED = tr("Failed to query daemon for master node list");
static const char *ERR_MSG_TOO_MANY_TXS_CONSTRUCTED = tr("Constructed too many transactions, please sweep_all first");
static const char *ERR_MSG_EXCEPTION_THROWN = tr("Exception thrown, staking process could not be completed: ");
static const char *ERR_MSG_BNS_HF_VERSION = tr("Bns buy option is not available in v17");

class ringdb;
class wallet2;
Expand Down

0 comments on commit d4202db

Please sign in to comment.