-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add parameter feature to serialization and use it for CAddress #19503
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
Concept ACK Getting rid of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. Can be rebased on master now that #19486 is merged to drop the first two commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, no idea why it is not compatible with the live network
8d1b1df474db73d3010324f728cb8b7851036b4f
Concept ACK as it will allow for a previously hacky solution to be neater. See #19477 for more details Perhaps a worthwhile followup: Completing the example documentations of our serialization "helpers" (seems like there's already a few examples, but not all of them are documented) |
Rebased after #19486 merge. Addressed comments. |
Looks like the fuzzers don't compile on some of the commits |
Concept ACK. |
9ee7bd0
to
f58fca6
Compare
@dongcarl Agree - I've added more comments to explain the feature for now, but a more comprehensive overview of all the things the serialization framework supports would be a nice further improvement. @MarcoFalke Hopefully fixed. I also added all variants of deserialization to the fuzzers. |
15ba614
to
3d3b095
Compare
Code coverage report for this PR from unit + functional tests (lines not modified by this PR are dimmed and files not modified by this PR are omitted from the report):
|
That line is pretty much a no-op and could be removed. It's ensuring that we never send more than 1000 CAddress records in a single ADDR message. However, the ADDR message is populated from vAddrToSend, which itself is limited to 1000 entries (see the PushAddress() function). So we could just remove that entire if block (and potentially replace it with an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concept ACK and code review ACK of the changes in protocol.h. The syntax/interface for WithParams()
and SERIALIZE_METHODS_PARAMS
seems reasonable, but I find it very difficult to understand the template code in serialize.h so I wasn't able to give it a thorough review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 483ed45
Thanks for adding input validation to the hex/dec examples in the unit tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 483ed45 code review over several sessions this week, verified the build at each commit, ran the 3 address deserialization fuzz tests as a sanity check. Thanks for the unit test coverage -- a good addition and demonstrates use of the feature. Edit: am running a node with this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 483ed45.
This seems all right, but I think it's significantly more complex than it needs to because it is making serialization with params something that can be done in conjunction with using a formatter, instead of just a special case of formatting. Simplification along lines of 106d803 branch) seems to work (only ran tests locally).
uint32_t data; | ||
bool ok; | ||
if (fmt == BaseFormat::DEC) { | ||
ok = ParseUint32(str, &data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "test: add tests that exercise WithParams()" (483ed45)
Think this needs to capitalize Int: ParseUInt32
@ryanofsky That approach works and is a lot simpler, but I think it misses the "automatic recursion" property I was hoping for, that you could e.g. serialize a CBlock with specified CTransaction parameters, and it would transparently pass those parameters down. Or a block could define its own type that can be converted to the CTransaction parameters type, but not need to anything beyond that. Whether that's a desirable depends how much you treat a higher-level structure as openly containing the lower-level structure, but I think in general most of our complex serializable data structures are like that. |
re-ACK 483ed45, though I did not review the serialize.h changes 🚤 Changes since last review:
Show signature and timestampSignature:
Timestamp of file with hash |
Note to myself, if this gets merged: It would be good to remove the now unused protocol version includes. I.e. commit 7ffff5b3237fa418637d30ddb59534ab47d3f610 (HEAD)
Author: MarcoFalke <falke.marco@gmail.com>
Date: Tue Aug 4 14:58:25 2020 +0200
Remove unused protocol version header from protocol.h
diff --git a/src/bench/rpc_blockchain.cpp b/src/bench/rpc_blockchain.cpp
index 4b45264a3c..09bfcb60a5 100644
--- a/src/bench/rpc_blockchain.cpp
+++ b/src/bench/rpc_blockchain.cpp
@@ -8,6 +8,7 @@
#include <rpc/blockchain.h>
#include <streams.h>
#include <validation.h>
+#include <version.h> // For PROTOCOL_VERSION
#include <univalue.h>
diff --git a/src/protocol.h b/src/protocol.h
index a564508f89..58669e20b5 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -14,7 +14,6 @@
#include <primitives/transaction.h>
#include <serialize.h>
#include <uint256.h>
-#include <version.h>
#include <stdint.h>
#include <string> and commit 4550d37e268e7ffe34b3f5ea11d6b3f231d9065a
Author: MarcoFalke <falke.marco@gmail.com>
Date: Tue Aug 4 12:56:55 2020 +0200
Remove unused protocol version header from undo.h
diff --git a/src/undo.h b/src/undo.h
index a98f046735..1fb9ac0688 100644
--- a/src/undo.h
+++ b/src/undo.h
@@ -11,7 +11,6 @@
#include <consensus/consensus.h>
#include <primitives/transaction.h>
#include <serialize.h>
-#include <version.h>
/** Formatter for undo information for a CTxIn
* |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs rebase (trivial)
{ | ||
SER_READ(obj, obj.nTime = TIME_INIT); | ||
int nVersion = s.GetVersion(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One include can now be removed, see #19503 (comment)
Needs rebase. |
This would resolve #19477. Also, |
Could also use |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
@sipa Let us know if someone should pick this up. I might take a stab at it. |
@MarcoFalke Not going to work on this for the time being. |
Removing up for grabs as this has mostly been picked up. i.e #25284. |
This introduces a concept of "serialization parameters". Every serializer can define its own parameter type, and a value of that type must be provided when serializing/deserializing, e.g. using
ss << WithParams(parameter, value)
, causingvalue
to be serialized toss
, with parameterparameter
. Note these parameters are automatically passed down the stack, so for example a vector can be serialized with a parameter, which will be available to all the elements' serializers.In this PR, the feature is only used for
CAddress
serialization, but I plan to also convertSERIALIZE_TRANSACTION_NO_WITNESS
in a follow-up. Eventually I hope to get rid of all GetVersion/GetType and replace it with this approach, which is type-safe (code won't compile if the correct parameter isn't passed somewhere), and avoids collisions between flags.