Fee changes from ArticMine

https://github.com/ArticMine/Monero-Documents/blob/master/MoneroScaling2021-02.pdf

with a change to use 1.7 instead of 2.0 for the max long term increase rate
This commit is contained in:
moneromooo-monero 2021-07-29 12:02:08 +00:00
parent 9f786f0550
commit b030f20751
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
15 changed files with 498 additions and 48 deletions

View file

@ -1064,6 +1064,69 @@ namespace cryptonote
return s;
}
//---------------------------------------------------------------
uint64_t round_money_up(uint64_t amount, unsigned significant_digits)
{
// round monetary amount up with the requested amount of significant digits
CHECK_AND_ASSERT_THROW_MES(significant_digits > 0, "significant_digits must not be 0");
static_assert(sizeof(unsigned long long) == sizeof(uint64_t), "Unexpected unsigned long long size");
// we don't need speed, so we do it via text, as it's easier to get right
char buf[32];
snprintf(buf, sizeof(buf), "%llu", (unsigned long long)amount);
const size_t len = strlen(buf);
if (len > significant_digits)
{
bool bump = false;
char *ptr;
for (ptr = buf + significant_digits; *ptr; ++ptr)
{
// bump digits by one if the following digits past significant digits were to be 5 or more
if (*ptr != '0')
{
bump = true;
*ptr = '0';
}
}
ptr = buf + significant_digits;
while (bump && ptr > buf)
{
--ptr;
// bumping a nine overflows
if (*ptr == '9')
*ptr = '0';
else
{
// bumping another digit means we can stop bumping (no carry)
++*ptr;
bump = false;
}
}
if (bump)
{
// carry reached the highest digit, we need to add a 1 in front
size_t offset = strlen(buf);
for (size_t i = offset + 1; i > 0; --i)
buf[i] = buf[i - 1];
buf[0] = '1';
}
}
char *end = NULL;
errno = 0;
const unsigned long long ull = strtoull(buf, &end, 10);
CHECK_AND_ASSERT_THROW_MES(ull != ULONG_MAX || errno == 0, "Failed to parse rounded amount: " << buf);
CHECK_AND_ASSERT_THROW_MES(ull != 0 || amount == 0, "Overflow in rounding");
return ull;
}
//---------------------------------------------------------------
std::string round_money_up(const std::string &s, unsigned significant_digits)
{
uint64_t amount;
CHECK_AND_ASSERT_THROW_MES(parse_amount(amount, s), "Failed to parse amount: " << s);
amount = round_money_up(amount, significant_digits);
return print_money(amount);
}
//---------------------------------------------------------------
crypto::hash get_blob_hash(const blobdata& blob)
{
crypto::hash h = null_hash;

View file

@ -144,6 +144,8 @@ namespace cryptonote
std::string get_unit(unsigned int decimal_point = -1);
std::string print_money(uint64_t amount, unsigned int decimal_point = -1);
std::string print_money(const boost::multiprecision::uint128_t &amount, unsigned int decimal_point = -1);
uint64_t round_money_up(uint64_t amount, unsigned significant_digits);
std::string round_money_up(const std::string &amount, unsigned significant_digits);
//---------------------------------------------------------------
template<class t_object>
bool t_serializable_object_from_blob(t_object& to, const blobdata& b_blob)