prepare_registration fixes for multi contributors

Adds two slightly different versions of prepare_registration: one that
works with the existing 4-person registrations (used up to the hard
fork), and one that produces HF19 amount-based registrations.

This also overhauls the questions to be a bit nicer to input;
specifically:

- allow "max" and "min" as stake amount options, and make "max" the
  default.
- eliminate the "do you want to contribute the whole stake?" question
  entirely.  We instantly figure that out if you choose "max" (or enter
  the 15000 manually).
- eliminate the "how many contributors?" question.  Instead we just keep
  taking additional contributors until you stop entering them.
- move the fee to later, after you've provided contributor info (if not
  a full stake).

There is, unfortunately, a *huge* amount of duplication here: I copy and
pasted the entire HF18 registration code and just eliminated the
portions parts of it.  This is temporary: as soon as we are into HF19 we
can eliminate the HF18 version entirely.
This commit is contained in:
Jason Rhinelander 2022-05-19 23:04:21 -03:00
parent 377cfecb09
commit 34ef746c95
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
6 changed files with 648 additions and 271 deletions

View File

@ -3924,9 +3924,11 @@ namespace service_nodes
tr("Run this command in the operator's wallet"),
cryptonote::get_account_address_as_str(nettype, false, reg.reserved[0].first));
cmd += "register_service_node";
cmd += tools::join(" ", args);
cmd += fmt::format(" {} {} {}", reg.hf, tools::type_to_hex(reg.service_node_pubkey), tools::type_to_hex(reg.signature));
cmd += fmt::format("register_service_node {} {} {} {}",
tools::join(" ", args),
reg.hf,
tools::type_to_hex(reg.service_node_pubkey),
tools::type_to_hex(reg.signature));
if (make_friendly && reg.uses_portions)
{

View File

@ -1,3 +1,4 @@
#include "common/string_util.h"
#include "cryptonote_config.h"
#include "cryptonote_basic/hardfork.h"
#include "common/oxen.h"
@ -257,24 +258,30 @@ static bool get_portions_from_percent(double cur_percent, uint64_t& portions) {
return true;
}
std::optional<double> parse_fee_percent(std::string_view fee)
{
if (tools::ends_with(fee, "%"))
fee.remove_suffix(1);
double percent;
try {
percent = boost::lexical_cast<double>(fee);
} catch(...) {
return std::nullopt;
}
if (percent < 0 || percent > 100)
return std::nullopt;
return percent;
}
bool get_portions_from_percent_str(std::string cut_str, uint64_t& portions) {
if(!cut_str.empty() && cut_str.back() == '%')
{
cut_str.pop_back();
}
if (auto pct = parse_fee_percent(cut_str))
return get_portions_from_percent(*pct, portions);
double cut_percent;
try
{
cut_percent = boost::lexical_cast<double>(cut_str);
}
catch(...)
{
return false;
}
return get_portions_from_percent(cut_percent, portions);
return false;
}
} // namespace service_nodes

View File

@ -290,6 +290,8 @@ uint64_t get_locked_key_image_unlock_height(cryptonote::network_type nettype
// Returns lowest x such that (staking_requirement * x/STAKING_PORTIONS) >= amount
uint64_t get_portions_to_make_amount(uint64_t staking_requirement, uint64_t amount, uint64_t max_portions = cryptonote::old::STAKING_PORTIONS);
std::optional<double> parse_fee_percent(std::string_view fee);
bool get_portions_from_percent_str(std::string cut_str, uint64_t& portions);
}

File diff suppressed because it is too large Load Diff

View File

@ -186,6 +186,8 @@ public:
bool print_sr(uint64_t height);
bool prepare_registration(bool force_registration=false);
// TODO FIXME: remove immediately after HF19 happens
bool prepare_registration_hf18(cryptonote::hf hf_version, bool force_registration);
bool print_sn(const std::vector<std::string> &args);

View File

@ -634,7 +634,7 @@ namespace rpc {
bool mainnet; // States if the node is on the mainnet (`true`) or not (`false`).
bool testnet; // States if the node is on the testnet (`true`) or not (`false`).
bool devnet; // States if the node is on the devnet (`true`) or not (`false`).
std::string nettype; // Nettype value used.
std::string nettype; // Network type as a string ("mainnet", "testnet", "devnet", or "fakechain").
std::string top_block_hash; // Hash of the highest block in the chain.
std::string immutable_block_hash; // Hash of the highest block in the chain that can not be reorganized.
uint64_t cumulative_difficulty; // Cumulative difficulty of all blocks in the blockchain.