From e7e48329f786aaf7333642f77b0daac418032a3e Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 13 Jan 2023 00:51:14 +0200 Subject: [PATCH] fix: Merklerootmnlist calc bls scheme (#5157) ## Issue being fixed or feature implemented Code was still using legacy scheme for `pubKeyOperator` of each `CSimplifiedMNListEntry` while calculating `MerklerootMNList` while v19 HF was active. ## What was done? When building `CSimplifiedMNList` for `MerklerootMNList`, this PR adds the correct set of `nVersion` for `CSimplifiedMNListEntry` so that basic scheme will be used instead of legacy. Furthermore, DIP3 unit tests suites for v19 will test for 1000 blocks instead of 900 to cover v19 activated period. ## How Has This Been Tested? ## Breaking Changes ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation **For repository code-owners and collaborators only** - [x] I have assigned this pull request to a milestone --- src/evo/cbtx.cpp | 3 ++- src/evo/simplifiedmns.cpp | 8 +++++--- src/evo/simplifiedmns.h | 5 +++-- src/test/util/setup_common.h | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 76519f4b73066..bea646f79b774 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -121,7 +121,8 @@ bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev int64_t nTime2 = GetTimeMicros(); nTimeDMN += nTime2 - nTime1; LogPrint(BCLog::BENCHMARK, " - BuildNewListFromBlock: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeDMN * 0.000001); - CSimplifiedMNList sml(tmpMNList); + bool v19active = llmq::utils::IsV19Active(pindexPrev); + CSimplifiedMNList sml(tmpMNList, v19active); int64_t nTime3 = GetTimeMicros(); nTimeSMNL += nTime3 - nTime2; LogPrint(BCLog::BENCHMARK, " - CSimplifiedMNList: %.2fms [%.2fs]\n", 0.001 * (nTime3 - nTime2), nTimeSMNL * 0.000001); diff --git a/src/evo/simplifiedmns.cpp b/src/evo/simplifiedmns.cpp index aae97fcf951e7..75be5354a2494 100644 --- a/src/evo/simplifiedmns.cpp +++ b/src/evo/simplifiedmns.cpp @@ -92,13 +92,15 @@ CSimplifiedMNList::CSimplifiedMNList(const std::vector& }); } -CSimplifiedMNList::CSimplifiedMNList(const CDeterministicMNList& dmnList) +CSimplifiedMNList::CSimplifiedMNList(const CDeterministicMNList& dmnList, bool isV19Active) { mnList.resize(dmnList.GetAllMNsCount()); size_t i = 0; - dmnList.ForEachMN(false, [this, &i](auto& dmn) { - mnList[i++] = std::make_unique(dmn); + dmnList.ForEachMN(false, [this, &i, isV19Active](auto& dmn) { + auto sme = std::make_unique(dmn); + sme->nVersion = isV19Active ? CSimplifiedMNListEntry::BASIC_BLS_VERSION : CSimplifiedMNListEntry::LEGACY_BLS_VERSION; + mnList[i++] = std::move(sme); }); std::sort(mnList.begin(), mnList.end(), [&](const std::unique_ptr& a, const std::unique_ptr& b) { diff --git a/src/evo/simplifiedmns.h b/src/evo/simplifiedmns.h index e90babe657fb2..95cb4aa3df8db 100644 --- a/src/evo/simplifiedmns.h +++ b/src/evo/simplifiedmns.h @@ -46,7 +46,8 @@ class CSimplifiedMNListEntry service == rhs.service && pubKeyOperator == rhs.pubKeyOperator && keyIDVoting == rhs.keyIDVoting && - isValid == rhs.isValid; + isValid == rhs.isValid && + nVersion == rhs.nVersion; } bool operator!=(const CSimplifiedMNListEntry& rhs) const @@ -79,7 +80,7 @@ class CSimplifiedMNList CSimplifiedMNList() = default; explicit CSimplifiedMNList(const std::vector& smlEntries); - explicit CSimplifiedMNList(const CDeterministicMNList& dmnList); + explicit CSimplifiedMNList(const CDeterministicMNList& dmnList, bool isV19Active); uint256 CalcMerkleRoot(bool* pmutated = nullptr) const; bool operator==(const CSimplifiedMNList& rhs) const; diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 551e66caae00f..72f1572a7ba3b 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -147,7 +147,7 @@ struct TestChainDIP3Setup : public TestChainSetup struct TestChainDIP3V19Setup : public TestChainSetup { - TestChainDIP3V19Setup() : TestChainSetup(900) {} + TestChainDIP3V19Setup() : TestChainSetup(1000) {} }; struct TestChainDIP3BeforeActivationSetup : public TestChainSetup