Skip to content

Commit

Permalink
Change CSigSharesInv and CBatchedSigShares to be sessionId based
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Feb 27, 2019
1 parent 2249413 commit 80375a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
29 changes: 12 additions & 17 deletions src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ void CSigShare::UpdateKey()

void CSigSharesInv::Merge(const CSigSharesInv& inv2)
{
assert(llmqType == inv2.llmqType);
assert(signHash == inv2.signHash);
for (size_t i = 0; i < inv.size(); i++) {
if (inv2.inv[i]) {
inv[i] = inv2.inv[i];
Expand All @@ -44,7 +42,7 @@ size_t CSigSharesInv::CountSet() const

std::string CSigSharesInv::ToString() const
{
std::string str = strprintf("signHash=%s, inv=(", signHash.ToString());
std::string str = "(";
bool first = true;
for (size_t i = 0; i < inv.size(); i++) {
if (!inv[i]) {
Expand All @@ -61,11 +59,8 @@ std::string CSigSharesInv::ToString() const
return str;
}

void CSigSharesInv::Init(Consensus::LLMQType _llmqType, const uint256& _signHash)
void CSigSharesInv::Init(Consensus::LLMQType _llmqType)
{
llmqType = _llmqType;
signHash = _signHash;

size_t llmqSize = (size_t)(Params().GetConsensus().llmqs.at(_llmqType).size);
inv.resize(llmqSize, false);
}
Expand All @@ -82,6 +77,16 @@ void CSigSharesInv::Set(uint16_t quorumMember, bool v)
inv[quorumMember] = v;
}

CSigSharesInv CBatchedSigShares::ToInv(Consensus::LLMQType llmqType) const
{
CSigSharesInv inv;
inv.Init(llmqType);
for (size_t i = 0; i < sigShares.size(); i++) {
inv.inv[sigShares[i].first] = true;
}
return inv;
}

CSigSharesNodeState::Session& CSigSharesNodeState::GetOrCreateSession(Consensus::LLMQType llmqType, const uint256& signHash)
{
auto& s = sessions[signHash];
Expand Down Expand Up @@ -134,16 +139,6 @@ void CSigSharesNodeState::RemoveSession(const uint256& signHash)
pendingIncomingSigShares.EraseAllForSignHash(signHash);
}

CSigSharesInv CBatchedSigShares::ToInv() const
{
CSigSharesInv inv;
inv.Init((Consensus::LLMQType)llmqType, CLLMQUtils::BuildSignHash(*this));
for (size_t i = 0; i < sigShares.size(); i++) {
inv.inv[sigShares[i].first] = true;
}
return inv;
}

//////////////////////

CSigSharesManager::CSigSharesManager()
Expand Down
31 changes: 9 additions & 22 deletions src/llmq/quorums_signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class CSigShare
class CSigSharesInv
{
public:
uint8_t llmqType;
uint256 signHash;
uint32_t sessionId{(uint32_t)-1};
std::vector<bool> inv;

public:
Expand All @@ -69,20 +68,14 @@ class CSigSharesInv
template<typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(llmqType);

auto& consensus = Params().GetConsensus();
auto it = consensus.llmqs.find((Consensus::LLMQType)llmqType);
if (it == consensus.llmqs.end()) {
throw std::ios_base::failure("invalid llmqType");
}
const auto& params = it->second;
uint64_t invSize = inv.size();

READWRITE(signHash);
READWRITE(AUTOBITSET(inv, (size_t)params.size));
READWRITE(VARINT(sessionId));
READWRITE(COMPACTSIZE(invSize));
READWRITE(AUTOBITSET(inv, (size_t)invSize));
}

void Init(Consensus::LLMQType _llmqType, const uint256& _signHash);
void Init(Consensus::LLMQType _llmqType);
bool IsSet(uint16_t quorumMember) const;
void Set(uint16_t quorumMember, bool v);
void Merge(const CSigSharesInv& inv2);
Expand All @@ -95,10 +88,7 @@ class CSigSharesInv
class CBatchedSigShares
{
public:
uint8_t llmqType;
uint256 quorumHash;
uint256 id;
uint256 msgHash;
uint32_t sessionId{(uint32_t)-1};
std::vector<std::pair<uint16_t, CBLSLazySignature>> sigShares;

public:
Expand All @@ -107,10 +97,7 @@ class CBatchedSigShares
template<typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(llmqType);
READWRITE(quorumHash);
READWRITE(id);
READWRITE(msgHash);
READWRITE(VARINT(sessionId));
READWRITE(sigShares);
}

Expand All @@ -129,7 +116,7 @@ class CBatchedSigShares
return sigShare;
}

CSigSharesInv ToInv() const;
CSigSharesInv ToInv(Consensus::LLMQType llmqType) const;
};

template<typename T>
Expand Down

0 comments on commit 80375a0

Please sign in to comment.