Skip to content

Commit

Permalink
Merge pull request #3 from bumbacoin/fork
Browse files Browse the repository at this point in the history
Fork - 
fix difficulty targeting, increase block time, increase min stake age

add new checkpoint key and testnet genesis
  • Loading branch information
bumbacoin committed Jan 13, 2019
2 parents b91115a + 31a08ed commit 32bc4b7
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 34 deletions.
5 changes: 3 additions & 2 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Checkpoints
( 300000, uint256("0xe0eb7dcfe1c5ec4480553e25d38e00e67b2acd82a05afe5c54158920b1ecc65e"))
( 400000, uint256("0xed66f89a31829197126e4b91397ad76e33ada6b062e26964475f464b7b82209d"))
( 500000, uint256("0x42cf6cd2dfd0affbd4830da96672c6d7111c602a1f27ece7fd689c6904192e12"))
( 2249000, uint256("0x0d027bd1a27f90e850f8aebc592453d6293366935f0b806a00d88367b7523e16"))
;

// TestNet has no checkpoints
Expand Down Expand Up @@ -347,12 +348,12 @@ namespace Checkpoints
assert(mapBlockIndex.count(hashSyncCheckpoint));
const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
return (nBestHeight >= pindexSync->nHeight + nCoinbaseMaturity ||
pindexSync->GetBlockTime() + nStakeMinAge < GetAdjustedTime());
pindexSync->GetBlockTime() + (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2) < GetAdjustedTime());
}
}

// ppcoin: sync-checkpoint master key
const std::string CSyncCheckpoint::strMasterPubKey = "null";
const std::string CSyncCheckpoint::strMasterPubKey = "047557b0a5abf1d48a1608c5a8dbff30453acce42a3d82b0ee9a6545ec981eafdb25bdf5d64eeed5dd1e9c451d3794f50278afac98bbb588bf80223aad4bfbfb3d";

std::string CSyncCheckpoint::strMasterPrivKey = "";

Expand Down
4 changes: 2 additions & 2 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 1
#define CLIENT_VERSION_MINOR 2
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 1
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
// Don't merge these into one macro!
Expand Down
10 changes: 6 additions & 4 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace std;

extern unsigned int nStakeMaxAge;
extern unsigned int nTargetSpacing;
extern unsigned int nTargetSpacing_2;

typedef std::map<int, unsigned int> MapModifierCheckpoints;

Expand All @@ -33,7 +34,7 @@ int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd)
// this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low

return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64_t)nStakeMaxAge);
return min(nIntervalEnd - nIntervalBeginning - (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2), (int64_t)nStakeMaxAge);
}

// Get the last stake modifier and its generation time from a given block
Expand Down Expand Up @@ -148,7 +149,8 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod

// Sort candidate blocks by timestamp
vector<pair<int64_t, uint256> > vSortedByTimestamp;
vSortedByTimestamp.reserve(64 * nModifierInterval / nTargetSpacing);
// vSortedByTimestamp.reserve(64 * nModifierInterval / nTargetSpacing);
vSortedByTimestamp.reserve(64 * nModifierInterval / (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nTargetSpacing : nTargetSpacing_2));
int64_t nSelectionInterval = GetStakeModifierSelectionInterval();
int64_t nSelectionIntervalStart = (pindexPrev->GetBlockTime() / nModifierInterval) * nModifierInterval - nSelectionInterval;
const CBlockIndex* pindex = pindexPrev;
Expand Down Expand Up @@ -232,7 +234,7 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifi
{
if (!pindex->pnext)
{ // reached best block; may happen if node is behind on block chain
if (fPrintProofOfStake || (pindex->GetBlockTime() + nStakeMinAge - nStakeModifierSelectionInterval > GetAdjustedTime()))
if (fPrintProofOfStake || (pindex->GetBlockTime() + (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2) - nStakeModifierSelectionInterval > GetAdjustedTime()))
return error("GetKernelStakeModifier() : reached best block %s at height %d from block %s",
pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, hashBlockFrom.ToString().c_str());
else
Expand Down Expand Up @@ -276,7 +278,7 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned
return error("CheckStakeKernelHash() : nTime violation");

unsigned int nTimeBlockFrom = blockFrom.GetBlockTime();
if (nTimeBlockFrom + nStakeMinAge > nTimeTx) // Min age requirement
if (nTimeBlockFrom + (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2) > nTimeTx) // Min age requirement
return error("CheckStakeKernelHash() : min age violation");

CBigNum bnTargetPerCoinDay;
Expand Down
46 changes: 30 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ CBigNum bnProofOfWorkLimit(~uint256(0) >> 20);
CBigNum bnProofOfStakeLimit(~uint256(0) >> 20);
CBigNum bnProofOfWorkLimitTestNet(~uint256(0) >> 16);

unsigned int nTargetSpacing = 1 * 60; // 1 minute
unsigned int nStakeMinAge = 1* 10 * 60; // 10 minutes
unsigned int nTargetSpacing = 60 ;
unsigned int nTargetSpacing_2 = 150;

unsigned int nStakeMinAge = 1 * 10 * 60; // 10 minutes
unsigned int nStakeMinAge_2 = 24 * 60 * 60; // 24 hours
unsigned int nStakeMaxAge = 30 * 24 * 60 * 60; // 30 days
unsigned int nModifierInterval = 10 * 60; // time to elapse before new modifier is computed

static const int64_t nTargetTimespan = 10 * 60;
static const int64_t nTargetTimespan_2 = 24 * 60 * 60;

int nCoinbaseMaturity = 40;
CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1;
Expand Down Expand Up @@ -999,20 +1005,24 @@ int64_t GetProofOfStakeReward(int64_t nCoinAge, int64_t nFees)
return nSubsidy + nFees;
}


else // change to fixed reward of 2 coins
else if (pindexBest->nHeight > LAST_POW_BLOCK && pindexBest->nHeight < HARD_FORK_DIFF_FIX)
{
int64_t nSubsidy = 2 * COIN;
return nSubsidy + nFees;
}

else // increase reward to match increased block time
{
int64_t nSubsidy = 5 * COIN;
return nSubsidy + nFees;
}

if (fDebug && GetBoolArg("-printcreation"))
printf("GetProofOfStakeReward(): create=%s nCoinAge=%"PRId64"\n", FormatMoney(nSubsidy).c_str(), nCoinAge);

return nSubsidy + nFees;
}

static const int64_t nTargetTimespan = 10 * 60; // 10 mins
//
// maximum nBits value could possible be required nTime after
//
Expand Down Expand Up @@ -1074,16 +1084,18 @@ static unsigned int GetNextTargetRequired_(const CBlockIndex* pindexLast, bool f
return bnTargetLimit.GetCompact(); // second block

int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();
if (nActualSpacing < 0)
nActualSpacing = nTargetSpacing;
if(pindexBest->nHeight < HARD_FORK_DIFF_FIX )
{ if (nActualSpacing < 0)
nActualSpacing = nTargetSpacing; }
unsigned int nSpacing = pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nTargetSpacing : nTargetSpacing_2;

// ppcoin: target change every block
// ppcoin: retarget with exponential moving toward target spacing
CBigNum bnNew;
bnNew.SetCompact(pindexPrev->nBits);
int64_t nInterval = nTargetTimespan / nTargetSpacing;
bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
bnNew /= ((nInterval + 1) * nTargetSpacing);
int64_t nInterval = (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nTargetTimespan : nTargetTimespan_2) / nSpacing;
bnNew *= ((nInterval - 1) * nSpacing + nActualSpacing + nActualSpacing);
bnNew /= ((nInterval + 1) * nSpacing);

if (bnNew <= 0 || bnNew > bnTargetLimit)
bnNew = bnTargetLimit;
Expand Down Expand Up @@ -1891,7 +1903,7 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64_t& nCoinAge) const
CBlock block;
if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
return false; // unable to read block of previous transaction
if (block.GetBlockTime() + nStakeMinAge > nTime)
if (block.GetBlockTime() + (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2) > nTime)
continue; // only count coins meeting min age requirement

int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue;
Expand Down Expand Up @@ -2453,7 +2465,8 @@ bool LoadBlockIndex(bool fAllowNew)
if (fTestNet)
{
bnProofOfWorkLimit = bnProofOfWorkLimitTestNet; // PoW base target is fixed in testnet
nStakeMinAge = 20 * 60; // test net min age is 20 min
nStakeMinAge = 1 * 60; // test net min age is 20 min
nStakeMinAge_2 = 1 * 90; // test net min age is 20 min
nCoinbaseMaturity = 10; // test maturity is 10 blocks
}

Expand Down Expand Up @@ -2489,7 +2502,8 @@ bool LoadBlockIndex(bool fAllowNew)
block.nNonce = 729236;
if(fTestNet)
{
block.nNonce = 729236;
block.nNonce = 0;
block.nTime = 1547414304;
}
if (false && (block.GetHash() != hashGenesisBlock)) {

Expand All @@ -2513,7 +2527,7 @@ bool LoadBlockIndex(bool fAllowNew)
printf("block.nNonce = %u \n", block.nNonce);

//// debug print
assert(block.hashMerkleRoot == uint256("0x30bc1694525feefebbe7066c9f138aa20f135846a51f3189608ada17dbed97d6"));
// assert(block.hashMerkleRoot == uint256("0x30bc1694525feefebbe7066c9f138aa20f135846a51f3189608ada17dbed97d6"));
block.print();
assert(block.GetHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet));

Expand Down Expand Up @@ -2806,7 +2820,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CAddress addrFrom;
uint64_t nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion < MIN_PROTO_VERSION)
if (pfrom->nVersion < (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? MIN_PROTO_VERSION : MIN_PROTO_VERSION_FORK))
{
printf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString().c_str(), pfrom->nVersion);
pfrom->fDisconnect = true;
Expand Down Expand Up @@ -3140,7 +3154,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
printf(" getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str());
// ppcoin: tell downloading node about the latest block if it's
// without risk being rejected due to stake connection check
if (hashStop != hashBestChain && pindex->GetBlockTime() + nStakeMinAge > pindexBest->GetBlockTime())
if (hashStop != hashBestChain && pindex->GetBlockTime() + (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2) > pindexBest->GetBlockTime())
pfrom->PushInventory(CInv(MSG_BLOCK, hashBestChain));
break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CRequestTracker;
class CNode;

static const int LAST_POW_BLOCK = 465000;
static const int64_t HARD_FORK_DIFF_FIX = 2280000; //allow -ve timestamps to effect difficulty, increase timespan and blocksize

static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
Expand Down Expand Up @@ -56,7 +57,7 @@ static const int fHaveUPnP = false;
#endif

static const uint256 hashGenesisBlock("0x00000e2781c9a29cbd75ee5a69394a950fc72276236d28e04f36d24034a293ae");
static const uint256 hashGenesisBlockTestNet("0x00000e2781c9a29cbd75ee5a69394a950fc72276236d28e04f36d24034a293ae");
static const uint256 hashGenesisBlockTestNet("0x000065b304016af954f8a57516beb7a910efb51b613fd8ea352167fe4403d8a7");
inline int64_t PastDrift(int64_t nTime) { return nTime - 10 * 60; } // up to 10 minutes from the past
inline int64_t FutureDrift(int64_t nTime) { return nTime + 10 * 60; } // up to 10 minutes from the future

Expand All @@ -67,6 +68,7 @@ extern std::map<uint256, CBlockIndex*> mapBlockIndex;
extern std::set<std::pair<COutPoint, unsigned int> > setStakeSeen;
extern CBlockIndex* pindexGenesisBlock;
extern unsigned int nStakeMinAge;
extern unsigned int nStakeMinAge_2;
extern unsigned int nNodeLifespan;
extern int nCoinbaseMaturity;
extern int nBestHeight;
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

extern CWallet* pwalletMain;
extern int64_t nLastCoinStakeSearchInterval;
extern unsigned int nTargetSpacing;
extern unsigned int nTargetSpacing_2;
double GetPoSKernelPS();

BitcoinGUI::BitcoinGUI(QWidget *parent):
Expand Down Expand Up @@ -974,7 +974,7 @@ void BitcoinGUI::updateStakingIcon()
if (nLastCoinStakeSearchInterval && nWeight)
{
uint64_t nNetworkWeight = GetPoSKernelPS();
unsigned nEstimateTime = nTargetSpacing * nNetworkWeight / nWeight;
unsigned nEstimateTime = nTargetSpacing_2 * nNetworkWeight / nWeight;

QString text;
if (nEstimateTime < 60)
Expand Down
4 changes: 2 additions & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using namespace json_spirit;
using namespace std;

extern unsigned int nTargetSpacing;
extern unsigned int nTargetSpacing_2;

Value getsubsidy(const Array& params, bool fHelp)
{
Expand Down Expand Up @@ -73,7 +73,7 @@ Value getstakinginfo(const Array& params, bool fHelp)

uint64_t nNetworkWeight = GetPoSKernelPS();
bool staking = nLastCoinStakeSearchInterval && nWeight;
int nExpectedTime = staking ? (nTargetSpacing * nNetworkWeight / nWeight) : -1;
int nExpectedTime = staking ? (nTargetSpacing_2 * nNetworkWeight / nWeight) : -1;

Object obj;

Expand Down
4 changes: 2 additions & 2 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ class CDataStream
iterator insert(iterator it, const char& x=char()) { return vch.insert(it, x); }
void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); }

void insert(iterator it, const_iterator first, const_iterator last)
/* void insert(iterator it, const_iterator first, const_iterator last)
{
assert(last - first >= 0);
if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
Expand All @@ -821,7 +821,7 @@ class CDataStream
else
vch.insert(it, first, last);
}

*/
void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
{
assert(last - first >= 0);
Expand Down
3 changes: 2 additions & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ static const int DATABASE_VERSION = 70508;
// network protocol versioning
//

static const int PROTOCOL_VERSION = 60014;
static const int PROTOCOL_VERSION = 60015;

// earlier versions not supported as of July 2014, and are disconnected
static const int MIN_PROTO_VERSION = 209;
static const int MIN_PROTO_VERSION_FORK = 60015;

// nTime field added to CAddress, starting with this version;
// if possible, avoid requesting addresses nodes older than this
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
}

static int nMaxStakeSearchInterval = 60;
if (block.GetBlockTime() + nStakeMinAge > txNew.nTime - nMaxStakeSearchInterval)
if (block.GetBlockTime() + (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2) > txNew.nTime - nMaxStakeSearchInterval)
continue; // only count coins meeting min age requirement

bool fKernelFound = false;
Expand Down Expand Up @@ -1713,7 +1713,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (pcoin.first->vout[pcoin.second].nValue >= nCombineThreshold)
continue;
// Do not add input that is still too young
if (nTimeWeight < nStakeMinAge)
if (nTimeWeight < (pindexBest->nHeight < HARD_FORK_DIFF_FIX ? nStakeMinAge : nStakeMinAge_2))
continue;

txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
Expand Down

0 comments on commit 32bc4b7

Please sign in to comment.