Fix min operator amount, rejigger math

A fixed 3750 amount won't work on testnet (and also was set to 3750
atomic units instead of 3750 coins).

This refactor the math a bit so that the amount falls out of the portion
constant when making a registration.
This commit is contained in:
Jason Rhinelander 2022-05-12 13:47:49 -03:00
parent f652aa09bc
commit fd020fcd83
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
3 changed files with 9 additions and 5 deletions

View File

@ -211,6 +211,9 @@ namespace config
// service node.
using MAXIMUM_ACCEPTABLE_STAKE = std::ratio<101, 100>;
// Required operator contribution is 1/4 of the staking requirement
inline constexpr uint64_t MINIMUM_OPERATOR_DIVISOR = 4;
// Used to estimate the blockchain height from a timestamp, with some grace time. This can drift
// slightly over time (because average block time is not typically *exactly*
// DIFFICULTY_TARGET_V2).

View File

@ -241,8 +241,7 @@ namespace service_nodes {
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;
constexpr uint64_t MINIMUM_OPERATOR_PORTION = STAKING_PORTIONS_V1 / config::MINIMUM_OPERATOR_DIVISOR;
static_assert(STAKING_PORTIONS_V1 != UINT64_MAX, "UINT64_MAX is used as the invalid value for failing to calculate the min_node_contribution");

View File

@ -2180,9 +2180,11 @@ bool rpc_command_executor::prepare_registration(bool force_registration)
{
bool is_operator = state.total_reserved_contributions == 0;
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::MINIMUM_OPERATOR_CONTRIBUTION : service_nodes::portions_to_amount(staking_requirement, min_contribution_portions);
uint64_t min_contribution_portions = is_operator
? service_nodes::MINIMUM_OPERATOR_PORTION
: service_nodes::get_min_node_contribution_in_portions(
hf_version, staking_requirement, state.total_reserved_contributions, state.contributions.size());
uint64_t min_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"