Skip to content

polls, voting, staking: Enhance voting consensus rules to allow for changeable magnitude weight factor and enhance CBR #2781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7e6ffec
Add several parameters to blockchain consensus
jamescowens Oct 22, 2024
46bcae4
Extend fraction class to construct from string
jamescowens Oct 22, 2024
f397bd2
Add TryLastBeforeTimestamp to Protocol Registry
jamescowens Oct 22, 2024
2ad8bca
Rewrite GRC::GetConstantBlockReward
jamescowens Oct 22, 2024
ec333ad
Introduce changeable magnitude weight factors for polling
jamescowens Oct 22, 2024
68b98f3
Additional changes to wire in magnitude weight factor
jamescowens Oct 23, 2024
9e3684c
Fix for AVW not correct with modified magnitude weight factor
jamescowens Oct 24, 2024
efea824
Change WaitMessage() to PollWaitMessage()
jamescowens Oct 24, 2024
5096b9c
Document overflow analysis for magnitude weight factor as fraction
jamescowens Oct 25, 2024
6eff430
Ensure ResolveMagnitudeWeightFactor returns Fraction(100, 567) prior …
jamescowens Oct 25, 2024
3dbbc21
Implement GRC::GetAvgNetworkWeight
jamescowens Oct 26, 2024
60362bd
Add thread safety keywords to difficulty functions
jamescowens Oct 27, 2024
9b8c8fd
Fix segmentation fault in GetMagnitudeWeightFactor
jamescowens Oct 27, 2024
0684b30
Ensure GetActiveNetworkWeight behavior is correct for all poll weight…
jamescowens Oct 27, 2024
2221ae0
Implement protocol entry changeable magnitude unit
jamescowens Dec 16, 2024
367ee55
Correct contract version for protocol contracts for block V13+
jamescowens Dec 16, 2024
838482e
Remove hardcoded accrual limit in UI warning tooltip
jamescowens Dec 18, 2024
a4bab8f
Enhance Fraction class FromString() and add tests
jamescowens Dec 28, 2024
4c765d4
Add MaxMagnitudeUnit to chain parameters
jamescowens Dec 28, 2024
ef683fc
Enforce MaxMagnitudeUnit clamp in GetMagnitudeUnit()
jamescowens Dec 28, 2024
c16bc50
Adjust CBR ceiling to 500 GRC.
jamescowens Feb 15, 2025
4f93788
Enforce clamp on MagnitudeWeightFactor
jamescowens Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enhance Fraction class FromString() and add tests
  • Loading branch information
jamescowens committed Apr 8, 2025
commit a4bab8fa0cc341955ded24e211a7c61e90d7a863
60 changes: 59 additions & 1 deletion src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,65 @@ BOOST_AUTO_TEST_CASE(util_Fraction_ToString)
Fraction fraction(123, 10000);

BOOST_CHECK_EQUAL(fraction.IsSimplified(), true);
BOOST_CHECK_EQUAL(fraction.ToString(),"123/10000");
BOOST_CHECK_EQUAL(fraction.ToString(), "123/10000");
}

BOOST_AUTO_TEST_CASE(util_Fraction_FromString)
{
Fraction fraction = Fraction().FromString("100/567");

BOOST_CHECK_EQUAL(fraction.IsSimplified(), true);
BOOST_CHECK(fraction == Fraction(100, 567, true));

fraction = Fraction().FromString("-100/567");

BOOST_CHECK_EQUAL(fraction.IsSimplified(), true);
BOOST_CHECK(fraction == Fraction(-100, 567, true));

fraction = Fraction().FromString("100/-567");

BOOST_CHECK_EQUAL(fraction.IsSimplified(), true);
BOOST_CHECK(fraction == Fraction(-100, 567, true));

fraction = Fraction().FromString("5");

BOOST_CHECK_EQUAL(fraction.IsSimplified(), true);
BOOST_CHECK(fraction == Fraction(5, 1, true));

std::string err;
std::string valid_err_message {"fraction input string cannot be parsed to fraction"};

try {
Fraction fraction = Fraction().FromString("100/567/300");
} catch (std::out_of_range& e) {
err = e.what();
}

BOOST_CHECK_EQUAL(err, valid_err_message);

try {
Fraction fraction = Fraction().FromString("100 / 567");
} catch (std::out_of_range& e) {
err = e.what();
}

BOOST_CHECK_EQUAL(err, valid_err_message);

try {
Fraction fraction = Fraction().FromString("100.1");
} catch (std::out_of_range& e) {
err = e.what();
}

BOOST_CHECK_EQUAL(err, valid_err_message);

try {
Fraction fraction = Fraction().FromString("");
} catch (std::out_of_range& e) {
err = e.what();
}

BOOST_CHECK_EQUAL(err, valid_err_message);
}

BOOST_AUTO_TEST_SUITE_END()
20 changes: 16 additions & 4 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,25 @@ class Fraction {
{
std::vector<std::string> string_fraction = split(string, "/");

if (string_fraction.size() > 2 || string_fraction.size() < 1) {
throw std::out_of_range("fraction input string cannot be parsed to fraction");
}

int64_t numerator;
int64_t denominator;

if (string_fraction.size() != 2
|| !ParseInt64(string_fraction[0], &numerator)
|| !ParseInt64(string_fraction[1], &denominator)) {
throw std::out_of_range("Fraction input string cannot be parsed to fraction.");
if (string_fraction.size() == 1) {
if (!ParseInt64(string_fraction[0], &numerator)) {
throw std::out_of_range("fraction input string cannot be parsed to fraction");
}

denominator = 1;
} else {
// There must be two elements to the string fraction if we are here.
if (!ParseInt64(string_fraction[0], &numerator)
|| !ParseInt64(string_fraction[1], &denominator)) {
throw std::out_of_range("fraction input string cannot be parsed to fraction");
}
}

return Fraction(numerator, denominator, true);
Expand Down