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
14 changes: 10 additions & 4 deletions src/llmq/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <llmq/quorums.h>
#include <llmq/signhash.h>
#include <llmq/signing_shares.h>
#include <llmq/options.h>

#include <bls/bls_batchverifier.h>
#include <chainparams.h>
Expand Down Expand Up @@ -516,7 +517,7 @@ void CSigningManager::ProcessPendingReconstructedRecoveredSigs(PeerManager& peer
WITH_LOCK(cs_pending, swap(m, pendingReconstructedRecoveredSigs));

for (const auto& p : m) {
ProcessRecoveredSig(p.second, peerman);
ProcessRecoveredSig(p.second, peerman, -1);
}
}

Expand Down Expand Up @@ -578,15 +579,15 @@ bool CSigningManager::ProcessPendingRecoveredSigs(PeerManager& peerman)
continue;
}

ProcessRecoveredSig(recSig, peerman);
ProcessRecoveredSig(recSig, peerman, nodeId);
}
}

return more_work;
}

// signature must be verified already
void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecoveredSig>& recoveredSig, PeerManager& peerman)
void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecoveredSig>& recoveredSig, PeerManager& peerman, NodeId from)
{
auto llmqType = recoveredSig->getLlmqType();

Expand Down Expand Up @@ -629,7 +630,12 @@ void CSigningManager::ProcessRecoveredSig(const std::shared_ptr<const CRecovered
peerman.PostProcessMessage(l->HandleNewRecoveredSig(*recoveredSig));
}

GetMainSignals().NotifyRecoveredSig(recoveredSig, recoveredSig->GetHash().ToString());
// TODO refactor to use a better abstraction analogous to IsAllMembersConnectedEnabled
auto proactive_relay = from == -1 &&
llmqType != Consensus::LLMQType::LLMQ_100_67 &&
llmqType != Consensus::LLMQType::LLMQ_400_60 &&
llmqType != Consensus::LLMQType::LLMQ_400_85;
GetMainSignals().NotifyRecoveredSig(recoveredSig, recoveredSig->GetHash().ToString(), proactive_relay);
}

void CSigningManager::PushReconstructedRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& recoveredSig)
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class CSigningManager

// Used by CSigSharesManager
CRecoveredSigsDb& GetDb() { return db; }
void ProcessRecoveredSig(const std::shared_ptr<const CRecoveredSig>& recoveredSig, PeerManager& peerman)
void ProcessRecoveredSig(const std::shared_ptr<const CRecoveredSig>& recoveredSig, PeerManager& peerman, NodeId pFrom)
EXCLUSIVE_LOCKS_REQUIRED(!cs_pending, !cs_listeners);

// Needed for access to GetDb() and ProcessRecoveredSig()
Expand Down
8 changes: 4 additions & 4 deletions src/llmq/signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void CSigSharesManager::TryRecoverSig(const CQuorum& quorum, const uint256& id,

// Handle single-member quorum case after releasing the lock
if (singleMemberRecoveredSig) {
sigman.ProcessRecoveredSig(singleMemberRecoveredSig, m_peerman);
sigman.ProcessRecoveredSig(singleMemberRecoveredSig, m_peerman, -1);
return; // end of single-quorum processing
}

Expand Down Expand Up @@ -867,7 +867,7 @@ void CSigSharesManager::TryRecoverSig(const CQuorum& quorum, const uint256& id,
}
}

sigman.ProcessRecoveredSig(rs, m_peerman);
sigman.ProcessRecoveredSig(rs, m_peerman, -1);
}

CDeterministicMNCPtr CSigSharesManager::SelectMemberForRecovery(const CQuorum& quorum, const uint256 &id, int attempt)
Expand Down Expand Up @@ -965,9 +965,9 @@ bool CSigSharesManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigning
return true;
}

void CSigSharesManager::NotifyRecoveredSig(const std::shared_ptr<const CRecoveredSig>& sig) const
void CSigSharesManager::NotifyRecoveredSig(const std::shared_ptr<const CRecoveredSig>& sig, bool proactive_relay) const
{
m_peerman.RelayRecoveredSig(Assert(sig)->GetHash());
m_peerman.RelayRecoveredSig(*Assert(sig), proactive_relay);
}

void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>>& sigSharesToRequest)
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class CSigSharesManager : public CRecoveredSigsListener
const uint256& msgHash, const uint256& quorumHash = uint256(), bool allowReSign = false,
bool allowDiffMsgHashSigning = false) EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingSigns, !cs);

void NotifyRecoveredSig(const std::shared_ptr<const CRecoveredSig>& sig) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
void NotifyRecoveredSig(const std::shared_ptr<const CRecoveredSig>& sig, bool proactive_relay) const EXCLUSIVE_LOCKS_REQUIRED(!cs);

private:
// all of these return false when the currently processed message should be aborted (as each message actually contains multiple messages)
Expand Down
14 changes: 13 additions & 1 deletion src/llmq/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,19 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman&
if (isMember) {
connections = GetQuorumConnections(llmqParams, dmnman, qsnapman, sporkman, pQuorumBaseBlockIndex, myProTxHash,
true);
relayMembers = GetQuorumRelayMembers(llmqParams, dmnman, qsnapman, pQuorumBaseBlockIndex, myProTxHash, true);
// If all-members-connected is enabled for this quorum type, leverage the full-mesh
// connections for low-latency recovered sig propagation by treating all members as
// relay members (instead of the ring-based subset). This ensures peers will send
// QSENDRECSIGS to each other across the full mesh and set m_wants_recsigs widely.
if (IsAllMembersConnectedEnabled(llmqParams.type, sporkman)) {
for (const auto& dmn : members) {
if (dmn->proTxHash != myProTxHash) {
relayMembers.emplace(dmn->proTxHash);
}
}
} else {
relayMembers = GetQuorumRelayMembers(llmqParams, dmnman, qsnapman, pQuorumBaseBlockIndex, myProTxHash, true);
}
} else {
auto cindexes = CalcDeterministicWatchConnections(llmqParams.type, pQuorumBaseBlockIndex, members.size(), 1);
for (auto idx : cindexes) {
Expand Down
4 changes: 2 additions & 2 deletions src/masternode/active/notificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void ActiveNotificationInterface::UpdatedBlockTip(const CBlockIndex* pindexNew,
m_active_ctx.gov_signer->UpdatedBlockTip(pindexNew);
}

void ActiveNotificationInterface::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
void ActiveNotificationInterface::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay)
{
m_active_ctx.shareman->NotifyRecoveredSig(sig);
m_active_ctx.shareman->NotifyRecoveredSig(sig, proactive_relay);
}

std::unique_ptr<ActiveNotificationInterface> g_active_notification_interface;
2 changes: 1 addition & 1 deletion src/masternode/active/notificationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ActiveNotificationInterface final : public CValidationInterface

protected:
// CValidationInterface
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig) override;
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay) override;
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;

private:
Expand Down
19 changes: 15 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ class PeerManagerImpl final : public PeerManager
void RelayInv(const CInv& inv) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayInv(const CInv& inv, const int minProtoVersion) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayTransaction(const uint256& txid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayRecoveredSig(const uint256& sigHash) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayRecoveredSig(const llmq::CRecoveredSig& sig, bool proactive_relay) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayDSQ(const CCoinJoinQueue& queue) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void SetBestHeight(int height) override { m_best_height = height; };
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message = "") override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
Expand Down Expand Up @@ -2467,9 +2467,20 @@ void PeerManagerImpl::_RelayTransaction(const uint256& txid)
};
}

void PeerManagerImpl::RelayRecoveredSig(const uint256& sigHash)
{
const CInv inv{MSG_QUORUM_RECOVERED_SIG, sigHash};
void PeerManagerImpl::RelayRecoveredSig(const llmq::CRecoveredSig& sig, bool proactive_relay) {
if (proactive_relay) {
// We were the peer that recovered this; avoid a bunch of `inv` -> `GetData` spam by proactively sending
m_connman.ForEachNode([this, &sig](CNode* pnode) -> bool {
// Skip nodes that don't want recovered signatures
PeerRef peer = GetPeerRef(pnode->GetId());
if (peer == nullptr || !peer->m_wants_recsigs) return true;
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
m_connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGREC, sig));
return true;
});
return;
}
const CInv inv{MSG_QUORUM_RECOVERED_SIG, sig.GetHash()};
READ_LOCK(m_peer_mutex);
for (const auto& [_, peer] : m_peer_map) {
if (peer->m_wants_recsigs) {
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
virtual void RelayTransaction(const uint256& txid) = 0;

/** Relay recovered sigs to all interested peers */
virtual void RelayRecoveredSig(const uint256& sigHash) = 0;
virtual void RelayRecoveredSig(const llmq::CRecoveredSig& sig, bool proactive_relay) = 0;

/** Set the best height */
virtual void SetBestHeight(int height) = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ void CMainSignals::NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& cu
previousTx->GetHash().ToString());
}

void CMainSignals::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, const std::string& id) {
auto event = [sig, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NotifyRecoveredSig(sig); });
void CMainSignals::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, const std::string& id, bool proactive_relay) {
auto event = [sig, proactive_relay, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NotifyRecoveredSig(sig, proactive_relay); });
};
ENQUEUE_AND_LOG_EVENT(event, "%s: notify recoveredsig=%s", __func__,
id);
Expand Down
4 changes: 2 additions & 2 deletions src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class CValidationInterface {
virtual void NotifyGovernanceVote(const std::shared_ptr<CDeterministicMNList>& tip_mn_list, const std::shared_ptr<const CGovernanceVote>& vote) {}
virtual void NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) {}
virtual void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx) {}
virtual void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig) {}
virtual void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay) {}
virtual void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) {}
/**
* Notifies listeners of the new active block chain on-disk.
Expand Down Expand Up @@ -236,7 +236,7 @@ class CMainSignals {
void NotifyGovernanceVote(const std::shared_ptr<CDeterministicMNList>& tip_mn_list, const std::shared_ptr<const CGovernanceVote>& vote, const std::string& id);
void NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object, const std::string& id);
void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef &currentTx, const CTransactionRef &previousTx);
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig, const std::string& id);
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig, const std::string &id, bool proactive_relay);
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff);
void ChainStateFlushed(const CBlockLocator &);
void BlockChecked(const CBlock&, const BlockValidationState&);
Expand Down
2 changes: 1 addition & 1 deletion src/zmq/zmqabstractnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool CZMQAbstractNotifier::NotifyInstantSendDoubleSpendAttempt(const CTransactio
return true;
}

bool CZMQAbstractNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> & /*sig*/)
bool CZMQAbstractNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> & /*sig*/, bool /*proactive_relay*/)
{
return true;
}
2 changes: 1 addition & 1 deletion src/zmq/zmqabstractnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CZMQAbstractNotifier
virtual bool NotifyGovernanceVote(const std::shared_ptr<CDeterministicMNList>& tip_mn_list, const std::shared_ptr<const CGovernanceVote>& vote);
virtual bool NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object);
virtual bool NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx);
virtual bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig);
virtual bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay);

protected:
void *psocket;
Expand Down
6 changes: 3 additions & 3 deletions src/zmq/zmqnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ void CZMQNotificationInterface::NotifyInstantSendDoubleSpendAttempt(const CTrans
});
}

void CZMQNotificationInterface::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
void CZMQNotificationInterface::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay)
{
TryForEachAndRemoveFailed(notifiers, [&sig](CZMQAbstractNotifier* notifier) {
return notifier->NotifyRecoveredSig(sig);
TryForEachAndRemoveFailed(notifiers, [&sig, proactive_relay](CZMQAbstractNotifier* notifier) {
return notifier->NotifyRecoveredSig(sig, proactive_relay);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/zmq/zmqnotificationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CZMQNotificationInterface final : public CValidationInterface
void NotifyGovernanceVote(const std::shared_ptr<CDeterministicMNList>& tip_mn_list, const std::shared_ptr<const CGovernanceVote>& vote) override;
void NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) override;
void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx) override;
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig) override;
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay) override;

private:
CZMQNotificationInterface();
Expand Down
4 changes: 2 additions & 2 deletions src/zmq/zmqpublishnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ bool CZMQPublishHashInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpend
&& SendZmqMessage(MSG_HASHISCON, dataPreviousHash, 32);
}

bool CZMQPublishHashRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig)
bool CZMQPublishHashRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig, bool proactive_relay)
{
LogPrint(BCLog::ZMQ, "Publish hashrecoveredsig %s to %s\n", sig->getMsgHash().ToString(), this->address);
char data[32];
Expand Down Expand Up @@ -462,7 +462,7 @@ bool CZMQPublishRawInstantSendDoubleSpendNotifier::NotifyInstantSendDoubleSpendA
&& SendZmqMessage(MSG_RAWISCON, &(*ssPrevious.begin()), ssPrevious.size());
}

bool CZMQPublishRawRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig)
bool CZMQPublishRawRecoveredSigNotifier::NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig, bool proactive_relay)
{
LogPrint(BCLog::ZMQ, "Publish rawrecoveredsig %s to %s\n", sig->getMsgHash().ToString(), this->address);

Expand Down
4 changes: 2 additions & 2 deletions src/zmq/zmqpublishnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CZMQPublishHashInstantSendDoubleSpendNotifier : public CZMQAbstractPublish
class CZMQPublishHashRecoveredSigNotifier : public CZMQAbstractPublishNotifier
{
public:
bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>&) override;
bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>&, bool proactive_relay) override;
};

class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
Expand Down Expand Up @@ -150,6 +150,6 @@ class CZMQPublishRawInstantSendDoubleSpendNotifier : public CZMQAbstractPublishN
class CZMQPublishRawRecoveredSigNotifier : public CZMQAbstractPublishNotifier
{
public:
bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig) override;
bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig, bool proactive_relay) override;
};
#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H
Loading