chia_protocol/
chia_protocol.rs

1use chia_streamable_macro::{streamable, Streamable};
2
3use crate::Bytes;
4
5#[cfg(feature = "py-bindings")]
6use chia_py_streamable_macro::{PyJsonDict, PyStreamable};
7
8#[repr(u8)]
9#[cfg_attr(feature = "py-bindings", derive(PyJsonDict, PyStreamable))]
10#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
11#[derive(Streamable, Hash, Debug, Copy, Clone, Eq, PartialEq)]
12pub enum ProtocolMessageTypes {
13    // Shared protocol (all services)
14    Handshake = 1,
15
16    // Harvester protocol (harvester <-> farmer)
17    HarvesterHandshake = 3,
18    // NewSignagePointHarvester = 4 Changed to 66 in new protocol
19    NewProofOfSpace = 5,
20    RequestSignatures = 6,
21    RespondSignatures = 7,
22
23    // Farmer protocol (farmer <-> fullNode)
24    NewSignagePoint = 8,
25    DeclareProofOfSpace = 9,
26    RequestSignedValues = 10,
27    SignedValues = 11,
28    FarmingInfo = 12,
29
30    // Timelord protocol (timelord <-> fullNode)
31    NewPeakTimelord = 13,
32    NewUnfinishedBlockTimelord = 14,
33    NewInfusionPointVdf = 15,
34    NewSignagePointVdf = 16,
35    NewEndOfSubSlotVdf = 17,
36    RequestCompactProofOfTime = 18,
37    RespondCompactProofOfTime = 19,
38
39    // Full node protocol (fullNode <-> fullNode)
40    NewPeak = 20,
41    NewTransaction = 21,
42    RequestTransaction = 22,
43    RespondTransaction = 23,
44    RequestProofOfWeight = 24,
45    RespondProofOfWeight = 25,
46    RequestBlock = 26,
47    RespondBlock = 27,
48    RejectBlock = 28,
49    RequestBlocks = 29,
50    RespondBlocks = 30,
51    RejectBlocks = 31,
52    NewUnfinishedBlock = 32,
53    RequestUnfinishedBlock = 33,
54    RespondUnfinishedBlock = 34,
55    NewSignagePointOrEndOfSubSlot = 35,
56    RequestSignagePointOrEndOfSubSlot = 36,
57    RespondSignagePoint = 37,
58    RespondEndOfSubSlot = 38,
59    RequestMempoolTransactions = 39,
60    RequestCompactVDF = 40,
61    RespondCompactVDF = 41,
62    NewCompactVDF = 42,
63    RequestPeers = 43,
64    RespondPeers = 44,
65    NoneResponse = 91,
66
67    // Wallet protocol (wallet <-> fullNode)
68    RequestPuzzleSolution = 45,
69    RespondPuzzleSolution = 46,
70    RejectPuzzleSolution = 47,
71    SendTransaction = 48,
72    TransactionAck = 49,
73    NewPeakWallet = 50,
74    RequestBlockHeader = 51,
75    RespondBlockHeader = 52,
76    RejectHeaderRequest = 53,
77    RequestRemovals = 54,
78    RespondRemovals = 55,
79    RejectRemovalsRequest = 56,
80    RequestAdditions = 57,
81    RespondAdditions = 58,
82    RejectAdditionsRequest = 59,
83    RequestHeaderBlocks = 60,
84    RejectHeaderBlocks = 61,
85    RespondHeaderBlocks = 62,
86
87    // Introducer protocol (introducer <-> fullNode)
88    RequestPeersIntroducer = 63,
89    RespondPeersIntroducer = 64,
90
91    // Simulator protocol
92    FarmNewBlock = 65,
93
94    // New harvester protocol
95    NewSignagePointHarvester = 66,
96    RequestPlots = 67,
97    RespondPlots = 68,
98    PlotSyncStart = 78,
99    PlotSyncLoaded = 79,
100    PlotSyncRemoved = 80,
101    PlotSyncInvalid = 81,
102    PlotSyncKeysMissing = 82,
103    PlotSyncDuplicates = 83,
104    PlotSyncDone = 84,
105    PlotSyncResponse = 85,
106
107    // More wallet protocol
108    CoinStateUpdate = 69,
109    RegisterForPhUpdates = 70,
110    RespondToPhUpdates = 71,
111    RegisterForCoinUpdates = 72,
112    RespondToCoinUpdates = 73,
113    RequestChildren = 74,
114    RespondChildren = 75,
115    RequestSesInfo = 76,
116    RespondSesInfo = 77,
117    RequestBlockHeaders = 86,
118    RejectBlockHeaders = 87,
119    RespondBlockHeaders = 88,
120    RequestFeeEstimates = 89,
121    RespondFeeEstimates = 90,
122
123    // Unfinished block protocol
124    NewUnfinishedBlock2 = 92,
125    RequestUnfinishedBlock2 = 93,
126
127    // New wallet sync protocol
128    RequestRemovePuzzleSubscriptions = 94,
129    RespondRemovePuzzleSubscriptions = 95,
130    RequestRemoveCoinSubscriptions = 96,
131    RespondRemoveCoinSubscriptions = 97,
132    RequestPuzzleState = 98,
133    RespondPuzzleState = 99,
134    RejectPuzzleState = 100,
135    RequestCoinState = 101,
136    RespondCoinState = 102,
137    RejectCoinState = 103,
138
139    // Wallet protocol mempool updates
140    MempoolItemsAdded = 104,
141    MempoolItemsRemoved = 105,
142    RequestCostInfo = 106,
143    RespondCostInfo = 107,
144}
145
146#[cfg(feature = "py-bindings")]
147impl chia_traits::ChiaToPython for ProtocolMessageTypes {
148    fn to_python<'a>(&self, py: pyo3::Python<'a>) -> pyo3::PyResult<pyo3::Bound<'a, pyo3::PyAny>> {
149        Ok(pyo3::IntoPyObject::into_pyobject(*self as u8, py)?
150            .clone()
151            .into_any())
152    }
153}
154
155pub trait ChiaProtocolMessage {
156    fn msg_type() -> ProtocolMessageTypes;
157}
158
159#[repr(u8)]
160#[cfg_attr(feature = "py-bindings", derive(PyJsonDict, PyStreamable))]
161#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
162#[derive(Streamable, Hash, Debug, Copy, Clone, Eq, PartialEq)]
163pub enum NodeType {
164    FullNode = 1,
165    Harvester = 2,
166    Farmer = 3,
167    Timelord = 4,
168    Introducer = 5,
169    Wallet = 6,
170    DataLayer = 7,
171}
172
173#[cfg(feature = "py-bindings")]
174impl chia_traits::ChiaToPython for NodeType {
175    fn to_python<'a>(&self, py: pyo3::Python<'a>) -> pyo3::PyResult<pyo3::Bound<'a, pyo3::PyAny>> {
176        Ok(pyo3::IntoPyObject::into_pyobject(*self as u8, py)?
177            .clone()
178            .into_any())
179    }
180}
181
182#[streamable(no_serde)]
183pub struct Message {
184    msg_type: ProtocolMessageTypes,
185    id: Option<u16>,
186    data: Bytes,
187}
188
189#[streamable(message)]
190pub struct Handshake {
191    // Network id, usually the genesis challenge of the blockchain
192    network_id: String,
193    // Protocol version to determine which messages the peer supports
194    protocol_version: String,
195    // Version of the software, to debug and determine feature support
196    software_version: String,
197    // Which port the server is listening on
198    server_port: u16,
199    // NodeType (full node, wallet, farmer, etc.)
200    node_type: NodeType,
201    // Key value dict to signal support for additional capabilities/features
202    capabilities: Vec<(u16, String)>,
203}