Skip to content

Commit

Permalink
Load initial stake table from file
Browse files Browse the repository at this point in the history
  • Loading branch information
sveitser committed Dec 5, 2024
1 parent f926e84 commit 0862ca7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
18 changes: 17 additions & 1 deletion contracts/rust/adapter/src/stake_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethers::{
prelude::{AbiError, EthAbiCodec, EthAbiType},
types::U256,
};
use hotshot_types::{light_client::StateVerKey, signature_key::BLSPubKey};
use hotshot_types::{light_client::StateVerKey, network::PeerConfigKeys, signature_key::BLSPubKey};
use serde::{Deserialize, Serialize};
use std::str::FromStr;

Expand Down Expand Up @@ -174,3 +174,19 @@ impl From<NodeInfo> for NodeInfoJf {
.into()
}
}

impl From<PeerConfigKeys<BLSPubKey>> for NodeInfoJf {
fn from(value: PeerConfigKeys<BLSPubKey>) -> Self {
let PeerConfigKeys {
stake_table_key,
state_ver_key,
da,
..
} = value;
Self {
stake_table_key,
state_ver_key,
da,
}
}
}
5 changes: 1 addition & 4 deletions sequencer/src/bin/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{fs::File, io::stdout, path::PathBuf};

use clap::Parser;
use espresso_types::PubKey;
use ethers::types::Address;
use futures::FutureExt;
use hotshot_stake_table::config::STAKE_TABLE_CAPACITY;
Expand Down Expand Up @@ -143,9 +142,7 @@ async fn main() -> anyhow::Result<()> {
let genesis = light_client_genesis(&sequencer_url, opt.stake_table_capacity).boxed();

let initial_stake_table = if let Some(path) = opt.initial_stake_table_path {
Some(PermissionedStakeTableConfig::<PubKey>::from_toml_file(
&path,
)?)
Some(PermissionedStakeTableConfig::from_toml_file(&path)?.into())
} else {
None
};
Expand Down
12 changes: 5 additions & 7 deletions utils/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use contract_bindings::{
light_client_mock::LIGHTCLIENTMOCK_ABI,
light_client_state_update_vk::LightClientStateUpdateVK,
light_client_state_update_vk_mock::LightClientStateUpdateVKMock,
permissioned_stake_table::PermissionedStakeTable,
permissioned_stake_table::{NodeInfo, PermissionedStakeTable},
plonk_verifier::PlonkVerifier,
};
use derive_more::Display;
Expand Down Expand Up @@ -311,7 +311,7 @@ pub async fn deploy_mock_light_client_contract<M: Middleware + 'static>(
}

#[allow(clippy::too_many_arguments)]
pub async fn deploy<K: SignatureKey>(
pub async fn deploy(
l1url: Url,
mnemonic: String,
account_index: u32,
Expand All @@ -321,7 +321,7 @@ pub async fn deploy<K: SignatureKey>(
genesis: BoxFuture<'_, anyhow::Result<(ParsedLightClientState, ParsedStakeTableState)>>,
permissioned_prover: Option<Address>,
mut contracts: Contracts,
initial_stake_table: Option<PermissionedStakeTableConfig<K>>,
initial_stake_table: Option<Vec<NodeInfo>>,
) -> anyhow::Result<Contracts> {
let provider = Provider::<Http>::try_from(l1url.to_string())?;
let chain_id = provider.get_chainid().await?.as_u64();
Expand Down Expand Up @@ -442,13 +442,11 @@ pub async fn deploy<K: SignatureKey>(

// `PermissionedStakeTable.sol`
if should_deploy(ContractGroup::PermissionedStakeTable, &only) {
let initial_stake_table: Vec<_> = initial_stake_table.unwrap_or_default();
let stake_table_address = contracts
.deploy_tx(
Contract::PermissonedStakeTable,
PermissionedStakeTable::deploy(
l1.clone(),
(), // TODO initial stake table
)?,
PermissionedStakeTable::deploy(l1.clone(), initial_stake_table)?,
)
.await?;
let stake_table = PermissionedStakeTable::new(stake_table_address, l1.clone());
Expand Down
38 changes: 19 additions & 19 deletions utils/src/stake_table.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
/// Utilities for loading an initial permissioned stake table from a toml file.
///
/// The initial stake table is passed to the permissioned stake table contract
/// on deployment.
use contract_bindings::permissioned_stake_table::NodeInfo;
use hotshot::types::SignatureKey;
use hotshot_contract_adapter::stake_table::ParsedEdOnBN254Point;
use hotshot::types::{BLSPubKey, SignatureKey};
use hotshot_contract_adapter::stake_table::{NodeInfoJf, ParsedEdOnBN254Point};
use hotshot_types::network::PeerConfigKeys;
use std::{fs, path::Path};

/// A stake table config stored in a file
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(bound(deserialize = ""))]
pub struct PermissionedStakeTableConfig<K: SignatureKey> {
pub struct PermissionedStakeTableConfig {
/// The list of public keys that are initially inserted into the
/// permissioned stake table contract.
#[serde(default)]
pub public_keys: Vec<PeerConfigKeys<K>>,
pub public_keys: Vec<PeerConfigKeys<BLSPubKey>>,
}

impl<K: SignatureKey> PermissionedStakeTableConfig<K> {
impl PermissionedStakeTableConfig {
pub fn from_toml_file(path: &Path) -> anyhow::Result<Self> {
let config_file_as_string: String = fs::read_to_string(path)
.unwrap_or_else(|_| panic!("Could not read config file located at {}", path.display()));

Ok(
toml::from_str::<Self>(&config_file_as_string).expect(&format!(
"Unable to convert config file {} to TOML",
path.display()
)),
toml::from_str::<Self>(&config_file_as_string).unwrap_or_else(|err| {
panic!(
"Unable to convert config file {} to TOML: {err}",
path.display()
)
}),
)
}
}

impl<K: SignatureKey> From<PermissionedStakeTableConfig<K>> for Vec<NodeInfo> {
fn from(value: PermissionedStakeTableConfig<K>) -> Self {
impl From<PermissionedStakeTableConfig> for Vec<NodeInfo> {
fn from(value: PermissionedStakeTableConfig) -> Self {
value
.public_keys
.into_iter()
.map(|peer_config| {
let g1: ParsedEdOnBN254Point = peer_config.state_ver_key.to_affine().into();
// XXX We don't have a trait on the Bls key to provide .to_affine()
// let g2: ParsedG2Point = peer_config.stake_table_key.to_affine().into();
NodeInfo {
bls_vk: todo!(),
schnorr_vk: g1.into(),
is_da: peer_config.da,
}
let node_info: NodeInfoJf = peer_config.clone().into();
node_info.into()
})
.collect()
}
Expand Down

0 comments on commit 0862ca7

Please sign in to comment.