Skip to content

Commit

Permalink
Review fixes (mostly if/else related but no change in logic)
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 22, 2019
1 parent c905f1f commit b0ad142
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/llmq/quorums_signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const CRecoveredS
if (ban) {
LOCK(cs_main);
Misbehaving(pfrom->id, 100);
return;
}
return;
}
Expand Down
84 changes: 41 additions & 43 deletions src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,29 +636,30 @@ void CSigSharesManager::TryRecoverSig(const CQuorumCPtr& quorum, const uint256&
if (!recoveredSig.Recover(sigSharesForRecovery, idsForRecovery)) {
LogPrintf("CSigSharesManager::%s -- failed to recover signature. id=%s, msgHash=%s, time=%d\n", __func__,
id.ToString(), msgHash.ToString(), t.count());
} else {
LogPrintf("CSigSharesManager::%s -- recovered signature. id=%s, msgHash=%s, time=%d\n", __func__,
id.ToString(), msgHash.ToString(), t.count());

CRecoveredSig rs;
rs.llmqType = quorum->params.type;
rs.quorumHash = quorum->quorumHash;
rs.id = id;
rs.msgHash = msgHash;
rs.sig = recoveredSig;
rs.UpdateHash();

auto signHash = CLLMQUtils::BuildSignHash(rs);
bool valid = rs.sig.VerifyInsecure(quorum->quorumPublicKey, signHash);
if (!valid) {
// this should really not happen as we have verified all signature shares before
LogPrintf("CSigSharesManager::%s -- own recovered signature is invalid. id=%s, msgHash=%s\n", __func__,
id.ToString(), msgHash.ToString());
return;
}
return;
}

quorumSigningManager->ProcessRecoveredSig(-1, rs, quorum, connman);
LogPrintf("CSigSharesManager::%s -- recovered signature. id=%s, msgHash=%s, time=%d\n", __func__,
id.ToString(), msgHash.ToString(), t.count());

CRecoveredSig rs;
rs.llmqType = quorum->params.type;
rs.quorumHash = quorum->quorumHash;
rs.id = id;
rs.msgHash = msgHash;
rs.sig = recoveredSig;
rs.UpdateHash();

auto signHash = CLLMQUtils::BuildSignHash(rs);
bool valid = rs.sig.VerifyInsecure(quorum->quorumPublicKey, signHash);
if (!valid) {
// this should really not happen as we have verified all signature shares before
LogPrintf("CSigSharesManager::%s -- own recovered signature is invalid. id=%s, msgHash=%s\n", __func__,
id.ToString(), msgHash.ToString());
return;
}

quorumSigningManager->ProcessRecoveredSig(-1, rs, quorum, connman);
}

// cs must be held
Expand Down Expand Up @@ -722,40 +723,37 @@ void CSigSharesManager::CollectSigSharesToRequest(std::map<NodeId, std::map<uint
// too many pending requests for this node
break;
}
bool doRequest = false;
auto it = sigSharesRequested.find(k);
if (it != sigSharesRequested.end()) {
if (now - it->second.second >= SIG_SHARE_REQUEST_TIMEOUT && nodeId != it->second.first) {
// other node timed out, re-request from this node
LogPrint("llmq", "CSigSharesManager::%s -- other node timeout while waiting for %s-%d, re-request from=%d, node=%d\n", __func__,
it->first.first.ToString(), it->first.second, nodeId, it->second.first);
doRequest = true;
} else {
continue;
}
} else {
doRequest = true;
}
// if we got this far we should do a request

if (doRequest) {
// track when we initiated the request so that we can detect timeouts
nodeState.requestedSigShares.emplace(k, now);

// don't request it from other nodes until a timeout happens
auto& r = sigSharesRequested[k];
r.first = nodeId;
r.second = now;
// track when we initiated the request so that we can detect timeouts
nodeState.requestedSigShares.emplace(k, now);

if (!invMap) {
invMap = &sigSharesToRequest[nodeId];
}
auto& inv = (*invMap)[signHash];
if (inv.inv.empty()) {
inv.Init((Consensus::LLMQType)session.announced.llmqType, signHash);
}
inv.inv[k.second] = true;
// don't request it from other nodes until a timeout happens
auto& r = sigSharesRequested[k];
r.first = nodeId;
r.second = now;

// dont't request it again from this node
session.announced.inv[i] = false;
if (!invMap) {
invMap = &sigSharesToRequest[nodeId];
}
auto& inv = (*invMap)[signHash];
if (inv.inv.empty()) {
inv.Init((Consensus::LLMQType)session.announced.llmqType, signHash);
}
inv.inv[k.second] = true;

// dont't request it again from this node
session.announced.inv[i] = false;
}
}
}
Expand Down

0 comments on commit b0ad142

Please sign in to comment.