Skip to content

Commit 9601f85

Browse files
proletesseractalex v
authored andcommitted
Static reward RC (#328)
* static rewards added * initial test and test util added * added new test to rpc test file * test updated * adding sleep print * removed extra bracket * updated perms. * cleanup test * checking before the soft fork * creating a few blocks to start * removing pre check
1 parent 7730c7b commit 9601f85

9 files changed

Lines changed: 153 additions & 17 deletions

File tree

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
'cfund-rawtx-proposal-vote.py',
159159
'cfund-vote.py',
160160
'reject-version-bit.py',
161+
'staticr-staking-amount.py',
161162

162163
]
163164
#if ENABLE_ZMQ:
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Navcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
from test_framework.test_framework import NavCoinTestFramework
7+
from test_framework.staticr_util import *
8+
9+
import time
10+
11+
class StaticRAmountTest(NavCoinTestFramework):
12+
"""Tests the staking amount after softfork activation."""
13+
14+
def __init__(self):
15+
super().__init__()
16+
self.setup_clean_chain = True
17+
self.num_nodes = 1
18+
19+
def setup_network(self, split=False):
20+
self.nodes = self.setup_nodes()
21+
self.is_network_split = split
22+
23+
def run_test(self):
24+
25+
#check the block reward is 2 NAV after the softfork
26+
27+
activate_staticr(self.nodes[0])
28+
29+
blockcount = self.nodes[0].getblockcount()
30+
wallet_info1 = self.nodes[0].getwalletinfo()
31+
32+
# wait for a new block to be mined
33+
while self.nodes[0].getblockcount() == blockcount:
34+
print("waiting for a new block...")
35+
time.sleep(5)
36+
37+
assert(blockcount != self.nodes[0].getblockcount())
38+
39+
wallet_info2 = self.nodes[0].getwalletinfo()
40+
balance_diff = wallet_info1['balance'] - wallet_info2['balance']
41+
42+
# check that only 2 new NAV were created
43+
assert(wallet_info2['immature_balance'] == wallet_info1['immature_balance'] + balance_diff + 2)
44+
45+
if __name__ == '__main__':
46+
StaticRAmountTest().main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2014-2016 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
7+
#
8+
# Expanded helper routines for regression testing of the NAV Coin community fund
9+
#
10+
11+
from test_framework.util import *
12+
13+
14+
def activate_staticr(node):
15+
slow_gen(node, 100)
16+
# Verify the Community Fund is started
17+
assert (get_bip9_status(node, "static")["status"] == "started")
18+
19+
slow_gen(node, 100)
20+
# Verify the Community Fund is locked_in
21+
assert (get_bip9_status(node, "static")["status"] == "locked_in")
22+
23+
slow_gen(node, 100)
24+
# Verify the Community Fund is active
25+
assert (get_bip9_status(node, "static")["status"] == "active")
26+
27+
def end_cycle(node):
28+
# Move to the end of the cycle
29+
slow_gen(node, node.cfundstats()["votingPeriod"]["ending"] - node.cfundstats()["votingPeriod"][
30+
"current"])

src/chainparams.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class CMainParams : public CChainParams {
122122
consensus.nPaymentRequestMaxVersion = 2;
123123
consensus.nProposalMaxVersion = 2;
124124
consensus.nMaxFutureDrift = 60;
125+
consensus.nStaticReward = 2 * COIN;
125126

126127
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
127128
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
@@ -171,6 +172,10 @@ class CMainParams : public CChainParams {
171172
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nStartTime = 1533081600; // Aug 1st, 2018
172173
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nTimeout = 1564617600; // Aug 1st, 2019
173174

175+
// Deployment of Static Reward
176+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].bit = 15;
177+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nStartTime = 1533081600; // August 1st, 2018
178+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nTimeout = 1564617600; // August 1st, 2019
174179

175180
/**
176181
* The message start string is designed to be unlikely to occur in normal data.
@@ -295,6 +300,7 @@ class CTestNetParams : public CChainParams {
295300
consensus.nPaymentRequestMaxVersion = 2;
296301
consensus.nProposalMaxVersion = 2;
297302
consensus.nMaxFutureDrift = 60;
303+
consensus.nStaticReward = 2 * COIN;
298304

299305
// Deployment of BIP68, BIP112, and BIP113.
300306
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
@@ -331,6 +337,11 @@ class CTestNetParams : public CChainParams {
331337
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nStartTime = 1533081600; // Aug 1st, 2018
332338
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nTimeout = 1564617600; // Aug 1st, 2019
333339

340+
// Deployment of Static Reward
341+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].bit = 15;
342+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nStartTime = 1533081600; // August 1st, 2018
343+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nTimeout = 1564617600; // August 1st, 2019
344+
334345
/**
335346
* The message start string is designed to be unlikely to occur in normal data.
336347
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -447,6 +458,7 @@ class CDevNetParams : public CChainParams {
447458
consensus.nPaymentRequestMaxVersion = 2;
448459
consensus.nProposalMaxVersion = 2;
449460
consensus.nMaxFutureDrift = 60000;
461+
consensus.nStaticReward = 2 * COIN;
450462

451463
// Deployment of BIP68, BIP112, and BIP113.
452464
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
@@ -483,6 +495,10 @@ class CDevNetParams : public CChainParams {
483495
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nStartTime = 1533081600; // Aug 1st, 2018
484496
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nTimeout = 1564617600; // Aug 1st, 2019
485497

498+
// Deployment of Static Reward
499+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].bit = 15;
500+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nStartTime = 1533081600; // August 1st, 2018
501+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nTimeout = 1564617600; // August 1st, 2019
486502

487503
/**
488504
* The message start string is designed to be unlikely to occur in normal data.
@@ -610,6 +626,7 @@ class CRegTestParams : public CChainParams {
610626
consensus.nPaymentRequestMaxVersion = 2;
611627
consensus.nProposalMaxVersion = 2;
612628
consensus.nMaxFutureDrift = 60000;
629+
consensus.nStaticReward = 2 * COIN;
613630

614631
// Deployment of BIP68, BIP112, and BIP113.
615632
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
@@ -646,6 +663,11 @@ class CRegTestParams : public CChainParams {
646663
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nStartTime = 1533081600; // Aug 1st, 2018
647664
consensus.vDeployments[Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2].nTimeout = 1564617600; // Aug 1st, 2019
648665

666+
// Deployment of Static Reward
667+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].bit = 15;
668+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nStartTime = 1533081600; // August 1st, 2018
669+
consensus.vDeployments[Consensus::DEPLOYMENT_STATIC_REWARD].nTimeout = 1564617600; // August 1st, 2019
670+
649671
/**
650672
* The message start string is designed to be unlikely to occur in normal data.
651673
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce

src/consensus/params.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum DeploymentPos
2626
DEPLOYMENT_COMMUNITYFUND_ACCUMULATION_SPREAD,
2727
DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2,
2828
DEPLOYMENT_NTPSYNC,
29+
DEPLOYMENT_STATIC_REWARD,
2930
MAX_VERSION_BITS_DEPLOYMENTS
3031
};
3132

@@ -99,6 +100,7 @@ struct Params {
99100
int64_t sigActivationTime;
100101
int64_t nCoinbaseTimeActivationHeight;
101102
int64_t nMaxFutureDrift;
103+
CAmount nStaticReward;
102104

103105
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
104106
};

src/main.cpp

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,9 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
25032503
if(IsCommunityFundAmountV2Enabled(pindexPrev,Params().GetConsensus()))
25042504
nVersion |= nCFundAmountV2Mask;
25052505

2506+
if(IsStaticRewardEnabled(pindexPrev,Params().GetConsensus()))
2507+
nVersion |= nStaticRewardVersionMask;
2508+
25062509
return nVersion;
25072510
}
25082511

@@ -2917,6 +2920,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29172920

29182921
}
29192922

2923+
if(IsStaticRewardEnabled(pindex->pprev, Params().GetConsensus()) && nStakeReward != Params().GetConsensus().nStaticReward)
2924+
return state.DoS(100, error("ConnectBlock(): block has incorrect block reward (actual=%d vs consensus=%d)",
2925+
nStakeReward, Params().GetConsensus().nStaticReward),
2926+
REJECT_INVALID, "bad-static-stake-amount");
2927+
29202928
}
29212929

29222930
std::vector<CScriptCheck> vChecks;
@@ -4648,6 +4656,18 @@ bool IsCommunityFundLocked(const CBlockIndex* pindexPrev, const Consensus::Param
46484656
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_COMMUNITYFUND, versionbitscache) == THRESHOLD_LOCKED_IN);
46494657
}
46504658

4659+
bool IsStaticRewardLocked(const CBlockIndex* pindexPrev, const Consensus::Params& params)
4660+
{
4661+
LOCK(cs_main);
4662+
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_STATIC_REWARD, versionbitscache) == THRESHOLD_LOCKED_IN);
4663+
}
4664+
4665+
bool IsStaticRewardEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params)
4666+
{
4667+
LOCK(cs_main);
4668+
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_STATIC_REWARD, versionbitscache) == THRESHOLD_ACTIVE);
4669+
}
4670+
46514671
// Compute at which vout of the block's coinbase transaction the witness
46524672
// commitment occurs, or -1 if not found.
46534673
static int GetWitnessCommitmentIndex(const CBlock& block)
@@ -4750,6 +4770,10 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
47504770
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
47514771
"rejected no nsync block");
47524772

4773+
if((block.nVersion & nStaticRewardVersionMask) != nStaticRewardVersionMask && IsStaticRewardEnabled(pindexPrev,Params().GetConsensus()))
4774+
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
4775+
"rejected no static reward block");
4776+
47534777
return true;
47544778
}
47554779

@@ -8638,23 +8662,29 @@ bool CheckKernel(CBlockIndex* pindexPrev, unsigned int nBits, int64_t nTime, con
86388662
// staker's coin stake reward based on coin age spent (coin-days)
86398663
int64_t GetProofOfStakeReward(int nHeight, int64_t nCoinAge, int64_t nFees, CBlockIndex* pindexPrev)
86408664
{
8641-
int64_t nRewardCoinYear;
8642-
nRewardCoinYear = MAX_MINT_PROOF_OF_STAKE;
8643-
8644-
if(nHeight-1 < 7 * Params().GetConsensus().nDailyBlockCount)
8645-
nRewardCoinYear = 1 * MAX_MINT_PROOF_OF_STAKE;
8646-
else if(nHeight-1 < (365 * Params().GetConsensus().nDailyBlockCount))
8647-
nRewardCoinYear = 0.5 * MAX_MINT_PROOF_OF_STAKE;
8648-
else if(nHeight-1 < (730 * Params().GetConsensus().nDailyBlockCount))
8649-
nRewardCoinYear = 0.5 * MAX_MINT_PROOF_OF_STAKE;
8650-
else if(IsCommunityFundAccumulationEnabled(pindexPrev, Params().GetConsensus(), false))
8651-
nRewardCoinYear = 0.4 * MAX_MINT_PROOF_OF_STAKE;
8652-
else
8653-
nRewardCoinYear = 0.5 * MAX_MINT_PROOF_OF_STAKE;
8654-
8655-
int64_t nSubsidy = nCoinAge * nRewardCoinYear / 365;
8656-
8657-
return nSubsidy + nFees;
8665+
int64_t nSubsidy;
8666+
8667+
if(IsStaticRewardEnabled(pindexPrev, Params().GetConsensus())){
8668+
nSubsidy = Params().GetConsensus().nStaticReward;
8669+
} else {
8670+
int64_t nRewardCoinYear;
8671+
nRewardCoinYear = MAX_MINT_PROOF_OF_STAKE;
8672+
8673+
if(nHeight-1 < 7 * Params().GetConsensus().nDailyBlockCount)
8674+
nRewardCoinYear = 1 * MAX_MINT_PROOF_OF_STAKE;
8675+
else if(nHeight-1 < (365 * Params().GetConsensus().nDailyBlockCount))
8676+
nRewardCoinYear = 0.5 * MAX_MINT_PROOF_OF_STAKE;
8677+
else if(nHeight-1 < (730 * Params().GetConsensus().nDailyBlockCount))
8678+
nRewardCoinYear = 0.5 * MAX_MINT_PROOF_OF_STAKE;
8679+
else if(IsCommunityFundAccumulationEnabled(pindexPrev, Params().GetConsensus(), false))
8680+
nRewardCoinYear = 0.4 * MAX_MINT_PROOF_OF_STAKE;
8681+
else
8682+
nRewardCoinYear = 0.5 * MAX_MINT_PROOF_OF_STAKE;
8683+
8684+
nSubsidy = nCoinAge * nRewardCoinYear / 365;
8685+
}
8686+
8687+
return nSubsidy + nFees;
86588688
}
86598689

86608690
unsigned int ComputeMaxBits(arith_uint256 bnTargetLimit, unsigned int nBase, int64_t nTime)

src/main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ bool IsCommunityFundAccumulationEnabled(const CBlockIndex* pindexPrev, const Con
507507
bool IsCommunityFundAccumulationSpreadEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
508508
bool IsCommunityFundAmountV2Enabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
509509

510+
/** Check whether the static reward has been activated **/
511+
bool IsStaticRewardEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
512+
bool IsStaticRewardLocked(const CBlockIndex* pindexPrev, const Consensus::Params& params);
510513

511514
/** Check whether NtpSync has been activated. */
512515
bool IsNtpSyncEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);

src/rpc/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
13121312
BIP9SoftForkDescPushBack(bip9_softforks, "ntpsync", consensusParams, Consensus::DEPLOYMENT_NTPSYNC);
13131313
BIP9SoftForkDescPushBack(bip9_softforks, "spread_cfund_accumulation", consensusParams, Consensus::DEPLOYMENT_COMMUNITYFUND_ACCUMULATION_SPREAD);
13141314
BIP9SoftForkDescPushBack(bip9_softforks, "communityfund_amount_v2", consensusParams, Consensus::DEPLOYMENT_COMMUNITYFUND_AMOUNT_V2);
1315+
BIP9SoftForkDescPushBack(bip9_softforks, "static", consensusParams, Consensus::DEPLOYMENT_STATIC_REWARD);
13151316
obj.push_back(Pair("softforks", softforks));
13161317
obj.push_back(Pair("bip9_softforks", bip9_softforks));
13171318

src/versionbits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static const int32_t nNSyncVersionMask = 0x00000080;
5252
static const int32_t nCFundAccVersionMask = 0x00000100;
5353
static const int32_t nCFundAccSpreadVersionMask = 0x00004000;
5454
static const int32_t nCFundAmountV2Mask = 0x00010000;
55+
static const int32_t nStaticRewardVersionMask = 0x00008000;
5556

5657
enum ThresholdState {
5758
THRESHOLD_DEFINED,

0 commit comments

Comments
 (0)