Skip to content

Commit

Permalink
Merge pull request #115 from myriadteam/master
Browse files Browse the repository at this point in the history
merge to 0.14 branch for release
  • Loading branch information
cryptapus committed Oct 2, 2018
2 parents 4325c84 + 7dfac65 commit a15ed17
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 31 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 14)
define(_CLIENT_VERSION_REVISION, 3)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)

Expand Down
56 changes: 56 additions & 0 deletions doc/mip3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
MIP 3: Longblocks

Status: Under development


Motivation


With the emergence of layer 2 solutions, the need for fast block confirmations
is lessened. Additionally, chainindex bloat is a significant issue to the
long-term health of Myriadcoin.

This proposal implements a gradual increase in block time from 1 to 8 minutes
using multiple intervals of block time adjustments.

Additional reasons for this change:

* Capturing additional improvements from upstream indexing and development.
* Individual block security is improved due to the higher difficulty.
* Orphan count is expected to decrease.


Implementation

In three phases this proposal plans an increase in block time while keeping
the reward amount essentially the same. In practice, this requires raising the
block reward at a scale proportional to the block time increase. Myriadcoin
would not see another block halving until the 6th block halving. Then block
halvings continue at the original schedule of ~2yrs.

Below is an approximate table to show how this progresses.

| Subsidy Halving Interval | Reward | Block Time | Final Blk | Aprox. Date |
| ------------------------ | ------- | ---------- | --------- | ----------- |
| 1 (967680 blocks) | 1000.0 | 0.5 min | 967680 | Feb 2015 |
| 2 (967680 blocks) | 500.0 | ~1 min | 1935360 | Jan 2017 |
| 3 (967680 blocks) | 250.0 | 1 min | 2903040 | ~May 2019 |
| 4 **(483840 blocks)** | 250.0 | **2 min** | 3386880 | ~May 2021 |
| 5 **(241920 blocks)** | 250.0 | **4 min** | 3628800 | ~May 2023 |
| 6 **(120960 blocks)** | 250.0 | **8 min** | 3749760 | ~May 2025 |
| 7 (120960 blocks) | 125.0 | 8 min | 3870720 | ~May 2027 |
| 8 (120960 blocks) | 62.5 | 8 min | 3991680 | ~May 2029 |
| ... (120960 blocks) | ... | 8 min | ... | ... |

Halvings would then continue at 120960 block intervals.

It should be noted that MAX_MONEY is not changed and emission rate vs. clock
time should not be affected.

Deployment of this rule is through version bit 5.



Reference implementation

https://github.com/cryptapus/bitcoin/tree/myriadcoin.master.lngblcks/doc/mip3.md
52 changes: 50 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ 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)

// 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)
consensus.nPowTargetSpacingV3c = 8 * 60; // new target time for block spacing across all algorithms (8min)
consensus.nLongblocks_StartV1a = 2903040; // Start of longblocks, original 3rd block halving
consensus.nLongblocks_StartV1b = 3386880; // Start of longblocks, original 4th block halving
consensus.nLongblocks_StartV1c = 3628800; // Start of longblocks, original 5th block halving
consensus.nSubsidyHalvingIntervalV2a = 483840; // Longblocks Subsidy halving after adjust block time (2min)
consensus.nSubsidyHalvingIntervalV2b = 241920; // Longblocks Subsidy halving after adjust block time (4min)
consensus.nSubsidyHalvingIntervalV2c = 120960; // Longblocks Subsidy halving after adjust block time (8min)

// 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 = 1507420800; // October 8th, 2017
Expand All @@ -116,9 +127,14 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_RESERVEALGO].nStartTime = 1516320000; // Jan 19th, 2018
consensus.vDeployments[Consensus::DEPLOYMENT_RESERVEALGO].nTimeout = 1548979200; // Feb 1st, 2019

// Deployment of MIP3 (longblocks)
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].bit = 5;
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].nStartTime = 1525132800; // May 1st, 2018
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].nTimeout = 1556668800; // May 1st, 2019

/*** Upstream Chainparams ***/

consensus.nSubsidyHalvingInterval = 80640 * 12;
consensus.nSubsidyHalvingInterval = 967680;
consensus.BIP34Height = 1;
consensus.BIP34Hash = uint256S("0xcb41589c918fba1beccca8bc6b34b2b928b4f9888595d7664afd6ec60a576291");
consensus.BIP65Height = 1764000; // 2ca9968704301897b956f7e326375413be505509489c06aee2b16fe73805481e
Expand Down Expand Up @@ -272,6 +288,17 @@ 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)

// 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)
consensus.nPowTargetSpacingV3c = 8 * 60; // new target time for block spacing across all algorithms (8min)
consensus.nLongblocks_StartV1a = 2903040; // Start of longblocks, original 3rd block halving
consensus.nLongblocks_StartV1b = 3386880; // Start of longblocks, original 4th block halving
consensus.nLongblocks_StartV1c = 3628800; // Start of longblocks, original 5th block halving
consensus.nSubsidyHalvingIntervalV2a = 483840; // Longblocks Subsidy halving after adjust block time (2min)
consensus.nSubsidyHalvingIntervalV2b = 241920; // Longblocks Subsidy halving after adjust block time (4min)
consensus.nSubsidyHalvingIntervalV2c = 120960; // Longblocks Subsidy halving after adjust block time (8min)

// 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 All @@ -281,9 +308,14 @@ class CTestNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_RESERVEALGO].nStartTime = 1516320000; // Jan 19th, 2018
consensus.vDeployments[Consensus::DEPLOYMENT_RESERVEALGO].nTimeout = 1548979200; // Feb 1st, 2019

// Deployment of MIP3 (longblocks)
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].bit = 5;
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].nStartTime = 1525132800; // May 1st, 2018
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].nTimeout = 1556668800; // May 1st, 2019

/*** Upstream Chainparams ***/

consensus.nSubsidyHalvingInterval = 80640 * 12;
consensus.nSubsidyHalvingInterval = 967680;
consensus.BIP34Height = 1;
consensus.BIP34Hash = uint256S("0x0000d23adc28e33bc05f4bee57c873ae0aab584a6a436e75ac0ed40396f6d86b");
consensus.BIP65Height = 641; // ff983c72147a81ac5b8ebfc68b62b39358cac4b8eb5518242e87f499b71c6a51
Expand Down Expand Up @@ -406,6 +438,17 @@ class CRegTestParams : public CChainParams {
consensus.nGeoAvgWork_Start = 0;
consensus.nFork1MinBlock = 601; // minimum block height where fork 1 takes effect (algo switch, seq algo count change)

// 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)
consensus.nPowTargetSpacingV3c = 8 * 60; // new target time for block spacing across all algorithms (8min)
consensus.nLongblocks_StartV1a = 450; // Start of longblocks, original 3rd block halving
consensus.nLongblocks_StartV1b = 525; // Start of longblocks, original 4th block halving
consensus.nLongblocks_StartV1c = 562; // Start of longblocks, original 5th block halving
consensus.nSubsidyHalvingIntervalV2a = 75; // Longblocks Subsidy halving after adjust block time (2min)
consensus.nSubsidyHalvingIntervalV2b = 37; // Longblocks Subsidy halving after adjust block time (4min)
consensus.nSubsidyHalvingIntervalV2c = 18; // Longblocks Subsidy halving after adjust block time (8min)

consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].bit = 2;
consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_LEGBIT].nTimeout = 999999999999ULL;
Expand All @@ -415,6 +458,11 @@ class CRegTestParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_RESERVEALGO].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_RESERVEALGO].nTimeout = 999999999999ULL;

// Deployment of MIP3 (longblocks)
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].bit = 5;
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_LONGBLOCKS].nTimeout = 999999999999ULL;

/*** Upstream Chainparams ***/

consensus.nSubsidyHalvingInterval = 150;
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 14
#define CLIENT_VERSION_REVISION 3
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 0

//! Set to true for release, false for prerelease or test build
Expand Down
10 changes: 10 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum DeploymentPos
DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
DEPLOYMENT_LEGBIT, // Deployment of Legacy Bits.
DEPLOYMENT_RESERVEALGO, // Deployment of MIP2 (Reserve algos)
DEPLOYMENT_LONGBLOCKS, // Deployment of MIP3 (longblocks)
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
MAX_VERSION_BITS_DEPLOYMENTS
};
Expand Down Expand Up @@ -89,6 +90,15 @@ struct Params {
int64_t nBlockAlgoNormalisedWorkDecayStart2;
int64_t nGeoAvgWork_Start;
int64_t nFork1MinBlock;
int64_t nPowTargetSpacingV3a;
int64_t nPowTargetSpacingV3b;
int64_t nPowTargetSpacingV3c;
int64_t nLongblocks_StartV1a;
int64_t nLongblocks_StartV1b;
int64_t nLongblocks_StartV1c;
int nSubsidyHalvingIntervalV2a;
int nSubsidyHalvingIntervalV2b;
int nSubsidyHalvingIntervalV2c;

/** Auxpow parameters */
int16_t nAuxpowChainId;
Expand Down
4 changes: 3 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vin[0].prevout.SetNull();
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
// 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.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
Expand Down
29 changes: 22 additions & 7 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#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 @@ -158,7 +159,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead

if (pindexLast->nHeight >= params.Phase2Timespan_Start)
{
return CalculateNextWorkRequiredV2(pindexPrev, pindexFirst, params, algo, nActualTimespan);
return CalculateNextWorkRequiredV2(pindexPrev, pindexFirst, params, algo, nActualTimespan, pindexLast->nHeight);
}
else
{
Expand Down Expand Up @@ -222,15 +223,29 @@ unsigned int CalculateNextWorkRequiredV1(const CBlockIndex* pindexPrev, const CB
}


unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CBlockIndex* pindexFirst, const Consensus::Params& params, int algo, int64_t nActualTimespan)
unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CBlockIndex* pindexFirst, const Consensus::Params& params, int algo, int64_t nActualTimespan, int nHeight)
{
if (params.fPowNoRetargeting)
return pindexPrev->nBits;

const arith_uint256 nProofOfWorkLimit = UintToArith256(params.powLimit);

int64_t nTargetSpacingPerAlgo = params.nPowTargetSpacingV2 * NUM_ALGOS; // 60 * 5 = 300s per algo
int64_t nAveragingTargetTimespan = params.nAveragingInterval * nTargetSpacingPerAlgo; // 10 * 300 = 3000s, 50 minutes
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";
}
}
int64_t nAveragingTargetTimespan = params.nAveragingInterval * nTargetSpacingPerAlgo; // 10 blocks per algo
int64_t nMinActualTimespan = nAveragingTargetTimespan * (100 - params.nMaxAdjustUpV2) / 100;
int64_t nMaxActualTimespan = nAveragingTargetTimespan * (100 + params.nMaxAdjustDown) / 100;

Expand All @@ -256,10 +271,10 @@ unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CB
/// debug print
if(fDebug)
{
LogPrintf("CalculateNextWorkRequiredV2(Algo=%d): RETARGET\n", algo);
LogPrintf("CalculateNextWorkRequiredV2(Algo=%d): nTargetTimespan = %d nActualTimespan = %d\n", algo, nAveragingTargetTimespan, nActualTimespan);
LogPrintf("CalculateNextWorkRequiredV2(Algo=%d): Before: %08x %s\n", algo, pindexPrev->nBits, bnOld.ToString());
LogPrintf("CalculateNextWorkRequiredV2(Algo=%d): After: %08x %s\n", algo, bnNew.GetCompact(), bnNew.ToString());
LogPrintf("CalculateNextWorkRequired%s(Algo=%d): RETARGET\n", sBlockTime, algo);
LogPrintf("CalculateNextWorkRequired%s(Algo=%d): nTargetTimespan = %d nActualTimespan = %d\n", sBlockTime, algo, nAveragingTargetTimespan, nActualTimespan);
LogPrintf("CalculateNextWorkRequired%s(Algo=%d): Before: %08x %s\n", sBlockTime, algo, pindexPrev->nBits, bnOld.ToString());
LogPrintf("CalculateNextWorkRequired%s(Algo=%d): After: %08x %s\n", sBlockTime, algo, bnNew.GetCompact(), bnNew.ToString());
}

return bnNew.GetCompact();
Expand Down
2 changes: 1 addition & 1 deletion src/pow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class uint256;

unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, int algo, const Consensus::Params&);
unsigned int CalculateNextWorkRequiredV1(const CBlockIndex* pindexPrev, const CBlockIndex* pindexFirst, const Consensus::Params& params, int algo, int64_t nActualTimespan, int nHeight);
unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CBlockIndex* pindexFirst, const Consensus::Params& params, int algo, int64_t nActualTimespan);
unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CBlockIndex* pindexFirst, const Consensus::Params& params, int algo, int64_t nActualTimespan, int nHeight);

/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
bool CheckProofOfWork(uint256 hash, int algo, unsigned int nBits, const Consensus::Params&);
Expand Down
1 change: 1 addition & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
BIP9SoftForkDescPushBack(bip9_softforks, "segwit", consensusParams, Consensus::DEPLOYMENT_SEGWIT);
BIP9SoftForkDescPushBack(bip9_softforks, "legbit", consensusParams, Consensus::DEPLOYMENT_LEGBIT);
BIP9SoftForkDescPushBack(bip9_softforks, "reservealgo", consensusParams, Consensus::DEPLOYMENT_RESERVEALGO);
BIP9SoftForkDescPushBack(bip9_softforks, "longblocks", consensusParams, Consensus::DEPLOYMENT_LONGBLOCKS);
obj.push_back(Pair("softforks", softforks));
obj.push_back(Pair("bip9_softforks", bip9_softforks));

Expand Down
Loading

0 comments on commit a15ed17

Please sign in to comment.