Skip to content

refactor(wire): split node.rs by behavior#790

Merged
Davidson-Souza merged 1 commit into
getfloresta:masterfrom
JoseSK999:refactor-node-impl
Jan 20, 2026
Merged

refactor(wire): split node.rs by behavior#790
Davidson-Souza merged 1 commit into
getfloresta:masterfrom
JoseSK999:refactor-node-impl

Conversation

@JoseSK999

Copy link
Copy Markdown
Member

Description and Notes

So far node.rs has been a catch-all file, since it was containing the definition for types, macros, and methods for anything needed during the UtreexoNode operation. It was already on the 2,250 lines, which makes it hard to reason about and test.

I think there are roughly four kind of behaviors:

  • Peer management (including inflight requests, addnode, message times, etc.)
  • Connectivity (opening connections, bootstrapping via DNS/seeds, and maintenance)
  • Block pipeline (requesting blocks/proofs and processing them)
  • Handling user requests

So I created four files under the new node/ folder for these behaviors.

The only code changes were:

  • Making broadcast_to_peers, resolve_connect_host, get_port and to_addr_v2 pub(crate)
  • Moving the Default impl for RunningNode to its own file
  • Renaming maybe_use_hadcoded_addresses to maybe_use_hardcoded_addresses (typo).

Hence, this change is move-only in terms of the method bodies (should be easy to verify).

How to verify the changes you have done?

Should be possible to check that method bodies are the exact same by checking git diffs or something.

@JoseSK999

Copy link
Copy Markdown
Member Author

I also think we may want to move to node/ our three node context impl (chain_selector, sync_node and running_node), what do you guys think?

@Davidson-Souza Davidson-Souza added code quality Generally improves code readability and maintainability refactor labels Jan 18, 2026
@JoseSK999

Copy link
Copy Markdown
Member Author

So this is how it would look like if we move contexts into node/ and remove the top-level p2p_wire module (follow up). I think it is better to use blocks, conn and peer_man. Wdyt?

Captura de pantalla 2026-01-19 a las 14 25 21 Captura de pantalla 2026-01-19 a las 14 31 02

@moisesPompilio

Copy link
Copy Markdown
Collaborator

ACK 27bd2a0

Nice! This refactoring makes it much clearer to me what each part is doing.

@Davidson-Souza

Copy link
Copy Markdown
Member

Strong concept ACK. Let the clean up session lead us to a brighter future 🚀

I also think we may want to move to node/ our three node context impl (chain_selector, sync_node and running_node), what do you guys think?

I think it makes sense

So this is how it would look like if we move contexts into node/ and remove the top-level p2p_wire module (follow up). I think it is better to use blocks, conn and peer_man. Wdyt?

Looks great! I can even see how this will make testing more approachable.

@JoseSK999 JoseSK999 force-pushed the refactor-node-impl branch 2 times, most recently from 7580cbb to 4b9a4cf Compare January 19, 2026 18:36
@JoseSK999

Copy link
Copy Markdown
Member Author
  • I've moved check_is_user_block_and_reply to node/user_req (its proper place)
  • Moved the three context impl there too, renamed as chain_selector_ctx, sync_ctx and running_ctx
  • Renamed the other files as blocks, conn and peer_man

In terms of docs-rs it is nice that we now have the context modules grouped under node:

Captura de pantalla 2026-01-19 a las 19 56 33

Comment thread crates/floresta-wire/src/p2p_wire/node/mod.rs Outdated
Comment thread crates/floresta-wire/src/p2p_wire/node/mod.rs Outdated
So far `node.rs` has been a catch-all file, since it was containing the definition for types, macros, and methods for anything needed during the `UtreexoNode` operation. It was already on the 2,250 lines, which makes it hard to reason about and test.

I think there are roughly four kind of behaviors:
- Peer management (including inflight requests, addnode, message times, etc.)
- Connectivity (opening connections, bootstrapping via DNS/seeds, and maintenance)
- Block pipeline (requesting blocks/proofs and processing them)
- Handling user requests

So I created four files under the new `node/` folder for these behaviors, along with the three node contexts.

The only code changes were:
- Making `broadcast_to_peers`, `resolve_connect_host`, `get_port` and `to_addr_v2` `pub(crate)`
- Moving the `Default` impl for `RunningNode` to its own file
- Renaming `maybe_use_hadcoded_addresses` to `maybe_use_hardcoded_addresses` (typo).

Hence, this change is move-only in terms of the method bodies (should be easy to verify).
@JoseSK999

Copy link
Copy Markdown
Member Author

Removed unused RescanStatus enum, and moved save_peers and save_utreexo_peers to peer_man.rs, at the end of the peer lifecycle methods.

@Davidson-Souza Davidson-Souza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 375e166

@moisesPompilio

Copy link
Copy Markdown
Collaborator

ACK 375e166

@Davidson-Souza Davidson-Souza merged commit f936f1c into getfloresta:master Jan 20, 2026
9 of 10 checks passed
Davidson-Souza added a commit that referenced this pull request Jan 24, 2026
…ave enough

c34c500 feat(wire)!: skip fetching seeds from DNS if the `AddressMan` is well populated (Luis Schwab)
f2034a8 feat(wire): add `get_addresses_by_service` and `enough_addresses` to `AddressMan` (Luis Schwab)

Pull request description:

  Closes #784.

  This PR adds some logic to skip fetching peers from DNS if we have enough in the `AddressMan`. The actual values are still up for discussion.

  ~~I'll rebase once #790 is merged.~~

ACKs for top commit:
  jaoleal:
    ACK c34c500
  Davidson-Souza:
    ACK c34c500
  JoseSK999:
    ACK c34c500

Tree-SHA512: 0416ca3b0a790d60c8827ae3188dc269bfdc13584ea2c21b04d8d7a949f69c918499f5c89bca28886f068fcc4eeb32b1b3cebeee40a10bd2dbab4bace0ec5131
@JoseSK999 JoseSK999 deleted the refactor-node-impl branch February 24, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Generally improves code readability and maintainability refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants