Skip to content

Commit

Permalink
Added 200_60 and 200_85 quorums with extended phases (Raptor3um#374)
Browse files Browse the repository at this point in the history
* Added 200_60 and 200_85 quorums with extended phases and Update vote for testnet.

* Updated quorum recovery for new quorums.

* Corrected height for LLMQ update
  • Loading branch information
CodeIsTheKey authored May 14, 2024
1 parent 0f25fe0 commit b8c6bbf
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 41 deletions.
58 changes: 36 additions & 22 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,32 @@ class CTestNetParams : public CChainParams {
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.nFutureForkBlock = 1000;

updateManager.Add
(
Update(EUpdate::DEPLOYMENT_V17, std::string("v17"), 0, 1440, 25920, 7, 365, 7, false,
VoteThreshold(95, 85, 5), VoteThreshold(0, 0, 1))
);
updateManager.Add
(
Update(EUpdate::ROUND_VOTING, std::string("Round Voting"),
1, //bit
1440, //roundSize
27360, // startHeight
7, //votingPeriod
365, //votingMaxRounds
7, // gracePeriod
false, // forceUpdate
VoteThreshold(85, 85, 1), //minerThreshold
VoteThreshold(0, 0, 1)) //nodeThreshold
updateManager.Add(
Update(EUpdate::DEPLOYMENT_V17, std::string("v17"), 0, 1440, 25920, 7, 365, 7, false,
VoteThreshold(95, 85, 5), VoteThreshold(0, 0, 1)));
updateManager.Add(
Update(EUpdate::ROUND_VOTING, std::string("Round Voting"),
1, // bit
1440, // roundSize
27360, // startHeight
7, // votingPeriod
365, // votingMaxRounds
7, // gracePeriod
false, // forceUpdate
VoteThreshold(85, 85, 1), // minerThreshold
VoteThreshold(0, 0, 1)) // nodeThreshold
);
updateManager.Add(
Update(EUpdate::QUORUMS_200_8, std::string("Quorums 200/8"),
2, // bit
1440, // roundSize
79200, // startHeight
3, // votingPeriod
365, // votingMaxRounds
2, // gracePeriod
false, // forceUpdate
VoteThreshold(85, 85, 1), // minerThreshold
VoteThreshold(85, 85, 1)) // nodeThreshold
);

// The best chain should have at least this much work.
Expand Down Expand Up @@ -996,8 +1005,8 @@ void SelectParams(const std::string &network) {
globalChainParams = CreateChainParams(network);
}

void UpdateLLMQParams(size_t totalMnCount, int height, bool lowLLMQParams) {
globalChainParams->UpdateLLMQParams(totalMnCount, height, lowLLMQParams);
void UpdateLLMQParams(size_t totalMnCount, int height, const CBlockIndex* blockIndex, bool lowLLMQParams) {
globalChainParams->UpdateLLMQParams(totalMnCount, height, blockIndex, lowLLMQParams);
}

bool IsMiningPhase(const Consensus::LLMQParams &params, int nHeight) {
Expand All @@ -1017,7 +1026,7 @@ bool IsLLMQsMiningPhase(int nHeight) {
return false;
}

void CChainParams::UpdateLLMQParams(size_t totalMnCount, int height, bool lowLLMQParams) {
void CChainParams::UpdateLLMQParams(size_t totalMnCount, int height, const CBlockIndex* blockIndex, bool lowLLMQParams) {
bool isNotLLMQsMiningPhase;
if (lastCheckHeight < height && (lastCheckMnCount != totalMnCount || lastCheckedLowLLMQParams != lowLLMQParams) &&
(isNotLLMQsMiningPhase = !IsLLMQsMiningPhase(height))) {
Expand Down Expand Up @@ -1047,8 +1056,13 @@ void CChainParams::UpdateLLMQParams(size_t totalMnCount, int height, bool lowLLM
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq40_85;
} else {
consensus.llmqs[Consensus::LLMQ_50_60] = Consensus::llmq50_60;
consensus.llmqs[Consensus::LLMQ_400_60] = Consensus::llmq400_60;
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq400_85;
if (Updates().IsActive(EUpdate::QUORUMS_200_8, blockIndex)) {
consensus.llmqs[Consensus::LLMQ_400_60] = Consensus::llmq200_60;
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq200_85;
} else {
consensus.llmqs[Consensus::LLMQ_400_60] = Consensus::llmq400_60;
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq400_85;
}
}
if (lowLLMQParams) {
consensus.llmqs[Consensus::LLMQ_50_60] = Consensus::llmq200_2;
Expand Down
4 changes: 2 additions & 2 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class CChainParams {

void UpdateLLMQInstantSend(Consensus::LLMQType llmqType);

void UpdateLLMQParams(size_t totalMnCount, int height, bool lowLLMQParams = false);
void UpdateLLMQParams(size_t totalMnCount, int height, const CBlockIndex* blockIndex, bool lowLLMQParams = false);

int PoolMinParticipants() const { return nPoolMinParticipants; }

Expand Down Expand Up @@ -213,6 +213,6 @@ UpdateManager& Updates();
*/
void SelectParams(const std::string &chain);

void UpdateLLMQParams(size_t totalMnCount, int height, bool lowLLMQParams = false);
void UpdateLLMQParams(size_t totalMnCount, int height, const CBlockIndex* blockIndex, bool lowLLMQParams = false);

#endif // BITCOIN_CHAINPARAMS_H
7 changes: 2 additions & 5 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock &block, const C
uint32_t quorumHeight = qc.nHeight - (qc.nHeight % llmq_params.dkgInterval);
auto pQuorumBaseBlockIndex = pindexPrev->GetAncestor(quorumHeight);
if (!pQuorumBaseBlockIndex || pQuorumBaseBlockIndex->GetBlockHash() != qc.commitment.quorumHash) {
// we should actually never get into this case as validation should have catched it...but lets be sure
// we should actually never get into this case as validation should have caught it...but lets be sure
return _state.DoS(100, false, REJECT_INVALID, "bad-qc-quorum-hash");
}

Expand Down Expand Up @@ -930,7 +930,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock &block, const C
}

mnListRet = std::move(newList);
UpdateLLMQParams(mnListRet.GetAllMNsCount(), nHeight, sporkManager.IsSporkActive(SPORK_21_LOW_LLMQ_PARAMS));
UpdateLLMQParams(mnListRet.GetAllMNsCount(), nHeight, pindexPrev, sporkManager.IsSporkActive(SPORK_21_LOW_LLMQ_PARAMS));
return true;
}

Expand Down Expand Up @@ -1039,9 +1039,6 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const CBlockIndex
}
}
}
// is this needed?
UpdateLLMQParams(snapshot.GetAllMNsCount(), snapshot.GetHeight(),
sporkManager.IsSporkActive(SPORK_21_LOW_LLMQ_PARAMS));
return snapshot;
}

Expand Down
42 changes: 42 additions & 0 deletions src/llmq/quorums_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,48 @@ namespace Consensus {
.recoveryMembers = 100,
};

static constexpr LLMQParams
llmq200_60 = {
.type = LLMQ_400_60,
.name = "llmq_200_60",
.size = 200,
.minSize = 150,
.threshold = 120,

.dkgInterval = 30 * 12, // one DKG every 12 hours
.dkgPhaseBlocks = 8,
.dkgMiningWindowStart = 40, // dkgPhaseBlocks * 5 = after finalization
.dkgMiningWindowEnd = 56,
.dkgBadVotesThreshold = 150,

.signingActiveQuorumCount = 4, // two days worth of LLMQs

.keepOldConnections = 5,
.recoveryMembers = 50,
};


// Used for deployment and min-proto-version signalling, so it needs a higher threshold
static constexpr LLMQParams
llmq200_85 = {
.type = LLMQ_400_85,
.name = "llmq_200_85",
.size = 200,
.minSize = 175,
.threshold = 170,

.dkgInterval = 30 * 24, // one DKG every 24 hours
.dkgPhaseBlocks = 8,
.dkgMiningWindowStart = 40, // dkgPhaseBlocks * 5 = after finalization
.dkgMiningWindowEnd = 56, // give it a larger mining window to make sure it is mined
.dkgBadVotesThreshold = 150,

.signingActiveQuorumCount = 4, // four days worth of LLMQs

.keepOldConnections = 5,
.recoveryMembers = 50,
};

// this one is for testing only
static constexpr LLMQParams
llmq_test_v17 = {
Expand Down
22 changes: 10 additions & 12 deletions src/update/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ VoteResult MinerRoundVoting::GetVote(const CBlockIndex *blockIndex, const Update

// assert(height % update.RoundSize == 0);
if (blockIndex->nHeight % update.RoundSize() != 0) {
LogPrint(BCLog::UPDATES, "Updates: MinerRoundVoting::GetVote, Height: %7d, Partial rounds not accepted\n",
blockIndex->nHeight);
LogPrint(BCLog::UPDATES, "Updates: Update: %s, MinerRoundVoting::GetVote, Height: %7d, Partial rounds not accepted\n",
update.Name().c_str(), blockIndex->nHeight);
return VoteResult(0, update.RoundSize()); // Assume everyone voted no
}

Expand Down Expand Up @@ -113,8 +113,8 @@ VoteResult MinerRoundVoting::GetVote(const CBlockIndex *blockIndex, const Update
}
}
VoteResult vote(yesCount, update.RoundSize());
LogPrint(BCLog::UPDATES, "Updates: MinerRoundVoting::GetVote, Height: %7d, %s\n", blockIndex->nHeight,
vote.ToString().c_str());
LogPrint(BCLog::UPDATES, "Updates: Update: %s, MinerRoundVoting::GetVote, Height: %7d, %s\n", blockIndex->nHeight,
update.Name().c_str(), vote.ToString().c_str());
cache[{update.UpdateId(), blockIndex}] = vote;
return vote;
}
Expand All @@ -124,14 +124,14 @@ VoteResult NodeRoundVoting::GetVote(const CBlockIndex *blockIndex, const Update

// assert(height % update.RoundSize == 0);
if (blockIndex->nHeight % update.RoundSize() != 0) {
LogPrint(BCLog::UPDATES, "Updates: NodeRoundVoting::GetVote, Height: %7d, Partial rounds not accepted\n",
blockIndex->nHeight);
LogPrint(BCLog::UPDATES, "Updates: Update: %s, NodeRoundVoting::GetVote, Height: %7d, Partial rounds not accepted\n",
update.Name().c_str(), blockIndex->nHeight);
return VoteResult();
}

if (blockIndex->nHeight < update.StartHeight() + update.RoundSize()) {
LogPrint(BCLog::UPDATES, "Updates: NodeRoundVoting::GetVote, Height: %7d, NodeRoundVoting - Before start\n",
blockIndex->nHeight);
LogPrint(BCLog::UPDATES, "Updates: Update: %s, NodeRoundVoting::GetVote, Height: %7d, NodeRoundVoting - Before start\n",
update.Name().c_str(), blockIndex->nHeight);
return VoteResult();
}

Expand Down Expand Up @@ -205,8 +205,7 @@ VoteResult NodeRoundVoting::GetVote(const CBlockIndex *blockIndex, const Update
VoteResult MinerUpdateVoting::GetVote(const CBlockIndex *blockIndex, const Update &update) {
// assert(height % update.roundSize == 0);
if (blockIndex->nHeight < update.StartHeight() + update.RoundSize() * update.VotingPeriod()) {
return VoteResult(0,
update.RoundSize() * update.VotingPeriod()); // Assume everyone voted no for the entire period
return VoteResult(0, update.RoundSize() * update.VotingPeriod()); // Assume everyone voted no for the entire period
}

// Simply collect all of the round votes for a full average in the voting period:
Expand All @@ -228,8 +227,7 @@ VoteResult MinerUpdateVoting::GetVote(const CBlockIndex *blockIndex, const Updat
VoteResult NodeUpdateVoting::GetVote(const CBlockIndex *blockIndex, const Update &update) {
// assert(height % update.roundSize == 0);
if (blockIndex->nHeight < update.StartHeight() + update.RoundSize() * update.VotingPeriod()) {
return VoteResult(0,
update.RoundSize() * update.VotingPeriod()); // Assume everyone voted no for the entire period
return VoteResult(0, update.RoundSize() * update.VotingPeriod()); // Assume everyone voted no for the entire period
}

// Simply collect all of the round votes for a full average in the voting period:
Expand Down
1 change: 1 addition & 0 deletions src/update/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
enum class EUpdate {
DEPLOYMENT_V17 = 0,
ROUND_VOTING = 1,
QUORUMS_200_8 = 2,

MAX_VERSION_BITS_DEPLOYMENTS
};
Expand Down

0 comments on commit b8c6bbf

Please sign in to comment.