Skip to content

Commit

Permalink
Enable Prime Node and Orion Controller;
Browse files Browse the repository at this point in the history
Add checkpoint to block 6888;
Release version 1.2.20
Change Copyright in About page;
	new file:   Makefile
	modified:   paycoin.pro
	modified:   share/setup.nsi
	modified:   src/checkpoints.cpp
	modified:   src/db.cpp
	modified:   src/kernel.cpp
	modified:   src/main.cpp
	modified:   src/main.h
	modified:   src/qt/forms/aboutdialog.ui
	modified:   src/script.cpp
	modified:   src/script.h
	modified:   src/version.h
	modified:   src/wallet.cpp
	modified:   src/wallet.h
  • Loading branch information
paycoindev committed Dec 20, 2014
1 parent 7948bdc commit 6fc98f9
Show file tree
Hide file tree
Showing 14 changed files with 2,351 additions and 39 deletions.
2,064 changes: 2,064 additions & 0 deletions Makefile

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion paycoin.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = paycoin
VERSION = 0.1.2.0
VERSION = 0.1.2.20
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE USE_IPV6
CONFIG += no_include_pwd
Expand Down
4 changes: 2 additions & 2 deletions share/setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SetCompressor /SOLID lzma

# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"
!define VERSION 0.1.2.0
!define VERSION 0.1.2.20
!define COMPANY "Paycoin project"
!define URL http://github.com/paycoin/paycoin/
!define URL https://github.com/GAWMiners/paycoin/

# MUI Symbol Definitions
!define MUI_ICON "../share/pixmaps/paycoin.ico"
Expand Down
1 change: 1 addition & 0 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Checkpoints
boost::assign::map_list_of
( 0, hashGenesisBlockOfficial )
( 276, uint256("0x0000000000000073a6b02412fc261414fde6304366ca7d90cc0c175516d52272"))
( 6888, uint256("0x00000000000000077ae1fcd6f73b21cb62e1410db57f4a5decb2728cdfc2df84"))
;

bool CheckHardened(int nHeight, const uint256& hash)
Expand Down
2 changes: 1 addition & 1 deletion src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ bool CTxDB::LoadBlockIndex()
pindex->bnChainTrust = (pindex->pprev ? pindex->pprev->bnChainTrust : 0) + pindex->GetBlockTrust();
// paycoin: calculate stake modifier checksum
pindex->nStakeModifierChecksum = GetStakeModifierChecksum(pindex);
printf("pindex->nStakeModifierChecksum = %x\n", pindex->nStakeModifierChecksum);
// printf("pindex->nStakeModifierChecksum = %x height = %d\n", pindex->nStakeModifierChecksum, pindex->nHeight);
if (!CheckStakeModifierCheckpoints(pindex->nHeight, pindex->nStakeModifierChecksum))
return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindex->nHeight, pindex->nStakeModifier);
}
Expand Down
3 changes: 2 additions & 1 deletion src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ unsigned int nModifierInterval = MODIFIER_INTERVAL;
static std::map<int, unsigned int> mapStakeModifierCheckpoints =
boost::assign::map_list_of
( 0, 0x0e00670bu )
( 276, 0xb0807bc0u )
( 276, 0x839c892fu )
( 6888, 0x876037ebu )
;

// Whether the given coinstake is subject to new v0.3 protocol
Expand Down
191 changes: 183 additions & 8 deletions src/main.cpp

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CRequestTracker;
class CNode;

static const unsigned int MAX_BLOCK_SIZE = 1000000;
//static const unsigned int MAX_BLOCK_SIZE = 100000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
Expand All @@ -45,18 +46,21 @@ static const int STAKE_TARGET_SPACING = 1 * 60; // 1-minute block
//static const int STAKE_TARGET_SPACING = 1; // 1 second block spacing
static const int STAKE_MIN_AGE = 60 * 60; // minimum age for coin age
//static const int STAKE_MIN_AGE = 60; // minimum age for coin age
static const int STAKE_MAX_AGE = 60 * 60 * 24 * 30; // stake age of full weight
static const int STAKE_MAX_AGE = 60 * 60 * 24 * 5; // stake age of full weight
//static const int STAKE_MAX_AGE = 60 * 2; // stake age of full weight
static const int STAKE_START_TIME = 1418470264; // Sat 13 Dec 2014 06:31:04 AM EST
//static const int STAKE_START_TIME = 1418345400; // Thu 11 Dec 2014 05:30:00 PM EST
static const unsigned int POW_START_TIME = 1418403600; // Fri 12 Dec 2014 12:00:00 PM EST
//static const unsigned int POW_START_TIME = 1418345100; // Thu 11 Dec 2014 05:00:00 PM EST
static const unsigned int POW_END_TIME = 1419094800; // Sat 20 Dec 2014 12:00:00 PM EST
static const unsigned int POW_END_TIME = 1419181200; // Sun 21 Dec 2014 12:00:00 PM EST
//static const unsigned int POW_END_TIME = 1418345700; // Thu 11 Dec 2014 05:40:00 PM EST
// MODIFIER_INTERVAL: time to elapse before new modifier is computed
static const unsigned int MODIFIER_INTERVAL = 6 * 60 * 60;
//static const unsigned int MODIFIER_INTERVAL = 6 * 60 * 60;
static const unsigned int MODIFIER_INTERVAL = 10 * 60;
//static const unsigned int MODIFIER_INTERVAL = 10;

static const int64 NUMBER_OF_PRIMENODE = 50;
static const int64 MINIMUM_FOR_ORION = 50 * COIN;
static const int64 MINIMUM_FOR_PRIMENODE = 125000 * COIN;

#ifdef USE_UPNP
static const int fHaveUPnP = true;
Expand Down Expand Up @@ -130,7 +134,7 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
int64 GetProofOfWorkReward(unsigned int nBits);
int64 GetProofOfStakeReward(int64 nCoinAge, bool isPrimeNode=false);
int64 GetProofOfStakeReward(int64 nCoinAge, int primeNodeRate=-1);
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime, bool fProofOfStake);
int GetNumBlocksOfPeers();
bool IsInitialBlockDownload();
Expand Down Expand Up @@ -541,8 +545,14 @@ class CTransaction

bool IsCoinStake() const
{
if(!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE){
return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].scriptPubKey[0] == OP_PRIMENODE);
if(!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE350){
return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].scriptPubKey[0] == OP_PRIMENODE350);
}else if(!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE100){
return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].scriptPubKey[0] == OP_PRIMENODE100);
}else if(!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE20){
return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].scriptPubKey[0] == OP_PRIMENODE20);
}else if(!vout[0].IsEmpty() && vout[0].scriptPubKey[0] == OP_PRIMENODE10){
return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].scriptPubKey[0] == OP_PRIMENODE10);
}else{
return (vin.size() > 0 && (!vin[0].prevout.IsNull()) && vout.size() >= 2 && vout[0].IsEmpty());
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/forms/aboutdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<item>
<widget class="QLabel" name="label_paycoin_copyright">
<property name="text">
<string>Copyright © 2011-2014 Paycoin Developers</string>
<string>Copyright © 2011-2014 Peercoin Developers</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down
6 changes: 5 additions & 1 deletion src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ const char* GetOpName(opcodetype opcode)
case OP_NOP10 : return "OP_NOP10";

// cool feature
case OP_PRIMENODE : return "OP_PRIMENODE";
case OP_PRIMENODE350 : return "OP_PRIMENODE350";
case OP_PRIMENODE100 : return "OP_PRIMENODE100";
case OP_PRIMENODE20 : return "OP_PRIMENODE20";
case OP_PRIMENODE10 : return "OP_PRIMENODE10";



// template matching params
Expand Down
6 changes: 5 additions & 1 deletion src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ enum opcodetype
OP_NOP10 = 0xb9,

// cool feature
OP_PRIMENODE = 0xc1,
OP_PRIMENODE350 = 0xc1,
OP_PRIMENODE100 = 0xc2,
OP_PRIMENODE20 = 0xc3,
OP_PRIMENODE10 = 0xc4,


// template matching params
OP_SMALLINTEGER = 0xfa,
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define PEERUNITY_VERSION_MAJOR 0
#define PEERUNITY_VERSION_MINOR 1
#define PEERUNITY_VERSION_REVISION 2
#define PEERUNITY_VERSION_BUILD 10
#define PEERUNITY_VERSION_BUILD 20

static const int PEERUNITY_VERSION =
1000000 * PEERUNITY_VERSION_MAJOR
Expand Down
81 changes: 67 additions & 14 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,14 @@ bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& w
}

// paycoin: create coin stake transaction
bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew)
bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, int64 nMoneySupply)
{
// The following split & combine thresholds are important to security
// Should not be adjusted if you don't understand the consequences
static unsigned int nStakeSplitAge = (60 * 60 * 24 * 90);
int64 nCombineThreshold = 50 * COIN;
static unsigned int nStakeSplitAge = (60 * 60 * 24 * 15);
// static unsigned int nStakeSplitAge = (60 * 6);
// orion controller
int64 nCombineThreshold = MINIMUM_FOR_ORION;


CBigNum bnTargetPerCoinDay;
Expand All @@ -1287,12 +1289,50 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
txNew.vout.clear();

// Make variable interested rate
bool isPrimeNode = false;
unsigned int primeNodeRate = 0;

if (mapArgs.count("-primenodekey") && mapArgs.count("-primenoderate")) // paycoin: primenode priv key
{
std::string strPrivKey = GetArg("-primenodekey", "");
std::vector<unsigned char> vchPrivKey = ParseHex(strPrivKey);
CKey key;
key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash
CScript scriptTime;
scriptTime << txNew.nTime;
uint256 hashScriptTime = Hash(scriptTime.begin(), scriptTime.end());
std::vector<unsigned char> vchSig;
if(!key.Sign(hashScriptTime, vchSig)){
return error("CreateCoinStake : Unable to sign checkpoint, wrong primenodekey?");
}
CScript scriptPrimeNode;
std::string primeNodeRateArg = GetArg("-primenoderate", "");
if (primeNodeRateArg.compare("350") == 0){
scriptPrimeNode << OP_PRIMENODE350 << vchSig;
primeNodeRate = 350;
nCombineThreshold = MINIMUM_FOR_PRIMENODE;
}else if (primeNodeRateArg.compare("100") == 0){
scriptPrimeNode << OP_PRIMENODE100 << vchSig;
primeNodeRate = 100;
nCombineThreshold = MINIMUM_FOR_PRIMENODE;
}else if (primeNodeRateArg.compare("20") == 0){
scriptPrimeNode << OP_PRIMENODE20 << vchSig;
primeNodeRate = 20;
nCombineThreshold = MINIMUM_FOR_PRIMENODE;
}else if (primeNodeRateArg.compare("10") == 0){
scriptPrimeNode << OP_PRIMENODE10 << vchSig;
primeNodeRate = 10;
nCombineThreshold = MINIMUM_FOR_PRIMENODE;
}else{
return error("CreateCoinStake : Primenode rate configuration is wrong or missing");
}
txNew.vout.push_back(CTxOut(0, scriptPrimeNode));
}else{
// Mark coin stake transaction
CScript scriptEmpty;
scriptEmpty.clear();
txNew.vout.push_back(CTxOut(0, scriptEmpty));
}

// Mark coin stake transaction
CScript scriptEmpty;
scriptEmpty.clear();
txNew.vout.push_back(CTxOut(0, scriptEmpty));
// Choose coins to use
int64 nBalance = GetBalance();
int64 nReserveBalance = 0;
Expand Down Expand Up @@ -1395,24 +1435,30 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
&& pcoin.first->GetHash() != txNew.vin[0].prevout.hash)
{
// Stop adding more inputs if already too many inputs
if (txNew.vin.size() >= 100)
if (txNew.vin.size() >= 100){
break;
}
// Stop adding more inputs if value is already pretty significant
if (nCredit > nCombineThreshold)
if (nCredit >= nCombineThreshold){
break;
}
// Stop adding inputs if reached reserve limit
if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance)
if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance){
break;
}
// Do not add additional significant input
if (pcoin.first->vout[pcoin.second].nValue > nCombineThreshold)
if (pcoin.first->vout[pcoin.second].nValue >= nCombineThreshold){
continue;
}
// Do not add input that is still too young
if (pcoin.first->nTime + STAKE_MAX_AGE > txNew.nTime)
if (pcoin.first->nTime + STAKE_MAX_AGE > txNew.nTime){
continue;
}
txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
nCredit += pcoin.first->vout[pcoin.second].nValue;
vwtxPrev.push_back(pcoin.first);
}

}
// Calculate coin age reward
{
Expand All @@ -1421,7 +1467,14 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (!txNew.GetCoinAge(txdb, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age");

int64 nReward = GetProofOfStakeReward(nCoinAge, isPrimeNode);
if (primeNodeRate != 0 && nCredit < MINIMUM_FOR_PRIMENODE){
return error("CreateCoinStake : credit doesn't meet requirement for primenode; credit = %lld; requirement = %lld nCombineThreshold = %lld\n", nCredit, MINIMUM_FOR_PRIMENODE, nCombineThreshold);
}else if (primeNodeRate == 0 && nCredit < MINIMUM_FOR_ORION){
return error("CreateCoinStake : credit doesn't meet requirement for orion controller; credit = %lld; requirement = %lld nCombineThreshold = %lld\n", nCredit, MINIMUM_FOR_ORION, nCombineThreshold);
}

int64 nReward = GetProofOfStakeReward(nCoinAge, primeNodeRate);

// Refuse to create mint that has zero or negative reward
if(nReward <= 0) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class CWallet : public CCryptoKeyStore
int64 GetNewMint() const;
bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew);
bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, int64 nMoneySupply);
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
Expand Down

0 comments on commit 6fc98f9

Please sign in to comment.