Skip to main content

forest/libp2p/chain_exchange/
mod.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4mod behaviour;
5mod message;
6mod provider;
7use std::time::Duration;
8
9pub use behaviour::*;
10
11pub use self::{message::*, provider::*};
12use super::rpc::{CborRequestResponse, CodecConfig};
13
14/// Libp2p protocol name for `ChainExchange`.
15pub const CHAIN_EXCHANGE_PROTOCOL_NAME: &str = "/fil/chain/xchg/0.0.1";
16
17/// Codec limits for the `ChainExchange` protocol.
18///
19/// - Request: tipset CIDs + length + options bitfield — well under 1 KiB. 4 KiB cap.
20/// - Response: cap matches Lotus's [`maxExchangeMessageSize`] (15 blocks × 8 MiB messages).
21/// - Decode timeout: 60 seconds — accommodates ~32 MiB realistic responses at
22///   ~5 Mbps per stream (we run up to 3 outbound chain-exchange streams in
23///   parallel, so per-stream bandwidth is a fraction of the peer's link).
24///
25/// [`maxExchangeMessageSize`]: https://github.com/filecoin-project/lotus/blob/v1.35.1/chain/exchange/client.go#L30
26pub struct ChainExchangeCodecConfig;
27
28impl CodecConfig for ChainExchangeCodecConfig {
29    const MAX_REQUEST_BYTES: usize = 4096;
30    const MAX_RESPONSE_BYTES: usize = 120 * 1024 * 1024;
31    const DECODE_TIMEOUT: Duration = Duration::from_secs(60);
32}
33
34pub type ChainExchangeCodec = CborRequestResponse<
35    &'static str,
36    ChainExchangeRequest,
37    ChainExchangeResponse,
38    ChainExchangeCodecConfig,
39>;