Skip to content

Commit

Permalink
Introduce QSIGSESANN/CSigSesAnn P2P message
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Feb 27, 2019
1 parent 80375a0 commit 55a6182
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ void CSigShare::UpdateKey()
key.second = quorumMember;
}

std::string CSigSesAnn::ToString() const
{
return strprintf("sessionId=%d, llmqType=%d, quorumHash=%s, id=%s, msgHash=%s",
sessionId, llmqType, quorumHash.ToString(), id.ToString(), msgHash.ToString());
}

void CSigSharesInv::Merge(const CSigSharesInv& inv2)
{
for (size_t i = 0; i < inv.size(); i++) {
Expand Down Expand Up @@ -196,7 +202,11 @@ void CSigSharesManager::ProcessMessage(CNode* pfrom, const std::string& strComma
return;
}

if (strCommand == NetMsgType::QSIGSHARESINV) {
if (strCommand == NetMsgType::QSIGSESANN) {
CSigSesAnn ann;
vRecv >> ann;
ProcessMessageSigSesAnn(pfrom, ann, connman);
} else if (strCommand == NetMsgType::QSIGSHARESINV) {
CSigSharesInv inv;
vRecv >> inv;
ProcessMessageSigSharesInv(pfrom, inv, connman);
Expand All @@ -211,6 +221,31 @@ void CSigSharesManager::ProcessMessage(CNode* pfrom, const std::string& strComma
}
}

void CSigSharesManager::ProcessMessageSigSesAnn(CNode* pfrom, const CSigSesAnn& ann, CConnman& connman)
{
auto llmqType = (Consensus::LLMQType)ann.llmqType;
if (!Params().GetConsensus().llmqs.count(llmqType)) {
BanNode(pfrom->id);
return;
}
if (ann.sessionId == (uint32_t)-1 || ann.quorumHash.IsNull() || ann.id.IsNull() || ann.msgHash.IsNull()) {
BanNode(pfrom->id);
return;
}

LogPrint("llmq", "CSigSharesManager::%s -- ann={%s}, node=%d\n", __func__, ann.ToString(), pfrom->id);

auto quorum = quorumManager->GetQuorum(llmqType, ann.quorumHash);
if (!quorum) {
// TODO should we ban here?
LogPrintf("CSigSharesManager::%s -- quorum %s not found, node=%d\n", __func__,
ann.quorumHash.ToString(), pfrom->id);
return;
}

auto signHash = CLLMQUtils::BuildSignHash(llmqType, ann.quorumHash, ann.id, ann.msgHash);
}

bool CSigSharesManager::VerifySigSharesInv(NodeId from, const CSigSharesInv& inv)
{
Consensus::LLMQType llmqType = (Consensus::LLMQType)inv.llmqType;
Expand Down
27 changes: 27 additions & 0 deletions src/llmq/quorums_signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ class CSigShare
}
};

// Nodes will first announce a signing session with a sessionId to be used in all future P2P messages related to that
// session. We locally keep track of the mapping for each node. We also assign new sessionIds for outgoing sessions
// and send QSIGSESANN messages appropriately. All values except the max value for uint32_t are valid as sessionId
class CSigSesAnn
{
public:
uint32_t sessionId{(uint32_t)-1};
uint8_t llmqType;
uint256 quorumHash;
uint256 id;
uint256 msgHash;

ADD_SERIALIZE_METHODS

template<typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(VARINT(sessionId));
READWRITE(llmqType);
READWRITE(quorumHash);
READWRITE(id);
READWRITE(msgHash);
}

std::string ToString() const;
};

class CSigSharesInv
{
public:
Expand Down Expand Up @@ -344,6 +370,7 @@ class CSigSharesManager : public CRecoveredSigsListener
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig);

private:
void ProcessMessageSigSesAnn(CNode* pfrom, const CSigSesAnn& ann, CConnman& connman);
void ProcessMessageSigSharesInv(CNode* pfrom, const CSigSharesInv& inv, CConnman& connman);
void ProcessMessageGetSigShares(CNode* pfrom, const CSigSharesInv& inv, CConnman& connman);
void ProcessMessageBatchedSigShares(CNode* pfrom, const CBatchedSigShares& batchedSigShares, CConnman& connman);
Expand Down
2 changes: 2 additions & 0 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const char *QJUSTIFICATION="qjustify";
const char *QPCOMMITMENT="qpcommit";
const char *QWATCH="qwatch";
const char *QDEBUGSTATUS="qdebugstatus";
const char *QSIGSESANN="qsigsesann";
const char *QSIGSHARESINV="qsigsinv";
const char *QGETSIGSHARES="qgetsigs";
const char *QBSIGSHARES="qbsigs";
Expand Down Expand Up @@ -165,6 +166,7 @@ const static std::string allNetMessageTypes[] = {
NetMsgType::QPCOMMITMENT,
NetMsgType::QWATCH,
NetMsgType::QDEBUGSTATUS,
NetMsgType::QSIGSESANN,
NetMsgType::QSIGSHARESINV,
NetMsgType::QGETSIGSHARES,
NetMsgType::QBSIGSHARES,
Expand Down
1 change: 1 addition & 0 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ extern const char *QJUSTIFICATION;
extern const char *QPCOMMITMENT;
extern const char *QWATCH;
extern const char *QDEBUGSTATUS;
extern const char *QSIGSESANN;
extern const char *QSIGSHARESINV;
extern const char *QGETSIGSHARES;
extern const char *QBSIGSHARES;
Expand Down

0 comments on commit 55a6182

Please sign in to comment.