p2p: Implement encoding traits for AddrV2Payload#5762
Conversation
|
Andrew just wrote up a good summary of the |
8714b85 to
b49b9a7
Compare
|
Is this ready for review @rustaceanrob? |
|
I was deciding what to do about the service flag oddities, but I think this should actually be ready to go. In @luisschwab what service bits are used for Utreexo? |
| Encoder4::new( | ||
| ArrayEncoder::without_length_prefix(self.time.to_le_bytes()), | ||
| // Silent high-bits cutoff on 32-bit arch | ||
| CompactSizeEncoder::new(self.services.to_u64() as usize), |
There was a problem hiding this comment.
Can you provide maybe a better description of why 64 bits is needed for the services?
It's usually not preferable to use as to silently truncate bits. Ideally you want to use into(), and if that's not an option, consider an explicit saturate so there's less surprise. Although, I'm having trouble finding a good description of what the upper bits for the services portion of AddrV2 could be. It seems silly that this services field needs 64 bits, so I wonder why there is a need to declare that many different service possibilities..
Lastly, other crates in this workspace do a specific // cast OK comment, for example "cast ok, 64 fits into a u8".
There was a problem hiding this comment.
Can you provide maybe a better description of why 64 bits is needed for the services?
No, I don't know the history and the documentation states experimental bits only go to 1 << 31 so I am unsure why 64 bits was used.
It seems silly that this services field needs 64 bits
Yes it does.
// cast OK comment, for example
I will adopt that, thanks.
There was a problem hiding this comment.
Updated the commit message and in-line code comment
There was a problem hiding this comment.
thanks for posting the link to protocol.h, that makes more sense now, sort of. ha, "temporary experiments"..
Maybe it would be better though to just explicitly panic with some such message like "temporary service experiments can not be run on 32bit architectures". It's such a rare case though that I think this is unlikely to ever be encountered. Just that it's much better to avoid using as so people don't need to think too hard about what could happen.
41127aa to
1ce00fa
Compare
|
@rustaceanrob |
Interesting. How is this supposed to work on 32 bit machines, though?
Oh cool, Where? |
Not sure what you mean by this, but 32-bit machines can just use two 32-bit registers to represent an /// Flags to indicate which network services a node supports.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ServiceFlags(u64);
|
Oh, I hadn't looked at the changes here. Utreexo stuff will be fine on 32-bit once we move to the bits defined in BIP-0183. |
1ce00fa to
20b1e3f
Compare
|
Interestingly there are nodes advertising As acknowledged in that thread, these services are unassigned and are meaningless. I updated the first commit to panic if the services are greater than |
Thanks. I'm not sure if others have the same opinion, although I would prefer knowing something experimental I'm working on isn't supported by a panic instead of silently succeeding and passing a service as Sadly we still need the pesky |
|
Actually, I'm wondering now if |
Yes, that's an unnaceptable DoS vector. Floresta and utreexod would make a lot of nodes crash if this was the case. |
To be fair, you'd have to be running some pretty ancient setup - 32 bits, no PAE kernel. Still, I think given what you said, debug_assert sounds better IMO |
20b1e3f to
98c213f
Compare
|
It looks like it would be better to wait for #5784 to merge. Since Services is a wrapped |
|
Putting on ice since #5784 is making good progress |
98c213f to
648f2a5
Compare
85a6da3 api: update for CompactSizeU64Decoder (Nick Johnson) bb7bf48 consensus_encoding: const the compact size prefix values (Nick Johnson) 4614515 consensus_encoding: add round trip test for compact size codecs (Nick Johnson) 77a60ae consensus_encoding: add a u64 decoder for compact size (Nick Johnson) 773b4a3 consensus_encoding: add a u64 constructor to compact size encoder (Nick Johnson) a06bf03 consensus_encoding: move compact size into its own module (Nick Johnson) Pull request description: Add u64 support to the Compact Size codec since there are non prefix length use cases (#5762). Kind of related to #5752. I believe this is the simplest way to add support, but the asymmetry kind of annoys me. On the encoding side, only a new constructor is necessary. But on the decoding side a new type is required since there is a 1:1 with the associated output. I don't think symmetry is a strong enough reason to put a type on the encoding side though. I didn't put much though into the names, focusing on minimal change. But maybe it would be worth it to name each encoder/decoder after its use case instead of impl? So the existing one would be called something like `LengthPrefixDecoder` and so on. The first commit moves the existing compact size stuff into its own `::compact_size` module, to kind of corner this weirdness. This creates kind of a funky dependency graph with `::decode` and `::decode::decoders` (and the equivalent encoders side), but none of that is exposed from the crate since it is a private module. ACKs for top commit: tcharding: ACK 85a6da3 apoelstra: ACK 85a6da3; successfully ran local tests Tree-SHA512: ba3dca8f698ede3538664e29edba3ba2cb5190515233a0b3afef93af656d6ef7538efad7f7173cad38e53263073d5ac6a69be5c940c907cbe5b20181786e23b2
5784 recently merged, so this work can be resumed. |
Member of `AddrV2Payload` which is ultimately apart of `NetworkMessage`. Some non-zero number of clients advertise services outside of 32 bits of precision, which requires decoding arbitrarily large compact sizes. As these integers do not represent collection lengths and will not be used for allocation, this is acceptable. ref: https://github.com/bitcoin/bitcoin/blob/4d7d5f6b79d4c11c47e7a828d81296918fd11d4d/src/protocol.h#L332 ref: bitcoin/bitcoin#34768
Vector counterpart of the previous commit.
648f2a5 to
cbfdb80
Compare
|
Rebased cbfdb80 with the compact size encoding changes |
Last prerequisite before implementing
encodingforNetworkMessage