1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};
use sp_runtime::{traits::Block as BlockT, RuntimeDebug};
use sp_std::prelude::*;
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain::primitives::{
DmpMessageHandler, Id as ParaId, UpwardMessage, ValidationParams, XcmpMessageFormat,
XcmpMessageHandler,
};
pub use polkadot_primitives::v1::{
AbridgedHostConfiguration, AbridgedHrmpChannel, PersistedValidationData,
};
pub mod relay_chain {
pub use polkadot_core_primitives::*;
pub use polkadot_primitives::{v1, v1::well_known_keys};
}
pub type InboundHrmpMessage = polkadot_primitives::v1::InboundHrmpMessage<relay_chain::BlockNumber>;
pub type OutboundHrmpMessage = polkadot_primitives::v1::OutboundHrmpMessage<ParaId>;
#[derive(Eq, PartialEq, Copy, Clone, RuntimeDebug, Encode, Decode)]
pub enum MessageSendError {
QueueFull,
NoChannel,
TooBig,
Other,
}
impl From<MessageSendError> for &'static str {
fn from(e: MessageSendError) -> Self {
use MessageSendError::*;
match e {
QueueFull => "QueueFull",
NoChannel => "NoChannel",
TooBig => "TooBig",
Other => "Other",
}
}
}
pub struct ChannelInfo {
pub max_capacity: u32,
pub max_total_size: u32,
pub max_message_size: u32,
pub msg_count: u32,
pub total_size: u32,
}
pub trait GetChannelInfo {
fn get_channel_status(id: ParaId) -> ChannelStatus;
fn get_channel_max(id: ParaId) -> Option<usize>;
}
pub trait UpwardMessageSender {
fn send_upward_message(msg: UpwardMessage) -> Result<u32, MessageSendError>;
}
impl UpwardMessageSender for () {
fn send_upward_message(_msg: UpwardMessage) -> Result<u32, MessageSendError> {
Err(MessageSendError::NoChannel)
}
}
pub enum ChannelStatus {
Closed,
Full,
Ready(usize, usize),
}
pub trait XcmpMessageSource {
fn take_outbound_messages(maximum_channels: usize) -> Vec<(ParaId, Vec<u8>)>;
}
impl XcmpMessageSource for () {
fn take_outbound_messages(_maximum_channels: usize) -> Vec<(ParaId, Vec<u8>)> {
Vec::new()
}
}
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, RuntimeDebug)]
pub enum ServiceQuality {
Ordered,
Fast,
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
pub trait OnValidationData {
fn on_validation_data(data: &PersistedValidationData);
}
#[derive(codec::Encode, codec::Decode, Clone)]
pub struct ParachainBlockData<B: BlockT> {
header: B::Header,
extrinsics: sp_std::vec::Vec<B::Extrinsic>,
storage_proof: sp_trie::CompactProof,
}
impl<B: BlockT> ParachainBlockData<B> {
pub fn new(
header: <B as BlockT>::Header,
extrinsics: sp_std::vec::Vec<<B as BlockT>::Extrinsic>,
storage_proof: sp_trie::CompactProof,
) -> Self {
Self { header, extrinsics, storage_proof }
}
pub fn into_block(self) -> B {
B::new(self.header, self.extrinsics)
}
pub fn into_header(self) -> B::Header {
self.header
}
pub fn header(&self) -> &B::Header {
&self.header
}
pub fn extrinsics(&self) -> &[B::Extrinsic] {
&self.extrinsics
}
pub fn storage_proof(&self) -> &sp_trie::CompactProof {
&self.storage_proof
}
pub fn deconstruct(self) -> (B::Header, sp_std::vec::Vec<B::Extrinsic>, sp_trie::CompactProof) {
(self.header, self.extrinsics, self.storage_proof)
}
}
#[derive(Clone, Debug, codec::Decode, codec::Encode, PartialEq)]
pub struct CollationInfo {
pub upward_messages: Vec<UpwardMessage>,
pub horizontal_messages: Vec<OutboundHrmpMessage>,
pub new_validation_code: Option<relay_chain::v1::ValidationCode>,
pub processed_downward_messages: u32,
pub hrmp_watermark: relay_chain::v1::BlockNumber,
}
sp_api::decl_runtime_apis! {
pub trait CollectCollationInfo {
fn collect_collation_info() -> CollationInfo;
}
}