Skip to content

Commit b213199

Browse files
Merge pull request #52 from Beldex-Coin/dev
Fixes in decommission and voting.
2 parents a6bfec3 + 8dc01d2 commit b213199

20 files changed

+984
-161
lines changed

.drone.yml

Lines changed: 749 additions & 0 deletions
Large diffs are not rendered by default.

src/cryptonote_basic/cryptonote_format_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ namespace cryptonote
647647
tx_extra_field field;
648648
if (hf_version < network_version_13_checkpointing)
649649
{
650+
650651
CHECK_AND_ASSERT_MES(state_change.state == master_nodes::new_state::deregister, false, "internal error: cannot construct an old deregistration for a non-deregistration state change (before hardfork v12)");
651652
field = tx_extra_master_node_deregister_old{state_change};
652653
}

src/cryptonote_core/master_node_quorum_cop.cpp

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ namespace master_nodes
317317
#ifndef BELDEX_ENABLE_INTEGRATION_TEST_HOOKS
318318
// NOTE: Wait at least 2 hours before we're allowed to vote so that we collect necessary
319319
// voting information from people on the network
320-
if (live_time < m_core.get_net_config().UPTIME_PROOF_VALIDITY)
321-
continue;
320+
if (live_time < m_core.get_net_config().UPTIME_PROOF_VALIDITY) {
321+
LOG_PRINT_L1("May not vote, this node needs to be online more time(>2hours) to be allowed to vote");
322+
continue;
323+
}
322324
#endif
323325

324326
if (!m_core.master_node())
@@ -356,23 +358,34 @@ namespace master_nodes
356358
const auto &node_key = worker_it->pubkey;
357359
const auto &info = *worker_it->info;
358360

359-
if (!info.can_be_voted_on(m_obligations_height))
361+
if (!info.can_be_voted_on(m_obligations_height)){
362+
LOG_PRINT_L2("process_quorums: Can not vote on:"); //TODO:VOTE
360363
continue;
364+
}
361365

362366
auto test_results = check_master_node(obligations_height_hf_version, node_key, info);
363367
bool passed = test_results.passed(hf_version==cryptonote::network_version_12_security_signature);
368+
LOG_PRINT_L2("process_quorums: check_master_node passed:");//TODO:VOTE
369+
LOG_PRINT_L3("NODE KEY:" << quorum->workers[node_index]);
364370

371+
int64_t credit = calculate_decommission_credit(info, latest_height,hf_version);
365372
new_state vote_for_state;
366373
uint16_t reason = 0;
367374
if (passed) {
368375
if (info.is_decommissioned()) {
369-
vote_for_state = new_state::recommission;
370-
LOG_PRINT_L2("Decommissioned master node " << quorum->workers[node_index] << " is now passing required checks; voting to recommission");
376+
if(credit>=0) {
377+
vote_for_state = new_state::recommission;
378+
LOG_PRINT_L2("process_quorums: passed and is_decommissioned credit>0 newstate:recommission node:" );
379+
}else{
380+
vote_for_state = new_state::deregister; // Credit ran out!
381+
LOG_PRINT_L2("process_quorums: passed and is_decommissioned credit 0 newstate:deregister node:" );
382+
}
383+
LOG_PRINT_L2("Decommissioned master node is now passing required checks; voting to recommission");
371384
} else if (!test_results.single_ip) {
372385
// Don't worry about this if the SN is getting recommissioned (above) -- it'll
373386
// already reenter at the bottom.
374387
vote_for_state = new_state::ip_change_penalty;
375-
LOG_PRINT_L2("Master node " << quorum->workers[node_index] << " was observed with multiple IPs recently; voting to reset reward position");
388+
LOG_PRINT_L2("Master node was observed with multiple IPs recently; voting to reset reward position");
376389
} else {
377390
good++;
378391
continue;
@@ -387,7 +400,7 @@ namespace master_nodes
387400
if (!test_results.belnet_reachable) reason |= cryptonote::Decommission_Reason::belnet_unreachable;
388401
if (!test_results.timestamp_participation) reason |= cryptonote::Decommission_Reason::timestamp_response_unreachable;
389402
if (!test_results.timesync_status) reason |= cryptonote::Decommission_Reason::timesync_status_out_of_sync;
390-
int64_t credit = calculate_decommission_credit(info, latest_height,hf_version);
403+
391404

392405
if (info.is_decommissioned()) {
393406
if (credit >= 0) {
@@ -459,6 +472,8 @@ namespace master_nodes
459472
LOG_PRINT_L0("Master Node is passing all local tests");
460473
LOG_PRINT_L0("(Note that some tests, such as storage server and belnet reachability, can only assessed by remote master nodes)");
461474
}
475+
}else{
476+
LOG_PRINT_L0("process_quorums: Cant be voted on my Master Node");
462477
}
463478
}
464479
}
@@ -534,27 +549,33 @@ namespace master_nodes
534549

535550
static bool handle_obligations_vote(cryptonote::core &core, const quorum_vote_t& vote, const std::vector<pool_vote_entry>& votes, const quorum& quorum)
536551
{
552+
LOG_PRINT_L2("start handle_obligations_vote");
537553
if (votes.size() < STATE_CHANGE_MIN_VOTES_TO_CHANGE_STATE)
538554
{
539555
LOG_PRINT_L2("Don't have enough votes yet to submit a state change transaction: have " << votes.size() << " of " << STATE_CHANGE_MIN_VOTES_TO_CHANGE_STATE << " required");
540556
return true;
541557
}
542-
558+
LOG_PRINT_L2("get_network_version");
543559
auto net = core.get_blockchain_storage().get_network_version();
544-
545560
// NOTE: Verify state change is still valid or have we processed some other state change already that makes it invalid
546561
{
547562
crypto::public_key const &master_node_pubkey = quorum.workers[vote.state_change.worker_index];
563+
LOG_PRINT_L2("get_master_node_list_state " << master_node_pubkey);
548564
auto master_node_infos = core.get_master_node_list_state({master_node_pubkey});
549-
if (!master_node_infos.size() ||
550-
!master_node_infos[0].info->can_transition_to_state(net, vote.block_height, vote.state_change.state))
565+
566+
if (master_node_infos.empty() ||
567+
!master_node_infos[0].info->can_transition_to_state(net, vote.block_height, vote.state_change.state)
568+
){
551569
// NOTE: Vote is valid but is invalidated because we cannot apply the change to a master node or it is not on the network anymore
552570
// So don't bother generating a state change tx.
571+
LOG_PRINT_L2("Vote is valid but is invalidated because we cannot apply the change to a master node" );
553572
return true;
573+
}
554574
}
555-
556575
using version_t = cryptonote::tx_extra_master_node_state_change::version_t;
576+
LOG_PRINT_L2("State not reachable A!?");
557577
auto ver = net >= HF_VERSION_PROOF_BTENC ? version_t::v4_reasons : version_t::v0;
578+
558579
cryptonote::tx_extra_master_node_state_change state_change{
559580
ver,
560581
vote.state_change.state,
@@ -573,8 +594,10 @@ namespace master_nodes
573594
}
574595

575596
cryptonote::transaction state_change_tx{};
597+
LOG_PRINT_L2("Before add_master_node_state_change_to_tx_extra ");//<< quorum.workers[vote.state_change.worker_index]);
576598
if (cryptonote::add_master_node_state_change_to_tx_extra(state_change_tx.extra, state_change, net))
577599
{
600+
LOG_PRINT_L2("add_master_node_state_change_to_tx_extra " );
578601
state_change_tx.version = cryptonote::transaction::get_max_version_for_hf(net);
579602
state_change_tx.type = cryptonote::txtype::state_change;
580603

@@ -592,8 +615,9 @@ namespace master_nodes
592615
else
593616
LOG_PRINT_L1("Failed to add state change to tx extra for height: "
594617
<< vote.block_height << " and master node: " << vote.state_change.worker_index);
595-
618+
LOG_PRINT_L2("handle_obligations_vote returned true");
596619
return true;
620+
597621
}
598622

599623
static bool handle_checkpoint_vote(cryptonote::core& core, const quorum_vote_t& vote, const std::vector<pool_vote_entry>& votes, const quorum& quorum)
@@ -671,22 +695,29 @@ namespace master_nodes
671695
bool quorum_cop::handle_vote(quorum_vote_t const &vote, cryptonote::vote_verification_context &vvc,uint8_t hf_version)
672696
{
673697
vvc = {};
674-
if (!verify_vote_age(vote, m_core.get_current_blockchain_height(), vvc,hf_version))
675-
return false;
698+
if (!verify_vote_age(vote, m_core.get_current_blockchain_height(), vvc,hf_version)) {
699+
LOG_PRINT_L1("failed verify_vote_age");
700+
return false;
701+
}
676702

677703
std::shared_ptr<const quorum> quorum = m_core.get_quorum(vote.type, vote.block_height);
678704
if (!quorum)
679705
{
680706
vvc.m_invalid_block_height = true;
707+
LOG_PRINT_L1("m_invalid_block_height (vote)");
681708
return false;
682709
}
683710

684-
if (!verify_vote_signature(get_network_version(m_core.get_nettype(), vote.block_height), vote, vvc, *quorum))
685-
return false;
686-
711+
if (!verify_vote_signature(get_network_version(m_core.get_nettype(), vote.block_height), vote, vvc, *quorum)) {
712+
LOG_PRINT_L1("failed verify_vote_signature");
713+
return false;
714+
}
687715
std::vector<pool_vote_entry> votes = m_vote_pool.add_pool_vote_if_unique(vote, vvc);
688716
if (!vvc.m_added_to_pool) // NOTE: Not unique vote
689-
return true;
717+
{
718+
LOG_PRINT_L1("NOTE: Not unique vote");
719+
return true;
720+
}
690721

691722
bool result = true;
692723
switch(vote.type)
@@ -699,17 +730,19 @@ namespace master_nodes
699730
};
700731

701732
case quorum_type::obligations:
733+
LOG_PRINT_L1("handle_obligations_vote");
702734
result &= handle_obligations_vote(m_core, vote, votes, *quorum);
703735
break;
704736

705737
case quorum_type::checkpointing:
738+
LOG_PRINT_L1("handle_checkpointing_vote ");
706739
result &= handle_checkpoint_vote(m_core, vote, votes, *quorum);
707740
break;
708741
}
709742
return result;
710743
}
711744

712-
// Calculate the decommission credit for a master node. If the SN is current decommissioned this
745+
// Calculate the decommission credit for a master node. If the MN is current decommissioned this
713746
// accumulated blocks.
714747
int64_t quorum_cop::calculate_decommission_credit(const master_node_info &info, uint64_t current_height,uint8_t hf_version)
715748
{

0 commit comments

Comments
 (0)