review notes

This commit is contained in:
Sean Darcy 2022-05-12 10:32:57 +10:00
parent 73e0a9eb61
commit f652aa09bc
4 changed files with 7 additions and 9 deletions

View file

@ -99,7 +99,7 @@ bool check_service_node_portions(uint8_t hf_version, const std::vector<uint64_t>
const size_t max_contributors = hf_version >= 19 ? MAX_NUMBER_OF_CONTRIBUTORS_V2 : MAX_NUMBER_OF_CONTRIBUTORS_V1;
if (portions.size() > max_contributors) return false;
if (portions[0] < get_min_node_operator_contribution(STAKING_PORTIONS_V1))
if (portions[0] < MINIMUM_OPERATOR_PORTION)
{
LOG_PRINT_L1("Register TX rejected: TX does not have sufficient operator stake");
return false;
@ -169,11 +169,6 @@ uint64_t get_min_node_contribution_in_portions(uint8_t version, uint64_t staking
return result;
}
uint64_t get_min_node_operator_contribution(uint64_t staking_requirement)
{
return staking_requirement / MAX_NUMBER_OF_CONTRIBUTORS_V1;
}
uint64_t get_portions_to_make_amount(uint64_t staking_requirement, uint64_t amount, uint64_t max_portions)
{
uint64_t lo, hi, resulthi, resultlo;

View file

@ -240,12 +240,15 @@ namespace service_nodes {
//If the below percentage of service nodes are out of sync we will consider our clock out of sync
constexpr uint8_t MAXIMUM_EXTERNAL_OUT_OF_SYNC = 80;
//The SN operator must contribute more than 25% of the nodes requirements
constexpr uint64_t MINIMUM_OPERATOR_PORTION = STAKING_PORTIONS_V1/4;
constexpr uint64_t MINIMUM_OPERATOR_CONTRIBUTION = 3750;
static_assert(STAKING_PORTIONS_V1 != UINT64_MAX, "UINT64_MAX is used as the invalid value for failing to calculate the min_node_contribution");
// return: UINT64_MAX if (num_contributions > the max number of contributions), otherwise the amount in oxen atomic units
uint64_t get_min_node_contribution (uint8_t version, uint64_t staking_requirement, uint64_t total_reserved, size_t num_contributions);
uint64_t get_min_node_contribution_in_portions(uint8_t version, uint64_t staking_requirement, uint64_t total_reserved, size_t num_contributions);
uint64_t get_min_node_operator_contribution(uint64_t staking_requirement);
// Gets the maximum allowed stake amount. This is used to prevent significant overstaking. The
// wallet tries to avoid this when submitting a stake, but it can still happen when competing stakes

View file

@ -2182,7 +2182,7 @@ bool rpc_command_executor::prepare_registration(bool force_registration)
uint64_t amount_left = staking_requirement - state.total_reserved_contributions;
uint64_t min_contribution_portions = service_nodes::get_min_node_contribution_in_portions(
hf_version, staking_requirement, state.total_reserved_contributions, state.contributions.size());
uint64_t min_contribution = is_operator ? service_nodes::get_min_node_operator_contribution(staking_requirement) : service_nodes::portions_to_amount(staking_requirement, min_contribution_portions);
uint64_t min_contribution = is_operator ? service_nodes::MINIMUM_OPERATOR_CONTRIBUTION : service_nodes::portions_to_amount(staking_requirement, min_contribution_portions);
auto [result, contribution_str] = input_line_value(fmt::format(
"The {} contribution must be between {} and {} to meet the staking requirements.\n\n"

View file

@ -3077,7 +3077,7 @@ bool oxen_service_nodes_sufficient_contribution_HF19::generate(std::vector<test_
gen.add_tx(register_tx);
gen.create_and_add_next_block({register_tx});
assert(single_contributed_amount == 0);
assert(single_contributed_amount != 0);
cryptonote::transaction stake = gen.create_and_add_staking_tx(sn_keys.pub, alice, single_contributed_amount);
gen.create_and_add_next_block({stake});