diff --git a/data/initial_stake_table.toml b/data/initial_stake_table.toml index 3bdf97ad3..59384a650 100644 --- a/data/initial_stake_table.toml +++ b/data/initial_stake_table.toml @@ -2,24 +2,29 @@ stake_table_key = "BLS_VER_KEY~bQszS-QKYvUij2g20VqS8asttGSb95NrTu2PUj0uMh1CBUxNy1FqyPDjZqB29M7ZbjWqj79QkEOWkpga84AmDYUeTuWmy-0P1AdKHD3ehc-dKvei78BDj5USwXPJiDUlCxvYs_9rWYhagaq-5_LXENr78xel17spftNd5MA1Mw5U" state_ver_key = "SCHNORR_VER_KEY~ibJCbfPOhDoURqiGLe683TDJ_KOLQCx8_Hdq43dOviSuL6WJJ_2mARKO3xA2k5zpXE3iiq4_z7mzvA-V1VXvIWw" da = true +stake = 1 [[public_keys]] stake_table_key = "BLS_VER_KEY~4zQnaCOFJ7m95OjxeNls0QOOwWbz4rfxaL3NwmN2zSdnf8t5Nw_dfmMHq05ee8jCegw6Bn5T8inmrnGGAsQJMMWLv77nd7FJziz2ViAbXg-XGGF7o4HyzELCmypDOIYF3X2UWferFE_n72ZX0iQkUhOvYZZ7cfXToXxRTtb_mwRR" state_ver_key = "SCHNORR_VER_KEY~lNCMqH5qLthH5OXxW_Z25tLXJUqmzzhsuQ6oVuaPWhtRPmgIKSqcBoJTaEbmGZL2VfTyQNguaoQL4U_4tCA_HmI" da = true +stake = 1 [[public_keys]] stake_table_key = "BLS_VER_KEY~IBRoz_Q1EXvcm1pNZcmVlyYZU8hZ7qmy337ePAjEMhz8Hl2q8vWPFOd3BaLwgRS1UzAPW3z4E-XIgRDGcRBTAMZX9b_0lKYjlyTlNF2EZfNnKmvv-xJ0yurkfjiveeYEsD2l5d8q_rJJbH1iZdXy-yPEbwI0SIvQfwdlcaKw9po4" state_ver_key = "SCHNORR_VER_KEY~nkFKzpLhJAafJ3LBkY_0h9OzxSyTu95Z029EUFPO4QNkeUo6DHQGTTVjxmprTA5H8jRSn73i0slJvig6dZ5kLX4" da = true +stake = 1 [[public_keys]] stake_table_key = "BLS_VER_KEY~rO2PIjyY30HGfapFcloFe3mNDKMIFi6JlOLkH5ZWBSYoRm5fE2-Rm6Lp3EvmAcB5r7KFJ0c1Uor308x78r04EY_sfjcsDCWt7RSJdL4cJoD_4fSTCv_bisO8k98hs_8BtqQt8BHlPeJohpUXvcfnK8suXJETiJ6Er97pfxRbzgAL" state_ver_key = "SCHNORR_VER_KEY~NwYhzlWarlZHxTNvChWuf74O3fP7zIt5NdC7V8gV6w2W92JOBDkrNmKQeMGxMUke-G5HHxUjHlZEWr1m1xLjEaI" da = false +stake = 1 [[public_keys]] stake_table_key = "BLS_VER_KEY~r6b-Cwzp-b3czlt0MHmYPJIow5kMsXbrNmZsLSYg9RV49oCCO4WEeCRFR02x9bqLCa_sgNFMrIeNdEa11qNiBAohApYFIvrSa-zP5QGj3xbZaMOCrshxYit6E2TR-XsWvv6gjOrypmugjyTAth-iqQzTboSfmO9DD1-gjJIdCaD7" state_ver_key = "SCHNORR_VER_KEY~qMfMj1c1hRVTnugvz3MKNnVC5JA9jvZcV3ZCLL_J4Ap-u0i6ulGWveTk3OOelZj2-kd_WD5ojtYGWV1jHx9wCaA" -da = true \ No newline at end of file +da = true +stake = 1 \ No newline at end of file diff --git a/utils/src/stake_table.rs b/utils/src/stake_table.rs index aa668eb25..0b3236083 100644 --- a/utils/src/stake_table.rs +++ b/utils/src/stake_table.rs @@ -5,11 +5,8 @@ use contract_bindings::permissioned_stake_table::NodeInfo; use hotshot::types::BLSPubKey; use hotshot_contract_adapter::stake_table::NodeInfoJf; -use hotshot_types::{light_client::StateVerKey, network::PeerConfigKeys}; -use serde::{ - de::{SeqAccess, Visitor}, - Deserializer, -}; +use hotshot_types::network::PeerConfigKeys; + use std::{fs, path::Path}; /// A stake table config stored in a file @@ -19,64 +16,9 @@ pub struct PermissionedStakeTableConfig { /// The list of public keys that are initially inserted into the /// permissioned stake table contract. #[serde(default)] - // Custom deserialization to handle toml file where the "stake" field is not provided. - // Defaults the "stake" field to 1 if not specified. - #[serde(deserialize_with = "deserialize_peer_config_keys")] pub public_keys: Vec>, } -fn deserialize_peer_config_keys<'de, D>( - deserializer: D, -) -> Result>, D::Error> -where - D: Deserializer<'de>, -{ - struct PeerConfigKeysVisitor; - - // We deserialize the toml file entries into this struct which contains optional stake field. - // which is then converted into `PeerConfigKeys` - #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] - pub struct PeerConfigKeysOptionalStakeField { - pub stake_table_key: BLSPubKey, - pub state_ver_key: StateVerKey, - pub stake: Option, - pub da: bool, - } - - impl<'de> Visitor<'de> for PeerConfigKeysVisitor { - type Value = Vec>; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("peer config keys") - } - - fn visit_seq(self, mut seq: A) -> Result>, A::Error> - where - A: SeqAccess<'de>, - { - let mut keys = vec![]; - while let Some(PeerConfigKeysOptionalStakeField { - stake_table_key, - state_ver_key, - stake, - da, - }) = seq.next_element::()? - { - keys.push(PeerConfigKeys { - stake_table_key, - state_ver_key, - stake: stake.unwrap_or(1), - da, - }); - } - - Ok(keys) - } - } - - deserializer.deserialize_seq(PeerConfigKeysVisitor) -} - impl PermissionedStakeTableConfig { pub fn from_toml_file(path: &Path) -> anyhow::Result { let config_file_as_string: String = fs::read_to_string(path) @@ -158,6 +100,7 @@ mod test { [[public_keys]] stake_table_key = st_key_3 state_ver_key = verkey_3 + stake = 2 da = da_3 } @@ -190,6 +133,6 @@ mod test { keys[2].stake_table_key ); assert_eq!(toml_st.public_keys[2].da, da_3); - assert_eq!(toml_st.public_keys[2].stake, 1); + assert_eq!(toml_st.public_keys[2].stake, 2); } }