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

Add v2 p2p support (BIP324) #373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nyonson
Copy link
Contributor

@nyonson nyonson commented Feb 12, 2025

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other:

Which crates are being modified?

  • floresta-chain
  • floresta-cli
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-watch-only
  • floresta-wire
  • floresta
  • florestad
  • Other: .

Description

The new transport module wraps up the V1 and V2 p2p protocols so that the rest of the app doesn't have to care, but this lead to a few refactors and open questions.

  • Shifted the use of RawNetworkMessage to NetworkMessage. RawNetworkMessage is essentially a V1 message (bit of a misnomer) whereas NetworkMessage is agnostic. Considering the transport module handles V1 or V2, the rest of the app doesn't care and can just use NetworkMessage.
  • The read and write enum types exposed by the transport module require some more explicit type bounds throughout the rest of the app. These aren't new requirements, they were just implicit before.
  • Pushed the TCP and SOCKS5 connection logic into the new transport module so that it can handle retries at that level. I believe this will make future transport extensions easier to implement.

Notes to the reviewers

  • There is a weird relationship between the high level WireError and the internal PeerError plus the new TransportError. TransportError can bubble up to both of them, but kinda feels like it should instead be a 1:1:1 hierarchy. Not sure the best way forward.

Checklist

  • I've signed all my commits
  • I ran just lint
  • I ran cargo test
  • I've checked the integration tests
  • I've followed the contribution guidelines
  • I'm linking the issue being fixed by this PR (if any)

@nyonson nyonson force-pushed the add-bip324 branch 3 times, most recently from 09685f8 to 9b6b614 Compare February 25, 2025 21:24
@nyonson nyonson force-pushed the add-bip324 branch 2 times, most recently from c4e17cf to 7f090a2 Compare March 3, 2025 19:30
@nyonson nyonson marked this pull request as ready for review March 3, 2025 19:31
@nyonson
Copy link
Contributor Author

nyonson commented Mar 3, 2025

I am going to attempt add one more commit to this patch to pull in the TCP and SOCKS5 connections into the transport module. At first I tried to avoid this, but it will make the connection handshake way more robust. I believe this is inline with your thoughts on other transports like websockets @Davidson-Souza

@nyonson nyonson force-pushed the add-bip324 branch 4 times, most recently from 90c6095 to bc3b68e Compare March 4, 2025 21:43
@nyonson
Copy link
Contributor Author

nyonson commented Mar 4, 2025

Pushed down the connection logic in 8fb1379

Ended up just squashing all the commits since the early ones were semi-broken use-ability.

@nyonson
Copy link
Contributor Author

nyonson commented Mar 6, 2025

I fired up florestad on mainnet with this branch and I see logs like the following so I think things are going smoothly, but I'll admit I am not sure the best way to exercise more of the utreexo specific things.

[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=0000000068d4ccd28b7ff330188cc8a5fa25d3388ce47986164aab2f761e2b14 height=37660 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 0000000068d4ccd28b7ff330188cc8a5fa25d3388ce47986164aab2f761e2b14
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::peer] Handling node request: GetBlock(([000000007dd40d8ad9ea5fdb025e5e7c1c5bfe302cce22a0bee62afbe04fc90b, 000000005439b2b713ef77f0efe190eff94f3a23fcb77924452c3b608258f167, 00000000b4eb89244eaa948ceb244e52a2a2c1f5fbaaaf0f9e0a263b79b70da9, 000000003bd56403a5aca689cb155208554b9c99d5073f5774d3d4c08c89e91a, 00000000a67afe459dbf14afd674a5c02f2fdb5149d4a99139f4704c3a842460, 000000000979f4b040042e49d2f8185f82af3d0787d67d7ceba7ee846a98775e, 0000000004085187731ee4cd129beb1359bd99214f63a1e940cdb7ddcd53a626, 00000000b0ee20565958f17304f3f063d917e119c5988b86956ea1c4660d1e0d, 0000000080887fdde3da8b54c7a831a5ae1a7def0b56453457aecdb24abaec71, 00000000b4fb1c76a4285481731567794eab86634e5532020b8fd16da634c89d], true))
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::peer] Writing getdata to peer 1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 000000007dd40d8ad9ea5fdb025e5e7c1c5bfe302cce22a0bee62afbe04fc90b
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=000000007dd40d8ad9ea5fdb025e5e7c1c5bfe302cce22a0bee62afbe04fc90b height=37661 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 000000007dd40d8ad9ea5fdb025e5e7c1c5bfe302cce22a0bee62afbe04fc90b
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 000000005439b2b713ef77f0efe190eff94f3a23fcb77924452c3b608258f167
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=000000005439b2b713ef77f0efe190eff94f3a23fcb77924452c3b608258f167 height=37662 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 000000005439b2b713ef77f0efe190eff94f3a23fcb77924452c3b608258f167
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 00000000b4eb89244eaa948ceb244e52a2a2c1f5fbaaaf0f9e0a263b79b70da9
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=00000000b4eb89244eaa948ceb244e52a2a2c1f5fbaaaf0f9e0a263b79b70da9 height=37663 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 00000000b4eb89244eaa948ceb244e52a2a2c1f5fbaaaf0f9e0a263b79b70da9
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 000000003bd56403a5aca689cb155208554b9c99d5073f5774d3d4c08c89e91a
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=000000003bd56403a5aca689cb155208554b9c99d5073f5774d3d4c08c89e91a height=37664 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 000000003bd56403a5aca689cb155208554b9c99d5073f5774d3d4c08c89e91a
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 00000000a67afe459dbf14afd674a5c02f2fdb5149d4a99139f4704c3a842460
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=00000000a67afe459dbf14afd674a5c02f2fdb5149d4a99139f4704c3a842460 height=37665 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 00000000a67afe459dbf14afd674a5c02f2fdb5149d4a99139f4704c3a842460
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 000000000979f4b040042e49d2f8185f82af3d0787d67d7ceba7ee846a98775e
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=000000000979f4b040042e49d2f8185f82af3d0787d67d7ceba7ee846a98775e height=37666 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 000000000979f4b040042e49d2f8185f82af3d0787d67d7ceba7ee846a98775e
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 0000000004085187731ee4cd129beb1359bd99214f63a1e940cdb7ddcd53a626
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=0000000004085187731ee4cd129beb1359bd99214f63a1e940cdb7ddcd53a626 height=37667 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 0000000004085187731ee4cd129beb1359bd99214f63a1e940cdb7ddcd53a626
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] processing block 00000000b0ee20565958f17304f3f063d917e119c5988b86956ea1c4660d1e0d
[2025-03-06 11:24:33 INFO floresta_chain::pruned_utreexo::chain_state] New tip! hash=00000000b0ee20565958f17304f3f063d917e119c5988b86956ea1c4660d1e0d height=37668 tx_count=1
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::sync_node] accepted block 00000000b0ee20565958f17304f3f063d917e119c5988b86956ea1c4660d1e0d
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::peer] Handling node request: GetBlock(([00000000674bad49597d1ef43f7240f05f88591d82fc7212e603f0abf693d1fd, 000000002e7e1c753d085015f87ac03bf953e8716d63fbd0fee07a2290cca502, 000000008fc9bc1074c3c63046371d589172773aa9853ec530b7574b049ad7cd, 000000004f7ae9a12c1d7874f20c2e0c515f67b0775c050770d149e595c6a5fb, 0000000085a8cfec2eb885cb424925f8cf07f2902a43c98766ad10ea5179d94b, 000000004b63ea15e443927dc207fcc7591af7b6a402aaed0789fbb53c56f5d7, 000000003201a98bbe922fa69e27f0083c3b4d26663e75c838415ec5ed04ce34, 000000005f5edd0dc432dc492f0c1be272e9c750825a8d4b2d1154f7cf8daa04, 000000000a405156704d02773f93bf5e7c24a2a7d0f505e57d48bbc3ec116fdd, 000000005c2278b0737ec3928b78f958ed002f6dab905912947f8b1dac831e70], true))
[2025-03-06 11:24:33 DEBUG floresta_wire::p2p_wire::peer] Writing getdata to peer 1

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.

1 participant