Skip to content

Commit

Permalink
feat: auto generation EHF
Browse files Browse the repository at this point in the history
add new networks message stub ..... to remove probably!

Revert "add new networks message stub ..... to remove probably!"

stub implementation of EHF signals manager

continue implementation

compilable now!

set up 0 as MN_RR activation MR height

some logs in mnehf.py

fixups and logs

comment logs

create new tx after recovered sig

more fixes for ehf_signals

some test bla-bla

fixes -Wreorder + throw exception

add delay in functional test
  • Loading branch information
knst committed Oct 1, 2023
1 parent a54866a commit c199862
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 20 deletions.
14 changes: 8 additions & 6 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,24 @@ BITCOIN_CORE_H = \
key_io.h \
dbwrapper.h \
limitedmap.h \
llmq/quorums.h \
llmq/blockprocessor.h \
llmq/commitment.h \
llmq/chainlocks.h \
llmq/clsig.h \
llmq/commitment.h \
llmq/context.h \
llmq/debug.h \
llmq/dkgsession.h \
llmq/dkgsessionhandler.h \
llmq/dkgsessionmgr.h \
llmq/dkgsession.h \
llmq/context.h \
llmq/ehf_signals.cpp \
llmq/ehf_signals.h \
llmq/instantsend.h \
llmq/snapshot.h \
llmq/params.h \
llmq/quorums.h \
llmq/signing.h \
llmq/signing_shares.h \
llmq/snapshot.h \
llmq/utils.h \
llmq/params.h \
logging.h \
logging/timer.h \
mapport.h \
Expand Down
4 changes: 4 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 3226; // 80% of 4032
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 2420; // 60% of 4032
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nMNActivationHeight = 0; // requires EHF activation

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000008677827656704520eb39"); // 1889000
Expand Down Expand Up @@ -420,6 +421,7 @@ class CTestNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nMNActivationHeight = 0; // requires EHF activation

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000002d68c8cc1b8e54b"); // 851000
Expand Down Expand Up @@ -591,6 +593,7 @@ class CDevNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nMNActivationHeight = 0; // requires EHF activation

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000");
Expand Down Expand Up @@ -829,6 +832,7 @@ class CRegTestParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 800; // 80% of 1000
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 600; // 60% of 1000
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nMNActivationHeight = 0; // requires EHF activation

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
Expand Down
3 changes: 3 additions & 0 deletions src/dsnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <llmq/chainlocks.h>
#include <llmq/context.h>
#include <llmq/dkgsessionmgr.h>
#include <llmq/ehf_signals.h>
#include <llmq/instantsend.h>
#include <llmq/quorums.h>

Expand Down Expand Up @@ -74,10 +75,12 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
#endif // ENABLE_WALLET

llmq_ctx->isman->UpdatedBlockTip(pindexNew);
// TODO - pass tip pindexNew ??
llmq_ctx->clhandler->UpdatedBlockTip();

llmq_ctx->qman->UpdatedBlockTip(pindexNew, fInitialDownload);
llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
llmq_ctx->ehfSignalsHandler->UpdatedBlockTip(pindexNew);

if (!fDisableGovernance) govman.UpdatedBlockTip(pindexNew, connman);
}
Expand Down
10 changes: 7 additions & 3 deletions src/evo/mnhftx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <string>
#include <vector>

extern const std::string MNEHF_REQUESTID_PREFIX = "mnhf";
const std::string MNEHF_REQUESTID_PREFIX = "mnhf";
static const std::string DB_SIGNALS = "mnhf_s";

CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pindexPrev)
Expand Down Expand Up @@ -53,6 +53,11 @@ CMNHFManager::Signals CMNHFManager::GetSignalsStage(const CBlockIndex* const pin
return signals;
}

const uint256 MNHFTx::GetRequestId() const
{
return ::SerializeHash(std::make_pair(MNEHF_REQUESTID_PREFIX, int64_t{versionBit}));
}

bool MNHFTx::Verify(const uint256& quorumHash, const uint256& msgHash, TxValidationState& state) const
{
if (versionBit >= VERSIONBITS_NUM_BITS) {
Expand All @@ -62,8 +67,7 @@ bool MNHFTx::Verify(const uint256& quorumHash, const uint256& msgHash, TxValidat
const Consensus::LLMQType& llmqType = Params().GetConsensus().llmqTypeMnhf;
const auto quorum = llmq::quorumManager->GetQuorum(llmqType, quorumHash);

const uint256 requestId = ::SerializeHash(std::make_pair(MNEHF_REQUESTID_PREFIX, int64_t{versionBit}));
const uint256 signHash = llmq::utils::BuildSignHash(llmqType, quorum->qc->quorumHash, requestId, msgHash);
const uint256 signHash = llmq::utils::BuildSignHash(llmqType, quorum->qc->quorumHash, GetRequestId(), msgHash);
if (!sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash)) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-invalid");
}
Expand Down
6 changes: 5 additions & 1 deletion src/evo/mnhftx.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CEvoDB;
class TxValidationState;
extern RecursiveMutex cs_main;

extern const std::string MNEHF_REQUESTID_PREFIX;

// mnhf signal special transaction
class MNHFTx
{
Expand All @@ -34,6 +36,8 @@ class MNHFTx
MNHFTx() = default;
bool Verify(const uint256& quorumHash, const uint256& msgHash, TxValidationState& state) const;

const uint256 GetRequestId() const;

SERIALIZE_METHODS(MNHFTx, obj)
{
READWRITE(obj.versionBit, obj.quorumHash);
Expand Down Expand Up @@ -119,6 +123,7 @@ class CMNHFManager
* This member function is not const because it calls non-const GetFromCache()
*/
Signals GetSignalsStage(const CBlockIndex* const pindexPrev);

private:
void AddToCache(const Signals& signals, const CBlockIndex* const pindex);

Expand All @@ -128,7 +133,6 @@ class CMNHFManager
* validate them by
*/
Signals GetFromCache(const CBlockIndex* const pindex);

};

std::optional<uint8_t> extractEHFSignal(const CTransaction& tx);
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
llmq::quorumSnapshotManager.reset();
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*node.evodb));
node.llmq_ctx.reset();
node.llmq_ctx.reset(new LLMQContext(chainman.ActiveChainstate(), *node.connman, *node.evodb, *::sporkManager, *node.mempool, node.peerman, false, fReset || fReindexChainState));
node.llmq_ctx.reset(new LLMQContext(chainman.ActiveChainstate(), *node.connman, *node.evodb, *::sporkManager, *node.mnhf_manager, *node.mempool, node.peerman, false, fReset || fReindexChainState));

if (fReset) {
pblocktree->WriteReindexing(true);
Expand Down
1 change: 1 addition & 0 deletions src/llmq/chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void CChainLocksHandler::UpdatedBlockTip()
// EnforceBestChainLock switching chains.
// atomic[If tryLockChainTipScheduled is false, do (set it to true] and schedule signing).
if (bool expected = false; tryLockChainTipScheduled.compare_exchange_strong(expected, true)) {
// TODO: use here pindexRev instead m_chainstate.m_chain.Tip()
scheduler->scheduleFromNow([&]() {
CheckActiveState();
EnforceBestChainLock();
Expand Down
6 changes: 4 additions & 2 deletions src/llmq/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include <llmq/commitment.h>
#include <llmq/debug.h>
#include <llmq/dkgsessionmgr.h>
#include <llmq/ehf_signals.h>
#include <llmq/instantsend.h>
#include <llmq/quorums.h>
#include <llmq/signing.h>
#include <llmq/signing_shares.h>
#include <llmq/utils.h>
#include <masternode/sync.h>

LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CEvoDB& evo_db, CSporkManager& sporkman, CTxMemPool& mempool,
LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CEvoDB& evo_db, CSporkManager& sporkman, CMNHFManager& mnhfman, CTxMemPool& mempool,
const std::unique_ptr<PeerManager>& peerman, bool unit_tests, bool wipe) :
bls_worker{std::make_shared<CBLSWorker>()},
dkg_debugman{std::make_unique<llmq::CDKGDebugManager>()},
Expand All @@ -45,7 +46,8 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CEvoDB& evo
assert(llmq::quorumInstantSendManager == nullptr);
llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(*llmq::chainLocksHandler, chainstate, connman, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, *::masternodeSync, peerman, unit_tests, wipe);
return llmq::quorumInstantSendManager.get();
}()}
}()},
ehfSignalsHandler{std::make_unique<llmq::CEHFSignalsHandler>(*sigman, *shareman, *llmq::quorumManager, mempool, mnhfman)}
{
// NOTE: we use this only to wipe the old db, do NOT use it for anything else
// TODO: remove it in some future version
Expand Down
14 changes: 9 additions & 5 deletions src/llmq/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ class CChainState;
class CConnman;
class CDBWrapper;
class CEvoDB;
class CTxMemPool;
class CMNHFManager;
class CSporkManager;
class CTxMemPool;
class PeerManager;

namespace llmq {
class CChainLocksHandler;
class CDKGDebugManager;
class CQuorumBlockProcessor;
class CDKGSessionManager;
class CEHFSignalsHandler;
class CInstantSendManager;
class CQuorumBlockProcessor;
class CQuorumManager;
class CSigSharesManager;
class CSigningManager;
class CChainLocksHandler;
class CInstantSendManager;
}

struct LLMQContext {
LLMQContext() = delete;
LLMQContext(const LLMQContext&) = delete;
LLMQContext(CChainState& chainstate, CConnman& connman, CEvoDB& evo_db, CSporkManager& sporkman, CTxMemPool& mempool,
LLMQContext(CChainState& chainstate, CConnman& connman, CEvoDB& evo_db, CSporkManager& sporkman,
CMNHFManager& mnhfman, CTxMemPool& mempool,
const std::unique_ptr<PeerManager>& peerman, bool unit_tests, bool wipe);
~LLMQContext();

Expand All @@ -57,6 +60,7 @@ struct LLMQContext {
const std::unique_ptr<llmq::CSigSharesManager> shareman;
llmq::CChainLocksHandler* const clhandler;
llmq::CInstantSendManager* const isman;
const std::unique_ptr<llmq::CEHFSignalsHandler> ehfSignalsHandler;
};

#endif // BITCOIN_LLMQ_CONTEXT_H
Loading

0 comments on commit c199862

Please sign in to comment.