From 9f79d80e36c0a4e30b2ba1a3c95f3ca6869046e4 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 26 Jan 2023 13:43:05 +0100 Subject: [PATCH 1/4] Disable neutral votes from RPC --- src/masternodes/rpc_proposals.cpp | 4 ++-- test/functional/feature_on_chain_government.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index be3913df09..f2a47ff63a 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -457,8 +457,8 @@ UniValue votegov(const JSONRPCRequest &request) { vote = CProposalVoteType::VoteNo; } else if (voteStr == "yes") { vote = CProposalVoteType::VoteYes; - } else if (voteStr != "neutral") { - throw JSONRPCError(RPC_INVALID_PARAMETER, "decision supports yes/no/neutral"); + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Decision supports yes or no. Neutral is currently disabled because of issue https://github.com/DeFiCh/ain/issues/1704"); } int targetHeight; diff --git a/test/functional/feature_on_chain_government.py b/test/functional/feature_on_chain_government.py index 2b0262fb1b..3eaa7e0b9f 100755 --- a/test/functional/feature_on_chain_government.py +++ b/test/functional/feature_on_chain_government.py @@ -143,6 +143,8 @@ def run_test(self): # cannot vote by non owning masternode assert_raises_rpc_error(-5, "Incorrect authorization", self.nodes[0].votegov, cfp1, mn1, "yes") + assert_raises_rpc_error(-8, "Decision supports yes or no. Neutral is currently disabled because of issue https://github.com/DeFiCh/ain/issues/1704", self.nodes[0].votegov, cfp1, mn0, "neutral") + # Vote on proposal self.nodes[0].votegov(cfp1, mn0, "yes") self.nodes[0].generate(1) @@ -153,7 +155,7 @@ def run_test(self): self.sync_blocks() # Try and vote with non-staked MN - assert_raises_rpc_error(None, "does not mine at least one block", self.nodes[3].votegov, cfp1, mn3, "neutral") + assert_raises_rpc_error(None, "does not mine at least one block", self.nodes[3].votegov, cfp1, mn3, "yes") # voting period votingPeriod = 70 From c1fb204c448c41894bdc5bf0e00f41c75e95a263 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 26 Jan 2023 14:47:53 +0100 Subject: [PATCH 2/4] Fix test --- test/functional/feature_on_chain_government_fee_distribution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/feature_on_chain_government_fee_distribution.py b/test/functional/feature_on_chain_government_fee_distribution.py index f18759fabc..7d826036ab 100755 --- a/test/functional/feature_on_chain_government_fee_distribution.py +++ b/test/functional/feature_on_chain_government_fee_distribution.py @@ -153,7 +153,7 @@ def run_test(self): self.nodes[0].generate(1) self.sync_blocks() - self.test_cfp_fee_distribution(amount=1000, expectedFee=10, burnPct=30, vote="neutral",) + # self.test_cfp_fee_distribution(amount=1000, expectedFee=10, burnPct=30, vote="neutral",) self.nodes[0].setgov({"ATTRIBUTES":{'v0/gov/proposals/cfp_fee':'2%'}}) self.nodes[0].generate(1) From bd34fa5f190454f3703bf0c72739b32d517814ba Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 27 Jan 2023 12:10:16 +0100 Subject: [PATCH 3/4] Add -rpc-governance-accept-neutral for JellyFish --- src/init.cpp | 1 + src/masternodes/rpc_proposals.cpp | 6 +++++- .../feature_on_chain_government_fee_distribution.py | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8117c15854..57a1b14988 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -630,6 +630,7 @@ void SetupServerArgs() gArgs.AddArg("-consolidaterewards=", "Consolidate rewards on startup. Accepted multiple times for each token symbol", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-rpccache=<0/1/2>", "Cache rpc results - uses additional memory to hold on to the last results per block, but faster (0=none, 1=all, 2=smart)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-negativeinterest", "(experimental) Track negative interest values", ArgsManager::ALLOW_ANY, OptionsCategory::HIDDEN); + gArgs.AddArg("-rpc-governance-accept-neutral", "Allow voting with neutral votes for JellyFish purpose", ArgsManager::ALLOW_ANY, OptionsCategory::HIDDEN); #if HAVE_DECL_DAEMON gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index f2a47ff63a..464a732e93 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -3,6 +3,8 @@ #include +const bool DEFAULT_RPC_GOV_NEUTRAL = false; + struct VotingInfo { int32_t votesPossible; int32_t votesPresent; @@ -457,7 +459,9 @@ UniValue votegov(const JSONRPCRequest &request) { vote = CProposalVoteType::VoteNo; } else if (voteStr == "yes") { vote = CProposalVoteType::VoteYes; - } else { + } else if (gArgs.GetBoolArg("-rpc-governance-accept-neutral", DEFAULT_RPC_GOV_NEUTRAL) && voteStr != "neutral") { + throw JSONRPCError(RPC_INVALID_PARAMETER, "decision supports yes/no/neutral"); + } else if (!gArgs.GetBoolArg("-rpc-governance-accept-neutral", DEFAULT_RPC_GOV_NEUTRAL)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Decision supports yes or no. Neutral is currently disabled because of issue https://github.com/DeFiCh/ain/issues/1704"); } diff --git a/test/functional/feature_on_chain_government_fee_distribution.py b/test/functional/feature_on_chain_government_fee_distribution.py index 7d826036ab..996a35878a 100755 --- a/test/functional/feature_on_chain_government_fee_distribution.py +++ b/test/functional/feature_on_chain_government_fee_distribution.py @@ -17,10 +17,10 @@ def set_test_params(self): self.num_nodes = 4 self.setup_clean_chain = True self.extra_args = [ - ['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], - ['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], - ['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], - ['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], + ['-dummypos=0', '-txnotokens=0', '-rpc-governance-accept-neutral', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], + ['-dummypos=0', '-txnotokens=0', '-rpc-governance-accept-neutral', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], + ['-dummypos=0', '-txnotokens=0', '-rpc-governance-accept-neutral', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], + ['-dummypos=0', '-txnotokens=0', '-rpc-governance-accept-neutral', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-grandcentralheight=101'], ] def test_cfp_fee_distribution(self, amount, expectedFee, burnPct, vote, cycles=2, changeFeeAndBurnPCT = False): @@ -153,7 +153,7 @@ def run_test(self): self.nodes[0].generate(1) self.sync_blocks() - # self.test_cfp_fee_distribution(amount=1000, expectedFee=10, burnPct=30, vote="neutral",) + self.test_cfp_fee_distribution(amount=1000, expectedFee=10, burnPct=30, vote="neutral",) self.nodes[0].setgov({"ATTRIBUTES":{'v0/gov/proposals/cfp_fee':'2%'}}) self.nodes[0].generate(1) From ef8fc4aa2aff2aac2478c2c7114aebd70a0fd82f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 1 Feb 2023 17:15:02 +0100 Subject: [PATCH 4/4] Code cleanup --- src/masternodes/rpc_proposals.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/masternodes/rpc_proposals.cpp b/src/masternodes/rpc_proposals.cpp index 464a732e93..8774c72ca4 100644 --- a/src/masternodes/rpc_proposals.cpp +++ b/src/masternodes/rpc_proposals.cpp @@ -453,15 +453,16 @@ UniValue votegov(const JSONRPCRequest &request) { auto propId = ParseHashV(request.params[0].get_str(), "proposalId"); auto mnId = ParseHashV(request.params[1].get_str(), "masternodeId"); auto vote = CProposalVoteType::VoteNeutral; - auto voteStr = ToLower(request.params[2].get_str()); + auto neutralVotesAllowed = gArgs.GetBoolArg("-rpc-governance-accept-neutral", DEFAULT_RPC_GOV_NEUTRAL); + if (voteStr == "no") { vote = CProposalVoteType::VoteNo; } else if (voteStr == "yes") { vote = CProposalVoteType::VoteYes; - } else if (gArgs.GetBoolArg("-rpc-governance-accept-neutral", DEFAULT_RPC_GOV_NEUTRAL) && voteStr != "neutral") { + } else if (neutralVotesAllowed && voteStr != "neutral") { throw JSONRPCError(RPC_INVALID_PARAMETER, "decision supports yes/no/neutral"); - } else if (!gArgs.GetBoolArg("-rpc-governance-accept-neutral", DEFAULT_RPC_GOV_NEUTRAL)) { + } else if (!neutralVotesAllowed) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Decision supports yes or no. Neutral is currently disabled because of issue https://github.com/DeFiCh/ain/issues/1704"); }