Skip to content

Commit d4d8a8c

Browse files
authored
Moves code walkthrough book chapters to docs (paradigmxyz#629)
* replaced template blocks with code blocks in stages chapter * replaced template blocks with code blocks in network chapter * moved book sections to docs * fix indentation in recover_signer codeblock * remove unnecessary TODO comment in network.md
1 parent a51fa4f commit d4d8a8c

File tree

29 files changed

+1179
-459
lines changed

29 files changed

+1179
-459
lines changed

bin/reth/src/node/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ impl Command {
105105
let genesis_hash = init_genesis(db.clone(), self.chain.genesis.clone())?;
106106

107107
info!("Connecting to p2p");
108-
// ANCHOR: snippet-execute
109108
let network = start_network(network_config(db.clone(), chain_id, genesis_hash)).await?;
110109

111110
// TODO: Are most of these Arcs unnecessary? For example, fetch client is completely
@@ -155,7 +154,6 @@ impl Command {
155154
// Run pipeline
156155
info!("Starting pipeline");
157156
pipeline.run(db.clone()).await?;
158-
// ANCHOR_END: snippet-execute
159157

160158
info!("Finishing up");
161159
Ok(())
@@ -224,7 +222,6 @@ fn network_config<DB: Database>(
224222
}
225223

226224
/// Starts the networking stack given a [NetworkConfig] and returns a handle to the network.
227-
// ANCHOR: fn-start_network
228225
async fn start_network<C>(config: NetworkConfig<C>) -> Result<NetworkHandle, NetworkError>
229226
where
230227
C: BlockProvider + HeaderProvider + 'static,
@@ -238,4 +235,3 @@ where
238235
tokio::task::spawn(eth);
239236
Ok(handle)
240237
}
241-
// ANCHOR_END: fn-start_network

book/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ The book is continuously rendered [here](https://paradigmxyz.github.io/reth/)!
1717
To get started with Reth, install, configure and sync your node.
1818
* To install and build reth, you can use the following [installation instruction](./installation.md).
1919

20-
**[A Tour Of Reth]()**
21-
22-
This section will take a deep dive into the inner workings of Reth.
2320

2421
[gh-book]: https://github.com/paradigmxyz/reth/tree/main/book

book/SUMMARY.md

-41
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,3 @@
77
<!-- An overview of all the flags, how they work and how to configure the node -->
88
- [Configuring The Node]()
99
- [Running Reth]()
10-
11-
# A Tour Of Reth
12-
13-
- [Database]()
14-
- [codecs]()
15-
- [libmdbx-rs]()
16-
- [db](./db/README.md)
17-
- [Networking]()
18-
- [P2P](./networking/p2p/README.md)
19-
- [network](./networking/p2p/network/README.md)
20-
- [eth-wire]()
21-
- [discv4]()
22-
- [ipc]()
23-
- [RPC]()
24-
- [rpc-api]()
25-
- [rpc]()
26-
- [rpc-types]()
27-
- [Downloaders]()
28-
- [bodies-downloaders]()
29-
- [headers-downloaders]()
30-
- [Ethereum]()
31-
- [executor]()
32-
- [consensus]()
33-
- [transaction-pool]()
34-
- [Staged Sync]()
35-
- [stages](./stages/README.md)
36-
- [Primitives]()
37-
- [primitives]()
38-
- [rlp]()
39-
- [rlp-derive]()
40-
- [Misc]()
41-
- [interfaces]()
42-
- [tracing]()
43-
- [crate-template]()
44-
- [examples]()
45-
46-
47-
48-
# Design
49-
50-
- [Goals](./design/goals.md)

book/networking/network.md

-1
This file was deleted.

book/networking/p2p/README.md

-1
This file was deleted.

book/networking/p2p/network/README.md

-327
This file was deleted.

crates/interfaces/src/p2p/headers/downloader.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use reth_primitives::{SealedHeader, H256};
1212
///
1313
/// A downloader represents a distinct strategy for submitting requests to download block headers,
1414
/// while a [HeadersClient] represents a client capable of fulfilling these requests.
15-
// ANCHOR: trait-HeaderDownloader
1615
#[auto_impl::auto_impl(&, Arc, Box)]
1716
pub trait HeaderDownloader: Downloader {
1817
/// Stream the headers
@@ -24,7 +23,6 @@ pub trait HeaderDownloader: Downloader {
2423
Ok(())
2524
}
2625
}
27-
// ANCHOR_END: trait-HeaderDownloader
2826

2927
/// Validate whether the header is valid in relation to it's parent
3028
///

crates/net/downloaders/src/bodies/concurrent.rs

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::{borrow::Borrow, sync::Arc};
1717
/// Downloads bodies in batches.
1818
///
1919
/// All blocks in a batch are fetched at the same time.
20-
// ANCHOR: struct-ConcurrentDownloader
2120
#[derive(Debug)]
2221
pub struct ConcurrentDownloader<Client, Consensus> {
2322
/// The bodies client
@@ -31,7 +30,6 @@ pub struct ConcurrentDownloader<Client, Consensus> {
3130
/// The maximum number of requests to send concurrently.
3231
concurrency: usize,
3332
}
34-
// ANCHOR_END: struct-ConcurrentDownloader
3533

3634
impl<Client, Consensus> Downloader for ConcurrentDownloader<Client, Consensus>
3735
where

crates/net/downloaders/src/headers/linear.rs

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::{
2121
};
2222

2323
/// Download headers in batches
24-
// ANCHOR: struct-LinearDownloader
2524
#[derive(Debug)]
2625
pub struct LinearDownloader<C, H> {
2726
/// The consensus client
@@ -33,7 +32,6 @@ pub struct LinearDownloader<C, H> {
3332
/// The number of retries for downloading
3433
pub request_retries: usize,
3534
}
36-
// ANCHOR_END: struct-LinearDownloader
3735

3836
impl<C, H> Downloader for LinearDownloader<C, H>
3937
where
@@ -194,7 +192,6 @@ where
194192
}
195193

196194
/// Get a current future or instantiate a new one
197-
// ANCHOR: fn-get_or_init_fut
198195
fn get_or_init_fut(&mut self) -> HeadersRequestFuture {
199196
match self.request.take() {
200197
None => {
@@ -215,7 +212,6 @@ where
215212
Some(fut) => fut,
216213
}
217214
}
218-
// ANCHOR_END: fn-get_or_init_fut
219215

220216
/// Tries to fuse the future with a new request.
221217
///

crates/net/eth-wire/src/types/blocks.rs

-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use serde::{Deserialize, Serialize};
1717
#[derive(
1818
Copy, Clone, Debug, PartialEq, Eq, Hash, RlpEncodable, RlpDecodable, Serialize, Deserialize,
1919
)]
20-
// ANCHOR: struct-GetBlockHeaders
2120
pub struct GetBlockHeaders {
2221
/// The block number or hash that the peer should start returning headers from.
2322
pub start_block: BlockHashOrNumber,
@@ -34,7 +33,6 @@ pub struct GetBlockHeaders {
3433
/// The direction in which the headers should be returned in.
3534
pub direction: HeadersDirection,
3635
}
37-
// ANCHOR_END: struct-GetBlockHeaders
3836

3937
/// The response to [`GetBlockHeaders`], containing headers if any headers were found.
4038
#[derive(
@@ -71,12 +69,10 @@ impl From<Vec<Header>> for BlockHeaders {
7169
Deserialize,
7270
Default,
7371
)]
74-
// ANCHOR: struct-GetBlockBodies
7572
pub struct GetBlockBodies(
7673
/// The block hashes to request bodies for.
7774
pub Vec<H256>,
7875
);
79-
// ANCHOR_END: struct-GetBlockBodies
8076

8177
impl From<Vec<H256>> for GetBlockBodies {
8278
fn from(hashes: Vec<H256>) -> Self {

crates/net/network/src/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub fn rng_secret_key() -> SecretKey {
3030
}
3131

3232
/// All network related initialization settings.
33-
// ANCHOR: struct-NetworkConfig
3433
pub struct NetworkConfig<C> {
3534
/// The client type that can interact with the chain.
3635
pub client: Arc<C>,
@@ -70,7 +69,6 @@ pub struct NetworkConfig<C> {
7069
/// Sets the hello message for the p2p handshake in RLPx
7170
pub hello_message: HelloMessage,
7271
}
73-
// ANCHOR_END: struct-NetworkConfig
7472

7573
// === impl NetworkConfig ===
7674

crates/net/network/src/eth_requests.rs

-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const APPROX_HEADER_SIZE: usize = 500;
4646
/// Manages eth related requests on top of the p2p network.
4747
///
4848
/// This can be spawned to another task and is supposed to be run as background service.
49-
// ANCHOR: struct-EthRequestHandler
5049
#[must_use = "Manager does nothing unless polled."]
5150
pub struct EthRequestHandler<C> {
5251
/// The client type that can interact with the chain.
@@ -58,7 +57,6 @@ pub struct EthRequestHandler<C> {
5857
/// Incoming request from the [NetworkManager](crate::NetworkManager).
5958
incoming_requests: UnboundedReceiverStream<IncomingEthRequest>,
6059
}
61-
// ANCHOR_END: struct-EthRequestHandler
6260

6361
// === impl EthRequestHandler ===
6462
impl<C> EthRequestHandler<C> {
@@ -77,7 +75,6 @@ where
7775
C: BlockProvider + HeaderProvider,
7876
{
7977
/// Returns the list of requested heders
80-
// ANCHOR:fn-get_headers_response
8178
fn get_headers_response(&self, request: GetBlockHeaders) -> Vec<Header> {
8279
let GetBlockHeaders { start_block, limit, skip, direction } = request;
8380

@@ -142,7 +139,6 @@ where
142139

143140
headers
144141
}
145-
// ANCHOR_END:fn-get_headers_response
146142

147143
fn on_headers_request(
148144
&mut self,
@@ -154,7 +150,6 @@ where
154150
let _ = response.send(Ok(BlockHeaders(headers)));
155151
}
156152

157-
// ANCHOR: fn-on_bodies_request
158153
fn on_bodies_request(
159154
&mut self,
160155
_peer_id: PeerId,
@@ -187,7 +182,6 @@ where
187182

188183
let _ = response.send(Ok(BlockBodies(bodies)));
189184
}
190-
// ANCHOR_END: fn-on_bodies_request
191185
}
192186

193187
/// An endless future.
@@ -199,7 +193,6 @@ where
199193
{
200194
type Output = ();
201195

202-
// ANCHOR: fn-poll
203196
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
204197
let this = self.get_mut();
205198

@@ -220,7 +213,6 @@ where
220213
}
221214
}
222215
}
223-
// ANCHOR_END: fn-poll
224216
}
225217

226218
/// Represents a handled [`GetBlockHeaders`] requests

crates/net/network/src/fetch/client.rs

-4
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@ use reth_primitives::{PeerId, WithPeerId, H256};
1515
use tokio::sync::{mpsc::UnboundedSender, oneshot};
1616

1717
/// Front-end API for fetching data from the network.
18-
// ANCHOR: struct-FetchClient
1918
#[derive(Debug)]
2019
pub struct FetchClient {
2120
/// Sender half of the request channel.
2221
pub(crate) request_tx: UnboundedSender<DownloadRequest>,
2322
/// The handle to the peers
2423
pub(crate) peers_handle: PeersHandle,
2524
}
26-
// ANCHOR_END: struct-FetchClient
2725

2826
impl DownloadClient for FetchClient {
2927
fn report_bad_message(&self, peer_id: PeerId) {
3028
self.peers_handle.reputation_change(peer_id, ReputationChangeKind::BadMessage);
3129
}
3230
}
3331

34-
// ANCHOR: trait-HeadersClient-BodiesClient
3532
#[async_trait::async_trait]
3633
impl HeadersClient for FetchClient {
3734
/// Sends a `GetBlockHeaders` request to an available peer.
@@ -50,4 +47,3 @@ impl BodiesClient for FetchClient {
5047
rx.await?
5148
}
5249
}
53-
// ANCHOR_END: trait-HeadersClient-BodiesClient

crates/net/network/src/fetch/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub use client::FetchClient;
2525
/// peers and sends the response once ready.
2626
///
2727
/// This type maintains a list of connected peers that are available for requests.
28-
// ANCHOR: struct-StateFetcher
2928
pub struct StateFetcher {
3029
/// Currently active [`GetBlockHeaders`] requests
3130
inflight_headers_requests:
@@ -44,7 +43,6 @@ pub struct StateFetcher {
4443
/// Sender for download requests, used to detach a [`FetchClient`]
4544
download_requests_tx: UnboundedSender<DownloadRequest>,
4645
}
47-
// ANCHOR_END: struct-StateFetcher
4846

4947
// === impl StateSyncer ===
5048

crates/net/network/src/manager.rs

-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ use tracing::{error, info, trace, warn};
7979
/// ethrequest <--> |ETH request handing| NetworkManager
8080
/// discovery --> |Discovered peers| NetworkManager
8181
/// ```
82-
// ANCHOR: struct-NetworkManager
8382
#[must_use = "The NetworkManager does nothing unless polled"]
8483
pub struct NetworkManager<C> {
8584
/// The type that manages the actual network part, which includes connections.
@@ -104,7 +103,6 @@ pub struct NetworkManager<C> {
104103
/// Updated by the `NetworkWorker` and loaded by the `NetworkService`.
105104
num_active_peers: Arc<AtomicUsize>,
106105
}
107-
// ANCHOR_END: struct-NetworkManager
108106

109107
// === impl NetworkManager ===
110108
impl<C> NetworkManager<C> {
@@ -672,7 +670,6 @@ where
672670
///
673671
/// This includes any event types that may be relevant to tasks, for metrics, keep track of peers
674672
/// etc.
675-
// ANCHOR: enum-NetworkEvent
676673
#[derive(Debug, Clone)]
677674
pub enum NetworkEvent {
678675
/// Closed the peer session.
@@ -698,7 +695,6 @@ pub enum NetworkEvent {
698695
/// Event emitted when a new peer is removed
699696
PeerRemoved(PeerId),
700697
}
701-
// ANCHOR_END: enum-NetworkEvent
702698

703699
/// Bundles all listeners for [`NetworkEvent`]s.
704700
#[derive(Default)]

crates/net/network/src/network.rs

-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ impl StatusUpdater for NetworkHandle {
167167
}
168168
}
169169

170-
// ANCHOR: struct-NetworkInner
171170
#[derive(Debug)]
172171
struct NetworkInner {
173172
/// Number of active peer sessions the node's currently handling.
@@ -183,7 +182,6 @@ struct NetworkInner {
183182
/// The mode of the network
184183
network_mode: NetworkMode,
185184
}
186-
// ANCHOR_END: struct-NetworkInner
187185

188186
/// Internal messages that can be passed to the [`NetworkManager`](crate::NetworkManager).
189187
#[allow(missing_docs)]

crates/net/network/src/state.rs

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const PEER_BLOCK_CACHE_LIMIT: usize = 512;
3939
/// then send to the session of the peer.
4040
///
4141
/// This type is also responsible for responding for received request.
42-
// ANCHOR: struct-NetworkState
4342
pub struct NetworkState<C> {
4443
/// All active peers and their state.
4544
active_peers: HashMap<PeerId, ActivePeer>,
@@ -59,7 +58,6 @@ pub struct NetworkState<C> {
5958
/// then queue in the request and notify the fetcher once the result has been received.
6059
state_fetcher: StateFetcher,
6160
}
62-
// ANCHOR_END: struct-NetworkState
6361

6462
impl<C> NetworkState<C>
6563
where

crates/net/network/src/swarm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use tracing::{trace, warn};
6161
/// fetchRequest --> |request Headers, Bodies| StateFetch
6262
/// State --> |poll pending requests| StateFetch
6363
/// ```
64-
// ANCHOR: struct-Swarm
6564
#[must_use = "Swarm does nothing unless polled"]
6665
pub(crate) struct Swarm<C> {
6766
/// Listens for new incoming connections.
@@ -71,7 +70,6 @@ pub(crate) struct Swarm<C> {
7170
/// Tracks the entire state of the network and handles events received from the sessions.
7271
state: NetworkState<C>,
7372
}
74-
// ANCHOR_END: struct-Swarm
7573

7674
// === impl Swarm ===
7775

0 commit comments

Comments
 (0)