Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key Management and Config File for Validator Onboarding #1990

Merged
merged 43 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
134d39a
remove some generated_from_seed_indexed()
dailinsubjam Oct 12, 2023
21061fe
remove some generated_from_seed_indexed()
dailinsubjam Oct 12, 2023
1189edb
fix lint
dailinsubjam Oct 12, 2023
45208dc
solve conflict
dailinsubjam Oct 12, 2023
9a856fe
make the key pair configurable
dailinsubjam Oct 13, 2023
615037b
get keypair and stakevalue from config in modDA.rs
dailinsubjam Oct 13, 2023
974357a
initialize known_nodes_sk
dailinsubjam Oct 13, 2023
d3374fe
generated_from_seed_indexed only appear in initialization or generato…
dailinsubjam Oct 13, 2023
e42635f
let the stake value be extractable if needed rather than assign 1u64 …
dailinsubjam Oct 13, 2023
41b287f
unwrap() to expect()
dailinsubjam Oct 13, 2023
fc81a8b
avoid too many generic type for OrchestratorState
dailinsubjam Oct 13, 2023
319a336
avoid too many generic type for NetworkConfig
dailinsubjam Oct 13, 2023
4a17875
avoid too many generic type for OrchestratorApi
dailinsubjam Oct 13, 2023
eaea764
fix lint
dailinsubjam Oct 13, 2023
0958125
add validator structure in config.rs
Oct 24, 2023
4e4fcbf
add validator config with default value
dailinsubjam Oct 24, 2023
87c5de6
simplify hotshot and add node's validator info to hotshotconfig
dailinsubjam Oct 26, 2023
0f97b09
move validator config from NetworkConfig to HotshotConfigFile
dailinsubjam Oct 26, 2023
c7ea1a3
fix lint
dailinsubjam Oct 26, 2023
f4197f9
remove useless comment
dailinsubjam Oct 26, 2023
dbe6450
merge, but why view number could be 0
dailinsubjam Oct 26, 2023
8d5c308
cargo update but now the issue is in block_impl.rs called unwrap() on…
dailinsubjam Oct 26, 2023
992fc67
solve view number overflow and downgrade to original cargo.lock
dailinsubjam Oct 26, 2023
3d36e9c
fix lint
dailinsubjam Oct 26, 2023
07e1f86
fix lint, PartialOrd for Key
dailinsubjam Oct 26, 2023
7958ec8
get other nodes' info during initialization
dailinsubjam Oct 26, 2023
83bedc7
fix lint
dailinsubjam Oct 26, 2023
362199d
add some comments and make sure key generation is only in system init…
dailinsubjam Oct 26, 2023
7acc7b2
Merge pull request #1949 from EspressoSystems/sishan/default_config_p…
dailinsubjam Oct 26, 2023
2b31188
add struct ValidatorConfigFile
dailinsubjam Oct 31, 2023
ac71f6b
add validator config file
dailinsubjam Nov 1, 2023
440ab12
Add validator config
dailinsubjam Nov 1, 2023
3319f38
Merge pull request #1964 from EspressoSystems/sishan/config_file_vali…
dailinsubjam Nov 1, 2023
091727c
fix lint
dailinsubjam Nov 1, 2023
4f1fa04
make config file path configurable
dailinsubjam Nov 2, 2023
753f4e5
scripts for generating key pairs added
dailinsubjam Nov 3, 2023
e571008
fix lint
dailinsubjam Nov 3, 2023
a73c690
forget to add new file for validator config
dailinsubjam Nov 3, 2023
aab444f
blank line at the end of the file
dailinsubjam Nov 3, 2023
66f5507
Merge pull request #1980 from EspressoSystems/sishan/scripts_gen_keypair
dailinsubjam Nov 3, 2023
9baa152
Merge branch 'sishan/validator_onboarding' into sishan/merge_validato…
dailinsubjam Nov 3, 2023
0ca0a4f
Update mod.rs for larger timeout duration
dailinsubjam Nov 9, 2023
4185ee5
Revert "Update mod.rs for larger timeout duration"
dailinsubjam Nov 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions config/ValidatorConfigExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ValidatorConfig {
public_key: BLSPubKey {
pub_key: VerKey(
(
QuadExtField(
2264797523581107490935262917175769123227923636811928330606075281145117212394
+ 15807017392833049888165434456991157794698032464874424842715555348468160607934 * u
),
QuadExtField(
7996517616082121122160563552650547601395271017260499735456299700133762512689
+ 7504045709281061282278228438613345070383424761478787301859187055302953740948 * u
),
QuadExtField(
1515973040548822760825076242090160370742046237881440422068330135941139244581
+ 20251846261653098602911417004145145971080304248810966341160788194007704966108 * u
)
)
)
},
private_key: BLSPrivKey {
priv_key: SignKey(
BigInt(
[3505488234151006356, 6655477166151225138, 3291219027844407676, 2153641080015542578]
)
)
},
stake_value: 1
}
2 changes: 2 additions & 0 deletions config/ValidatorConfigFile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
seed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
node_id = 0
1 change: 1 addition & 0 deletions config/ValidatorConfigOutput
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ValidatorConfig { public_key: BLSPubKey { pub_key: VerKey((QuadExtField(2264797523581107490935262917175769123227923636811928330606075281145117212394 + 15807017392833049888165434456991157794698032464874424842715555348468160607934 * u), QuadExtField(7996517616082121122160563552650547601395271017260499735456299700133762512689 + 7504045709281061282278228438613345070383424761478787301859187055302953740948 * u), QuadExtField(1515973040548822760825076242090160370742046237881440422068330135941139244581 + 20251846261653098602911417004145145971080304248810966341160788194007704966108 * u))) }, private_key: BLSPrivKey { priv_key: SignKey(BigInt([3505488234151006356, 6655477166151225138, 3291219027844407676, 2153641080015542578])) }, stake_value: 1 }
7 changes: 2 additions & 5 deletions crates/hotshot-signature-key/src/bn254/bn254_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use std::cmp::Ordering;

/// Private key type for a bn254 keypair
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug)]
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Hash)]
pub struct BLSPrivKey {
/// The private key for this keypair
pub(super) priv_key: QCSignKey,
Expand Down Expand Up @@ -54,12 +54,9 @@ impl BLSPrivKey {
}
}

#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this as long as it still works as intended ! I wonder why we implemented it this way to begin with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering about that. In the beginning the implementation on this was very long ago, and later implementation just follow that. There are more discussions on whether we want to keep this on zullip.

impl PartialOrd for BLSPrivKey {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let self_bytes = &self.priv_key.to_string();
let other_bytes = &other.priv_key.to_string();
self_bytes.partial_cmp(other_bytes)
Some(self.cmp(other))
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/hotshot-signature-key/src/bn254/bn254_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ pub struct BLSPubKey {
pub_key: VerKey,
}

#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
impl PartialOrd for BLSPubKey {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let self_bytes = &self.pub_key.to_string();
let other_bytes = &other.pub_key.to_string();
self_bytes.partial_cmp(other_bytes)
Some(self.cmp(other))
}
}

Expand Down
113 changes: 24 additions & 89 deletions crates/hotshot/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,14 @@ pub struct OrchestratorArgs {
/// Reads a network configuration from a given filepath
pub fn load_config_from_file<TYPES: NodeType>(
config_file: String,
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> {
) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
let config_file_as_string: String = fs::read_to_string(config_file.as_str())
.unwrap_or_else(|_| panic!("Could not read config file located at {config_file}"));
let config_toml: NetworkConfigFile =
toml::from_str::<NetworkConfigFile>(&config_file_as_string)
let config_toml: NetworkConfigFile<TYPES::SignatureKey> =
Copy link
Collaborator

@rob-maron rob-maron Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is clean! Love it

toml::from_str::<NetworkConfigFile<TYPES::SignatureKey>>(&config_file_as_string)
.expect("Unable to convert config file to TOML");

let mut config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> = config_toml.into();

// Generate network's public keys
let known_nodes: Vec<_> = (0..config.config.total_nodes.get())
.map(|node_id| {
TYPES::SignatureKey::generated_from_seed_indexed(
config.seed,
node_id.try_into().unwrap(),
)
.0
})
.collect();

config.config.known_nodes_with_stake = (0..config.config.total_nodes.get())
.map(|node_id| known_nodes[node_id].get_stake_table_entry(1u64))
.collect();

let config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> = config_toml.into();
config
}

Expand Down Expand Up @@ -238,11 +214,7 @@ pub trait RunDA<
{
/// Initializes networking, returns self
async fn initialize_networking(
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
) -> Self;

/// Initializes the genesis state and HotShot instance; does not start HotShot consensus
Expand All @@ -258,8 +230,8 @@ pub trait RunDA<
let config = self.get_config();

// Get KeyPair for certificate Aggregation
let (pk, sk) =
TYPES::SignatureKey::generated_from_seed_indexed(config.seed, config.node_index);
let pk = config.config.my_own_validator_config.public_key.clone();
let sk = config.config.my_own_validator_config.private_key.clone();
let known_nodes_with_stake = config.config.known_nodes_with_stake.clone();
let entry = pk.get_stake_table_entry(1u64);

Expand Down Expand Up @@ -426,13 +398,7 @@ pub trait RunDA<
fn get_vid_network(&self) -> VIDNETWORK;

/// Returns the config for this run
fn get_config(
&self,
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>;
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>;
}

// WEB SERVER
Expand All @@ -443,11 +409,7 @@ pub struct WebServerDARun<
I: NodeImplementation<TYPES>,
MEMBERSHIP: Membership<TYPES>,
> {
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
quorum_network: WebCommChannel<TYPES, I, MEMBERSHIP>,
da_network: WebCommChannel<TYPES, I, MEMBERSHIP>,
view_sync_network: WebCommChannel<TYPES, I, MEMBERSHIP>,
Expand Down Expand Up @@ -516,18 +478,10 @@ where
Self: Sync,
{
async fn initialize_networking(
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
) -> WebServerDARun<TYPES, NODE, MEMBERSHIP> {
// Generate our own key
let (pub_key, _priv_key) =
<<TYPES as NodeType>::SignatureKey as SignatureKey>::generated_from_seed_indexed(
config.seed,
config.node_index,
);
// Get our own key
let pub_key = config.config.my_own_validator_config.public_key.clone();

// Get the configuration for the web server
let WebServerConfig {
Expand Down Expand Up @@ -599,13 +553,7 @@ where
self.vid_network.clone()
}

fn get_config(
&self,
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> {
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
self.config.clone()
}
}
Expand All @@ -615,11 +563,7 @@ where
/// Represents a libp2p-based run
pub struct Libp2pDARun<TYPES: NodeType, I: NodeImplementation<TYPES>, MEMBERSHIP: Membership<TYPES>>
{
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
quorum_network: Libp2pCommChannel<TYPES, I, MEMBERSHIP>,
da_network: Libp2pCommChannel<TYPES, I, MEMBERSHIP>,
view_sync_network: Libp2pCommChannel<TYPES, I, MEMBERSHIP>,
Expand Down Expand Up @@ -688,17 +632,9 @@ where
Self: Sync,
{
async fn initialize_networking(
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
) -> Libp2pDARun<TYPES, NODE, MEMBERSHIP> {
let (pubkey, _privkey) =
<<TYPES as NodeType>::SignatureKey as SignatureKey>::generated_from_seed_indexed(
config.seed,
config.node_index,
);
let pubkey = config.config.my_own_validator_config.public_key.clone();
let mut config = config;
let libp2p_config = config
.libp2p_config
Expand Down Expand Up @@ -779,8 +715,13 @@ where
let mut all_keys = BTreeSet::new();
let mut da_keys = BTreeSet::new();
for i in 0..config.config.total_nodes.get() as u64 {
let privkey = TYPES::SignatureKey::generated_from_seed_indexed([0u8; 32], i).1;
let pubkey = TYPES::SignatureKey::from_private(&privkey);
let pubkey = <<TYPES as NodeType>::SignatureKey>::get_public_key(
config
.config
.known_nodes_with_stake
.get(i as usize)
.expect("node_id should be within the range of known_nodes"),
);
if i < config.config.da_committee_size as u64 {
da_keys.insert(pubkey.clone());
}
Expand Down Expand Up @@ -848,13 +789,7 @@ where
self.vid_network.clone()
}

fn get_config(
&self,
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> {
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
self.config.clone()
}
}
Expand Down
15 changes: 3 additions & 12 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ pub struct SystemContextInner<TYPES: NodeType, I: NodeImplementation<TYPES>> {
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,

/// Configuration items for this hotshot instance
config: HotShotConfig<
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: HotShotConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,

/// Networking interface for this hotshot instance
// networking: I::Networking,
Expand Down Expand Up @@ -172,10 +169,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
public_key: TYPES::SignatureKey,
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
nonce: u64,
config: HotShotConfig<
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: HotShotConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
storage: I::Storage,
exchanges: I::Exchanges,
initializer: HotShotInitializer<TYPES, I::Leaf>,
Expand Down Expand Up @@ -380,10 +374,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
public_key: TYPES::SignatureKey,
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
node_id: u64,
config: HotShotConfig<
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
config: HotShotConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
storage: I::Storage,
exchanges: I::Exchanges,
initializer: HotShotInitializer<TYPES, I::Leaf>,
Expand Down
2 changes: 2 additions & 0 deletions crates/hotshot/src/traits/networking/libp2p_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ where
"DA committee size must be less than or equal to total # nodes"
);
let bootstrap_addrs: PeerInfoVec = Arc::default();
// We assign known_nodes' public key and stake value rather than read from config file since it's a test
let mut all_keys = BTreeSet::new();
let mut da_keys = BTreeSet::new();

Expand All @@ -176,6 +177,7 @@ where
let addr =
// Multiaddr::from_str(&format!("/ip4/127.0.0.1/udp/0/quic-v1")).unwrap();
Multiaddr::from_str(&format!("/ip4/127.0.0.1/udp/{}{}/quic-v1", 5000 + node_id, network_id)).unwrap();
// We assign node's public key and stake value rather than read from config file since it's a test
let privkey =
TYPES::SignatureKey::generated_from_seed_indexed([0u8; 32], node_id).1;
let pubkey = TYPES::SignatureKey::from_private(&privkey);
Expand Down
1 change: 1 addition & 0 deletions crates/hotshot/src/traits/networking/memory_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>>
_is_da: bool,
) -> Box<dyn Fn(u64) -> Self + 'static> {
let master: Arc<_> = MasterMap::new();
// We assign known_nodes' public key and stake value rather than read from config file since it's a test
Box::new(move |node_id| {
let privkey = TYPES::SignatureKey::generated_from_seed_indexed([0u8; 32], node_id).1;
let pubkey = TYPES::SignatureKey::from_private(&privkey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>>
port,
));

// We assign known_nodes' public key and stake value rather than read from config file since it's a test
let known_nodes = (0..expected_node_count as u64)
.map(|id| {
TYPES::SignatureKey::from_private(
Expand Down
1 change: 1 addition & 0 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ libp2p = { workspace = true }
blake3 = { workspace = true, features = ["traits-preview"] }
hotshot-types = { version = "0.1.0", path = "../types", default-features = false }
hotshot-utils = { path = "../utils" }
hotshot-signature-key = { path = "../hotshot-signature-key" }
libp2p-networking = { workspace = true }
tide-disco = { git = "https://github.com/EspressoSystems/tide-disco.git", tag = "v0.4.1" }
surf-disco = { workspace = true }
Expand Down
Loading
Loading