Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Nov 23, 2023

Currently it is only possible to attach one serialization parameter to a stream at a time. For example, it is not possible to set a parameter controlling the transaction format and a parameter controlling the address format at the same time because one parameter will override the other.

This limitation is inconvenient for multiprocess code since it is not possible to create just one type of stream and serialize any object to it. Instead it is necessary to create different streams for different object types, which requires extra boilerplate and makes using the new parameter fields a lot more awkward than the older version and type fields.

Fix this problem by allowing an unlimited number of serialization stream parameters to be set, and allowing them to be requested by type. Later parameters will still override earlier parameters, but only if they have the same type.

For an example of different ways multiple parameters can be set, see the new with_params_multi unit test.

This change requires replacing the stream.GetParams() method with a stream.GetParams<T>() method in order for serialization code to retrieve the desired parameters. The change is more verbose, but probably a good thing for readability because previously it could be difficult to know what type the GetParams() method would return, and now it is more obvious.


This PR is part of the process separation project.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 23, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, TheCharlatan, sipa
Concept ACK dergoegge
Ignored review ajtowns

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29409 (multiprocess: Add capnp wrapper for Chain interface by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

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

Concept ACK

@dergoegge
Copy link
Member

Concept ACK

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 334f75a -> 97338ee (pr/iparams.1 -> pr/iparams.2, compare) adding comments and improving test

This commit makes a minimal change to the ParamsStream class to let it retrieve
multiple parameters. Followup commits after this commit clean up code using
ParamsStream and make it easier to set multiple parameters.

Currently it is only possible to attach one serialization parameter to a stream
at a time. For example, it is not possible to set a parameter controlling the
transaction format and a parameter controlling the address format at the same
time because one parameter will override the other.

This limitation is inconvenient for multiprocess code since it is not possible
to create just one type of stream and serialize any object to it. Instead it is
necessary to create different streams for different object types, which
requires extra boilerplate and makes using the new parameter fields a lot more
awkward than the older version and type fields.

Fix this problem by allowing an unlimited number of serialization stream
parameters to be set, and allowing them to be requested by type. Later
parameters will still override earlier parameters, but only if they have the
same type.

This change requires replacing the stream.GetParams() method with a
stream.GetParams<T>() method in order for serialization code to retrieve the
desired parameters. This change is more verbose, but probably a good thing for
readability because previously it could be difficult to know what type the
GetParams() method would return, and now it is more obvious.
@ryanofsky
Copy link
Contributor Author

Rebased 97338ee -> ffc1e9f (pr/iparams.2 -> pr/iparams.3, compare) due to minor conflict with #28451

@maflcko
Copy link
Member

maflcko commented Jan 12, 2024

test/serialize_tests.cpp:394:11: error: unused variable 'oi2' [-Werror,-Wunused-variable]
  394 |     Other oi2;
      |           ^~~

@ryanofsky
Copy link
Contributor Author

Updated ffc1e9f -> 3c31173 (pr/iparams.3 -> pr/iparams.4, compare) to fix unused variable in test https://cirrus-ci.com/task/4527517751574528?logs=ci#L2260

re: #28929 (comment)

test/serialize_tests.cpp:394:11: error: unused variable 'oi2' [-Werror,-Wunused-variable]

Fixed, thanks. Also renamed variables in the test to make it more readable

@maflcko
Copy link
Member

maflcko commented Feb 9, 2024

nit: retreive -> retrieve in the first commit msg

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

did not review the last commit 3c31173 🚔

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: did not review the last commit 3c311734d2fc6a4ca410f254ba3c8e923d58be70 🚔
HgBPRyZaqsA6IWO/nWpFwiv5/omKRQ3fZmFGkrNfInSb0WBx0SgqbIdQPEkb2NkO/KoxscmLPJRXjk2Ia3ixCA==

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 3c31173 -> e02ab15 (pr/iparams.4 -> pr/iparams.5, compare) using && and std::forward to support rvalue substream arguments and adding tests and documentation

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated e02ab15 -> 33d99ba (pr/iparams.5 -> pr/iparams.6, compare) adding a new commit simplifying usage of ParamsStream in net.cpp, and fixing inaccurate lifetimebound annotations

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

left some comments/nits. Feel free to ignore.

very nice. lgtm ACK 33d99ba 👆

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: very nice. lgtm ACK 33d99bad01 👆
vYXG8JolRRudeR/EvljO02nNhTpLVh7ae9EjSBP82mgGSRDkUFhYYlnx9S2EOpzD0z1dE4QHOEHx7YYNx8ksAQ==

@DrahtBot DrahtBot requested a review from dergoegge February 21, 2024 10:56
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 33d99ba -> 9dc839a (pr/iparams.6 -> pr/iparams.7, compare) applying various suggestions and splitting commits

@maflcko
Copy link
Member

maflcko commented Feb 21, 2024

ACK 9dc839a 📇

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 9dc839a7fd1c8c7648f9e0a025d5ebecee8d289a  📇
l7D2bi74heXcy2zawxMPGghg5EiPAxy6Xi+GITolujanITODEnXLVYYbrun8tyMXi780u9apadIJVoXtoXYaAQ==

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 9dc839a -> 40f5055 (pr/iparams.7 -> pr/iparams.8, compare) using concept to replace bool nested as suggested

@maflcko
Copy link
Member

maflcko commented Feb 21, 2024

ACK 40f5055 🎦

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 40f505583f4edeb2859aeb70da20c6374d331a4f  🎦
jZImqPjGUJwt/833rdSh2DiEjsg6nNxFTHOhUb3GhAl6bvntsIwjLrN4sAtM3nFCw97147fhRhcAtUoKEkNJDg==

@sipa
Copy link
Member

sipa commented Feb 21, 2024

utACK 40f5055

@sipa sipa closed this Feb 21, 2024
@sipa sipa reopened this Feb 21, 2024
@maflcko maflcko added this to the 28.0 milestone Feb 22, 2024
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 40f5055 -> 8d491ae (pr/iparams.8 -> pr/iparams.9, compare) just adding const as suggested

@maflcko
Copy link
Member

maflcko commented Feb 28, 2024

ACK 8d491ae 🔵

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 8d491ae9ecf1948ea29f67b50ca7259123f602aa 🔵
TqzZNNCRqUT9JcNGY4BCaauByEiHoCa8EyBV4AqQzgBWqs0t3pK98OnLYdtt+8vzsdHbkeivD4o29SOgxiVICA==

@ryanofsky
Copy link
Contributor Author

@theuni any chance you'd be interested in reviewing this? (There are 7 commits so this looks looks like a bigger change, but all the complexity is basically in the first commit, the other commits are small or obvious changes.)

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

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

Nice, reviewing this was fun.
ACK 8d491ae

@@ -1142,6 +1146,24 @@ class ParamsStream
return m_substream.template GetParams<P>();
}
}

//! Get reference to underlying stream.
auto& GetStream()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you going to be using this method for other purposes besides tests and as an internal getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28929 (comment)

Are you going to be using this method for other purposes besides tests and as an internal getter?

I could see some other uses. Initially this was just added for testing, but then marco pointed out it could be used as an internal getter in #28929 (comment) to avoid recursion in read, write, size, etc methods. The other case it might be useful is if you have have a custom stream type like a file or socket and want to call some method on that stream that ParamsStream() is not wrapping, without having to pass around separate pointers to both streams.

auto& GetStream()
{
if constexpr (ContainsStream<SubStream>) {
return m_substream.GetStream();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a comment: This does indeed not trigger clang-tidy's recursion check (I'm guessing because of the constexpr condition).

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Thanks for the review!

@@ -1142,6 +1146,24 @@ class ParamsStream
return m_substream.template GetParams<P>();
}
}

//! Get reference to underlying stream.
auto& GetStream()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28929 (comment)

Are you going to be using this method for other purposes besides tests and as an internal getter?

I could see some other uses. Initially this was just added for testing, but then marco pointed out it could be used as an internal getter in #28929 (comment) to avoid recursion in read, write, size, etc methods. The other case it might be useful is if you have have a custom stream type like a file or socket and want to call some method on that stream that ParamsStream() is not wrapping, without having to pass around separate pointers to both streams.

@ryanofsky
Copy link
Contributor Author

@sipa, could you re-ack? Only change since your last review was adding a missing const (compare)

@sipa
Copy link
Member

sipa commented May 15, 2024

utACK 8d491ae

@achow101 achow101 merged commit 71f0f22 into bitcoin:master May 15, 2024
@theuni
Copy link
Member

theuni commented May 16, 2024

@ryanofsky Sorry for not getting to this before merge. Will give it a look tomorrow.

@bitcoin bitcoin locked and limited conversation to collaborators May 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants