Skip to content

Commit

Permalink
Merge pull request #873 from qtumproject/time/blocktime
Browse files Browse the repository at this point in the history
Reduce block spacing + Port EVM to Aleth 1.8
  • Loading branch information
qtum-neil committed Mar 18, 2021
2 parents 5971f30 + 7ecc678 commit 631efb9
Show file tree
Hide file tree
Showing 164 changed files with 4,502 additions and 1,181 deletions.
10 changes: 5 additions & 5 deletions configure.ac
@@ -1,11 +1,11 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 20)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2020)
define(_COPYRIGHT_YEAR, 2021)
define(_COPYRIGHT_HOLDERS,[The %s Developers])
define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Qtum Core]])
AC_INIT([Qtum Core],m4_join([.], _CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MINOR, _CLIENT_VERSION_REVISION, m4_if(_CLIENT_VERSION_BUILD, [0], [], _CLIENT_VERSION_BUILD))m4_if(_CLIENT_VERSION_RC, [0], [], [rc]_CLIENT_VERSION_RC),[https://github.com/qtumproject/qtum/issues],[qtum],[https://qtum.org/])
Expand Down Expand Up @@ -56,16 +56,16 @@ AC_PROG_CXX
dnl By default, libtool for mingw refuses to link static libs into a dll for
dnl fear of mixing pic/non-pic objects, and import/export complications. Since
dnl we have those under control, re-enable that functionality.
dnl Compiler with posix support is needed for cross compile some of c++ 11 features for mingw like threads and mutexes.
dnl Compiler with posix support is needed for cross compile some of c++ 14 features for mingw like threads and mutexes.
case $host in
*mingw*)
lt_cv_deplibs_check_method="pass_all"
CC="$CC-posix"
CXX="$CXX-posix"
;;
esac
dnl Require C++11 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
dnl Require C++14 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([14], [noext], [mandatory], [nodefault])
dnl Check if -latomic is required for <std::atomic>
CHECK_ATOMIC

Expand Down
3 changes: 2 additions & 1 deletion contrib/macdeploy/macdeployqtplus
Expand Up @@ -586,7 +586,8 @@ if len(config.fancy) == 1:
sys.exit(1)

try:
fancy = plistlib.readPlist(p)
with open(p, 'rb') as fp:
fancy = plistlib.load(fp, fmt=plistlib.FMT_XML)
except:
if verbose >= 1:
sys.stderr.write("Error: Could not parse fancy disk image plist at \"{}\"\n".format(p))
Expand Down
286 changes: 147 additions & 139 deletions src/Makefile.am

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Makefile.test.include
Expand Up @@ -253,7 +253,8 @@ BITCOIN_TESTS =\
test/qtumtests/dgp_tests.cpp \
test/qtumtests/constantinoplefork_tests.cpp \
test/qtumtests/btcecrecoverfork_tests.cpp \
test/qtumtests/delegations_tests.cpp
test/qtumtests/delegations_tests.cpp \
test/qtumtests/istanbulfork_tests.cpp


if ENABLE_WALLET
Expand Down
7 changes: 4 additions & 3 deletions src/bench/block_assemble.cpp
Expand Up @@ -28,14 +28,15 @@ static void AssembleBlock(benchmark::State& state)
const CScript SCRIPT_PUB{CScript(OP_0) << std::vector<unsigned char>{witness_program.begin(), witness_program.end()}};

// Collect some loose transactions that spend the coinbases of our mined blocks
constexpr size_t NUM_BLOCKS{600};
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
constexpr size_t NUM_BLOCKS{2100};
constexpr size_t coinbaseMaturity = 2000;
std::array<CTransactionRef, NUM_BLOCKS - coinbaseMaturity + 1> txs;
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
CMutableTransaction tx;
tx.vin.push_back(MineBlock(g_testing_setup->m_node, SCRIPT_PUB));
tx.vin.back().scriptWitness = witness;
tx.vout.emplace_back(1337, SCRIPT_PUB);
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
if (NUM_BLOCKS - b >= coinbaseMaturity)
txs.at(b) = MakeTransactionRef(tx);
}
{
Expand Down
3 changes: 2 additions & 1 deletion src/bench/wallet_balance.cpp
Expand Up @@ -29,7 +29,8 @@ static void WalletBalance(benchmark::State& state, const bool set_dirty, const b
const Optional<std::string> address_mine{add_mine ? Optional<std::string>{getnewaddress(wallet)} : nullopt};
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);

for (int i = 0; i < 600; ++i) {
int blockCount = Params().GetConsensus().CoinbaseMaturity(0) + 100;
for (int i = 0; i < blockCount; ++i) {
generatetoaddress(g_testing_setup->m_node, address_mine.get_value_or(ADDRESS_WATCHONLY));
generatetoaddress(g_testing_setup->m_node, ADDRESS_WATCHONLY);
}
Expand Down
2 changes: 1 addition & 1 deletion src/chain.cpp
Expand Up @@ -145,7 +145,7 @@ int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& fr
r = from.nChainWork - to.nChainWork;
sign = -1;
}
r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
r = r * arith_uint256(params.TargetSpacing(tip.nHeight)) / GetBlockProof(tip);
if (r.bits() > 63) {
return sign * std::numeric_limits<int64_t>::max();
}
Expand Down
130 changes: 116 additions & 14 deletions src/chainparams.cpp
Expand Up @@ -87,12 +87,17 @@ class CMainParams : public CChainParams {
consensus.QIP7Height = 466600;
consensus.QIP9Height = 466600;
consensus.nOfflineStakeHeight = 680000;
consensus.nReduceBlocktimeHeight = 845000;
consensus.nMuirGlacierHeight = 845000;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("0000000000001fffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
consensus.RBTPosLimit = uint256S("0000000000003fffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 16 * 60; // 16 minutes
consensus.nPowTargetTimespanV2 = 4000;
consensus.nRBTPowTargetTimespan = 1000;
consensus.nPowTargetSpacing = 2 * 64;
consensus.nRBTPowTargetSpacing = 32;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = true;
consensus.fPoSNoRetargeting = false;
Expand Down Expand Up @@ -176,19 +181,27 @@ class CMainParams : public CChainParams {
0.02433574394826639 // * estimated number of transactions per second after that timestamp
};

consensus.nBlocktimeDownscaleFactor = 4;
consensus.nCoinbaseMaturity = 500;
consensus.nRBTCoinbaseMaturity = consensus.nBlocktimeDownscaleFactor*500;
consensus.nSubsidyHalvingIntervalV2 = consensus.nBlocktimeDownscaleFactor*985500; // qtum halving every 4 years (nSubsidyHalvingInterval * nBlocktimeDownscaleFactor)

consensus.nLastPOWBlock = 5000;
consensus.nLastBigReward = 5000;
consensus.nMPoSRewardRecipients = 10;
consensus.nFirstMPoSBlock = consensus.nLastPOWBlock +
consensus.nMPoSRewardRecipients +
COINBASE_MATURITY;
consensus.nCoinbaseMaturity;
consensus.nLastMPoSBlock = 679999;


consensus.nFixUTXOCacheHFHeight = 100000;
consensus.nEnableHeaderSignatureHeight = 399100;
consensus.nCheckpointSpan = COINBASE_MATURITY;
consensus.nCheckpointSpan = consensus.nCoinbaseMaturity;
consensus.nRBTCheckpointSpan = consensus.nRBTCoinbaseMaturity;
consensus.delegationsAddress = uint160(ParseHex("0000000000000000000000000000000000000086")); // Delegations contract for offline staking
consensus.nStakeTimestampMask = 15;
consensus.nRBTStakeTimestampMask = 3;
}
};

Expand All @@ -213,12 +226,17 @@ class CTestNetParams : public CChainParams {
consensus.QIP7Height = 446320;
consensus.QIP9Height = 446320;
consensus.nOfflineStakeHeight = 625000;
consensus.nReduceBlocktimeHeight = 806600;
consensus.nMuirGlacierHeight = 806600;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("0000000000001fffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
consensus.RBTPosLimit = uint256S("0000000000003fffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 16 * 60; // 16 minutes
consensus.nPowTargetTimespanV2 = 4000;
consensus.nRBTPowTargetTimespan = 1000;
consensus.nPowTargetSpacing = 2 * 64;
consensus.nRBTPowTargetSpacing = 32;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = true;
consensus.fPoSNoRetargeting = false;
Expand Down Expand Up @@ -289,18 +307,26 @@ class CTestNetParams : public CChainParams {
0.016913121136215
};

consensus.nBlocktimeDownscaleFactor = 4;
consensus.nCoinbaseMaturity = 500;
consensus.nRBTCoinbaseMaturity = consensus.nBlocktimeDownscaleFactor*500;
consensus.nSubsidyHalvingIntervalV2 = consensus.nBlocktimeDownscaleFactor*985500; // qtum halving every 4 years (nSubsidyHalvingInterval * nBlocktimeDownscaleFactor)

consensus.nLastPOWBlock = 5000;
consensus.nLastBigReward = 5000;
consensus.nMPoSRewardRecipients = 10;
consensus.nFirstMPoSBlock = consensus.nLastPOWBlock +
consensus.nMPoSRewardRecipients +
COINBASE_MATURITY;
consensus.nCoinbaseMaturity;
consensus.nLastMPoSBlock = 624999;

consensus.nFixUTXOCacheHFHeight = 84500;
consensus.nEnableHeaderSignatureHeight = 391993;
consensus.nCheckpointSpan = COINBASE_MATURITY;
consensus.nCheckpointSpan = consensus.nCoinbaseMaturity;
consensus.nRBTCheckpointSpan = consensus.nRBTCoinbaseMaturity;
consensus.delegationsAddress = uint160(ParseHex("0000000000000000000000000000000000000086")); // Delegations contract for offline staking
consensus.nStakeTimestampMask = 15;
consensus.nRBTStakeTimestampMask = 3;
}
};

Expand All @@ -325,12 +351,17 @@ class CRegTestParams : public CChainParams {
consensus.QIP7Height = 0;
consensus.QIP9Height = 0;
consensus.nOfflineStakeHeight = 1;
consensus.nReduceBlocktimeHeight = 0;
consensus.nMuirGlacierHeight = 0;
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // The new POS-limit activated after QIP9
consensus.RBTPosLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 16 * 60; // 16 minutes (960 = 832 + 128; multiplier is 832)
consensus.nPowTargetTimespanV2 = 4000;
consensus.nRBTPowTargetTimespan = 1000;
consensus.nPowTargetSpacing = 2 * 64;
consensus.nRBTPowTargetSpacing = 32;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.fPoSNoRetargeting = true;
Expand Down Expand Up @@ -382,6 +413,12 @@ class CRegTestParams : public CChainParams {
0,
0
};

consensus.nBlocktimeDownscaleFactor = 4;
consensus.nCoinbaseMaturity = 500;
consensus.nRBTCoinbaseMaturity = consensus.nBlocktimeDownscaleFactor*500;
consensus.nSubsidyHalvingIntervalV2 = consensus.nBlocktimeDownscaleFactor*985500; // qtum halving every 4 years (nSubsidyHalvingInterval * nBlocktimeDownscaleFactor)

consensus.nLastPOWBlock = 0x7fffffff;
consensus.nLastBigReward = 5000;
consensus.nMPoSRewardRecipients = 10;
Expand All @@ -390,8 +427,12 @@ class CRegTestParams : public CChainParams {

consensus.nFixUTXOCacheHFHeight=0;
consensus.nEnableHeaderSignatureHeight = 0;
consensus.nCheckpointSpan = COINBASE_MATURITY;

consensus.nCheckpointSpan = consensus.nCoinbaseMaturity;
consensus.nRBTCheckpointSpan = consensus.nRBTCoinbaseMaturity;
consensus.delegationsAddress = uint160(ParseHex("0000000000000000000000000000000000000086")); // Delegations contract for offline staking
consensus.nStakeTimestampMask = 15;
consensus.nRBTStakeTimestampMask = 3;

base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,120);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,110);
Expand Down Expand Up @@ -469,16 +510,23 @@ class CUnitTestParams : public CRegTestParams
consensus.BIP16Exception = uint256();
consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
consensus.QIP6Height = 1000;
consensus.BIP65Height = consensus.nBlocktimeDownscaleFactor*500 + 851; // BIP65 activated on regtest (Used in rpc activation tests)
consensus.BIP66Height = consensus.nBlocktimeDownscaleFactor*500 + 751; // BIP66 activated on regtest (Used in rpc activation tests)
consensus.QIP6Height = consensus.nBlocktimeDownscaleFactor*500 + 500;
consensus.QIP7Height = 0; // QIP7 activated on regtest

// QTUM have 500 blocks of maturity, increased values for regtest in unit tests in order to correspond with it
consensus.nSubsidyHalvingInterval = 750;
consensus.nRuleChangeActivationThreshold = 558; // 75% for testchains
consensus.nMinerConfirmationWindow = 744; // Faster than normal for regtest (744 instead of 2016)
consensus.nCheckpointSpan = 1000; // Increase the check point span for the reorganization tests from 500 to 1000
consensus.nSubsidyHalvingIntervalV2 = consensus.nBlocktimeDownscaleFactor*750;
consensus.nRuleChangeActivationThreshold = consensus.nBlocktimeDownscaleFactor*558; // 75% for testchains
consensus.nMinerConfirmationWindow = consensus.nBlocktimeDownscaleFactor*744; // Faster than normal for regtest (744 instead of 2016)

consensus.nBlocktimeDownscaleFactor = 4;
consensus.nCoinbaseMaturity = 500;
consensus.nRBTCoinbaseMaturity = consensus.nBlocktimeDownscaleFactor*500;

consensus.nCheckpointSpan = consensus.nCoinbaseMaturity*2; // Increase the check point span for the reorganization tests from 500 to 1000
consensus.nRBTCheckpointSpan = consensus.nRBTCoinbaseMaturity*2; // Increase the check point span for the reorganization tests from 500 to 1000
}
};

Expand Down Expand Up @@ -511,8 +559,9 @@ void SelectParams(const std::string& network)
std::string CChainParams::EVMGenesisInfo() const
{
std::string genesisInfo = dev::eth::genesisInfo(GetEVMNetwork());
ReplaceInt(consensus.QIP7Height, "QIP7_STARTING_BLOCK", genesisInfo);
ReplaceInt(consensus.QIP6Height, "QIP6_STARTING_BLOCK", genesisInfo);
ReplaceInt(consensus.QIP7Height, "QIP7_STARTING_BLOCK", genesisInfo);
ReplaceInt(consensus.QIP6Height, "QIP6_STARTING_BLOCK", genesisInfo);
ReplaceInt(consensus.nMuirGlacierHeight, "MUIR_STARTING_BLOCK", genesisInfo);
return genesisInfo;
}

Expand All @@ -521,6 +570,7 @@ std::string CChainParams::EVMGenesisInfo(int nHeight) const
std::string genesisInfo = dev::eth::genesisInfo(GetEVMNetwork());
ReplaceInt(nHeight, "QIP7_STARTING_BLOCK", genesisInfo);
ReplaceInt(nHeight, "QIP6_STARTING_BLOCK", genesisInfo);
ReplaceInt(nHeight, "MUIR_STARTING_BLOCK", genesisInfo);
return genesisInfo;
}

Expand Down Expand Up @@ -562,8 +612,10 @@ void UpdateConstantinopleBlockHeight(int nHeight)
void CChainParams::UpdateDifficultyChangeBlockHeight(int nHeight)
{
consensus.nSubsidyHalvingInterval = 985500; // qtum halving every 4 years
consensus.nSubsidyHalvingIntervalV2 = consensus.nBlocktimeDownscaleFactor*985500; // qtum halving every 4 years (nSubsidyHalvingInterval * nBlocktimeDownscaleFactor)
consensus.posLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9PosLimit = uint256S("0000000000001fffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.RBTPosLimit = uint256S("0000000000003fffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.QIP9Height = nHeight;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = true;
Expand All @@ -572,7 +624,7 @@ void CChainParams::UpdateDifficultyChangeBlockHeight(int nHeight)
consensus.nMPoSRewardRecipients = 10;
consensus.nFirstMPoSBlock = consensus.nLastPOWBlock +
consensus.nMPoSRewardRecipients +
COINBASE_MATURITY;
consensus.nCoinbaseMaturity;
consensus.nLastMPoSBlock = 0;
}

Expand Down Expand Up @@ -610,3 +662,53 @@ void UpdateLastMPoSBlockHeight(int nHeight)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdateLastMPoSBlockHeight(nHeight);
}

void CChainParams::UpdateReduceBlocktimeHeight(int nHeight)
{
consensus.nReduceBlocktimeHeight = nHeight;
}

void UpdateReduceBlocktimeHeight(int nHeight)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdateReduceBlocktimeHeight(nHeight);
}

void CChainParams::UpdatePowAllowMinDifficultyBlocks(bool fValue)
{
consensus.fPowAllowMinDifficultyBlocks = fValue;
}

void UpdatePowAllowMinDifficultyBlocks(bool fValuet)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdatePowAllowMinDifficultyBlocks(fValuet);
}

void CChainParams::UpdatePowNoRetargeting(bool fValue)
{
consensus.fPowNoRetargeting = fValue;
}

void UpdatePowNoRetargeting(bool fValuet)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdatePowNoRetargeting(fValuet);
}

void CChainParams::UpdatePoSNoRetargeting(bool fValue)
{
consensus.fPoSNoRetargeting = fValue;
}

void UpdatePoSNoRetargeting(bool fValuet)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdatePoSNoRetargeting(fValuet);
}

void CChainParams::UpdateMuirGlacierHeight(int nHeight)
{
consensus.nMuirGlacierHeight = nHeight;
}

void UpdateMuirGlacierHeight(int nHeight)
{
const_cast<CChainParams*>(globalChainParams.get())->UpdateMuirGlacierHeight(nHeight);
}
30 changes: 30 additions & 0 deletions src/chainparams.h
Expand Up @@ -99,6 +99,11 @@ class CChainParams
void UpdateOfflineStakingBlockHeight(int nHeight);
void UpdateDelegationsAddress(const uint160& address);
void UpdateLastMPoSBlockHeight(int nHeight);
void UpdateReduceBlocktimeHeight(int nHeight);
void UpdatePowAllowMinDifficultyBlocks(bool fValue);
void UpdatePowNoRetargeting(bool fValue);
void UpdatePoSNoRetargeting(bool fValue);
void UpdateMuirGlacierHeight(int nHeight);
protected:
dev::eth::Network GetEVMNetwork() const;
CChainParams() {}
Expand Down Expand Up @@ -179,4 +184,29 @@ void UpdateDelegationsAddress(const uint160& address);
*/
void UpdateLastMPoSBlockHeight(int nHeight);

/**
* Allows modifying the reduce block time height regtest parameter.
*/
void UpdateReduceBlocktimeHeight(int nHeight);

/**
* Allows modifying the pow allow for min difficulty blocks regtest parameter.
*/
void UpdatePowAllowMinDifficultyBlocks(bool fValue);

/**
* Allows modifying the pow no retargeting regtest parameter.
*/
void UpdatePowNoRetargeting(bool fValue);

/**
* Allows modifying the pos no retargeting regtest parameter.
*/
void UpdatePoSNoRetargeting(bool fValue);

/**
* Allows modifying the muir glacier block height regtest parameter.
*/
void UpdateMuirGlacierHeight(int nHeight);

#endif // BITCOIN_CHAINPARAMS_H

0 comments on commit 631efb9

Please sign in to comment.