Skip to content

Commit

Permalink
Merge pull request #116 from cryptapus/myriadcoin.0.14.postlngblks
Browse files Browse the repository at this point in the history
Myriadcoin.0.14.postlngblks
  • Loading branch information
cryptapus committed Nov 13, 2018
2 parents a15ed17 + 9b7ce65 commit 76e35a4
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 69 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 14)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_IS_RELEASE, true)


Expand Down
24 changes: 19 additions & 5 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class CMainParams : public CChainParams {
consensus.nGeoAvgWork_Start = 1400000;
consensus.nFork1MinBlock = 1764000; // minimum block height where fork 1 takes effect (algo switch, seq algo count change)

// Legbit parameters (used for v0.11 -> v0.14 compatability)
consensus.nLegbitStart = 2306304;
consensus.nLegbitStop = 2586528;

// MIP3 parameters
consensus.nPowTargetSpacingV3a = 2 * 60; // new target time for block spacing across all algorithms (2min)
consensus.nPowTargetSpacingV3b = 4 * 60; // new target time for block spacing across all algorithms (4min)
Expand Down Expand Up @@ -162,10 +166,10 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1544832000; // December 15th, 2018

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
consensus.nMinimumChainWork = uint256S("0x0ce400000000000000000000000000000000000000000b55d277080a82d333b4"); //2587043

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x9e16b567c393c46e40b4b4c4a21283b998aec17b3c7edf8319b3860e4403e4bf"); //2210002
consensus.defaultAssumeValid = uint256S("0x6bebe78892419acf8f47fa34ac08417036c244a244d209dbb5113edfda7ae480"); //2587043

/**
* The message start string is designed to be unlikely to occur in normal data.
Expand Down Expand Up @@ -234,12 +238,13 @@ class CMainParams : public CChainParams {
(1764003, uint256S("0xf969487c0ba2426bf767a5cb83c6bb7f3f9a19cccdcfc50cf5db0b39032aae55"))
(1863106, uint256S("0xc2a2012bac1de0e0039efb958e3465390eb7dcd439d83be077dc1c1006d0ebd6"))
(2210002, uint256S("0x9e16b567c393c46e40b4b4c4a21283b998aec17b3c7edf8319b3860e4403e4bf"))
(2587043, uint256S("0x6bebe78892419acf8f47fa34ac08417036c244a244d209dbb5113edfda7ae480"))
};

chainTxData = ChainTxData{
// Data as of block 00000000000000000166d612d5595e2b1cd88d71d695fc580af64d8da8658c23 (height 2210002).
1507861206, // * UNIX timestamp of last known number of transactions
5243041, // * total number of transactions between genesis and that timestamp
// Data as of block 6bebe78892419acf8f47fa34ac08417036c244a244d209dbb5113edfda7ae480 (height 2587043).
1540383040, // * UNIX timestamp of last known number of transactions
6055359, // * total number of transactions between genesis and that timestamp
// (the tx=... number in the SetBestChain debug.log lines)
0.02 // * estimated number of transactions per second after that timestamp
};
Expand Down Expand Up @@ -288,6 +293,10 @@ class CTestNetParams : public CChainParams {
consensus.nGeoAvgWork_Start = 150;
consensus.nFork1MinBlock = 601; // minimum block height where fork 1 takes effect (algo switch, seq algo count change)

// Legbit parameters (used for v0.11 -> v0.14 compatability)
consensus.nLegbitStart = 8064;
consensus.nLegbitStop = 26208;

// MIP3 parameters
consensus.nPowTargetSpacingV3a = 2 * 60; // new target time for block spacing across all algorithms (2min)
consensus.nPowTargetSpacingV3b = 4 * 60; // new target time for block spacing across all algorithms (4min)
Expand All @@ -299,6 +308,7 @@ class CTestNetParams : public CChainParams {
consensus.nSubsidyHalvingIntervalV2b = 241920; // Longblocks Subsidy halving after adjust block time (4min)
consensus.nSubsidyHalvingIntervalV2c = 120960; // Longblocks Subsidy halving after adjust block time (8min)

// Notice for BIP9 bit 2: Please see 'legbit' notes in validation.cpp prior to future use.
// Deployment of Legacy Blocks. Once activated, keeps v0.11 nodes on the same chain. Should be the first softfork.
consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].bit = 2;
consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].nStartTime = 1504224000; // September 1st, 2017
Expand Down Expand Up @@ -449,6 +459,10 @@ class CRegTestParams : public CChainParams {
consensus.nSubsidyHalvingIntervalV2b = 37; // Longblocks Subsidy halving after adjust block time (4min)
consensus.nSubsidyHalvingIntervalV2c = 18; // Longblocks Subsidy halving after adjust block time (8min)

// Legbit parameters (used for v0.11 -> v0.14 compatability)
consensus.nLegbitStart = 0;
consensus.nLegbitStop = 0;

consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].bit = 2;
consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].nTimeout = 999999999999ULL;
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 14
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 0
#define CLIENT_VERSION_BUILD 1

//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ struct Params {
int nSubsidyHalvingIntervalV2a;
int nSubsidyHalvingIntervalV2b;
int nSubsidyHalvingIntervalV2c;
int nLegbitStart;
int nLegbitStop;

/** Auxpow parameters */
int16_t nAuxpowChainId;
Expand Down
4 changes: 1 addition & 3 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vin[0].prevout.SetNull();
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
// TODO Myriadcoin LONGBLOCKS: GetBlockSubsidy needs pindexPrev. Remove after activation.
//coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus(), pindexPrev);
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
Expand Down
22 changes: 9 additions & 13 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "primitives/block.h"
#include "uint256.h"
#include "util.h"
#include "validation.h" // TODO Myriadcoin LONGBLOCKS: needed for versionbitscache, remove after activation.
#include "bignum.h"

unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, int algo, const Consensus::Params& params)
Expand Down Expand Up @@ -232,18 +231,15 @@ unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CB

int64_t nTargetSpacingPerAlgo = params.nPowTargetSpacingV2 * NUM_ALGOS; // 60 * 5 = 300s per algo
std::string sBlockTime = "V2";
// TODO Myriadcoin LONGBLOCKS: remove VersionBitsState check post activation.
if (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_LONGBLOCKS, versionbitscache) == THRESHOLD_ACTIVE) {
if (nHeight >= params.nLongblocks_StartV1c) {
nTargetSpacingPerAlgo = params.nPowTargetSpacingV3c * NUM_ALGOS; // 8 * 60 * 5 = 2400s per algo
sBlockTime = "V2_longblocks_8min";
} else if (nHeight >= params.nLongblocks_StartV1b) {
nTargetSpacingPerAlgo = params.nPowTargetSpacingV3b * NUM_ALGOS; // 4 * 60 * 5 = 1200s per algo
sBlockTime = "V2_longblocks_4min";
} else if (nHeight >= params.nLongblocks_StartV1a) {
nTargetSpacingPerAlgo = params.nPowTargetSpacingV3a * NUM_ALGOS; // 2 * 60 * 5 = 600s per algo
sBlockTime = "V2_longblocks_2min";
}
if (nHeight >= params.nLongblocks_StartV1c) {
nTargetSpacingPerAlgo = params.nPowTargetSpacingV3c * NUM_ALGOS; // 8 * 60 * 5 = 2400s per algo
sBlockTime = "V2_longblocks_8min";
} else if (nHeight >= params.nLongblocks_StartV1b) {
nTargetSpacingPerAlgo = params.nPowTargetSpacingV3b * NUM_ALGOS; // 4 * 60 * 5 = 1200s per algo
sBlockTime = "V2_longblocks_4min";
} else if (nHeight >= params.nLongblocks_StartV1a) {
nTargetSpacingPerAlgo = params.nPowTargetSpacingV3a * NUM_ALGOS; // 2 * 60 * 5 = 600s per algo
sBlockTime = "V2_longblocks_2min";
}
int64_t nAveragingTargetTimespan = params.nAveragingInterval * nTargetSpacingPerAlgo; // 10 blocks per algo
int64_t nMinActualTimespan = nAveragingTargetTimespan * (100 - params.nMaxAdjustUpV2) / 100;
Expand Down
75 changes: 32 additions & 43 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,41 +1238,31 @@ bool ReadBlockHeaderFromDisk(CBlockHeader& block, const CBlockIndex* pindex, con
return ReadBlockOrHeader(block, pindex, consensusParams);
}

// TODO Myriadcoin LONGBLOCKS: remove pindex arg and VersionBitsState check post activation
//CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, const CBlockIndex* pindex)
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
if (VersionBitsState(pindex, consensusParams, Consensus::DEPLOYMENT_LONGBLOCKS, versionbitscache) == THRESHOLD_ACTIVE) {
if (nHeight >= consensusParams.nLongblocks_StartV1a) {
halvings = consensusParams.nLongblocks_StartV1a / consensusParams.nSubsidyHalvingInterval;
}
if (nHeight >= consensusParams.nLongblocks_StartV1b) {
halvings += 1;
}
if (nHeight >= consensusParams.nLongblocks_StartV1c) {
halvings += 1;
halvings += ( nHeight - consensusParams.nLongblocks_StartV1c ) / consensusParams.nSubsidyHalvingIntervalV2c;
}
// Force block reward to 1 after 10 halvings (tail emission).
if (halvings >= 13) // tail emission happens later with longblocks.
return 1 * COIN;
} else {
// Force block reward to 1 after 10 halvings (tail emission).
if (halvings >= 10)
return 1 * COIN;
if (nHeight >= consensusParams.nLongblocks_StartV1a) {
halvings = consensusParams.nLongblocks_StartV1a / consensusParams.nSubsidyHalvingInterval;
}
if (nHeight >= consensusParams.nLongblocks_StartV1b) {
halvings += 1;
}
if (nHeight >= consensusParams.nLongblocks_StartV1c) {
halvings += 1;
halvings += ( nHeight - consensusParams.nLongblocks_StartV1c ) / consensusParams.nSubsidyHalvingIntervalV2c;
}
// Force block reward to 1 after 13 halvings (tail emission).
if (halvings >= 13) // tail emission happens later with longblocks.
return 1 * COIN;

CAmount nSubsidy = 1000 * COIN;
if (VersionBitsState(pindex, consensusParams, Consensus::DEPLOYMENT_LONGBLOCKS, versionbitscache) == THRESHOLD_ACTIVE) {
// longblocks require larger reward scaled for time.
if (nHeight >= consensusParams.nLongblocks_StartV1c) {
nSubsidy *= 8; // 1min -> 8min
} else if (nHeight >= consensusParams.nLongblocks_StartV1b) {
nSubsidy *= 4; // 1min -> 4min
} else if (nHeight >= consensusParams.nLongblocks_StartV1a) {
nSubsidy *= 2; // 1min -> 2min
}
// longblocks require larger reward scaled for time.
if (nHeight >= consensusParams.nLongblocks_StartV1c) {
nSubsidy *= 8; // 1min -> 8min
} else if (nHeight >= consensusParams.nLongblocks_StartV1b) {
nSubsidy *= 4; // 1min -> 4min
} else if (nHeight >= consensusParams.nLongblocks_StartV1a) {
nSubsidy *= 2; // 1min -> 2min
}
// Subsidy is cut in half every 967680 blocks.
nSubsidy >>= halvings;
Expand Down Expand Up @@ -1800,14 +1790,15 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
}
}

/* TODO Myriadcoin: add legbit back for 0.11 post consensus, remove this when 0.11 clients are forked off network */
if (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_LEGBIT, versionbitscache) == THRESHOLD_ACTIVE) {
nVersion += 4;
}
/* TODO Myriadcoin LONGBLOCKS: remove legbit if LONGBLOCKS activates, now 0.11 clients are forked off network,
remove this and above legbit check once LONGBLOCKS is activated */
if (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_LONGBLOCKS, versionbitscache) == THRESHOLD_ACTIVE) {
nVersion -= 4;
/* Myriadcoin: As a suspected consequence of `legbit` signaling longer than multiple BIP9 activation
* windows, artificially increase nVersion for the length of blocks legbit was active. bit 2 should still be
* usable as a BIP9 bit, however it is advisable that this behavior is verified on a testnet soft-fork for
* future use. This tweak of nVersion has been necessary on v0.14-v0.16 in order to not trigger a
* "Warning: unknown new rules activated (versionbit 2)" in UpdateTip().
*/
if (pindexPrev!=NULL) {
if (pindexPrev->nHeight >= params.nLegbitStart && pindexPrev->nHeight < params.nLegbitStop)
nVersion += 4;
}

return nVersion;
Expand Down Expand Up @@ -2045,9 +2036,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * 0.000001);

// TODO Myriadcoin LONGBLOCKS: pindex needed for versionbits check. Remove if activated.
//CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus(), pindex);
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
if (block.vtx[0]->GetValueOut() > blockReward)
return state.DoS(100,
error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)",
Expand Down Expand Up @@ -2261,8 +2250,8 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
{
int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus());
/* Myriadcoin: we only use the lowest 8 bits for BIP9, so we mask the chainid and algo (0x00FFFF00)*/
//if (pindex->GetBaseVersion() > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0)
if (pindex->GetBaseVersion() > VERSIONBITS_LAST_OLD_BLOCK_VERSION && ((pindex->nVersion & ~nExpectedVersion) & 0xFF0000FF) != 0)
//if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0)
if ((pindex->nVersion & 0xFF0000FF) > VERSIONBITS_LAST_OLD_BLOCK_VERSION && ((pindex->nVersion & ~nExpectedVersion) & 0xFF0000FF) != 0)
++nUpgraded;
pindex = pindex->pprev;
}
Expand Down
4 changes: 1 addition & 3 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ std::string GetWarnings(const std::string& strFor);
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
/** Find the best known block, and make it the tip of the block chain */
bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
// TODO Myriadcoin LONGBLOCKS: remove pindex if activated.
//CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, const CBlockIndex* pindex = nullptr);
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);

/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
Expand Down

0 comments on commit 76e35a4

Please sign in to comment.