sp_mixnet/
runtime_api.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Runtime API for querying mixnet configuration and registering mixnodes.
19
20use super::types::{Mixnode, MixnodesErr, SessionIndex, SessionStatus};
21use alloc::vec::Vec;
22
23sp_api::decl_runtime_apis! {
24	/// API to query the mixnet session status and mixnode sets, and to register mixnodes.
25	pub trait MixnetApi {
26		/// Get the index and phase of the current session.
27		fn session_status() -> SessionStatus;
28
29		/// Get the mixnode set for the previous session.
30		fn prev_mixnodes() -> Result<Vec<Mixnode>, MixnodesErr>;
31
32		/// Get the mixnode set for the current session.
33		fn current_mixnodes() -> Result<Vec<Mixnode>, MixnodesErr>;
34
35		/// Try to register a mixnode for the next session.
36		///
37		/// If a registration extrinsic is submitted, `true` is returned. The caller should avoid
38		/// calling `maybe_register` again for a few blocks, to give the submitted extrinsic a
39		/// chance to get included.
40		///
41		/// With the above exception, `maybe_register` is designed to be called every block. Most
42		/// of the time it will not do anything, for example:
43		///
44		/// - If it is not an appropriate time to submit a registration extrinsic.
45		/// - If the local node has already registered a mixnode for the next session.
46		/// - If the local node is not permitted to register a mixnode for the next session.
47		///
48		/// `session_index` should match `session_status().current_index`; if it does not, `false`
49		/// is returned immediately.
50		fn maybe_register(session_index: SessionIndex, mixnode: Mixnode) -> bool;
51	}
52}