oxen-core/src/cryptonote_core/service_node_rules.h
Doyle 43436b081d
Infinite Staking Part 2 (#406)
* Cleanup and undoing some protocol breakages

* Simplify expiration of nodes

* Request unlock schedules entire node for expiration

* Fix off by one in expiring nodes

* Undo expiring code for pre v10 nodes

* Fix RPC returning register as unlock height and not checking 0

* Rename key image unlock height const

* Undo testnet hardfork debug changes

* Remove is_type for get_type, fix missing var rename

* Move serialisable data into public namespace

* Serialise tx types properly

* Fix typo in no service node known msg

* Code review

* Fix == to >= on serialising tx type

* Code review 2

* Fix tests and key image unlock

* Add command to print locked key images

* Update ui to display lock stakes, query in print cmd blacklist

* Modify print stakes to be less slow

* Remove autostaking code

* Refactor staking into sweep functions

It appears staking was derived off stake_main written separately at
implementation at the beginning. This merges them back into a common
code path, after removing autostake there's only some minor differences.

It also makes sure that any changes to sweeping upstream are going to be
considered in the staking process which we want.

* Display unlock height for stakes

* Begin creating output blacklist

* Make blacklist output a migration step

* Implement get_output_blacklist for lmdb

* In wallet output selection ignore blacklisted outputs

* Apply blacklisted outputs to output selection

* Fix broken tests, switch key image unlock

* Fix broken unit_tests

* Begin change to limit locked key images to 4 globally

* Revamp prepare registration for new min contribution rules

* Fix up old back case in prepare registration

* Remove debug code

* Cleanup debug code and some unecessary changes

* Fix migration step on mainnet db

* Fix blacklist outputs for pre-existing DB's

* Remove irrelevant note

* Tweak scanning addresses for locked stakes

Since we only now allow contributions from the primary address we can
skip checking all subaddress + lookahead to speed up wallet scanning

* Define macro for SCNu64 for Mingw

* Fix failure on empty DB

* Add missing error msg, remove contributor from stake

* Improve staking messages

* Flush prompt to always display

* Return the msg from stake failure and fix stake parsing error

* Tweak fork rules for smaller bulletproofs

* Tweak pooled nodes minimum amounts

* Fix crash on exit, there's no need to store on destructor

Since all information about service nodes is derived from the blockchain
and we store state every time we receive a block, storing in the
destructor is redundant as there is no new information to store.

* Make prompt be consistent with CLI

* Check max number of key images from per user to node

* Implement error message on get_output_blacklist failure

* Remove resolved TODO's/comments

* Handle infinite staking in print_sn

* Atoi->strtol, fix prepare_registration, virtual override, stale msgs
2019-02-14 12:12:57 +11:00

56 lines
2.5 KiB
C++

#pragma once
#include "crypto/crypto.h"
#include "cryptonote_config.h"
#include "service_node_deregister.h"
namespace service_nodes {
constexpr size_t QUORUM_SIZE = 10;
constexpr size_t QUORUM_LIFETIME = (6 * deregister_vote::DEREGISTER_LIFETIME_BY_HEIGHT);
constexpr size_t MIN_VOTES_TO_KICK_SERVICE_NODE = 7;
constexpr size_t NTH_OF_THE_NETWORK_TO_TEST = 100;
constexpr size_t MIN_NODES_TO_TEST = 50;
constexpr size_t MAX_SWARM_SIZE = 10;
// We never create a new swarm unless there are SWARM_BUFFER extra nodes
// available in the queue.
constexpr size_t SWARM_BUFFER = 5;
// if a swarm has strictly less nodes than this, it is considered unhealthy
// and nearby swarms will mirror it's data. It will disappear, and is already considered gone.
constexpr size_t MIN_SWARM_SIZE = 5;
constexpr int MAX_KEY_IMAGES_PER_CONTRIBUTOR = 1;
constexpr uint64_t QUEUE_SWARM_ID = 0;
constexpr uint64_t KEY_IMAGE_AWAITING_UNLOCK_HEIGHT = 0;
inline uint64_t staking_num_lock_blocks(cryptonote::network_type nettype)
{
switch(nettype)
{
case cryptonote::FAKECHAIN: return 30;
case cryptonote::TESTNET: return BLOCKS_EXPECTED_IN_DAYS(2);
default: return BLOCKS_EXPECTED_IN_DAYS(30);
}
}
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_staking_requirement(cryptonote::network_type nettype, uint64_t height);
uint64_t portions_to_amount(uint64_t portions, uint64_t staking_requirement);
/// Check if portions are sufficiently large (provided the contributions
/// are made in the specified order) and don't exceed the required amount
bool check_service_node_portions(uint8_t version, const std::vector<uint64_t>& portions);
crypto::hash generate_request_stake_unlock_hash(uint32_t nonce);
uint64_t get_locked_key_image_unlock_height(cryptonote::network_type nettype, uint64_t node_register_height, uint64_t curr_height);
// 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);
bool get_portions_from_percent_str(std::string cut_str, uint64_t& portions);
}