Skip to content
Open
17 changes: 16 additions & 1 deletion src/chainlock/chainlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@

#include <chainlock/chainlock.h>

#include <chainlock/clsig.h>
#include <chain.h>
#include <logging.h>
#include <spork.h>

namespace chainlock {

ChainLockSig::ChainLockSig() = default;
ChainLockSig::~ChainLockSig() = default;

ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) :
nHeight{nHeight},
blockHash{blockHash},
sig{sig}
{
}

std::string ChainLockSig::ToString() const
{
return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
}

Chainlocks::Chainlocks(const CSporkManager& sporkman) :
m_sporks(sporkman)
{
Expand Down
30 changes: 28 additions & 2 deletions src/chainlock/chainlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,45 @@
#ifndef BITCOIN_CHAINLOCK_CHAINLOCK_H
#define BITCOIN_CHAINLOCK_CHAINLOCK_H

#include <chain.h>
#include <chainlock/clsig.h>
#include <bls/bls.h>
#include <gsl/pointers.h>
#include <serialize.h>
#include <sync.h>
#include <uint256.h>

class CBlockIndex;
class CSporkManager;
class uint256;
Comment on lines +14 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Redundant forward declaration of uint256

#include <uint256.h> at line 12 already brings in the full type, so class uint256; at line 16 is redundant. uint256 is also used as a complete type later in the file (member blockHash, return values, equality comparisons), so the forward declaration is misleading about the include dependency. Drop it.

💡 Suggested change
Suggested change
class CBlockIndex;
class CSporkManager;
class uint256;
class CBlockIndex;
class CSporkManager;

source: ['claude']

Comment on lines +14 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Redundant forward declaration of uint256

Line 12 #include <uint256.h> already provides the complete definition of uint256, so the class uint256; forward declaration on line 16 is dead. The include itself is necessary because IsNull() value-initializes a uint256 and SERIALIZE_METHODS reads/writes one — drop only the forward declaration.

💡 Suggested change
Suggested change
class CBlockIndex;
class CSporkManager;
class uint256;
class CBlockIndex;
class CSporkManager;

source: ['claude']


namespace chainlock {

//! Depth of block including transactions before it's considered safe
static constexpr int32_t TX_CONFIRM_THRESHOLD{5};

struct ChainLockSig {
private:
int32_t nHeight{-1};
uint256 blockHash;
CBLSSignature sig;

public:
ChainLockSig();
~ChainLockSig();

ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig);

[[nodiscard]] int32_t getHeight() const { return nHeight; }
[[nodiscard]] const uint256& getBlockHash() const { return blockHash; }
[[nodiscard]] const CBLSSignature& getSig() const { return sig; }
[[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); }
[[nodiscard]] std::string ToString() const;

SERIALIZE_METHODS(ChainLockSig, obj)
{
READWRITE(obj.nHeight, obj.blockHash, obj.sig);
}
};

class Chainlocks
{
private:
Expand Down
25 changes: 11 additions & 14 deletions src/chainlock/clsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@

#include <chainlock/clsig.h>

#include <tinyformat.h>
#include <chainparams.h>
#include <chainlock/chainlock.h>
#include <llmq/quorumsman.h>

#include <string_view>

namespace chainlock {
static constexpr std::string_view CLSIG_REQUESTID_PREFIX{"clsig"};

ChainLockSig::ChainLockSig() = default;
ChainLockSig::~ChainLockSig() = default;

ChainLockSig::ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig) :
nHeight{nHeight},
blockHash{blockHash},
sig{sig}
uint256 GenSigRequestId(const int32_t nHeight)
{
return ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, nHeight));
}

std::string ChainLockSig::ToString() const
llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig)
{
return strprintf("ChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
}
const auto llmqType = params.llmqTypeChainLocks;
const uint256 request_id = GenSigRequestId(clsig.getHeight());

uint256 GenSigRequestId(const int32_t nHeight)
{
return ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, nHeight));
return llmq::VerifyRecoveredSig(llmqType, chain, qman, clsig.getHeight(), request_id, clsig.getBlockHash(),
clsig.getSig());
}
} // namespace chainlock
42 changes: 15 additions & 27 deletions src/chainlock/clsig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,28 @@
#ifndef BITCOIN_CHAINLOCK_CLSIG_H
#define BITCOIN_CHAINLOCK_CLSIG_H

#include <serialize.h>
#include <uint256.h>
#include <cstdint>

#include <bls/bls.h>
class CChain;
class uint256;

#include <cstdint>
namespace Consensus {
struct Params;
} // namespace Consensus

namespace llmq {
class CQuorumManager;
enum class VerifyRecSigStatus : uint8_t;
} // namespace llmq

namespace chainlock {
struct ChainLockSig {
private:
int32_t nHeight{-1};
uint256 blockHash;
CBLSSignature sig;

public:
ChainLockSig();
~ChainLockSig();

ChainLockSig(int32_t nHeight, const uint256& blockHash, const CBLSSignature& sig);

[[nodiscard]] int32_t getHeight() const { return nHeight; }
[[nodiscard]] const uint256& getBlockHash() const { return blockHash; }
[[nodiscard]] const CBLSSignature& getSig() const { return sig; }
[[nodiscard]] bool IsNull() const { return nHeight == -1 && blockHash == uint256(); }
[[nodiscard]] std::string ToString() const;

SERIALIZE_METHODS(ChainLockSig, obj)
{
READWRITE(obj.nHeight, obj.blockHash, obj.sig);
}
};
struct ChainLockSig;

//! Generate clsig request ID with block height
uint256 GenSigRequestId(const int32_t nHeight);

llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
const llmq::CQuorumManager& qman, const ChainLockSig& clsig);
} // namespace chainlock

#endif // BITCOIN_CHAINLOCK_CLSIG_H
21 changes: 6 additions & 15 deletions src/chainlock/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

#include <chainlock/handler.h>

#include <chain.h>
#include <chainlock/chainlock.h>
#include <chainlock/clsig.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <instantsend/instantsend.h>
#include <llmq/quorumsman.h>
#include <masternode/sync.h>
#include <msg_result.h>
#include <stats/client.h>
#include <util/std23.h>

#include <chain.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <node/interface_ui.h>
#include <scheduler.h>
#include <stats/client.h>
#include <txmempool.h>
#include <util/std23.h>
#include <util/thread.h>
#include <util/time.h>
#include <validation.h>
Expand Down Expand Up @@ -325,13 +325,4 @@ void ChainlockHandler::Cleanup()
}
}

llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig)
{
const auto llmqType = params.llmqTypeChainLocks;
const uint256 request_id = chainlock::GenSigRequestId(clsig.getHeight());

return llmq::VerifyRecoveredSig(llmqType, chain, qman, clsig.getHeight(), request_id, clsig.getBlockHash(),
clsig.getSig());
}
} // namespace chainlock
9 changes: 0 additions & 9 deletions src/chainlock/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,14 @@

class CBlock;
class CBlockIndex;
class CChain;
class CMasternodeSync;
class ChainstateManager;
class CScheduler;
class CTxMemPool;
struct MessageProcessingResult;

namespace Consensus {
struct Params;
} // namespace Consensus

namespace llmq {
class CQuorumManager;
enum class VerifyRecSigStatus : uint8_t;
} // namespace llmq

namespace chainlock {
Expand Down Expand Up @@ -107,9 +101,6 @@ class ChainlockHandler final : public CValidationInterface
private:
void Cleanup() EXCLUSIVE_LOCKS_REQUIRED(!cs);
};

llmq::VerifyRecSigStatus VerifyChainLock(const Consensus::Params& params, const CChain& chain,
const llmq::CQuorumManager& qman, const chainlock::ChainLockSig& clsig);
} // namespace chainlock

#endif // BITCOIN_CHAINLOCK_HANDLER_H
1 change: 0 additions & 1 deletion src/chainlock/signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define BITCOIN_CHAINLOCK_SIGNING_H

#include <chainlock/chainlock.h>
#include <chainlock/clsig.h>
#include <llmq/signing.h>
#include <util/time.h>
#include <validationinterface.h>
Expand Down
43 changes: 8 additions & 35 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@

#include <evo/deterministicmns.h>

#include <chainparams.h>
#include <coins.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <evo/dmn_types.h>
#include <evo/dmnstate.h>
#include <evo/evodb.h>
#include <evo/providertx.h>
#include <evo/simplifiedmns.h>
#include <evo/specialtx.h>
#include <masternode/meta.h>
#include <stats/client.h>
#include <util/helpers.h>

#include <chainparams.h>
#include <coins.h>
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <index/txindex.h>
#include <node/blockstorage.h>
#include <script/standard.h>
#include <stats/client.h>
#include <uint256.h>
#include <util/helpers.h>

#include <univalue.h>

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

#include <univalue.h>

static const std::string DB_LIST_SNAPSHOT = "dmn_S3";
static const std::string DB_LIST_DIFF = "dmn_D4"; // Bumped for nVersion-first format
static const std::string DB_LIST_DIFF_LEGACY = "dmn_D3"; // Legacy format key
Expand All @@ -55,31 +53,6 @@ std::string CDeterministicMN::ToString() const
return strprintf("CDeterministicMN(proTxHash=%s, collateralOutpoint=%s, nOperatorReward=%f, state=%s", proTxHash.ToString(), collateralOutpoint.ToStringShort(), (double)nOperatorReward / 100, pdmnState->ToString());
}

UniValue CDeterministicMN::ToJson() const
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("type", std::string(GetMnType(nType).description));
obj.pushKV("proTxHash", proTxHash.ToString());
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
obj.pushKV("collateralIndex", collateralOutpoint.n);

if (g_txindex) {
CTransactionRef collateralTx;
uint256 nBlockHash;
g_txindex->FindTx(collateralOutpoint.hash, nBlockHash, collateralTx);
if (collateralTx) {
CTxDestination dest;
if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) {
obj.pushKV("collateralAddress", EncodeDestination(dest));
}
}
}

obj.pushKV("operatorReward", (double)nOperatorReward / 100);
obj.pushKV("state", pdmnState->ToJson(nType));
return obj;
}

bool CDeterministicMNList::IsMNValid(const uint256& proTxHash) const
{
auto p = mnMap.find(proTxHash);
Expand Down
5 changes: 1 addition & 4 deletions src/evo/dmnstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

#include <evo/dmnstate.h>

#include <script/standard.h>

#include <evo/netinfo.h>
#include <rpc/evo_util.h>

#include <script/standard.h>
#include <univalue.h>

std::string CDeterministicMNState::ToString() const
Expand Down
Loading
Loading