Skip to content

Commit c723ab6

Browse files
committed
[Core] Add threshold for P2CS value (hardcoded to 10 PIV)
1 parent 6e28ec1 commit c723ab6

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

src/chainparams.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class CMainParams : public CChainParams
168168
nFutureTimeDriftPoS = 180;
169169
nMasternodeCountDrift = 20;
170170
nMaxMoneyOut = 21000000 * COIN;
171+
nMinColdStakingAmount = 10 * COIN;
171172

172173
/** Height or Time Based Activations **/
173174
nLastPOWBlock = 259200;

src/chainparams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class CChainParams
104104
int GetBudgetCycleBlocks() const { return nBudgetCycleBlocks; }
105105
int64_t GetProposalEstablishmentTime() const { return nProposalEstablishmentTime; }
106106

107+
CAmount GetMinColdStakingAmount() const { return nMinColdStakingAmount; }
108+
107109
/** Spork key and Masternode Handling **/
108110
std::string SporkPubKey() const { return strSporkPubKey; }
109111
std::string SporkPubKeyOld() const { return strSporkPubKeyOld; }
@@ -231,6 +233,7 @@ class CChainParams
231233
int nBlockStakeModifierlV2;
232234
int nBlockEnforceNewMessageSignatures;
233235
int nColdStakingStart;
236+
CAmount nMinColdStakingAmount;
234237

235238
// fake serial attack
236239
int nFakeSerialBlockheightEnd = 0;

src/main.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,13 +1210,13 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
12101210
return state.DoS(100, error("CheckTransaction() : size limits failed"),
12111211
REJECT_INVALID, "bad-txns-oversize");
12121212

1213+
const CAmount minColdStakingAmount = Params().GetMinColdStakingAmount();
1214+
12131215
// Check for negative or overflow output values
12141216
CAmount nValueOut = 0;
12151217
for (const CTxOut& txout : tx.vout) {
12161218
if (txout.IsEmpty() && !tx.IsCoinBase() && !tx.IsCoinStake())
12171219
return state.DoS(100, error("CheckTransaction(): txout empty for user transaction"));
1218-
if (txout.scriptPubKey.IsPayToColdStaking() && !fColdStakingActive)
1219-
return state.DoS(100, error("CheckTransaction(): cold staking not active"));
12201220
if (txout.nValue < 0)
12211221
return state.DoS(100, error("CheckTransaction() : txout.nValue negative"),
12221222
REJECT_INVALID, "bad-txns-vout-negative");
@@ -1231,11 +1231,19 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
12311231
if(!CheckZerocoinMint(tx.GetHash(), txout, state, true))
12321232
return state.DoS(100, error("CheckTransaction() : invalid zerocoin mint"));
12331233
}
1234+
// check cold staking enforcement and value out
1235+
if (txout.scriptPubKey.IsPayToColdStaking()) {
1236+
if (!fColdStakingActive)
1237+
return state.DoS(100, error("%s: cold staking not active", __func__), REJECT_INVALID, "bad-txns-cold-stake");
1238+
if (txout.nValue < minColdStakingAmount)
1239+
return state.DoS(100, error("%s: dust amount (%d) not allowed for cold staking. Min amount: %d",
1240+
__func__, txout.nValue, minColdStakingAmount), REJECT_INVALID, "bad-txns-cold-stake");
1241+
}
12341242
}
12351243

12361244
// Additional check for cold staking
12371245
if (tx.IsCoinStake() && !tx.HasZerocoinSpendInputs() && !CheckColdStake(tx, state, fColdStakingActive))
1238-
return state.DoS(100, error("CheckTransaction() : invalid cold stake"), REJECT_INVALID, "bad-txns-cold-stake");
1246+
return state.DoS(100, error("%s: invalid cold stake", __func__), REJECT_INVALID, "bad-txns-cold-stake");
12391247

12401248
std::set<COutPoint> vInOutPoints;
12411249
std::set<CBigNum> vZerocoinSpendSerials;

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,9 @@ UniValue CreateColdStakeDelegation(const UniValue& params, CWalletTx& wtxNew, CR
512512

513513
// Get Amount
514514
CAmount nValue = AmountFromValue(params[1]);
515-
if (nValue <= 0)
516-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
515+
if (nValue <= Params().GetMinColdStakingAmount())
516+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid amount (%d). Min amount: %d",
517+
nValue, Params().GetMinColdStakingAmount()));
517518

518519
// Get Owner Address
519520
CBitcoinAddress ownerAddr;

test/functional/feature_coldStaking.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ def run_test(self):
125125
assert(res is not None and res != "")
126126
self.log.info("Good. Warning NOT triggered.")
127127
self.log.info("Now delegate with internal owner address..")
128+
self.log.info("Try first with a value (5) below the threshold")
129+
try:
130+
self.nodes[0].delegatestake(staker_address, 5, owner_address)
131+
assert(False)
132+
except JSONRPCException as e:
133+
assert("Invalid amount" in str(e))
134+
self.log.info("Nice. it was not possible.")
128135
self.log.info("Creating %d stake-delegation txes..." % NUM_OF_INPUTS)
129136
for i in range(NUM_OF_INPUTS):
130137
res = self.nodes[0].delegatestake(staker_address, INPUT_VALUE, owner_address)

0 commit comments

Comments
 (0)