Skip to content

Commit a09bb19

Browse files
committed
switch to vec of versioneddacommittee
1 parent ebd970c commit a09bb19

File tree

5 files changed

+40
-69
lines changed

5 files changed

+40
-69
lines changed

crates/hotshot/types/src/hotshot_config_file.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
// You should have received a copy of the MIT License
55
// along with the HotShot repository. If not, see <https://mit-license.org/>.
66

7-
use std::{collections::BTreeMap, num::NonZeroUsize, time::Duration};
7+
use std::{num::NonZeroUsize, time::Duration};
88

99
use alloy::primitives::U256;
1010
use url::Url;
11-
use vbs::version::Version;
1211
use vec1::Vec1;
1312

1413
use crate::{
1514
constants::REQUEST_DATA_DELAY, upgrade_config::UpgradeConfig, HotShotConfig, NodeType,
16-
PeerConfig, ValidatorConfig,
15+
PeerConfig, ValidatorConfig, VersionedDaCommittee,
1716
};
1817

1918
/// Default builder URL, used as placeholder
@@ -48,7 +47,7 @@ pub struct HotShotConfigFile<TYPES: NodeType> {
4847
pub known_da_nodes: Vec<PeerConfig<TYPES>>,
4948
#[serde(skip)]
5049
/// The known DA nodes' public keys and stake values, by start epoch
51-
pub da_committees: BTreeMap<Version, BTreeMap<u64, Vec<PeerConfig<TYPES>>>>,
50+
pub da_committees: Vec<VersionedDaCommittee<TYPES>>,
5251
/// Number of staking DA nodes
5352
pub staked_da_nodes: usize,
5453
/// Number of fixed leaders for GPU VID

crates/hotshot/types/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// along with the HotShot repository. If not, see <https://mit-license.org/>.
66

77
//! Types and Traits for the `HotShot` consensus module
8-
use std::{
9-
collections::BTreeMap, fmt::Debug, future::Future, num::NonZeroUsize, pin::Pin, time::Duration,
10-
};
8+
use std::{fmt::Debug, future::Future, num::NonZeroUsize, pin::Pin, time::Duration};
119

1210
use alloy::primitives::U256;
1311
use bincode::Options;
@@ -184,6 +182,14 @@ impl<TYPES: NodeType> Debug for PeerConfig<TYPES> {
184182
}
185183
}
186184

185+
#[derive(Clone, derive_more::Debug, serde::Serialize, serde::Deserialize)]
186+
#[serde(bound(deserialize = ""))]
187+
pub struct VersionedDaCommittee<TYPES: NodeType> {
188+
pub start_version: Version,
189+
pub start_epoch: u64,
190+
pub committee: Vec<PeerConfig<TYPES>>,
191+
}
192+
187193
/// Holds configuration for a `HotShot`
188194
#[derive(Clone, derive_more::Debug, serde::Serialize, serde::Deserialize)]
189195
#[serde(bound(deserialize = ""))]
@@ -199,7 +205,7 @@ pub struct HotShotConfig<TYPES: NodeType> {
199205
/// All public keys known to be DA nodes
200206
pub known_da_nodes: Vec<PeerConfig<TYPES>>,
201207
/// All public keys known to be DA nodes, by start epoch
202-
pub da_committees: BTreeMap<Version, BTreeMap<u64, Vec<PeerConfig<TYPES>>>>,
208+
pub da_committees: Vec<VersionedDaCommittee<TYPES>>,
203209
/// List of DA committee (staking)nodes for static DA committee
204210
pub da_staked_committee_size: usize,
205211
/// Number of fixed leaders for GPU VID, normally it will be 0, it's only used when running GPU VID

sequencer/src/genesis.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,21 @@ pub enum L1Finalized {
4545
Timestamp { timestamp: Timestamp },
4646
}
4747

48-
/// Helper type to deal with TOML keys that are u64 but represented as strings
49-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
50-
pub struct TomlKeyU64(u64);
51-
52-
impl<'de> Deserialize<'de> for TomlKeyU64 {
53-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
54-
where
55-
D: serde::Deserializer<'de>,
56-
{
57-
tracing::warn!("Using TomlKeyU64::deserialize");
58-
let s = String::deserialize(deserializer)?;
59-
60-
let n = s
61-
.parse::<u64>()
62-
.map_err(|_| serde::de::Error::custom("invalid epoch"))?;
63-
64-
std::result::Result::Ok(TomlKeyU64(n))
65-
}
66-
}
67-
68-
impl Serialize for TomlKeyU64 {
69-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
70-
where
71-
S: serde::Serializer,
72-
{
73-
serializer.serialize_str(&self.0.to_string())
74-
}
75-
}
76-
77-
impl From<&TomlKeyU64> for u64 {
78-
fn from(val: &TomlKeyU64) -> Self {
79-
val.0
80-
}
81-
}
82-
8348
#[derive(Clone, Debug, Deserialize, Serialize)]
8449
pub struct PeerConfigData {
8550
pub stake_table_key: <SeqTypes as NodeType>::SignatureKey,
8651
pub state_ver_key: <SeqTypes as NodeType>::StateSignatureKey,
8752
pub stake: u64,
8853
}
8954

55+
#[derive(Clone, Debug, Deserialize, Serialize)]
56+
pub struct VersionedDaCommittee {
57+
#[serde(with = "version_ser")]
58+
pub start_version: Version,
59+
pub start_epoch: u64,
60+
pub committee: Vec<PeerConfigData>,
61+
}
62+
9063
/// Genesis of an Espresso chain.
9164
#[derive(Clone, Debug, Deserialize, Serialize)]
9265
pub struct Genesis {
@@ -111,7 +84,7 @@ pub struct Genesis {
11184
#[serde(default)]
11285
pub upgrades: BTreeMap<Version, Upgrade>,
11386
#[serde(default)]
114-
pub da_committees: Option<BTreeMap<Version, BTreeMap<TomlKeyU64, Vec<PeerConfigData>>>>,
87+
pub da_committees: Option<Vec<VersionedDaCommittee>>,
11588
}
11689

11790
impl Genesis {

sequencer/src/lib.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use hotshot_types::{
6565
storage::Storage,
6666
},
6767
utils::BuilderCommitment,
68-
ValidatorConfig,
68+
ValidatorConfig, VersionedDaCommittee,
6969
};
7070
pub use options::Options;
7171
use serde::{Deserialize, Serialize};
@@ -395,26 +395,20 @@ where
395395
tracing::warn!("setting da_committees from genesis");
396396
network_config.config.da_committees = da_committees
397397
.iter()
398-
.map(|(k, v)| {
399-
(
400-
*k,
401-
v.iter()
402-
.map(|(k, v)| {
403-
(
404-
k.into(),
405-
v.iter()
406-
.map(|pcd| hotshot_types::PeerConfig {
407-
stake_table_entry: StakeTableEntry {
408-
stake_key: pcd.stake_table_key,
409-
stake_amount: U256::from(pcd.stake),
410-
},
411-
state_ver_key: pcd.state_ver_key.clone(),
412-
})
413-
.collect(),
414-
)
415-
})
416-
.collect(),
417-
)
398+
.map(|src| VersionedDaCommittee::<SeqTypes> {
399+
start_version: src.start_version,
400+
start_epoch: src.start_epoch,
401+
committee: src
402+
.committee
403+
.iter()
404+
.map(|pcd| hotshot_types::PeerConfig {
405+
stake_table_entry: StakeTableEntry {
406+
stake_key: pcd.stake_table_key,
407+
stake_amount: U256::from(pcd.stake),
408+
},
409+
state_ver_key: pcd.state_ver_key.clone(),
410+
})
411+
.collect(),
418412
})
419413
.collect();
420414
}

types/src/v0/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
use std::{collections::BTreeMap, num::NonZeroUsize, time::Duration};
1+
use std::{num::NonZeroUsize, time::Duration};
22

33
use hotshot_types::{
44
network::{
55
BuilderType, CombinedNetworkConfig, Libp2pConfig, NetworkConfig, RandomBuilderConfig,
66
},
7-
HotShotConfig, PeerConfig, ValidatorConfig,
7+
HotShotConfig, PeerConfig, ValidatorConfig, VersionedDaCommittee,
88
};
99
use serde::{Deserialize, Serialize};
1010
use tide_disco::Url;
11-
use vbs::version::Version;
1211
use vec1::Vec1;
1312

1413
use crate::{PubKey, SeqTypes};
@@ -57,7 +56,7 @@ pub struct PublicHotShotConfig {
5756
known_nodes_with_stake: Vec<PeerConfig<SeqTypes>>,
5857
known_da_nodes: Vec<PeerConfig<SeqTypes>>,
5958
#[serde(default)]
60-
da_committees: BTreeMap<Version, BTreeMap<u64, Vec<PeerConfig<SeqTypes>>>>,
59+
da_committees: Vec<VersionedDaCommittee<SeqTypes>>,
6160
da_staked_committee_size: usize,
6261
fixed_leader_for_gpuvid: usize,
6362
next_view_timeout: u64,

0 commit comments

Comments
 (0)