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

WIP: A draft PR for collaborating on ZIP155 #5276

Closed
wants to merge 5 commits into from

Conversation

zancas
Copy link
Contributor

@zancas zancas commented Aug 14, 2021

High Level

@AloeareV, @dannasessha and I began this project by inspecting the PR that merged TorV3 addresses into bitcoin main.

From the perspective of "bitcoin main" circa 2019, there are two upgrades that were required. Add support for BIP155-style version 2 network addresses, part of BIP155:

  1. Implement ADDRv2 support (part of BIP155) bitcoin/bitcoin#19031

And, given support for BIP155 addrv2s, add support for TorV3 addresses:

  1. Complete the BIP155 implementation and upgrade to TORv3 bitcoin/bitcoin#19954

Adding Support for BIP155

The addition of addrv2 support was initiated by adding regression tests:

  1. test: add two edge case tests for CSubNet bitcoin/bitcoin#19351

When we inspected that regression test code, we saw that the netbase code had been updated (relative to zcash main circa 2021) to reduce the responsibilities of the CNetAddr, CService, and CSubNet classes. In particular newer versions are not responsible for name resolution.

We discovered that we minimally required:

bitcoin/bitcoin@b6c3ff3

In order to proceed with the backport of 19351.

We noted the coherent structure of:

  1. Net: Turn net structures into dumb storage classes bitcoin/bitcoin#8128

We surmised that all of 8128 would eventually be relevant for TorV3 support, and further noted it's dependence on:

  1. net: Split DNS resolving functionality out of net structures bitcoin/bitcoin#7868

Following the above reasoning we backported 7868 which depended on a small upgrade to error message formatting:

  1. Combine common error strings for different options so translations can be shared and reused bitcoin/bitcoin#7257

The

We need this code for NODE_NONE:

bitcoin/bitcoin@ee06e04

We cherry-picked bitcoin/bitcoin@07c493f for the NET_TOR to NET_ONION change.

This commit introduces GetAddrBytes: bitcoin/bitcoin@b691f2d

This commit introduces the NET_INTERNAL network variant: bitcoin/bitcoin@7f31762

The FLEXIBLE_SIZE change is part of prepation for us:

bitcoin/bitcoin@1ea57ad

We're going to need to backport span, prior to other bps (Making CNetAddr members variable length), because Span is used in core methods.

ADDING SUPPORT FOR BITCOIN STYLE SERIALIZATION:

https://github.com/bitcoin/bitcoin/pulls?q=is%3Apr+is%3Amerged+%22Serialization+improvements%22+in%3Atitle

NOTES:

  • I use main as slang for master where I deem it to be (sufficiently) unambiguous.

src/net.cpp Outdated
@@ -144,7 +144,7 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn
{
struct in6_addr ip;
memcpy(&ip, i->addr, sizeof(ip));
CAddress addr(CService(ip, i->port));
CAddress addr(CService(ip, i->port), NODE_NETWORK);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AloeareV I am still skeptical about the definition of NODE_NETWORK:

NODE_NETWORK = (1 << 0)

but your hypothesis that it's to make it explicit that the value is to be used as a bit-flag is consistent with other patterns we've seen in C++ code (e.g. type hints in names), so it's plausible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://www.stroustrup.com/C++11FAQ.html <-- Let's stay aware of the strong enum pattern.

src/net.cpp Outdated
///* We want -addnode to work even for nodes that don't provide all
// * wanted services, so pass in nServices=0 to CAddress. */
//OpenNetworkConnection(CAddress(vserv[i % vserv.size()], 0), false, &grant);
//>>>>>>> 15bf863219 (Don't require services in -addnode)

Choose a reason for hiding this comment

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

We can probably remove the commented diff, the bool in the commented arg is only something other than false in bitcoin in a single call in ThreadOpenConnections, which looks to have been significantly refactored in zcash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright let's leave this comment thread open for now. Likely we'll circle back and clean up, per your recommendation.

src/protocol.h Outdated
@@ -87,7 +87,7 @@ class CAddress : public CService
{
public:
CAddress();
explicit CAddress(CService ipIn, uint64_t nServicesIn = NODE_NETWORK);
explicit CAddress(CService ipIn, uint64_t nServicesIn);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO this move toward explicitness is healthy.

src/protocol.cpp Outdated
@@ -79,7 +79,7 @@ CAddress::CAddress(CService ipIn, uint64_t nServicesIn) : CService(ipIn)

void CAddress::Init()
{
nServices = NODE_NETWORK;
nServices = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

luke-jr and others added 5 commits September 20, 2021 16:15
…n be shared and reused

(cherry picked from commit 5e10922)
To make it clear where DNS resolves are happening

(cherry picked from commit e9fc71e)
Note: Some seeds aren't actually returning an IP for their name entries, so
they're being added to addrman with a source of [::].

This commit shouldn't change that behavior, for better or worse.

(cherry picked from commit a98cd1f)
Rather than allowing CNetAddr/CService/CSubNet to launch DNS queries, require
that addresses are already resolved.

This greatly simplifies async resolve logic, and makes it harder to
accidentally leak DNS queries.

(cherry picked from commit 3675699)
CNetAddr/CService/CSubnet can no longer resolve DNS.

(cherry picked from commit d39f5b4)
@zancas
Copy link
Contributor Author

zancas commented Jan 7, 2022

I am reorganizing this code, will track elsewhere.

@zancas zancas closed this Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants