Skip to content

Commit 08d5fb5

Browse files
committed
v1.1.0.0
1 parent d5ba36e commit 08d5fb5

16 files changed

+406
-95
lines changed

cropcoin-qt.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TEMPLATE = app
22
TARGET = cropcoin-qt
3-
VERSION = 1.0.0.3
3+
VERSION = 1.1.0.0
44
INCLUDEPATH += src src/json src/qt src/qt/plugins/mrichtexteditor
55
QT += network printsupport
66
DEFINES += ENABLE_WALLET

src/activemasternode.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,12 @@ bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, C
206206
CMasternode* pmn = mnodeman.Find(vin);
207207
if(pmn != NULL)
208208
{
209-
if(stop)
209+
if(stop) {
210210
mnodeman.Remove(pmn->vin);
211-
else
211+
}
212+
else{
212213
pmn->UpdateLastSeen();
214+
}
213215
} else {
214216
// Seems like we are trying to send a ping while the masternode is not registered in the network
215217
retErrorMessage = "Darksend Masternode List doesn't include our masternode, Shutting down masternode pinging service! " + vin.ToString();
@@ -438,7 +440,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()
438440
// Filter
439441
BOOST_FOREACH(const COutput& out, vCoins)
440442
{
441-
if(out.tx->vout[out.i].nValue == GetMNCollateral(pindexBest->nHeight)*COIN) { //exactly
443+
if (IsMNCollateralValid(out.tx->vout[out.i].nValue, pindexBest->nHeight)) {
442444
filteredCoins.push_back(out);
443445
}
444446
}
@@ -460,7 +462,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternodeForPubKey(std::string co
460462
// Filter
461463
BOOST_FOREACH(const COutput& out, vCoins)
462464
{
463-
if(out.tx->vout[out.i].scriptPubKey == scriptPubKey && out.tx->vout[out.i].nValue == GetMNCollateral(pindexBest->nHeight)*COIN) { //exactly
465+
if(out.tx->vout[out.i].scriptPubKey == scriptPubKey && IsMNCollateralValid(out.tx->vout[out.i].nValue, pindexBest->nHeight)) { //exactly
464466
filteredCoins.push_back(out);
465467
}
466468
}
@@ -473,6 +475,7 @@ bool CActiveMasternode::EnableHotColdMasterNode(CTxIn& newVin, CService& newServ
473475
if(!fMasterNode) return false;
474476

475477
status = MASTERNODE_REMOTELY_ENABLED;
478+
notCapableReason = "Successfully started masternode.";
476479

477480
//The values below are needed for signing dseep messages going forward
478481
this->vin = newVin;

src/clientversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
99
#define CLIENT_VERSION_MAJOR 1
10-
#define CLIENT_VERSION_MINOR 0
10+
#define CLIENT_VERSION_MINOR 1
1111
#define CLIENT_VERSION_REVISION 0
12-
#define CLIENT_VERSION_BUILD 3
12+
#define CLIENT_VERSION_BUILD 0
1313

1414
// Set to true for release, false for prerelease or test build
1515
#define CLIENT_VERSION_IS_RELEASE true

src/darksend.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,12 +2100,13 @@ bool CDarkSendSigner::IsVinAssociatedWithPubkey(CTxIn& vin, CPubKey& pubkey){
21002100
//if(GetTransaction(vin.prevout.hash, txVin, hash, true)){
21012101
if(GetTransaction(vin.prevout.hash, txVin, hash)){
21022102
BOOST_FOREACH(CTxOut out, txVin.vout){
2103-
if(out.nValue == GetMNCollateral(pindexBest->nHeight)*COIN){
2104-
if(out.scriptPubKey == payee2) return true;
2103+
if( IsMNCollateralValid(out.nValue, pindexBest->nHeight) ){
2104+
if(out.scriptPubKey == payee2) {
2105+
return true;
2106+
}
21052107
}
21062108
}
21072109
}
2108-
21092110
return false;
21102111
}
21112112

src/kernel.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
129129

130130
// Sort candidate blocks by timestamp
131131
vector<pair<int64_t, uint256> > vSortedByTimestamp;
132-
133132
if (pindexPrev->nTime > FORK_TIME)
134-
vSortedByTimestamp.reserve(64 * nModifierInterval / TARGET_SPACING_NEW);
135-
else
136-
vSortedByTimestamp.reserve(64 * nModifierInterval / TARGET_SPACING);
133+
vSortedByTimestamp.reserve(64 * nModifierInterval / TARGET_SPACING_NEW);
134+
else
135+
vSortedByTimestamp.reserve(64 * nModifierInterval / TARGET_SPACING);
137136

138137
int64_t nSelectionInterval = GetStakeModifierSelectionInterval();
139138
int64_t nSelectionIntervalStart = (pindexPrev->GetBlockTime() / nModifierInterval) * nModifierInterval - nSelectionInterval;

src/main.cpp

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,28 @@ struct CMainSignals {
110110
} g_signals;
111111
}
112112

113+
bool IsMNCollateralValid(int64_t value, int nHeight) {
114+
if (nHeight < TIERED_MASTERNODES_START_BLOCK) {
115+
return value == 5000*COIN;
116+
} else {
117+
// Using BOOST_FOREACH for concistency with the rest of the code, everything should be using a plain for from c++ 11 or 17
118+
BOOST_FOREACH(PAIRTYPE(const int, int)& mntier, masternodeTiers)
119+
{
120+
if (value == (mntier.second)*COIN)
121+
return true;
122+
}
123+
}
124+
return false;
125+
}
126+
127+
int64_t GetMNCollateral(int nHeight, int tier) {
128+
if (nHeight < TIERED_MASTERNODES_START_BLOCK) {
129+
return 5000;
130+
} else {
131+
return masternodeTiers[tier];
132+
}
133+
}
134+
113135
void RegisterWallet(CWalletInterface* pwalletIn) {
114136
g_signals.SyncTransaction.connect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3));
115137
g_signals.EraseTransaction.connect(boost::bind(&CWalletInterface::EraseFromWallet, pwalletIn, _1));
@@ -1368,6 +1390,33 @@ int64_t GetProofOfWorkReward(int nHeight, int64_t nFees)
13681390
return nSubsidy + nFees;
13691391
}
13701392

1393+
// Checks if a given reward present in a block is valid
1394+
bool IsPOSRewardValid(int64_t value, int64_t nFees) {
1395+
int nHeight = pindexBest->nHeight+1;
1396+
if (nHeight < 20000) {
1397+
return value == (25*COIN + nFees);
1398+
}
1399+
else {
1400+
if (nHeight < TIERED_MASTERNODES_START_BLOCK) {
1401+
return value == (120*COIN + nFees);
1402+
}
1403+
else {
1404+
// Using BOOST_FOREACH for concistency with the rest of the code
1405+
BOOST_FOREACH(PAIRTYPE(const int, int)& tier, masternodeTierRewards)
1406+
{
1407+
if (value == (tier.second*COIN + POS_REWARD_TIERED_MN*COIN + nFees))
1408+
return true;
1409+
}
1410+
// The case of a wallet staking with no mns up
1411+
if (value == POS_REWARD_TIERED_MN*COIN + nFees) {
1412+
return true;
1413+
}
1414+
}
1415+
}
1416+
return false;
1417+
}
1418+
1419+
13711420
// miner's coin stake reward
13721421
int64_t GetProofOfStakeReward(const CBlockIndex* pindexPrev, int64_t nCoinAge, int64_t nFees)
13731422
{
@@ -1376,15 +1425,11 @@ int64_t GetProofOfStakeReward(const CBlockIndex* pindexPrev, int64_t nCoinAge, i
13761425
if (pindexBest->nHeight+1 > 1 && pindexBest->nHeight+1 <= 20000) {
13771426
nSubsidy = 25 * COIN;
13781427
}
1379-
else if (pindexBest->nHeight+1 > 20000 && pindexBest->nHeight+1 <= 540000)
1428+
else if (pindexBest->nHeight+1 > 20000 && pindexBest->nHeight+1 < TIERED_MASTERNODES_START_BLOCK)
13801429
{
13811430
nSubsidy = 120 * COIN;
13821431
}
1383-
else if (pindexBest->nHeight+1 > 540000)
1384-
{
1385-
nSubsidy = 20 * COIN;
1386-
}
1387-
1432+
13881433
return nSubsidy + nFees;
13891434
}
13901435

@@ -1403,9 +1448,9 @@ unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfS
14031448
CBigNum bnTargetLimit = fProofOfStake ? GetProofOfStakeLimit(pindexLast->nHeight) : Params().ProofOfWorkLimit();
14041449

14051450
unsigned int nTargetTemp = TARGET_SPACING;
1406-
if (pindexLast->nTime > FORK_TIME)
1407-
nTargetTemp = TARGET_SPACING_NEW;
1408-
1451+
if (pindexLast->nTime > FORK_TIME)
1452+
nTargetTemp = TARGET_SPACING_NEW;
1453+
14091454
if (pindexLast == NULL)
14101455
return bnTargetLimit.GetCompact(); // genesis block
14111456

@@ -1976,10 +2021,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
19762021
if (!vtx[1].GetCoinAge(txdb, pindex->pprev, nCoinAge))
19772022
return error("ConnectBlock() : %s unable to get coin age for coinstake", vtx[1].GetHash().ToString());
19782023

1979-
int64_t nCalculatedStakeReward = GetProofOfStakeReward(pindex->pprev, nCoinAge, nFees);
1980-
1981-
if (nStakeReward > nCalculatedStakeReward)
1982-
return DoS(100, error("ConnectBlock() : coinstake pays too much(actual=%d vs calculated=%d)", nStakeReward, nCalculatedStakeReward));
2024+
if (!IsPOSRewardValid(nStakeReward, nFees))
2025+
return DoS(100, error("ConnectBlock() : coinstake pays too much(actual=%d)", nStakeReward));
19832026
}
19842027

19852028
// ppcoin: track money supply and mint amount info
@@ -2692,6 +2735,20 @@ bool CBlock::AcceptBlock()
26922735
pnode->PushInventory(CInv(MSG_BLOCK, hash));
26932736
}
26942737

2738+
// Record masternode payment
2739+
if (IsProofOfStake()) {
2740+
CScript payee;
2741+
for (int i = vtx[1].vout.size(); i--> 0; ) {
2742+
payee = vtx[1].vout[i].scriptPubKey;
2743+
break;
2744+
}
2745+
CTxDestination address1;
2746+
ExtractDestination(payee, address1);
2747+
CCropCoincoinAddress address2(address1);
2748+
2749+
mnodeman.RecordMasternodePayment(payee, nTime, PROTOCOL_VERSION);
2750+
}
2751+
26952752
return true;
26962753
}
26972754

src/main.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ inline int64_t FutureDrift(int64_t nTime) { return nTime + DRIFT; }
7575
/** "reject" message codes **/
7676
static const unsigned char REJECT_INVALID = 0x10;
7777

78-
inline int64_t GetMNCollateral(int nHeight) { return nHeight>=33333 ? 5000 : 2500; }
78+
int64_t GetMNCollateral(int nHeight, int tier);
79+
bool IsPOSRewardValid(int64_t value, int64_t nFees);
7980

8081
extern CScript COINBASE_FLAGS;
8182
extern CCriticalSection cs_main;
@@ -119,6 +120,8 @@ class CTxIndex;
119120
class CWalletInterface;
120121
struct CNodeStateStats;
121122

123+
/** Check a given amount to see if it matches any of the masternode tiers */
124+
bool IsMNCollateralValid(int64_t, int nHeight);
122125
/** Register a wallet to receive updates from core */
123126
void RegisterWallet(CWalletInterface* pwalletIn);
124127
/** Unregister a wallet from core */
@@ -329,7 +332,10 @@ class CTransaction
329332
{
330333
nValueOut += txout.nValue;
331334
if (!MoneyRange(txout.nValue) || !MoneyRange(nValueOut))
335+
{
336+
LogPrintf("OUT OF RANGE - txout.nValue: %i - nValueOut %i", txout.nValue, nValueOut);
332337
throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
338+
}
333339
}
334340
return nValueOut;
335341
}

src/masternode-payments.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDa
4242

4343
LOCK(cs_masternodepayments);
4444

45+
LogPrintf("MasternodePayments: declare winner");
4546
//this is required in litemode
4647
CMasternodePaymentWinner winner;
4748
vRecv >> winner;
@@ -88,6 +89,7 @@ void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDa
8889

8990
bool CMasternodePayments::CheckSignature(CMasternodePaymentWinner& winner)
9091
{
92+
LogPrintf("MasternodePayments: check signature");
9193
//note: need to investigate why this is failing
9294
std::string strMessage = winner.vin.ToString().c_str() + boost::lexical_cast<std::string>(winner.nBlockHeight) + winner.payee.ToString();
9395
std::string strPubKey = strMainPubKey ;
@@ -135,9 +137,9 @@ uint64_t CMasternodePayments::CalculateScore(uint256 blockHash, CTxIn& vin)
135137
uint256 n3 = Hash(BEGIN(vin.prevout.hash), END(vin.prevout.hash));
136138
uint256 n4 = n3 > n2 ? (n3 - n2) : (n2 - n3);
137139

138-
//printf(" -- CMasternodePayments CalculateScore() n2 = %d \n", n2.Get64());
139-
//printf(" -- CMasternodePayments CalculateScore() n3 = %d \n", n3.Get64());
140-
//printf(" -- CMasternodePayments CalculateScore() n4 = %d \n", n4.Get64());
140+
// printf(" -- CMasternodePayments CalculateScore() n2 = %d \n", n2.Get64());
141+
// printf(" -- CMasternodePayments CalculateScore() n3 = %d \n", n3.Get64());
142+
// printf(" -- CMasternodePayments CalculateScore() n4 = %d \n", n4.Get64());
141143

142144
return n4.Get64();
143145
}

src/masternode.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ CMasternode::CMasternode()
9090
//mark last paid as current for new entries
9191
nLastPaid = GetAdjustedTime();
9292
isPortOpen = true;
93+
tier = 0;
9394
}
9495

9596
CMasternode::CMasternode(const CMasternode& other)
@@ -117,8 +118,9 @@ CMasternode::CMasternode(const CMasternode& other)
117118
nScanningErrorCount = other.nScanningErrorCount;
118119
nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight;
119120
nLastPaid = other.nLastPaid;
120-
nLastPaid = GetAdjustedTime();
121121
isPortOpen = other.isPortOpen;
122+
tier = other.tier;
123+
score = other.score;
122124
}
123125

124126
CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64_t newSigTime, CPubKey newPubkey2, int protocolVersionIn, CScript newRewardAddress, int newRewardPercentage)
@@ -146,6 +148,10 @@ CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std:
146148
nScanningErrorCount = 0;
147149
nLastScanningErrorBlockHeight = 0;
148150
isPortOpen = true;
151+
tier = 1;
152+
score = 0;
153+
// On new additions set last paid to now
154+
nLastPaid = GetAdjustedTime();
149155
}
150156

151157
//
@@ -192,14 +198,45 @@ void CMasternode::Check()
192198
return;
193199
}
194200

195-
if(!unitTest){
196-
CValidationState state;
197-
CTransaction tx = CTransaction();
198-
CTxOut vout = CTxOut((GetMNCollateral(pindexBest->nHeight)-1)*COIN, darkSendPool.collateralPubKey);
199-
tx.vin.push_back(vin);
200-
tx.vout.push_back(vout);
201+
bool fAcceptable = false;
201202

202-
if(!AcceptableInputs(mempool, tx, false, NULL)){
203+
if(!unitTest) {
204+
CTransaction tx = CTransaction();
205+
if (tier == 0) {
206+
BOOST_FOREACH(PAIRTYPE(const int, int) & mntier, masternodeTiers)
207+
{
208+
if (!fAcceptable) {
209+
CTxOut vout = CTxOut((GetMNCollateral(pindexBest->nHeight, mntier.first)) * COIN,
210+
darkSendPool.collateralPubKey);
211+
tx.vin.push_back(vin);
212+
tx.vout.push_back(vout);
213+
{
214+
TRY_LOCK(cs_main, lockMain);
215+
if (!lockMain) return;
216+
fAcceptable = AcceptableInputs(mempool, tx, false, NULL);
217+
if (fAcceptable) { // Update mn tier on our records
218+
tier = (mntier.first);
219+
}
220+
else {
221+
tx.vin.pop_back();
222+
tx.vout.pop_back();
223+
}
224+
}
225+
}
226+
}
227+
}
228+
else {
229+
CTxOut vout = CTxOut((GetMNCollateral(pindexBest->nHeight, tier)) * COIN,
230+
darkSendPool.collateralPubKey);
231+
tx.vin.push_back(vin);
232+
tx.vout.push_back(vout);
233+
{
234+
TRY_LOCK(cs_main, lockMain);
235+
if (!lockMain) return;
236+
fAcceptable = AcceptableInputs(mempool, tx, false, NULL);
237+
}
238+
}
239+
if (!fAcceptable) {
203240
activeState = MASTERNODE_VIN_SPENT;
204241
return;
205242
}

0 commit comments

Comments
 (0)