Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/REST-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<BLOCKHASH>.json`

Returns an object containing various state info regarding deployments of
consensus changes at the current chain tip, or at <BLOCKHASH> if provided.
Only supports JSON as output format.
Refer to the `getdeploymentinfo` RPC help for details.

#### Query UTXO set
- `GET /rest/getutxos/<TXID>-<N>/<TXID>-<N>/.../<TXID>-<N>.<bin|hex|json>`
- `GET /rest/getutxos/checkmempool/<TXID>-<N>/<TXID>-<N>/.../<TXID>-<N>.<bin|hex|json>`
Expand Down
17 changes: 17 additions & 0 deletions doc/release-notes-6888.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 2 additions & 3 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,8 @@ CDeterministicMNCPtr CCoinJoinClientManager::GetRandomNotUsedMasternode()
// fill a vector
std::vector<CDeterministicMNCPtr> 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());
Expand Down
2 changes: 0 additions & 2 deletions src/deploymentstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include <type_traits>

VersionBitsCache g_versionbitscache;

/* Basic sanity checking for BuriedDeployment/DeploymentPos enums and
* ValidDeployment check */

Expand Down
11 changes: 4 additions & 7 deletions src/deploymentstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@

#include <limits>

/** 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)
{
assert(Consensus::ValidDeployment(dep));
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 */
Expand All @@ -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) */
Expand Down
29 changes: 15 additions & 14 deletions src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static std::optional<CreditPoolDataPerBlock> 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;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ std::string CCreditPool::ToString() const

std::optional<CCreditPool> 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;
Expand Down Expand Up @@ -148,10 +148,9 @@ void CCreditPoolManager::AddToCache(const uint256& block_hash, int height, const
}
}

CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null<const CBlockIndex*> block_index,
CCreditPool prev, const Consensus::Params& consensusParams)
CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null<const CBlockIndex*> block_index, CCreditPool prev)
{
std::optional<CreditPoolDataPerBlock> opt_block_data = GetCreditDataFromBlock(block_index, consensusParams);
std::optional<CreditPoolDataPerBlock> 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
Expand All @@ -178,20 +177,21 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null<const CB
}

const CBlockIndex* distant_block_index{
block_index->GetAncestor(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<CreditPoolDataPerBlock> distant_block{GetCreditDataFromBlock(distant_block_index, consensusParams)};
if (std::optional<CreditPoolDataPerBlock> distant_block{
GetCreditDataFromBlock(distant_block_index, m_chainman.GetConsensus())};
distant_block) {
distantUnlocked = distant_block->unlocked;
}
}

CAmount currentLimit = blockData.credit_pool;
const CAmount latelyUnlocked = prev.latelyUnlocked + blockData.unlocked - distantUnlocked;
if (DeploymentActiveAt(*block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_V24)) {
if (DeploymentActiveAt(*block_index, m_chainman, Consensus::DEPLOYMENT_V24)) {
currentLimit = std::max(CAmount(0), std::min(currentLimit, LimitAmountV24 - latelyUnlocked));
} else if (DeploymentActiveAt(*block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_WITHDRAWALS)) {
} else if (DeploymentActiveAt(*block_index, m_chainman.GetConsensus(), Consensus::DEPLOYMENT_WITHDRAWALS)) {
currentLimit = std::min(currentLimit, LimitAmountV22);
} else {
// Unlock limits in pre-v22 are max(100, min(.10 * assetlockpool, 1000)) inside window
Expand Down Expand Up @@ -221,7 +221,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null<const CB

}

CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index, const Consensus::Params& consensusParams)
CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index)
{
std::stack<gsl::not_null<const CBlockIndex*>> to_calculate;

Expand All @@ -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}
{
}

Expand Down Expand Up @@ -326,7 +327,7 @@ std::optional<CCreditPoolDiff> 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) {
Expand Down
14 changes: 8 additions & 6 deletions src/evo/creditpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include <evo/assetlocktx.h>

#include <gsl/pointers.h>

#include <optional>
#include <unordered_set>

class BlockValidationState;
class CBlock;
class CBlockIndex;
class BlockValidationState;
class ChainstateManager;
class CEvoDB;
class TxValidationState;
namespace Consensus {
Expand Down Expand Up @@ -114,6 +116,7 @@ class CCreditPoolManager
Uint256LruHashMap<CCreditPool> creditPoolCache GUARDED_BY(cache_mutex){CreditPoolCacheSize};

CEvoDB& evoDb;
const ChainstateManager& m_chainman;

static constexpr int DISK_SNAPSHOT_PERIOD = 576; // once per day

Expand All @@ -126,23 +129,22 @@ 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();

/**
* @return CCreditPool with data or with empty depends on activation V19 at that block
* 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<CCreditPool> 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<const CBlockIndex*> block_index, CCreditPool prev,
const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex);
CCreditPool ConstructCreditPool(const gsl::not_null<const CBlockIndex*> block_index, CCreditPool prev)
EXCLUSIVE_LOCKS_REQUIRED(!cache_mutex);
};

std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const node::BlockManager& blockman, const llmq::CQuorumManager& qman,
Expand Down
Loading
Loading