Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Serialization framework updates #2412

Merged
merged 40 commits into from
Jul 5, 2021

Conversation

furszy
Copy link

@furszy furszy commented Jun 8, 2021

@furszy furszy self-assigned this Jun 8, 2021
@furszy furszy added this to the 6.0.0 milestone Jun 8, 2021
@furszy furszy added the Upstream label Jun 8, 2021
@furszy furszy force-pushed the 2021_serialization_updates branch from 475c54d to adba8de Compare June 9, 2021 20:25
@furszy
Copy link
Author

furszy commented Jun 9, 2021

rebased on master, ready to go.

@random-zebra
Copy link

random-zebra commented Jun 18, 2021

This is a great job, really loved it.
Although I think that 068facd contains an error, which causes the warning for which f767d26 was introduced (which, in turn, fyi, results in a bunch of -Wunknown-pragmas warnings on GCC).

The issue here is a mis-use of SER_READ.
This macro is not meant to be used to actually read a value from the stream and save it to the variable passed as argument (like READWRITE). The second argument to SER_READ is a function, to be applied bypassing the const-ness of the object inside SERIALIZE_METHODS.

So, for example, we have something like:

std::vector<unsigned char> bytes;
READWRITE(bytes);
SER_READ(obj, obj.vBits = BytesToBits(bytes));

where, when ser_action.ForRead, READWRITE stores the vector contents inside the bytes local variable, and then SER_READ is used to update the object's member vBits.

When, instead, we do things like:

SER_READ(obj, nMoneySupply);

we are essentially passing this lambda to ::SerRead

[&](Stream& s, typename std::remove_const<Type>::type& obj) { nMoneySupply; }

which is a statement that has no effect on obj.
This is what the -Wunused-value is warning about (not because those variables are dummy containers inside SERIALIZE_METHODS).

And IMO this actually signals an error: as we are not reading anything with those SER_READ calls, we are not skipping the dummy fields, and so the serialization will fail with old DB versions.

random-zebra@3e20242

@furszy
Copy link
Author

furszy commented Jun 18, 2021

yeah great, nice catch ☕ . Updating.

@furszy furszy force-pushed the 2021_serialization_updates branch from adba8de to 4f80853 Compare June 18, 2021 15:29
@furszy
Copy link
Author

furszy commented Jun 18, 2021

Updated per feedback, cherry-picked your commit zebra and removed the warning suppress.

@furszy furszy force-pushed the 2021_serialization_updates branch from 4f80853 to 6cfd257 Compare June 19, 2021 15:06
@furszy
Copy link
Author

furszy commented Jun 19, 2021

Rebased on master, migrating the recently merged ProUpServPL class to the new serialization form. Preventing a post-merge "fix missing" PR.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a change in the serialization of CBudgetVote, which makes it impossible to sync proposal votes from nodes that are not running this PR.

src/budget/budgetvote.h Outdated Show resolved Hide resolved
@furszy furszy force-pushed the 2021_serialization_updates branch from 6cfd257 to d361548 Compare June 26, 2021 13:07
@furszy
Copy link
Author

furszy commented Jun 26, 2021

Updated per feedback, squashed change in 8a12b0c.
Fast diff check with git range-diff master 6cfd257 d361548.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK d361548

Will run it live for some time.

sipa and others added 9 commits July 3, 2021 09:02
Based on btc@da74db0940720407fafaf3582bbaf9c81a4d3b4d
Now that `GetType()` is not propagated, the benefits are not worth the code.
This new approach uses a static method which takes the object as
a argument. This has the advantage that its constness can be a
template parameter, allowing a single implementation that sees the
object as const for serialization and non-const for deserialization,
without casts.

More boilerplate is included in the new macro as well.
… other classes

This adds the (internal) Wrapper class, and the Using function that uses it. Given
a class F that implements Ser(stream, const object&) and Unser(stream, object&)
functions, this permits writing e.g. READWRITE(Using<F>(object)).
sipa and others added 22 commits July 3, 2021 09:02
This removes the need for the GNU C++ extension of variadic macros.
Extracted by Pieter Wuille from a comment by Russ Yanofsky, see
bitcoin#18317 (comment).
Extracted and extended by Pieter Wuille from a comment by Russ
Yanofsky (see
bitcoin#18317 (comment)).
…ions that doesn't require an special treatment.
Adaptation of btc@ef17c03e074b6c3f185afa4eff572ba687c2a171
@furszy furszy force-pushed the 2021_serialization_updates branch from d361548 to bd4b846 Compare July 3, 2021 12:04
@furszy
Copy link
Author

furszy commented Jul 3, 2021

Rebased on master, no code changes. So this branch does not reject blocks v10 on mainnet due the recently merged #2434 for v5.2 (requirement signaled by zebra that has been testing it ☕ ☕).

Can easily verify that nothing has changed with git range-diff master d361548 bd4b846d

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bd4b846

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bd4b846

perpetual updating PIVX Core to BTC Core automation moved this from In Progress to Ready Jul 5, 2021
@furszy furszy merged commit 5c93f15 into PIVX-Project:master Jul 5, 2021
perpetual updating PIVX Core to BTC Core automation moved this from Ready to Done Jul 5, 2021
@furszy furszy deleted the 2021_serialization_updates branch November 29, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

7 participants