near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.31k stars 618 forks source link

Write reference level documentation for the network code #5156

Closed pmnoxx closed 2 years ago

pmnoxx commented 2 years ago

To make network code easier to understand we should write a reference level documentation. That will make it easier for new developers to understand different parts of the networking code.

Add in-code documentation

Dead code

Improve code quality:

pmnoxx commented 2 years ago

@bowenwang1996 @mm-near @matklad

matklad commented 2 years ago

Great idea! I've just spend five minutes reading the doc in the wip PR, and I feel I've already learned more about near networking more than I knew before.

I have one high-level comment here: we might want to ensure strict separation between protocol specification and code-level documentation. Ideally, I'd love to see two documents: "NEAR P2P protocol" and "Implementation of networking in nearcore". The first documents abstract protocol without references to a particular implementation. It doesn't mention Rust, tokio, nearcore or actors, but it does mention TCP, borsh format, persistent nonces etc. So if you want to implement a nearcore node in Go, you can use that document as a spec. The second document describes how we implement protocol in nearcore (eg, "to maintain persistent nonces, we store removed edges into the database using this column").

Don't think that we should immediately create that, but it might make sense to keep the separation between proper protocol and specific implementation in mind while writing the docs.

matklad commented 2 years ago

The first documents abstract protocol without references to a particular implementation

I guess the right home for that doc is https://nomicon.io/ChainSpec/NetworkSpec.html (and network spec should probably be lifted one level up and become a sibling of ChanSpec)