diff --git a/ci/dash/lint-tidy.sh b/ci/dash/lint-tidy.sh index bd78e85ef22b..bf466d46bf6e 100755 --- a/ci/dash/lint-tidy.sh +++ b/ci/dash/lint-tidy.sh @@ -25,6 +25,7 @@ iwyu_tool.py \ "src/init" \ "src/node/chainstate.cpp" \ "src/node/minisketchwrapper.cpp" \ + "src/node/mempool_args.cpp" \ "src/policy/feerate.cpp" \ "src/policy/packages.cpp" \ "src/policy/settings.cpp" \ diff --git a/doc/REST-interface.md b/doc/REST-interface.md index 4b95ec1e3210..bb925fb24435 100644 --- a/doc/REST-interface.md +++ b/doc/REST-interface.md @@ -86,6 +86,15 @@ Returns various state info regarding block chain processing. Only supports JSON as output format. Refer to the `getblockchaininfo` RPC help for details. +#### Deployment info +`GET /rest/deploymentinfo.json` +`GET /rest/deploymentinfo/.json` + +Returns an object containing various state info regarding deployments of +consensus changes at the current chain tip, or at if provided. +Only supports JSON as output format. +Refer to the `getdeploymentinfo` RPC help for details. + #### Query UTXO set - `GET /rest/getutxos/-/-/.../-.` - `GET /rest/getutxos/checkmempool/-/-/.../-.` diff --git a/doc/release-notes-6888.md b/doc/release-notes-6888.md new file mode 100644 index 000000000000..82021659f129 --- /dev/null +++ b/doc/release-notes-6888.md @@ -0,0 +1,17 @@ +Updated RPCs +------------ + +- Information on soft fork status has been moved from `getblockchaininfo` + to the new `getdeploymentinfo` RPC which allows querying soft fork status at any + block, rather than just at the chain tip. Inclusion of soft fork + status in `getblockchaininfo` can currently be restored using the + configuration `-deprecatedrpc=softforks`, but this will be removed in + a future release. Note that in either case, the `status` field + now reflects the status of the current block rather than the next + block. + +New REST endpoint +----------------- + +- A new `/rest/deploymentinfo` endpoint has been added for fetching various + state info regarding deployments of consensus changes. diff --git a/src/Makefile.am b/src/Makefile.am index cc3a31cf7366..f1928e042711 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -263,7 +263,12 @@ BITCOIN_CORE_H = \ instantsend/lock.h \ instantsend/net_instantsend.h \ instantsend/signing.h \ + kernel/chain.h \ + kernel/checks.h \ kernel/coinstats.h \ + kernel/context.h \ + kernel/mempool_limits.h \ + kernel/mempool_options.h \ key.h \ key_io.h \ limitedmap.h \ @@ -315,18 +320,20 @@ BITCOIN_CORE_H = \ node/connection_types.h \ node/context.h \ node/eviction.h \ + node/interface_ui.h \ + node/mempool_args.h \ node/miner.h \ node/minisketchwrapper.h \ node/psbt.h \ node/sync_manager.h \ node/transaction.h \ node/txreconciliation.h \ - node/interface_ui.h \ node/utxo_snapshot.h \ noui.h \ outputtype.h \ policy/feerate.h \ policy/fees.h \ + policy/fees_args.h \ policy/packages.h \ policy/policy.h \ policy/settings.h \ @@ -536,7 +543,10 @@ libbitcoin_node_a_SOURCES = \ instantsend/lock.cpp \ instantsend/net_instantsend.cpp \ instantsend/signing.cpp \ + kernel/chain.cpp \ + kernel/checks.cpp \ kernel/coinstats.cpp \ + kernel/context.cpp \ llmq/blockprocessor.cpp \ llmq/commitment.cpp \ llmq/context.cpp \ @@ -572,16 +582,18 @@ libbitcoin_node_a_SOURCES = \ node/connection_types.cpp \ node/context.cpp \ node/eviction.cpp \ + node/interface_ui.cpp \ node/interfaces.cpp \ + node/mempool_args.cpp \ node/miner.cpp \ node/minisketchwrapper.cpp \ node/psbt.cpp \ node/sync_manager.cpp \ node/transaction.cpp \ node/txreconciliation.cpp \ - node/interface_ui.cpp \ noui.cpp \ policy/fees.cpp \ + policy/fees_args.cpp \ policy/packages.cpp \ policy/policy.cpp \ policy/settings.cpp \ diff --git a/src/bench/duplicate_inputs.cpp b/src/bench/duplicate_inputs.cpp index fbb24445be4d..a5c80b3bad94 100644 --- a/src/bench/duplicate_inputs.cpp +++ b/src/bench/duplicate_inputs.cpp @@ -36,7 +36,7 @@ static void DuplicateInputs(benchmark::Bench& bench) coinbaseTx.vin[0].prevout.SetNull(); coinbaseTx.vout.resize(1); coinbaseTx.vout[0].scriptPubKey = SCRIPT_PUB; - coinbaseTx.vout[0].nValue = GetBlockSubsidyInner(block.nBits, nHeight, chainparams.GetConsensus(), /*fV20Active=*/ false); + coinbaseTx.vout[0].nValue = GetBlockSubsidyInner(block.nBits, nHeight, chainparams.GetConsensus(), /*is_v20_active_override=*/false); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; naughtyTx.vout.resize(1); diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 2bc239b915e5..0a790a4ff3d1 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -193,11 +193,14 @@ static bool AppInit(NodeContext& node, int argc, char* argv[]) // InitError will have been called with detailed error, which ends up on console return false; } - if (!AppInitSanityChecks()) + + node.kernel = std::make_unique(); + if (!AppInitSanityChecks(*node.kernel)) { // InitError will have been called with detailed error, which ends up on console return false; } + if (args.GetBoolArg("-daemon", DEFAULT_DAEMON) || args.GetBoolArg("-daemonwait", DEFAULT_DAEMONWAIT)) { #if HAVE_DECL_FORK tfm::format(std::cout, PACKAGE_NAME " starting\n"); diff --git a/src/bls/bls.cpp b/src/bls/bls.cpp index 347184f3a2bb..aec91f56c2a2 100644 --- a/src/bls/bls.cpp +++ b/src/bls/bls.cpp @@ -386,7 +386,6 @@ bool CBLSSignature::Recover(Span sigs, Span ids) } #ifndef BUILD_BITCOIN_INTERNAL - static std::once_flag init_flag; static mt_pooled_secure_allocator* secure_allocator_instance; static void create_secure_allocator() @@ -423,12 +422,11 @@ static void secure_free(void* p) size_t n = *reinterpret_cast(ptr); return get_secure_allocator().deallocate(ptr, n); } -#endif +#endif // BUILD_BITCOIN_INTERNAL -bool BLSInit() +void BLSInit() { #ifndef BUILD_BITCOIN_INTERNAL bls::BLS::SetSecureAllocator(secure_allocate, secure_free); -#endif - return true; +#endif // BUILD_BITCOIN_INTERNAL } diff --git a/src/bls/bls.h b/src/bls/bls.h index a99cec3114cf..3eb19dc3b319 100644 --- a/src/bls/bls.h +++ b/src/bls/bls.h @@ -594,6 +594,6 @@ class CBLSLazyPublicKeyVersionWrapper { using BLSVerificationVectorPtr = std::shared_ptr>; -bool BLSInit(); +void BLSInit(); #endif // DASH_CRYPTO_BLS_H diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 79651d64e428..8299cd9d86cb 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -1044,9 +1044,8 @@ CDeterministicMNCPtr CCoinJoinClientManager::GetRandomNotUsedMasternode() // fill a vector std::vector vpMasternodesShuffled; vpMasternodesShuffled.reserve(nCountEnabled); - mnList.ForEachMNShared(true, [&vpMasternodesShuffled](const CDeterministicMNCPtr& dmn) { - vpMasternodesShuffled.emplace_back(dmn); - }); + mnList.ForEachMNShared(/*onlyValid=*/true, + [&vpMasternodesShuffled](const auto& dmn) { vpMasternodesShuffled.emplace_back(dmn); }); // shuffle pointers Shuffle(vpMasternodesShuffled.begin(), vpMasternodesShuffled.end(), FastRandomContext()); diff --git a/src/deploymentstatus.cpp b/src/deploymentstatus.cpp index ae19a6e40d7f..3a524af29e26 100644 --- a/src/deploymentstatus.cpp +++ b/src/deploymentstatus.cpp @@ -9,8 +9,6 @@ #include -VersionBitsCache g_versionbitscache; - /* Basic sanity checking for BuriedDeployment/DeploymentPos enums and * ValidDeployment check */ diff --git a/src/deploymentstatus.h b/src/deploymentstatus.h index eab4efd98b5a..2651baac7349 100644 --- a/src/deploymentstatus.h +++ b/src/deploymentstatus.h @@ -10,9 +10,6 @@ #include -/** Global cache for versionbits deployment status */ -extern VersionBitsCache g_versionbitscache; - /** Determine if a deployment is active for the next block */ inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::BuriedDeployment dep) { @@ -20,10 +17,10 @@ inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus return (pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1) >= params.DeploymentHeight(dep); } -inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep) +inline bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos dep, VersionBitsCache& versionbitscache) { assert(Consensus::ValidDeployment(dep)); - return ThresholdState::ACTIVE == g_versionbitscache.State(pindexPrev, params, dep); + return ThresholdState::ACTIVE == versionbitscache.State(pindexPrev, params, dep); } /** Determine if a deployment is active for this block */ @@ -33,10 +30,10 @@ inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params return index.nHeight >= params.DeploymentHeight(dep); } -inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::DeploymentPos dep) +inline bool DeploymentActiveAt(const CBlockIndex& index, const Consensus::Params& params, Consensus::DeploymentPos dep, VersionBitsCache& versionbitscache) { assert(Consensus::ValidDeployment(dep)); - return DeploymentActiveAfter(index.pprev, params, dep); + return DeploymentActiveAfter(index.pprev, params, dep, versionbitscache); } /** Determine if a deployment is enabled (can ever be active) */ diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 772ac70630ac..ec07eba70451 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -61,7 +61,7 @@ static std::optional GetCreditDataFromBlock(const gsl::n const Consensus::Params& consensusParams) { // There's no CbTx before DIP0003 activation - if (!DeploymentActiveAt(*block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003)) { + if (!DeploymentActiveAt(*block_index, consensusParams, Consensus::DEPLOYMENT_DIP0003)) { return std::nullopt; } @@ -117,7 +117,7 @@ std::string CCreditPool::ToString() const std::optional CCreditPoolManager::GetFromCache(const CBlockIndex& block_index) { - if (!DeploymentActiveAt(block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return CCreditPool{}; + if (!DeploymentActiveAt(block_index, m_chainman.GetConsensus(), Consensus::DEPLOYMENT_V20)) return CCreditPool{}; const uint256 block_hash = block_index.GetBlockHash(); CCreditPool pool; @@ -148,10 +148,9 @@ void CCreditPoolManager::AddToCache(const uint256& block_hash, int height, const } } -CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null block_index, - CCreditPool prev, const Consensus::Params& consensusParams) +CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null block_index, CCreditPool prev) { - std::optional opt_block_data = GetCreditDataFromBlock(block_index, consensusParams); + std::optional opt_block_data = GetCreditDataFromBlock(block_index, m_chainman.GetConsensus()); if (!opt_block_data) { // If reading of previous block is not successfully, but // prev contains credit pool related data, something strange happened @@ -178,10 +177,11 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_nullGetAncestor(block_index->nHeight - Params().CreditPoolPeriodBlocks())}; + block_index->GetAncestor(block_index->nHeight - m_chainman.GetParams().CreditPoolPeriodBlocks())}; CAmount distantUnlocked{0}; if (distant_block_index) { - if (std::optional distant_block{GetCreditDataFromBlock(distant_block_index, consensusParams)}; + if (std::optional distant_block{ + GetCreditDataFromBlock(distant_block_index, m_chainman.GetConsensus())}; distant_block) { distantUnlocked = distant_block->unlocked; } @@ -189,9 +189,9 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null> to_calculate; @@ -232,14 +232,15 @@ CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index, co } if (block_index == nullptr) poolTmp = CCreditPool{}; while (!to_calculate.empty()) { - poolTmp = ConstructCreditPool(to_calculate.top(), *poolTmp, consensusParams); + poolTmp = ConstructCreditPool(to_calculate.top(), *poolTmp); to_calculate.pop(); } return *poolTmp; } -CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb) : - evoDb{_evoDb} +CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb, const ChainstateManager& chainman) : + evoDb{_evoDb}, + m_chainman{chainman} { } @@ -254,7 +255,7 @@ CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex* pindexP if (DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_MN_RR)) { // If credit pool exists, it means v20 is activated - platformReward = PlatformShare(GetMasternodePayment(pindexPrev->nHeight + 1, blockSubsidy, /*fV20Active=*/ true)); + platformReward = PlatformShare(GetMasternodePayment(pindexPrev->nHeight + 1, blockSubsidy, consensusParams)); } } @@ -326,7 +327,7 @@ std::optional GetCreditPoolDiffForBlock(CCreditPoolManager& cpo const CAmount blockSubsidy, BlockValidationState& state) { try { - const CCreditPool creditPool = cpoolman.GetCreditPool(pindexPrev, consensusParams); + const CCreditPool creditPool = cpoolman.GetCreditPool(pindexPrev); LogPrint(BCLog::CREDITPOOL, "%s: CCreditPool is %s\n", __func__, creditPool.ToString()); CCreditPoolDiff creditPoolDiff(creditPool, pindexPrev, consensusParams, blockSubsidy); for (size_t i = 1; i < block.vtx.size(); ++i) { diff --git a/src/evo/creditpool.h b/src/evo/creditpool.h index b0d0f57061c7..f58a3fa1e331 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -17,12 +17,14 @@ #include #include + #include #include +class BlockValidationState; class CBlock; class CBlockIndex; -class BlockValidationState; +class ChainstateManager; class CEvoDB; class TxValidationState; namespace Consensus { @@ -114,6 +116,7 @@ class CCreditPoolManager Uint256LruHashMap creditPoolCache GUARDED_BY(cache_mutex){CreditPoolCacheSize}; CEvoDB& evoDb; + const ChainstateManager& m_chainman; static constexpr int DISK_SNAPSHOT_PERIOD = 576; // once per day @@ -126,7 +129,7 @@ class CCreditPoolManager CCreditPoolManager() = delete; CCreditPoolManager(const CCreditPoolManager&) = delete; CCreditPoolManager& operator=(const CCreditPoolManager&) = delete; - explicit CCreditPoolManager(CEvoDB& _evoDb); + explicit CCreditPoolManager(CEvoDB& _evoDb, const ChainstateManager& chainman); ~CCreditPoolManager(); /** @@ -134,15 +137,14 @@ class CCreditPoolManager * In case if block is invalid the function GetCreditPool throws an exception * it can happen if there limits of withdrawal (unlock) exceed */ - CCreditPool GetCreditPool(const CBlockIndex* block, const Consensus::Params& consensusParams) - EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex); + CCreditPool GetCreditPool(const CBlockIndex* block) EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex); private: std::optional GetFromCache(const CBlockIndex& block_index) EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex); void AddToCache(const uint256& block_hash, int height, const CCreditPool& pool) EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex); - CCreditPool ConstructCreditPool(const gsl::not_null block_index, CCreditPool prev, - const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex); + CCreditPool ConstructCreditPool(const gsl::not_null block_index, CCreditPool prev) + EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex); }; std::optional GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const node::BlockManager& blockman, const llmq::CQuorumManager& qman, diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 805c4c8f46f1..aa97f67de072 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -3,32 +3,35 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include + #include #include #include #include #include #include +#include +#include +#include +#include +#include #include #include #include #include #include -#include -#include #include #include