hotshot_types/
hotshot_config_file.rs1use std::{num::NonZeroUsize, time::Duration};
8
9use alloy::primitives::U256;
10use url::Url;
11use vec1::Vec1;
12
13use crate::{
14 constants::REQUEST_DATA_DELAY, upgrade_config::UpgradeConfig, HotShotConfig, NodeType,
15 PeerConfig, ValidatorConfig,
16};
17
18fn default_builder_urls() -> Vec1<Url> {
20 vec1::vec1![Url::parse("http://0.0.0.0:3311").unwrap()]
21}
22
23#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
25#[serde(bound(deserialize = ""))]
26pub struct HotShotConfigFile<TYPES: NodeType> {
27 pub start_threshold: (u64, u64),
30 pub num_nodes_with_stake: NonZeroUsize,
32 #[serde(skip)]
33 pub known_nodes_with_stake: Vec<PeerConfig<TYPES>>,
35 #[serde(skip)]
36 pub known_da_nodes: Vec<PeerConfig<TYPES>>,
38 pub staked_da_nodes: usize,
40 pub fixed_leader_for_gpuvid: usize,
42 pub next_view_timeout: u64,
44 pub view_sync_timeout: Duration,
46 pub num_bootstrap: usize,
48 pub builder_timeout: Duration,
50 pub data_request_delay: Option<Duration>,
52 #[serde(default = "default_builder_urls")]
54 pub builder_urls: Vec1<Url>,
55 pub upgrade: UpgradeConfig,
57 pub epoch_height: u64,
59 pub epoch_start_block: u64,
61}
62
63impl<TYPES: NodeType> From<HotShotConfigFile<TYPES>> for HotShotConfig<TYPES> {
64 fn from(val: HotShotConfigFile<TYPES>) -> Self {
65 HotShotConfig {
66 start_threshold: val.start_threshold,
67 num_nodes_with_stake: val.num_nodes_with_stake,
68 known_da_nodes: val.known_da_nodes,
69 known_nodes_with_stake: val.known_nodes_with_stake,
70 da_staked_committee_size: val.staked_da_nodes,
71 fixed_leader_for_gpuvid: val.fixed_leader_for_gpuvid,
72 next_view_timeout: val.next_view_timeout,
73 view_sync_timeout: val.view_sync_timeout,
74 num_bootstrap: val.num_bootstrap,
75 builder_timeout: val.builder_timeout,
76 data_request_delay: val
77 .data_request_delay
78 .unwrap_or(Duration::from_millis(REQUEST_DATA_DELAY)),
79 builder_urls: val.builder_urls,
80 start_proposing_view: val.upgrade.start_proposing_view,
81 stop_proposing_view: val.upgrade.stop_proposing_view,
82 start_voting_view: val.upgrade.start_voting_view,
83 stop_voting_view: val.upgrade.stop_voting_view,
84 start_proposing_time: val.upgrade.start_proposing_time,
85 stop_proposing_time: val.upgrade.stop_proposing_time,
86 start_voting_time: val.upgrade.start_voting_time,
87 stop_voting_time: val.upgrade.stop_voting_time,
88 epoch_height: val.epoch_height,
89 epoch_start_block: val.epoch_start_block,
90 }
91 }
92}
93
94impl<TYPES: NodeType> HotShotConfigFile<TYPES> {
95 #[must_use]
101 pub fn hotshot_config_5_nodes_10_da() -> Self {
102 let staked_da_nodes: usize = 5;
103
104 let mut known_da_nodes = Vec::new();
105
106 let gen_known_nodes_with_stake = (0..10)
107 .map(|node_id| {
108 let mut cur_validator_config: ValidatorConfig<TYPES> =
109 ValidatorConfig::generated_from_seed_indexed(
110 [0u8; 32],
111 node_id,
112 U256::from(1),
113 false,
114 );
115
116 if node_id < staked_da_nodes as u64 {
117 known_da_nodes.push(cur_validator_config.public_config());
118 cur_validator_config.is_da = true;
119 }
120
121 cur_validator_config.public_config()
122 })
123 .collect();
124
125 Self {
126 num_nodes_with_stake: NonZeroUsize::new(10).unwrap(),
127 start_threshold: (1, 1),
128 known_nodes_with_stake: gen_known_nodes_with_stake,
129 staked_da_nodes,
130 known_da_nodes,
131 fixed_leader_for_gpuvid: 1,
132 next_view_timeout: 10000,
133 view_sync_timeout: Duration::from_millis(1000),
134 num_bootstrap: 5,
135 builder_timeout: Duration::from_secs(10),
136 data_request_delay: Some(Duration::from_millis(REQUEST_DATA_DELAY)),
137 builder_urls: default_builder_urls(),
138 upgrade: UpgradeConfig::default(),
139 epoch_height: 0,
140 epoch_start_block: 0,
141 }
142 }
143}