Skip to content

Commit

Permalink
fix: Merklerootmnlist calc bls scheme (#5157)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
ogabrielides committed Jan 12, 2023
1 parent 26cc723 commit e7e4832
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/evo/cbtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/evo/simplifiedmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ CSimplifiedMNList::CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>&
});
}

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<CSimplifiedMNListEntry>(dmn);
dmnList.ForEachMN(false, [this, &i, isV19Active](auto& dmn) {
auto sme = std::make_unique<CSimplifiedMNListEntry>(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<CSimplifiedMNListEntry>& a, const std::unique_ptr<CSimplifiedMNListEntry>& b) {
Expand Down
5 changes: 3 additions & 2 deletions src/evo/simplifiedmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +80,7 @@ class CSimplifiedMNList

CSimplifiedMNList() = default;
explicit CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>& 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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct TestChainDIP3Setup : public TestChainSetup

struct TestChainDIP3V19Setup : public TestChainSetup
{
TestChainDIP3V19Setup() : TestChainSetup(900) {}
TestChainDIP3V19Setup() : TestChainSetup(1000) {}
};

struct TestChainDIP3BeforeActivationSetup : public TestChainSetup
Expand Down

0 comments on commit e7e4832

Please sign in to comment.