Change CSigSharesInv and CBatchedSigShares to be sessionId based

This commit is contained in:
Alexander Block 2019-02-26 08:07:44 +01:00
parent 2249413a7c
commit 80375a0b4f
2 changed files with 21 additions and 39 deletions

View File

@ -28,8 +28,6 @@ void CSigShare::UpdateKey()
void CSigSharesInv::Merge(const CSigSharesInv& inv2) void CSigSharesInv::Merge(const CSigSharesInv& inv2)
{ {
assert(llmqType == inv2.llmqType);
assert(signHash == inv2.signHash);
for (size_t i = 0; i < inv.size(); i++) { for (size_t i = 0; i < inv.size(); i++) {
if (inv2.inv[i]) { if (inv2.inv[i]) {
inv[i] = inv2.inv[i]; inv[i] = inv2.inv[i];
@ -44,7 +42,7 @@ size_t CSigSharesInv::CountSet() const
std::string CSigSharesInv::ToString() const std::string CSigSharesInv::ToString() const
{ {
std::string str = strprintf("signHash=%s, inv=(", signHash.ToString()); std::string str = "(";
bool first = true; bool first = true;
for (size_t i = 0; i < inv.size(); i++) { for (size_t i = 0; i < inv.size(); i++) {
if (!inv[i]) { if (!inv[i]) {
@ -61,11 +59,8 @@ std::string CSigSharesInv::ToString() const
return str; 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); size_t llmqSize = (size_t)(Params().GetConsensus().llmqs.at(_llmqType).size);
inv.resize(llmqSize, false); inv.resize(llmqSize, false);
} }
@ -82,6 +77,16 @@ void CSigSharesInv::Set(uint16_t quorumMember, bool v)
inv[quorumMember] = 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) CSigSharesNodeState::Session& CSigSharesNodeState::GetOrCreateSession(Consensus::LLMQType llmqType, const uint256& signHash)
{ {
auto& s = sessions[signHash]; auto& s = sessions[signHash];
@ -134,16 +139,6 @@ void CSigSharesNodeState::RemoveSession(const uint256& signHash)
pendingIncomingSigShares.EraseAllForSignHash(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() CSigSharesManager::CSigSharesManager()

View File

@ -59,8 +59,7 @@ public:
class CSigSharesInv class CSigSharesInv
{ {
public: public:
uint8_t llmqType; uint32_t sessionId{(uint32_t)-1};
uint256 signHash;
std::vector<bool> inv; std::vector<bool> inv;
public: public:
@ -69,20 +68,14 @@ public:
template<typename Stream, typename Operation> template<typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) inline void SerializationOp(Stream& s, Operation ser_action)
{ {
READWRITE(llmqType); uint64_t invSize = inv.size();
auto& consensus = Params().GetConsensus(); READWRITE(VARINT(sessionId));
auto it = consensus.llmqs.find((Consensus::LLMQType)llmqType); READWRITE(COMPACTSIZE(invSize));
if (it == consensus.llmqs.end()) { READWRITE(AUTOBITSET(inv, (size_t)invSize));
throw std::ios_base::failure("invalid llmqType");
}
const auto& params = it->second;
READWRITE(signHash);
READWRITE(AUTOBITSET(inv, (size_t)params.size));
} }
void Init(Consensus::LLMQType _llmqType, const uint256& _signHash); void Init(Consensus::LLMQType _llmqType);
bool IsSet(uint16_t quorumMember) const; bool IsSet(uint16_t quorumMember) const;
void Set(uint16_t quorumMember, bool v); void Set(uint16_t quorumMember, bool v);
void Merge(const CSigSharesInv& inv2); void Merge(const CSigSharesInv& inv2);
@ -95,10 +88,7 @@ public:
class CBatchedSigShares class CBatchedSigShares
{ {
public: public:
uint8_t llmqType; uint32_t sessionId{(uint32_t)-1};
uint256 quorumHash;
uint256 id;
uint256 msgHash;
std::vector<std::pair<uint16_t, CBLSLazySignature>> sigShares; std::vector<std::pair<uint16_t, CBLSLazySignature>> sigShares;
public: public:
@ -107,10 +97,7 @@ public:
template<typename Stream, typename Operation> template<typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) inline void SerializationOp(Stream& s, Operation ser_action)
{ {
READWRITE(llmqType); READWRITE(VARINT(sessionId));
READWRITE(quorumHash);
READWRITE(id);
READWRITE(msgHash);
READWRITE(sigShares); READWRITE(sigShares);
} }
@ -129,7 +116,7 @@ public:
return sigShare; return sigShare;
} }
CSigSharesInv ToInv() const; CSigSharesInv ToInv(Consensus::LLMQType llmqType) const;
}; };
template<typename T> template<typename T>