Skip to content

Commit

Permalink
Merge pull request #715 from charlesrocket/backports-wGPXUHk
Browse files Browse the repository at this point in the history
LLMQ backports
  • Loading branch information
charlesrocket committed Nov 6, 2020
2 parents d500bc9 + 009d8e8 commit d6a41d0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void CChainLocksHandler::ProcessMessage(CNode* pfrom, const std::string& strComm

void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLockSig& clsig, const uint256& hash)
{
{
if (from != -1) {
LOCK(cs_main);
EraseObjectRequest(from, CInv(MSG_CLSIG, hash));
}
Expand Down
9 changes: 8 additions & 1 deletion src/llmq/quorums_dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ bool CDKGSession::PreVerifyMessage(const uint256& hash, const CDKGContribution&

void CDKGSession::ReceiveMessage(const uint256& hash, const CDKGContribution& qc, bool& retBan)
{
LOCK(cs_pending);

CDKGLogger logger(*this, __func__);

retBan = false;
Expand Down Expand Up @@ -359,6 +361,8 @@ void CDKGSession::ReceiveMessage(const uint256& hash, const CDKGContribution& qc
// See CBLSWorker::VerifyContributionShares for more details.
void CDKGSession::VerifyPendingContributions()
{
AssertLockHeld(cs_pending);

CDKGLogger logger(*this, __func__);

cxxtimer::Timer t1(true);
Expand Down Expand Up @@ -412,7 +416,10 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
return;
}

VerifyPendingContributions();
{
LOCK(cs_pending);
VerifyPendingContributions();
}

CDKGLogger logger(*this, __func__);

Expand Down
1 change: 1 addition & 0 deletions src/llmq/quorums_dkgsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class CDKGSession
std::map<uint256, CDKGJustification> justifications;
std::map<uint256, CDKGPrematureCommitment> prematureCommitments;

mutable CCriticalSection cs_pending;
std::vector<size_t> pendingContributionVerifications;

// filled by ReceivePrematureCommitment and used by FinalizeCommitments
Expand Down
31 changes: 13 additions & 18 deletions src/llmq/quorums_dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,29 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, CDataStream& vRecv)
// this will also consume the data, even if we bail out early
auto pm = std::make_shared<CDataStream>(std::move(vRecv));

{
LOCK(cs);

if (messagesPerNode[from] >= maxMessagesPerNode) {
// TODO ban?
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
return;
}
messagesPerNode[from]++;
}

CHashWriter hw(SER_GETHASH, 0);
hw.write(pm->data(), pm->size());
uint256 hash = hw.GetHash();

LOCK2(cs_main, cs);
if (from != -1) {
LOCK(cs_main);
EraseObjectRequest(from, CInv(invType, hash));
}

LOCK(cs);

if (messagesPerNode[from] >= maxMessagesPerNode) {
// TODO ban?
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
return;
}
messagesPerNode[from]++;

if (!seenMessages.emplace(hash).second) {
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from);
return;
}

EraseObjectRequest(from, CInv(invType, hash));

pendingMessages.emplace_back(std::make_pair(from, std::move(pm)));
}

Expand Down Expand Up @@ -454,10 +453,6 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
const auto& msg = *p.second;

auto hash = ::SerializeHash(msg);
{
LOCK(cs_main);
EraseObjectRequest(p.first, CInv(MessageType, hash));
}

bool ban = false;
if (!session.PreVerifyMessage(hash, msg, ban)) {
Expand Down
14 changes: 7 additions & 7 deletions src/llmq/quorums_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,13 @@ void CInstantSendManager::ProcessMessage(CNode* pfrom, const std::string& strCom

void CInstantSendManager::ProcessMessageInstantSendLock(CNode* pfrom, const llmq::CInstantSendLock& islock, CConnman& connman)
{
auto hash = ::SerializeHash(islock);

{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_ISLOCK, hash));
}

bool ban = false;
if (!PreVerifyInstantSendLock(pfrom->GetId(), islock, ban)) {
if (ban) {
Expand All @@ -689,8 +696,6 @@ void CInstantSendManager::ProcessMessageInstantSendLock(CNode* pfrom, const llmq
return;
}

auto hash = ::SerializeHash(islock);

LOCK(cs);
if (db.GetInstantSendLockByHash(hash) != nullptr) {
return;
Expand Down Expand Up @@ -883,11 +888,6 @@ std::unordered_set<uint256> CInstantSendManager::ProcessPendingInstantSendLocks(

void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& hash, const CInstantSendLock& islock)
{
{
LOCK(cs_main);
EraseObjectRequest(from, CInv(MSG_ISLOCK, hash));
}

CTransactionRef tx;
uint256 hashBlock;
const CBlockIndex* pindexMined = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions src/llmq/quorums_signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ void CSigningManager::ProcessMessage(CNode* pfrom, const std::string& strCommand

void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const CRecoveredSig& recoveredSig, CConnman& connman)
{
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash()));
}

bool ban = false;
if (!PreVerifyRecoveredSig(pfrom->GetId(), recoveredSig, ban)) {
if (ban) {
Expand Down Expand Up @@ -682,11 +687,6 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re
{
auto llmqType = (Consensus::LLMQType)recoveredSig.llmqType;

{
LOCK(cs_main);
EraseObjectRequest(nodeId, CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash()));
}

if (db.HasRecoveredSigForHash(recoveredSig.GetHash())) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
CInv inv(nInvType, tx.GetHash());
pfrom->AddInventoryKnown(inv);

{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), inv);
}

// Process custom logic, no matter if tx will be accepted to mempool later or not
if (nInvType == MSG_DSTX) {
uint256 hashTx = tx.GetHash();
Expand Down Expand Up @@ -2786,8 +2791,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
bool fMissingInputs = false;
CValidationState state;

EraseObjectRequest(pfrom->GetId(), inv);

if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs /* pfMissingInputs */,
false /* bypass_limits */, 0 /* nAbsurdFee */)) {
// Process custom txes, this changes AlreadyHave to "true"
Expand Down

0 comments on commit d6a41d0

Please sign in to comment.