From 91f355fd69f4346dfaf1206e73250e45596cc131 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 24 Nov 2018 08:39:23 -1100 Subject: [PATCH] 4MB block size with sapling --- src/chainparams.cpp | 9 +++++++++ src/consensus/consensus.h | 2 +- src/consensus/params.h | 3 ++- src/komodo-tx.cpp | 2 +- src/komodo_defs.h | 1 + src/main.cpp | 10 +++++----- src/main.h | 4 ++-- src/merkleblock.cpp | 2 +- src/miner.cpp | 2 +- src/rpc/mining.cpp | 2 +- 10 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index b757fd570..ee7f10925 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -89,6 +89,7 @@ class CMainParams : public CChainParams { public: CMainParams() { + strNetworkID = "main"; strCurrencyUnits = "KMD"; bip44CoinType = 133; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md (ZCASH, should be VRSC) @@ -206,6 +207,7 @@ public: } } }; + static CMainParams mainParams; void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointData) @@ -213,6 +215,12 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat CChainParams::checkpointData = checkpointData; } +int32_t MAX_BLOCK_SIZE(int32_t height) +{ + if ( height >= mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) + return(4000000); + else return(2000000); +} void komodo_setactivation(int32_t height) { mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; @@ -224,6 +232,7 @@ void komodo_setactivation(int32_t height) void *chainparams_commandline(void *ptr) { CChainParams::CCheckpointData checkpointData; + mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].MAX_BLOCKSIZE = 2000000; while ( ASSETCHAINS_P2PPORT == 0 ) { #ifdef _WIN32 diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 829959dea..3f44bcafd 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -19,7 +19,7 @@ static const int32_t SAPLING_MIN_TX_VERSION = 4; /** The maximum allowed Sapling transaction version (network rule) */ static const int32_t SAPLING_MAX_TX_VERSION = 4; /** The maximum allowed size for a serialized block, in bytes (network rule) */ -static const unsigned int MAX_BLOCK_SIZE = 2000000; +//static const unsigned int MAX_BLOCK_SIZE = 2000000; /** The maximum allowed number of signature check operations in a block (network rule) */ extern unsigned int MAX_BLOCK_SIGOPS; /** The maximum size of a transaction (network rule) */ diff --git a/src/consensus/params.h b/src/consensus/params.h index 8add4ce9f..b7dc8b475 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -10,6 +10,8 @@ #include +int32_t MAX_BLOCK_SIZE(int32_t height); + namespace Consensus { /** @@ -40,7 +42,6 @@ struct NetworkUpgrade { * Height of the first block for which the new consensus rules will be active */ int nActivationHeight; - /** * Special value for nActivationHeight indicating that the upgrade is always active. * This is useful for testing, as it means tests don't need to deal with the activation diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 9683c2988..d24509c54 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -220,7 +220,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu uint256 txid(uint256S(strTxid)); static const unsigned int minTxOutSz = 9; - static const unsigned int maxVout = MAX_BLOCK_SIZE / minTxOutSz; + static const unsigned int maxVout = MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1) / minTxOutSz; // extract and validate vout std::string strVout = vStrInputParts[1]; diff --git a/src/komodo_defs.h b/src/komodo_defs.h index c2e77c9ef..b65caff1c 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -15,5 +15,6 @@ #define KOMODO_SAPLING_DEADLINE 1550188800 // Feb 15th, 2019 extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; +int32_t MAX_BLOCK_SIZE(); #endif diff --git a/src/main.cpp b/src/main.cpp index cf29c34ac..8e3dba7b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1089,7 +1089,7 @@ bool ContextualCheckTransaction( // Rules that apply before Sapling: if (!saplingActive) { // Size limits - BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE > MAX_TX_SIZE_BEFORE_SAPLING); // sanity + BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1) > MAX_TX_SIZE_BEFORE_SAPLING); // sanity if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_TX_SIZE_BEFORE_SAPLING) return state.DoS(100, error("ContextualCheckTransaction(): size limits failed"), REJECT_INVALID, "bad-txns-oversize"); @@ -1311,7 +1311,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio REJECT_INVALID, "bad-txns-vout-empty"); // Size limits - BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE >= MAX_TX_SIZE_AFTER_SAPLING); // sanity + BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1) >= MAX_TX_SIZE_AFTER_SAPLING); // sanity BOOST_STATIC_ASSERT(MAX_TX_SIZE_AFTER_SAPLING > MAX_TX_SIZE_BEFORE_SAPLING); // sanity if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_TX_SIZE_AFTER_SAPLING) return state.DoS(100, error("CheckTransaction(): size limits failed"), @@ -4645,7 +4645,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // because we receive the wrong transactions for it. // Size limits - if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE) + if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE(height) || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE(height)) return state.DoS(100, error("CheckBlock: size limits failed"), REJECT_INVALID, "bad-blk-length"); @@ -5977,7 +5977,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) try { // This takes over fileIn and calls fclose() on it in the CBufferedFile destructor //CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION); - CBufferedFile blkdat(fileIn, 32*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION); + CBufferedFile blkdat(fileIn, 32*MAX_BLOCK_SIZE(10000000), MAX_BLOCK_SIZE(10000000)+8, SER_DISK, CLIENT_VERSION); uint64_t nRewind = blkdat.GetPos(); while (!blkdat.eof()) { boost::this_thread::interruption_point(); @@ -5996,7 +5996,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) continue; // read size blkdat >> nSize; - if (nSize < 80 || nSize > MAX_BLOCK_SIZE) + if (nSize < 80 || nSize > MAX_BLOCK_SIZE(10000000)) continue; } catch (const std::exception&) { // no valid block header found; don't complain diff --git a/src/main.h b/src/main.h index 7ba413852..149078de8 100644 --- a/src/main.h +++ b/src/main.h @@ -54,7 +54,7 @@ struct CNodeStateStats; #define _COINBASE_MATURITY 100 /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/ -static const unsigned int DEFAULT_BLOCK_MAX_SIZE = MAX_BLOCK_SIZE; +static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 2000000;//MAX_BLOCK_SIZE; static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0; /** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/ static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = DEFAULT_BLOCK_MAX_SIZE / 2; @@ -113,7 +113,7 @@ static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000; static const bool DEFAULT_DB_COMPRESSION = true; // Sanity check the magic numbers when we change them -BOOST_STATIC_ASSERT(DEFAULT_BLOCK_MAX_SIZE <= MAX_BLOCK_SIZE); +BOOST_STATIC_ASSERT(DEFAULT_BLOCK_MAX_SIZE <= MAX_BLOCK_SIZE(10000000)); BOOST_STATIC_ASSERT(DEFAULT_BLOCK_PRIORITY_SIZE <= DEFAULT_BLOCK_MAX_SIZE); #define equihash_parameters_acceptable(N, K) \ diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp index a368b31ad..a983caa0d 100644 --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -153,7 +153,7 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector &vMatch) { if (nTransactions == 0) return uint256(); // check for excessively high numbers of transactions - if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction + if (nTransactions > MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1) / 60) // 60 is the lower bound for the size of a serialized CTransaction return uint256(); // there can never be more hashes provided than one for every txid if (vHash.size() > nTransactions) diff --git a/src/miner.cpp b/src/miner.cpp index c6b69c28e..45785a9a4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -179,7 +179,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: - nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize)); + nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)-1000), nBlockMaxSize)); // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index afdc8d4ca..aed10944c 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -795,7 +795,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS)); - result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE)); + result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1))); result.push_back(Pair("curtime", pblock->GetBlockTime())); result.push_back(Pair("bits", strprintf("%08x", pblock->nBits))); result.push_back(Pair("height", (int64_t)(pindexPrev->GetHeight()+1)));