sc_mixnet/config.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19pub use mixnet::core::Config as CoreConfig;
20use std::time::Duration;
21
22/// Substrate-specific mixnet configuration.
23#[derive(Clone, Debug)]
24pub struct SubstrateConfig {
25 /// Attempt to register the local node as a mixnode?
26 pub register: bool,
27 /// Maximum number of incoming mixnet connections to accept from non-mixnodes. If the local
28 /// node will never be a mixnode, this can be set to 0.
29 pub num_gateway_slots: u32,
30
31 /// Number of requests to the mixnet service that can be buffered, in addition to the one per
32 /// [`Api`](super::api::Api) instance. Note that this does not include requests that are being
33 /// actively handled.
34 pub request_buffer: usize,
35 /// Used to determine the number of SURBs to include in request messages: the maximum number of
36 /// SURBs needed for a single reply is multiplied by this. This should not be set to 0.
37 pub surb_factor: usize,
38
39 /// Maximum number of submit extrinsic requests waiting for their delay to elapse. When at the
40 /// limit, any submit extrinsic requests that arrive will simply be dropped.
41 pub extrinsic_queue_capacity: usize,
42 /// Mean delay between receiving a submit extrinsic request and actually submitting the
43 /// extrinsic. This should really be the same for all nodes!
44 pub mean_extrinsic_delay: Duration,
45 /// Maximum number of extrinsics being actively submitted. If a submit extrinsic request's
46 /// delay elapses and we are already at this limit, the request will simply be dropped.
47 pub max_pending_extrinsics: usize,
48}
49
50impl Default for SubstrateConfig {
51 fn default() -> Self {
52 Self {
53 register: true,
54 num_gateway_slots: 150,
55
56 request_buffer: 4,
57 surb_factor: 2,
58
59 extrinsic_queue_capacity: 50,
60 mean_extrinsic_delay: Duration::from_secs(1),
61 max_pending_extrinsics: 20,
62 }
63 }
64}
65
66/// Mixnet configuration.
67#[derive(Clone, Debug)]
68pub struct Config {
69 /// Core configuration.
70 pub core: CoreConfig,
71 /// Request manager configuration.
72 pub request_manager: mixnet::request_manager::Config,
73 /// Reply manager configuration.
74 pub reply_manager: mixnet::reply_manager::Config,
75 /// Substrate-specific configuration.
76 pub substrate: SubstrateConfig,
77}
78
79impl Default for Config {
80 fn default() -> Self {
81 Self {
82 core: Default::default(),
83 request_manager: Default::default(),
84 reply_manager: Default::default(),
85 substrate: Default::default(),
86 }
87 }
88}