Skip to content

Commit

Permalink
fix: non-aligned BLS serialization within MNLISTDIFF (#5151)
Browse files Browse the repository at this point in the history
## Issue being fixed or feature implemented
When constructing `CSimplifiedMNListDiff`,
`CSimplifiedMNListDiff::nVersion` is set to 2 if the v19 fork is active.
It turns out that `CSimplifiedMNListEntry::nVersion` wasn't set to 2 as
well as it was supposed.

Because we used `emplace_back` when filling the list of
`CSimplifiedMNListEntry`, this actually constructed the object with the
default value of 1 instead of copying it.

Surprising but I managed to see that while debugging.

## What was done?

## 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
- [ ] 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

Co-authored-by: pasta <[email protected]>
  • Loading branch information
ogabrielides and PastaPastaPasta committed Jan 10, 2023
1 parent 30fa322 commit 4927135
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,24 +356,24 @@ CSimplifiedMNListDiff CDeterministicMNList::BuildSimplifiedDiff(const CDetermini
diffRet.blockHash = to.blockHash;
diffRet.nVersion = llmq::utils::IsV19Active(::ChainActive().Tip()) ? CSimplifiedMNListDiff::BASIC_BLS_VERSION : CSimplifiedMNListDiff::LEGACY_BLS_VERSION;

to.ForEachMN(false, [&](auto& toPtr) {
to.ForEachMN(false, [&](const auto& toPtr) {
auto fromPtr = GetMN(toPtr.proTxHash);
if (fromPtr == nullptr) {
CSimplifiedMNListEntry sme(toPtr);
sme.nVersion = diffRet.nVersion;
diffRet.mnList.emplace_back(toPtr);
diffRet.mnList.push_back(std::move(sme));
} else {
CSimplifiedMNListEntry sme1(toPtr);
CSimplifiedMNListEntry sme2(*fromPtr);
sme1.nVersion = diffRet.nVersion;
sme2.nVersion = diffRet.nVersion;
if (sme1 != sme2) {
diffRet.mnList.emplace_back(toPtr);
} else if (extended && (sme1.scriptPayout != sme2.scriptPayout || sme1.scriptOperatorPayout != sme2.scriptOperatorPayout)) {
diffRet.mnList.emplace_back(toPtr);
if ((sme1 != sme2) ||
(extended && (sme1.scriptPayout != sme2.scriptPayout || sme1.scriptOperatorPayout != sme2.scriptOperatorPayout))) {
diffRet.mnList.push_back(std::move(sme1));
}
}
});

ForEachMN(false, [&](auto& fromPtr) {
auto toPtr = to.GetMN(fromPtr.proTxHash);
if (toPtr == nullptr) {
Expand Down

0 comments on commit 4927135

Please sign in to comment.