Skip to content

Commit

Permalink
Merge pull request #142 from AdminXeq/rpc_stake_fix
Browse files Browse the repository at this point in the history
RPC Stake Fixes
  • Loading branch information
AdminXeq committed Mar 31, 2023
2 parents b462161 + 77c0c38 commit 76c93c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/simplewallet/simplewallet.cpp
Expand Up @@ -7302,7 +7302,7 @@ bool simple_wallet::stake_main(
if (!full)
{
can_contrib_total = staking_req - snode_info.total_reserved;
must_contrib_total = (hf_ver >= 12) ? MIN_POOL_STAKERS_V12 * COIN : (hf_ver < 12 && hf_ver >= 10) ? std::min(snode_info.staking_requirement - snode_info.total_reserved, snode_info.staking_requirement / MAX_NUMBER_OF_CONTRIBUTORS_V2) : std::min(snode_info.staking_requirement - snode_info.total_reserved, snode_info.staking_requirement / MAX_NUMBER_OF_CONTRIBUTORS);
must_contrib_total = (hf_ver < 17) ? MIN_POOL_STAKERS_V12 * COIN : service_nodes::get_min_node_contribution(hf_ver, snode_info.staking_requirement, snode_info.total_reserved);
}

unlock_block = m_wallet->use_fork_rules(12, 0) ? snode_info.registration_height + locked_blocks : bc_height + locked_blocks;
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp.in
@@ -1,5 +1,5 @@
#define DEF_XEQ_VERSION_MAJOR 17
#define DEF_XEQ_VERSION_MINOR 1
#define DEF_XEQ_VERSION_MINOR 2
#define DEF_XEQ_VERSION_PATCH 0
#define DEF_XEQ_VERSION_IS_RELEASE @VERSION_IS_RELEASE@

Expand Down
15 changes: 12 additions & 3 deletions src/wallet/wallet2.cpp
Expand Up @@ -7797,11 +7797,12 @@ bool wallet2::check_stake_allowed(const crypto::public_key& sn_key, const crypto
}

const auto& snode_info = response.service_node_states.front();
uint8_t hf_ver = get_current_hard_fork();

const bool full = use_fork_rules(10, 0) ? snode_info.contributors.size() >= MAX_NUMBER_OF_CONTRIBUTORS_V2 : snode_info.contributors.size() >= MAX_NUMBER_OF_CONTRIBUTORS;
bool full = false;

/// maximum to contribute (unless we have some amount reserved for us)
uint64_t max_contrib_total = use_fork_rules(12,0) ? MAX_POOL_STAKERS_V12 * COIN - snode_info.total_reserved : snode_info.staking_requirement - snode_info.total_reserved;
uint64_t max_contrib_total = (hf_ver < 17) ? MAX_POOL_STAKERS_V12 * COIN - snode_info.total_reserved : snode_info.staking_requirement - snode_info.total_reserved;

/// decrease if some reserved for us
uint64_t min_contrib_total = use_fork_rules(12, 0) ? MIN_POOL_STAKERS_V12 * COIN : use_fork_rules(10, 0) ? std::min(snode_info.staking_requirement - snode_info.total_reserved, snode_info.staking_requirement / MAX_NUMBER_OF_CONTRIBUTORS_V2) : std::min(snode_info.staking_requirement - snode_info.total_reserved, snode_info.staking_requirement / MAX_NUMBER_OF_CONTRIBUTORS);
Expand Down Expand Up @@ -7843,6 +7844,12 @@ bool wallet2::check_stake_allowed(const crypto::public_key& sn_key, const crypto
amount = max_contrib_total;
}

if (max_contrib_total == 0)
{
LOG_ERROR("You may not contribute any more to this service node");
return false;
}

reg_height = snode_info.registration_height;

return true;
Expand All @@ -7861,9 +7868,11 @@ std::vector<wallet2::pending_tx> wallet2::create_stake_tx(const crypto::public_k
return {};

const cryptonote::account_public_address& address = addr_info.address;
uint8_t hf_ver = get_current_hard_fork();

uint64_t to_burn = 0;
if (get_current_hard_fork() < 16) to_burn += (amount / 1000);

if (hf_ver < 16) to_burn += (amount / 1000);
else to_burn += 1;

std::vector<uint8_t> extra;
Expand Down

0 comments on commit 76c93c1

Please sign in to comment.