Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/evo/chainhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
CChainstateHelper::CChainstateHelper(CEvoDB& evodb, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync,
llmq::CInstantSendManager& isman, llmq::CQuorumBlockProcessor& qblockman,
llmq::CQuorumSnapshotManager& qsnapman, const ChainstateManager& chainman,
const Consensus::Params& consensus_params, const chainlock::Chainlocks& chainlocks,
const llmq::CQuorumManager& qman) :
const node::BlockManager& blockman, const Consensus::Params& consensus_params,
const chainlock::Chainlocks& chainlocks, const llmq::CQuorumManager& qman) :
isman{isman},
mn_sync{mn_sync},
m_dmnman{dmnman},
credit_pool_manager{std::make_unique<CCreditPoolManager>(evodb, chainman)},
m_chainlocks{chainlocks},
ehf_manager{std::make_unique<CMNHFManager>(evodb, chainman)},
ehf_manager{std::make_unique<CMNHFManager>(evodb, consensus_params)},
superblocks{std::make_unique<governance::SuperblockManager>()},
mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, *superblocks, consensus_params)},
special_tx{std::make_unique<CSpecialTxProcessor>(*credit_pool_manager, dmnman, *ehf_manager, qblockman, qsnapman,
chainman, consensus_params, chainlocks, qman)}
chainman, blockman, consensus_params, chainlocks, qman)}
{}

CChainstateHelper::~CChainstateHelper() = default;
Expand Down
7 changes: 5 additions & 2 deletions src/evo/chainhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CQuorumBlockProcessor;
class CQuorumManager;
class CQuorumSnapshotManager;
} // namespace llmq
namespace node {
class BlockManager;
} // namespace node
class CChainstateHelper
{
private:
Expand All @@ -59,8 +62,8 @@ class CChainstateHelper
explicit CChainstateHelper(CEvoDB& evodb, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync,
llmq::CInstantSendManager& isman, llmq::CQuorumBlockProcessor& qblockman,
llmq::CQuorumSnapshotManager& qsnapman, const ChainstateManager& chainman,
const Consensus::Params& consensus_params, const chainlock::Chainlocks& chainlocks,
const llmq::CQuorumManager& qman);
const node::BlockManager& blockman, const Consensus::Params& consensus_params,
const chainlock::Chainlocks& chainlocks, const llmq::CQuorumManager& qman);
~CChainstateHelper();

bool IsSuperblockValidationRequired(const CBlockIndex* const pindex);
Expand Down
3 changes: 1 addition & 2 deletions src/evo/creditpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BITCOIN_EVO_CREDITPOOL_H

#include <consensus/amount.h>
#include <primitives/transaction.h>
#include <saltedhasher.h>
#include <serialize.h>
#include <sync.h>
Expand All @@ -14,8 +15,6 @@
#include <unordered_lru_cache.h>
#include <util/ranges_set.h>

#include <evo/assetlocktx.h>

#include <gsl/pointers.h>

#include <optional>
Expand Down
9 changes: 3 additions & 6 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <univalue.h>

#include <functional>
#include <optional>
#include <memory>
#include <ranges>

Expand Down Expand Up @@ -624,7 +623,7 @@ CDeterministicMNManager::~CDeterministicMNManager() = default;

bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex,
BlockValidationState& state, const CDeterministicMNList& newList,
std::optional<MNListUpdates>& updatesRet)
MNListUpdates& updatesRet)
{
AssertLockHeld(::cs_main);

Expand Down Expand Up @@ -692,9 +691,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<co
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "failed-dmn-block");
}

if (diff.HasChanges()) {
updatesRet = {.old_list = oldList, .new_list = newList, .diff = diff};
}
updatesRet = {.old_list = oldList, .new_list = newList, .diff = diff};

if (::g_stats_client->active()) {
const auto counts{newList.GetCounts()};
Expand Down Expand Up @@ -723,7 +720,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<co
return true;
}

bool CDeterministicMNManager::UndoBlock(gsl::not_null<const CBlockIndex*> pindex, std::optional<MNListUpdates>& updatesRet)
bool CDeterministicMNManager::UndoBlock(gsl::not_null<const CBlockIndex*> pindex, MNListUpdates& updatesRet)
{
int nHeight = pindex->nHeight;
uint256 blockHash = pindex->GetBlockHash();
Expand Down
10 changes: 6 additions & 4 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

#include <evo/dmn_types.h>
#include <evo/dmnstate.h>
#include <evo/providertx.h>
#include <evo/types.h>

#include <arith_uint256.h>
#include <clientversion.h>
#include <consensus/params.h>
#include <crypto/common.h>
#include <saltedhasher.h>
#include <scheduler.h>
#include <sync.h>

#include <gsl/pointers.h>
Expand Down Expand Up @@ -717,6 +715,10 @@ constexpr int llmq_max_blocks() {
return max_blocks;
}

/** Outcome of applying a block to the deterministic masternode list: the list
* before and after the block and the diff between them. A block that leaves
* the list untouched yields an empty diff (see diff.HasChanges()); for an
* undone block the lists are only filled when the diff has changes. */
struct MNListUpdates
{
CDeterministicMNList old_list;
Expand Down Expand Up @@ -777,9 +779,9 @@ class CDeterministicMNManager
~CDeterministicMNManager();

bool ProcessBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex, BlockValidationState& state,
const CDeterministicMNList& newList, std::optional<MNListUpdates>& updatesRet)
const CDeterministicMNList& newList, MNListUpdates& updatesRet)
EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main);
bool UndoBlock(gsl::not_null<const CBlockIndex*> pindex, std::optional<MNListUpdates>& updatesRet) EXCLUSIVE_LOCKS_REQUIRED(!cs);
bool UndoBlock(gsl::not_null<const CBlockIndex*> pindex, MNListUpdates& updatesRet) EXCLUSIVE_LOCKS_REQUIRED(!cs);

void UpdatedBlockTip(gsl::not_null<const CBlockIndex*> pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs);

Expand Down
31 changes: 15 additions & 16 deletions src/evo/mnhftx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <chain.h>
#include <chainparams.h>
#include <validation.h>
#include <versionbits.h>

#include <algorithm>
Expand Down Expand Up @@ -45,9 +44,9 @@ CMutableTransaction MNHFTxPayload::PrepareTx() const
return tx;
}

CMNHFManager::CMNHFManager(CEvoDB& evoDb, const ChainstateManager& chainman) :
CMNHFManager::CMNHFManager(CEvoDB& evoDb, const Consensus::Params& consensus_params) :
m_evoDb(evoDb),
m_chainman{chainman}
m_consensus_params{consensus_params}
{
assert(globalInstance == nullptr);
globalInstance = this;
Expand All @@ -61,7 +60,7 @@ CMNHFManager::~CMNHFManager()

CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pindexPrev)
{
if (!DeploymentActiveAfter(pindexPrev, m_chainman.GetConsensus(), Consensus::DEPLOYMENT_V20)) return {};
if (!DeploymentActiveAfter(pindexPrev, m_consensus_params, Consensus::DEPLOYMENT_V20)) return {};

Signals signals_tmp = GetForBlock(pindexPrev);

Expand Down Expand Up @@ -105,7 +104,7 @@ bool MNHFTxPayload::IsTriviallyValid(TxValidationState& state) const
}

template <typename GetQuorum>
static bool CheckMNHFTxImpl(const ChainstateManager& chainman, GetQuorum&& get_quorum,
static bool CheckMNHFTxImpl(const node::BlockManager& blockman, GetQuorum&& get_quorum,
const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
{
if (!tx.IsSpecialTxVersion() || tx.nType != TRANSACTION_MNHF_SIGNAL) {
Expand All @@ -126,7 +125,7 @@ static bool CheckMNHFTxImpl(const ChainstateManager& chainman, GetQuorum&& get_q
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-non-ehf");
}

const CBlockIndex* pindexQuorum = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(mnhfTx.signal.quorumHash));
const CBlockIndex* pindexQuorum = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(mnhfTx.signal.quorumHash));
if (!pindexQuorum) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-quorum-hash");
}
Expand Down Expand Up @@ -157,19 +156,19 @@ static bool CheckMNHFTxImpl(const ChainstateManager& chainman, GetQuorum&& get_q
return true;
}

bool CheckMNHFTx(const ChainstateManager& chainman, const llmq::CQuorumManager& qman,
bool CheckMNHFTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman,
const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
{
return CheckMNHFTxImpl(chainman, [&](Consensus::LLMQType llmq_type, const uint256& quorum_hash) {
return CheckMNHFTxImpl(blockman, [&](Consensus::LLMQType llmq_type, const uint256& quorum_hash) {
return qman.GetQuorum(llmq_type, quorum_hash);
}, tx, pindexPrev, state);
}

bool CheckMNHFTx(const ChainstateManager& chainman, const llmq::CQuorumManager& qman, const CChain& chain,
bool CheckMNHFTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CChain& chain,
const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
{
AssertLockHeld(::cs_main);
return CheckMNHFTxImpl(chainman, [&](Consensus::LLMQType llmq_type, const uint256& quorum_hash) NO_THREAD_SAFETY_ANALYSIS {
return CheckMNHFTxImpl(blockman, [&](Consensus::LLMQType llmq_type, const uint256& quorum_hash) NO_THREAD_SAFETY_ANALYSIS {
return qman.GetQuorum(llmq_type, quorum_hash, chain);
}, tx, pindexPrev, state);
}
Expand Down Expand Up @@ -301,7 +300,7 @@ CMNHFManager::Signals CMNHFManager::GetForBlock(const CBlockIndex* pindex)
LogPrintf("re-index EHF signals at block %d\n", pindex_top->nHeight);
}
CBlock block;
if (!ReadBlockFromDisk(block, pindex_top, m_chainman.GetConsensus())) {
if (!ReadBlockFromDisk(block, pindex_top, m_consensus_params)) {
throw std::runtime_error("failed-getehfforblock-read");
}
BlockValidationState state;
Expand Down Expand Up @@ -341,7 +340,7 @@ std::optional<CMNHFManager::Signals> CMNHFManager::GetFromCache(const CBlockInde
}
{
LOCK(cs_cache);
if (!DeploymentActiveAt(*pindex, m_chainman.GetConsensus(), Consensus::DEPLOYMENT_V20)) {
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) {
mnhfCache.insert(blockHash, signals);
return signals;
}
Expand All @@ -351,7 +350,7 @@ std::optional<CMNHFManager::Signals> CMNHFManager::GetFromCache(const CBlockInde
mnhfCache.insert(blockHash, signals);
return signals;
}
if (!DeploymentActiveAt(*pindex, m_chainman.GetConsensus(), Consensus::DEPLOYMENT_MN_RR)) {
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_MN_RR)) {
// before mn_rr activation we are safe
if (m_evoDb.Read(std::make_pair(DB_SIGNALS, blockHash), signals)) {
LOCK(cs_cache);
Expand All @@ -366,7 +365,7 @@ void CMNHFManager::AddToCache(const Signals& signals, const CBlockIndex* const p
{
assert(pindex != nullptr);
const uint256& blockHash = pindex->GetBlockHash();
if (DeploymentActiveAt(*pindex, m_chainman.GetConsensus(), Consensus::DEPLOYMENT_V20) &&
if (DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20) &&
!m_evoDb.WriteDerived(std::make_pair(DB_SIGNALS_v2, blockHash), signals)) {
// A mismatch is local EvoDB corruption, not a statement about the
// block. Abort here: some callers (miner, RPC) never pass through a
Expand All @@ -390,14 +389,14 @@ void CMNHFManager::AddSignal(const CBlockIndex* const pindex, int bit)
AddToCache(signals, pindex);
}

bool CMNHFManager::ForceSignalDBUpdate()
bool CMNHFManager::ForceSignalDBUpdate(const CBlockIndex* tip)
{
// force ehf signals db update
auto dbTx = m_evoDb.BeginTransaction();

const bool last_legacy = bls::bls_legacy_scheme.load();
bls::bls_legacy_scheme.store(false);
GetSignalsStage(m_chainman.ActiveTip());
GetSignalsStage(tip);
bls::bls_legacy_scheme.store(last_legacy);

dbTx->Commit();
Expand Down
18 changes: 9 additions & 9 deletions src/evo/mnhftx.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ class CBlockIndex;
class CChain;
class CEvoDB;
class CTransaction;
class ChainstateManager;
class TxValidationState;
struct RPCResult;
namespace llmq {
class CQuorumManager;
}
namespace node {
class BlockManager;
} // namespace node

// mnhf signal special transaction
class MNHFTx
Expand Down Expand Up @@ -94,12 +96,10 @@ class CMNHFManager : public AbstractEHFManager
{
private:
CEvoDB& m_evoDb;
// TODO: move its functionallity of ProcessBlock, UndoBlock to specialtxman;
// it will help to drop dependency on m_chainman here (and validation.h)
// Secondly, store in database active EHF signals not for each block;
// TODO: store in database active EHF signals not for each block;
// but quite opposite: keep only hash of block where signal is added.
// TODO: implement migration to a new format
const ChainstateManager& m_chainman;
const Consensus::Params& m_consensus_params;

static constexpr size_t MNHFCacheSize = 1000;
Mutex cs_cache;
Expand All @@ -110,7 +110,7 @@ class CMNHFManager : public AbstractEHFManager
CMNHFManager() = delete;
CMNHFManager(const CMNHFManager&) = delete;
CMNHFManager& operator=(const CMNHFManager&) = delete;
explicit CMNHFManager(CEvoDB& evoDb, const ChainstateManager& chainman);
explicit CMNHFManager(CEvoDB& evoDb, const Consensus::Params& consensus_params);
~CMNHFManager() override;

/**
Expand All @@ -135,7 +135,7 @@ class CMNHFManager : public AbstractEHFManager
*/
void AddSignal(const CBlockIndex* const pindex, int bit) EXCLUSIVE_LOCKS_REQUIRED(!cs_cache);

bool ForceSignalDBUpdate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main, !cs_cache);
bool ForceSignalDBUpdate(const CBlockIndex* tip) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, !cs_cache);

private:
void AddToCache(const Signals& signals, const CBlockIndex* const pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs_cache);
Expand All @@ -156,8 +156,8 @@ class CMNHFManager : public AbstractEHFManager
};

std::optional<uint8_t> extractEHFSignal(const CTransaction& tx);
bool CheckMNHFTx(const ChainstateManager& chainman, const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state);
bool CheckMNHFTx(const ChainstateManager& chainman, const llmq::CQuorumManager& qman, const CChain& chain,
bool CheckMNHFTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state);
bool CheckMNHFTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CChain& chain,
const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

Expand Down
4 changes: 3 additions & 1 deletion src/evo/providertx_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ std::optional<ProviderTxError> Preflight(node::NodeContext& node, const CTransac
}

TxValidationState state;
if (!chain_helper.special_tx->CheckSpecialTx(tx, tip, chainman.ActiveChainstate().CoinsTip(), true, state)) {
const bool is_v24_active{DeploymentActiveAfter(tip, chainman, Consensus::DEPLOYMENT_V24)};
if (!chain_helper.special_tx->CheckSpecialTx(tx, tip, is_v24_active, chainman.ActiveChainstate().CoinsTip(), true,
state)) {
return Error(ProviderTxErrorCode::CONSENSUS_REJECTED, state.ToString(), state.GetRejectReason());
}
return std::nullopt;
Expand Down
Loading
Loading