Skip to content

Commit

Permalink
Merge pull request #47 from IngCr3at1on/reset-stake-rate
Browse files Browse the repository at this point in the history
Reset stake rate
  • Loading branch information
PaycoinMaster committed Apr 12, 2015
2 parents 9d584a7 + e09a4ec commit cf1eaf6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#include "util.h"
#include "ui_interface.h"
#include "checkpoints.h"
#include "version.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <ctime>

#ifndef WIN32
#include <signal.h>
Expand All @@ -25,6 +27,7 @@ using namespace std;
using namespace boost;

CWallet* pwalletMain;
int MIN_PROTO_VERSION = 70001;

//////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -373,6 +376,13 @@ bool AppInit2(int argc, char* argv[])
return false;
}

/* Check and update minium version protocol after a given time (same time
* as resetting the primenode stake rates; do this here to insure that it's
* done before attempting to load the blockchain, etc (this is also why we
* use a time instead of a block number). */
if(time(NULL) >= RESET_PRIMERATES)
MIN_PROTO_VERSION = 70002;

std::ostringstream strErrors;
//
// Load data files
Expand Down
37 changes: 30 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,15 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
return DoS(10, error("CTransaction::ConnectInputs() : verify signature failed"));
if (GetValueOut() < MINIMUM_FOR_PRIMENODE)
return DoS(100, error("ConnectInputs() : credit doesn't meet requirement for primenode = %lld while you only have %lld", MINIMUM_FOR_PRIMENODE, GetValueOut()));
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 350) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
/* Use time instead of block number because we can better
* control when a manditory wallet update is required. */
if (nTime >= RESET_PRIMERATES) {
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 100) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
} else {
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 350) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
}

}else if (!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE100){
std::vector<string> pubKeyList;
Expand Down Expand Up @@ -1453,7 +1460,8 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
return DoS(10, error("CTransaction::ConnectInputs() : verify signature failed"));
if (GetValueOut() < MINIMUM_FOR_PRIMENODE)
return DoS(100, error("ConnectInputs() : credit doesn't meet requirement for primenode = %lld while you only have %lld", MINIMUM_FOR_PRIMENODE, GetValueOut()));
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 100) - GetMinFee() + MIN_TX_FEE)
// No need to adjust as this is already at 100.
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 100) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));

}else if (!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE20){
Expand Down Expand Up @@ -1481,8 +1489,16 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
return DoS(10, error("CTransaction::ConnectInputs() : verify signature failed"));
if (GetValueOut() < MINIMUM_FOR_PRIMENODE)
return DoS(100, error("ConnectInputs() : credit doesn't meet requirement for primenode = %lld while you only have %lld", MINIMUM_FOR_PRIMENODE, GetValueOut()));
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 20) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));

/* Use time instead of block number because we can better
* control when a manditory wallet update is required. */
if (nTime >= RESET_PRIMERATES) {
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 100) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
} else {
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 20) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
}

}else if (!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE10){
std::vector<string> pubKeyList;
Expand All @@ -1509,8 +1525,15 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
return DoS(10, error("CTransaction::ConnectInputs() : verify signature failed"));
if (GetValueOut() < MINIMUM_FOR_PRIMENODE)
return DoS(100, error("ConnectInputs() : credit doesn't meet requirement for primenode = %lld while you only have %lld", MINIMUM_FOR_PRIMENODE, GetValueOut()));
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 10) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
/* Use time instead of block number because we can better
* control when a manditory wallet update is required. */
if (nTime >= RESET_PRIMERATES) {
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 100) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
} else {
if (nStakeReward > GetProofOfStakeReward(nCoinAge, 10) - GetMinFee() + MIN_TX_FEE)
return DoS(100, error("ConnectInputs() : %s stake reward exceeded", GetHash().ToString().substr(0,10).c_str()));
}

}else if (vout[0].IsEmpty()) {
if(GetValueOut() <= MINIMUM_FOR_ORION){
Expand Down
3 changes: 2 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ static const int64 NUMBER_OF_PRIMENODE = 50;
static const int64 MINIMUM_FOR_ORION = 50 * COIN;
static const int64 MINIMUM_FOR_PRIMENODE = 125000 * COIN;
static const int MAX_TIME_SINCE_BEST_BLOCK = 10; // how many seconds to wait before sending next PushGetBlocks()

// Reset all primenode stakerates to 100% after the given date
static const unsigned int RESET_PRIMERATES = 1429531200; // Mon, 20 Apr 2015 12:00:00 GMT

#ifdef USE_UPNP
static const int fHaveUPnP = true;
Expand Down
14 changes: 14 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,17 @@ void ThreadSocketHandler2(void* parg)
printf("ThreadSocketHandler started\n");
list<CNode*> vNodesDisconnected;
unsigned int nPrevNodeCount = 0;
bool droppedPostVersionChange = false;
bool droppingPostVersionChange = false;

loop
{
if (MIN_PROTO_VERSION != 70002 && !droppedPostVersionChange && time(NULL) >= RESET_PRIMERATES)
{
droppedPostVersionChange = true;
droppingPostVersionChange = true;
MIN_PROTO_VERSION = 70002;
}
//
// Disconnect nodes
//
Expand All @@ -666,6 +674,9 @@ void ThreadSocketHandler2(void* parg)
vector<CNode*> vNodesCopy = vNodes;
BOOST_FOREACH(CNode* pnode, vNodesCopy)
{
if (droppingPostVersionChange)
pnode->fDisconnect = true;

if (pnode->fDisconnect ||
(pnode->GetRefCount() <= 0 && pnode->vRecv.empty() && pnode->vSend.empty()))
{
Expand All @@ -687,6 +698,9 @@ void ThreadSocketHandler2(void* parg)
}
}

if (droppingPostVersionChange)
droppingPostVersionChange = false;

// Delete disconnected nodes
list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected;
BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy)
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ extern const std::string CLIENT_DATE;
// network protocol versioning
//

static const int PROTOCOL_VERSION = 70001;
static const int PROTOCOL_VERSION = 70002;

// earlier versions not supported as of Feb 2012, and are disconnected
// NOTE: as of bitcoin v0.6 message serialization (vSend, vRecv) still
// uses MIN_PROTO_VERSION(209), where message format uses PROTOCOL_VERSION
static const int MIN_PROTO_VERSION = 70001;
extern int MIN_PROTO_VERSION;

// nTime field added to CAddress, starting with this version;
// if possible, avoid requesting addresses nodes older than this
Expand Down
5 changes: 5 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,11 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
}else{
return error("CreateCoinStake : Primenode rate configuration is wrong or missing");
}

if (txNew.nTime >= RESET_PRIMERATES) {
primeNodeRate = 100;
}

printf("Primenode rate for staking is %d\n", primeNodeRate);
txNew.vout.push_back(CTxOut(0, scriptPrimeNode));
}else{
Expand Down

0 comments on commit cf1eaf6

Please sign in to comment.