Skip to content

Commit

Permalink
Merge pull request #1 from nandofw/ft/round_voting
Browse files Browse the repository at this point in the history
fix gbt
  • Loading branch information
CodeIsTheKey authored Feb 29, 2024
2 parents 1983611 + 1268e8d commit 7eac731
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 192 deletions.
5 changes: 2 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,8 @@ AC_ARG_ENABLE([util-cli],

AC_ARG_ENABLE([util-tx],
[AS_HELP_STRING([--enable-util-tx],
[build raptoreum-tx])],
[build_bitcoin_tx=$enableval],
[build_bitcoin_tx=$build_bitcoin_utils])
[build raptoreum-tx (default=no)])],
[build_bitcoin_tx=$enableval])

AC_ARG_ENABLE([util-wallet],
[AS_HELP_STRING([--enable-util-wallet],
Expand Down
10 changes: 5 additions & 5 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ class CDevNetParams : public CChainParams {
(
Update(EUpdate::DEPLOYMENT_V17, std::string("v17"), 0, 10, 0, 10, 100, 10, false, VoteThreshold(95, 95, 5), VoteThreshold(0, 0, 1))
);
// UpdateManager::Instance().Add
// (
// Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 7, 100, 100000, 5, 10, 5, false, VoteThreshold(85, 85, 1), VoteThreshold(95, 95, 1))
// );

UpdateManager::Instance().Add
(
Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 1, 100, 2000, 5, 10, 5, false, VoteThreshold(85, 85, 1), VoteThreshold(0, 0, 1))
);
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000");

Expand Down
4 changes: 2 additions & 2 deletions src/llmq/quorums_commitment.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace llmq {
// This is mined on-chain as part of TRANSACTION_QUORUM_COMMITMENT
class CFinalCommitment {
public:
static const uint16_t CURRENT_VERSION = 1;
static const uint16_t CURRENT_VERSION = 2;

uint16_t nVersion{CURRENT_VERSION};
uint16_t nVersion{1};
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE};
uint256 quorumHash;
std::vector<bool> signers;
Expand Down
16 changes: 13 additions & 3 deletions src/llmq/quorums_dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ namespace llmq {
CDKGContribution qc;
if (UpdateManager::Instance().IsActive(EUpdate::ROUND_VOTING, m_quorum_base_block_index)) {
qc.nVersion = 1;
// TODO: JB Vote on active update proposals
// Vote on active update proposals
qc.nVersion = UpdateManager::Instance().ComputeBlockVersion(m_quorum_base_block_index);
}
qc.llmqType = params.type;
qc.quorumHash = m_quorum_base_block_index->GetBlockHash();
Expand Down Expand Up @@ -357,6 +358,7 @@ namespace llmq {
std::vector <size_t> memberIndexes;
std::vector <BLSVerificationVectorPtr> vvecs;
BLSSecretKeyVector skContributions;
std::vector <uint32_t> voteVersions;

for (const auto &idx: pend) {
const auto &m = members[idx];
Expand All @@ -366,6 +368,7 @@ namespace llmq {
memberIndexes.emplace_back(idx);
vvecs.emplace_back(receivedVvecs[idx]);
skContributions.emplace_back(receivedSkContributions[idx]);
voteVersions.emplace_back(receivedVersions[idx]);
// Write here to definitely store one contribution for each member no matter if
// our share is valid or not, could be that others are still correct
dkgManager.WriteEncryptedContributions(params.type, m_quorum_base_block_index, m->dmn->proTxHash,
Expand Down Expand Up @@ -393,6 +396,9 @@ namespace llmq {
size_t memberIdx = memberIndexes[i];
dkgManager.WriteVerifiedSkContribution(params.type, m_quorum_base_block_index,
members[memberIdx]->dmn->proTxHash, skContributions[i]);
//Write vote to disc
dkgManager.WriteUpdateVote(params.type, m_quorum_base_block_index,
members[memberIdx]->dmn->proTxHash, voteVersions[i]);
}
}

Expand Down Expand Up @@ -995,6 +1001,7 @@ namespace llmq {

uint256 commitmentHash;
if (UpdateManager::Instance().IsActive(EUpdate::ROUND_VOTING, m_quorum_base_block_index)) {
qc.roundVoting = true;
commitmentHash = CLLMQUtils::BuildCommitmentHash(qc.llmqType, qc.quorumHash, qc.validMembers, qc.quorumUpdateVotes, qc.quorumPublicKey, qc.quorumVvecHash);
}
else {
Expand All @@ -1005,8 +1012,7 @@ namespace llmq {
(*commitmentHash.begin())++;
}

qc.sig = WITH_LOCK(activeSmartnodeInfoCs,
return activeSmartnodeInfo.blsKeyOperator->Sign(commitmentHash));
qc.sig = WITH_LOCK(activeSmartnodeInfoCs, return activeSmartnodeInfo.blsKeyOperator->Sign(commitmentHash));
qc.quorumSig = skShare.Sign(commitmentHash);

if (lieType == 3) {
Expand Down Expand Up @@ -1244,6 +1250,10 @@ namespace llmq {
fqc.quorumVvecHash = first.quorumVvecHash;
fqc.quorumUpdateVotes = first.quorumUpdateVotes;

if (first.roundVoting) {
fqc.nVersion = 2;
}

uint256 commitmentHash;
if (UpdateManager::Instance().IsActive(EUpdate::ROUND_VOTING, m_quorum_base_block_index)) {
commitmentHash = CLLMQUtils::BuildCommitmentHash(fqc.llmqType, fqc.quorumHash, fqc.validMembers, fqc.quorumUpdateVotes, fqc.quorumPublicKey, fqc.quorumVvecHash);
Expand Down
52 changes: 42 additions & 10 deletions src/llmq/quorums_dkgsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ namespace llmq {
inline void SerializeWithoutSig(Stream &s) const {
if (nVersion != 0) {
s << (uint8_t)0; // Marker for new serialization (old serialization was not versioned)
s << llmqType;
s << nVersion;
} else {
s << llmqType;
}
s << llmqType;
s << quorumHash;
s << proTxHash;
s << *vvec;
Expand All @@ -67,8 +69,8 @@ namespace llmq {
s >> llmqType;
if (llmqType == Consensus::LLMQType::LLMQ_INVALID) {
// New version, deserialize the version, then the real llmqType
s >> nVersion;
s >> llmqType;
s >> nVersion;
}
s >> quorumHash;
s >> proTxHash;
Expand Down Expand Up @@ -168,17 +170,47 @@ namespace llmq {
return int(std::count(validMembers.begin(), validMembers.end(), true));
}

SERIALIZE_METHODS(CDKGPrematureCommitment, obj
)
{
READWRITE(obj.llmqType, obj.quorumHash, obj.proTxHash, DYNBITSET(obj.validMembers));
if (obj.roundVoting) {
READWRITE(obj.quorumUpdateVotes);
template<typename Stream>
inline void Serialize(Stream &s) const {
if (roundVoting) {
s << (uint8_t)0; // Marker for new serialization (old serialization was not versioned)
s << llmqType;
s << roundVoting;
s << quorumUpdateVotes;
} else {
s << llmqType;
}
READWRITE(obj.quorumPublicKey, obj.quorumVvecHash, obj.quorumSig, obj.sig);
s << quorumHash;
s << proTxHash;
s << DYNBITSET(validMembers);
s << quorumPublicKey;
s << quorumVvecHash;
s << quorumSig;
s << sig;
}


template<typename Stream>
inline void Unserialize(Stream &s) {
s >> llmqType;
if (llmqType == Consensus::LLMQType::LLMQ_INVALID) {
// New version, deserialize the version, then the real llmqType
s >> llmqType;
s >> roundVoting;
s >> quorumUpdateVotes;
}
s >> quorumHash;
s >> proTxHash;
s >> DYNBITSET(validMembers);
s >> quorumPublicKey;
s >> quorumVvecHash;
s >> quorumSig;
s >> sig;
}

[[nodiscard]] uint256 GetSignHash() const {
if (roundVoting) {
return CLLMQUtils::BuildCommitmentHash(llmqType, quorumHash, validMembers, quorumUpdateVotes, quorumPublicKey, quorumVvecHash);
}
return CLLMQUtils::BuildCommitmentHash(llmqType, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
}
};
Expand Down
Loading

0 comments on commit 7eac731

Please sign in to comment.