Skip to content

Commit

Permalink
Only accept fixed lockin times for MN collateral (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Jul 19, 2021
1 parent 700a8cc commit 719932c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class CMasternode
UNKNOWN // unreachable
};

enum TimeLock {
ZEROYEAR,
FIVEYEAR = 260,
TENYEAR = 520
};

//! Minted blocks counter
uint32_t mintedBlocks;

Expand Down
11 changes: 10 additions & 1 deletion src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,16 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("masternode creation needs owner auth");
}

if (height < static_cast<uint32_t>(Params().GetConsensus().EunosPayaHeight) && obj.timelock != 0) {
if (height >= static_cast<uint32_t>(Params().GetConsensus().EunosPayaHeight)) {
switch(obj.timelock) {
case CMasternode::ZEROYEAR:
case CMasternode::FIVEYEAR:
case CMasternode::TENYEAR:
break;
default:
return Res::Err("Timelock must be set to either 0, 5 or 10 years");
}
} else if (obj.timelock != 0) {
return Res::Err("collateral timelock cannot be set below EunosPaya");
}

Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/rpc_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ UniValue createmasternode(const JSONRPCRequest& request)
}
std::string timelockStr = request.params[3].getValStr();
if (timelockStr == "FIVEYEARTIMELOCK") {
timelock = 5 * 52;
timelock = CMasternode::FIVEYEAR;
} else if (timelockStr == "TENYEARTIMELOCK") {
timelock = 10 * 52;
timelock = CMasternode::TENYEAR;
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/functional/feature_longterm_lockin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def run_test(self):
collateral = self.nodes[0].getnewaddress("", "legacy")
collateral5 = self.nodes[0].getnewaddress("", "legacy")
collateral10 = self.nodes[0].getnewaddress("", "legacy")
collateral20 = self.nodes[0].getnewaddress("", "legacy")

# Try to set time lock before EunosPaya
try:
Expand All @@ -37,11 +38,25 @@ def run_test(self):
self.nodes[0].generate(39)

# Create MNs with locked funds
self.nodes[0].sendtoaddress(collateral20, 1)
nodeid = self.nodes[0].createmasternode(collateral)
nodeid5 = self.nodes[0].createmasternode(collateral5, "", [], "FIVEYEARTIMELOCK")
nodeid10 = self.nodes[0].createmasternode(collateral10, "", [], "TENYEARTIMELOCK")
self.nodes[0].generate(1)

# Test MN creation with non-standard 20 year lock-in
nodeid20 = self.nodes[0].createmasternode(collateral20, "", [], "TENYEARTIMELOCK")
nodeid20_raw = self.nodes[0].getrawtransaction(nodeid20)
self.nodes[0].clearmempool()
pos = nodeid20_raw.find('446654784301')
nodeid20_raw = nodeid20_raw[:pos + 52] + '1004' + nodeid20_raw[pos + 52 + 4:]

try:
self.nodes[0].sendrawtransaction(nodeid20_raw)
except JSONRPCException as e:
errorString = e.error['message']
assert("Timelock must be set to either 0, 5 or 10 years" in errorString)

# Check state and timelock length
result = self.nodes[0].getmasternode(nodeid)
assert_equal(result[nodeid]['state'], 'PRE_ENABLED')
Expand Down

0 comments on commit 719932c

Please sign in to comment.