Skip to main content

avalanche_types/subnet/config/
consensus.rs

1use serde::{Deserialize, Serialize};
2
3/// ref. <https://pkg.go.dev/github.com/ava-labs/avalanchego/snow/consensus/snowball#Parameters>
4///
5/// ref. <https://pkg.go.dev/github.com/ava-labs/avalanchego/snow/consensus/avalanche#Parameters>
6#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
7#[serde(rename_all = "camelCase")]
8pub struct SnowballParameters {
9    /// Sample size.
10    pub k: i32,
11    /// Quorum size.
12    pub alpha: i32,
13
14    /// Virtuous commit threshold.
15    pub beta_virtuous: i32,
16    /// Rogue commit threshold.
17    pub beta_rogue: i32,
18
19    /// Minimum number of concurrent polls for finalizing consensus.
20    pub concurrent_repolls: i32,
21    /// Optimal number of processing containers in consensus.
22    pub optimal_processing: i32,
23
24    /// Maximum number of processing items to be considered healthy.
25    pub max_outstanding_items: i32,
26    /// Maximum amount of time an item should be processing and still be healthy.
27    pub max_item_processing_time: i64,
28
29    pub mixed_query_num_push_vdr: i32,
30    pub mixed_query_num_push_non_vdr: i32,
31}
32
33impl Default for SnowballParameters {
34    /// The defaults do not match with the ones in avalanchego,
35    /// as this is for avalanche-ops based deployments.
36    fn default() -> Self {
37        Self {
38            k: 20,
39            alpha: 15,
40            beta_virtuous: 15,
41            beta_rogue: 20,
42            concurrent_repolls: 4,
43            optimal_processing: 50,
44            max_outstanding_items: 1024,
45            max_item_processing_time: 2 * 1000 * 1000 * 1000, // 2-minute
46            mixed_query_num_push_vdr: 10,
47            mixed_query_num_push_non_vdr: 0,
48        }
49    }
50}
51
52#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
53#[serde(rename_all = "camelCase")]
54pub struct Parameters {
55    /// Embeds "SnowballParameters" at the same level as other fields.
56    #[serde(flatten)]
57    pub snowball_parameters: SnowballParameters,
58    pub parents: i32,
59    pub batch_size: i32,
60}
61
62impl Default for Parameters {
63    /// The defaults do not match with the ones in avalanchego,
64    /// as this is for avalanche-ops based deployments.
65    fn default() -> Self {
66        Self {
67            snowball_parameters: SnowballParameters::default(),
68            parents: 5,
69            batch_size: 30,
70        }
71    }
72}