Skip to main content

blvm_protocol/
p2p_framing.rs

1//! Bitcoin P2P framing constants: magic bytes, max message size, and common count limits.
2
3/// Mainnet P2P magic (first four bytes of each message on the wire).
4pub const BITCOIN_MAGIC_MAINNET: [u8; 4] = [0xf9, 0xbe, 0xb4, 0xd9];
5
6/// Mainnet magic as `u32` (little-endian), for comparison with `u32::from_le_bytes` on the header.
7pub const BITCOIN_P2P_MAGIC_MAINNET_LE: u32 = u32::from_le_bytes(BITCOIN_MAGIC_MAINNET);
8
9/// Testnet magic.
10pub const BITCOIN_MAGIC_TESTNET: [u8; 4] = [0x0b, 0x11, 0x09, 0x07];
11
12/// Regtest magic.
13pub const BITCOIN_MAGIC_REGTEST: [u8; 4] = [0xfa, 0xbf, 0xb5, 0xda];
14
15/// Maximum P2P message size including 24-byte header (32 MiB payload cap in practice).
16pub const MAX_PROTOCOL_MESSAGE_LENGTH: usize = 32 * 1024 * 1024;
17
18/// Maximum addresses in an `addr` message (`MAX_ADDR_TO_SEND`).
19pub const MAX_ADDR_TO_SEND: usize = 1000;
20
21/// Maximum inventory entries in `inv` / `getdata` (`MAX_INV_SZ`).
22pub const MAX_INV_SZ: usize = 50000;
23
24/// Maximum headers in a `headers` message (`MAX_HEADERS_RESULTS`).
25pub const MAX_HEADERS_RESULTS: usize = 2000;