Skip to content

Commit

Permalink
load stake table from toml file (#2377)
Browse files Browse the repository at this point in the history
* change lc proxy addr

* fix deploy-sequencer-contracts in docker compose

* test for stake table from toml file

* initial stake table toml file

* exclude toml file in typos

* remove custom deser
  • Loading branch information
imabdulbasit authored Dec 10, 2024
1 parent e19186a commit 77ff146
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ ESPRESSO_BUILDER_ETH_ACCOUNT_INDEX=8
ESPRESSO_DEPLOYER_ACCOUNT_INDEX=9

# Contracts
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0x0c8e79f3534b00d9a3d4a856b665bf4ebc22f2ba
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0xf7cd8fa9b94db2aa972023b379c7f72c65e4de9d
ESPRESSO_SEQUENCER_LIGHTCLIENT_ADDRESS=$ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS
ESPRESSO_SEQUENCER_PERMISSIONED_PROVER=0x14dc79964da2c08b23698b3d3cc7ca32193d9955
SPRESSO_SEQUENCER_PERMISSIONED_STAKE_TABLE_ADDRESS=0x8ce361602b935680e8dec218b820ff5056beb7af

# Example sequencer demo private keys
ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_0=BLS_SIGNING_KEY~lNDh4Pn-pTAyzyprOAFdXHwhrKhEwqwtMtkD3CZF4x3o
Expand Down
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[files]
extend-exclude = [
"data/initial_stake_table.toml",
".env",
"*.json",
"**/*.pdf",
Expand Down
30 changes: 30 additions & 0 deletions data/initial_stake_table.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[[public_keys]]
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
stake = 1
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:

deploy-sequencer-contracts:
image: ghcr.io/espressosystems/espresso-sequencer/deploy:main
command: deploy --only sequencer,permissioned-stake-table
command: deploy --only fee-contract,permissioned-stake-table
environment:
- ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS
- ESPRESSO_SEQUENCER_L1_PROVIDER
Expand Down
1 change: 1 addition & 0 deletions process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ environment:
- ESPRESSO_SEQUENCER_L1_PROVIDER=http://localhost:$ESPRESSO_SEQUENCER_L1_PORT
- ESPRESSO_SEQUENCER_GENESIS_FILE=data/genesis/demo.toml
- ESPRESSO_BUILDER_GENESIS_FILE=data/genesis/demo.toml
- ESPRESSO_SEQUENCER_INITIAL_PERMISSIONED_STAKE_TABLE_PATH=data/initial_stake_table.toml
- ESPRESSO_STATE_RELAY_SERVER_URL=http://localhost:$ESPRESSO_STATE_RELAY_SERVER_PORT
- QUERY_SERVICE_URI=http://localhost:$ESPRESSO_SEQUENCER1_API_PORT/v0/
- NODE_VALIDATOR_URI=ws://localhost:$ESPRESSO_NODE_VALIDATOR_PORT/v0/
Expand Down
13 changes: 11 additions & 2 deletions sequencer-sqlite/Cargo.lock

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

90 changes: 90 additions & 0 deletions utils/src/stake_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use contract_bindings::permissioned_stake_table::NodeInfo;
use hotshot::types::BLSPubKey;
use hotshot_contract_adapter::stake_table::NodeInfoJf;
use hotshot_types::network::PeerConfigKeys;

use std::{fs, path::Path};

/// A stake table config stored in a file
Expand Down Expand Up @@ -46,3 +47,92 @@ impl From<PermissionedStakeTableConfig> for Vec<NodeInfo> {
.collect()
}
}

#[cfg(test)]
mod test {
use crate::stake_table::PermissionedStakeTableConfig;
use crate::test_utils::setup_test;
use hotshot::types::{BLSPubKey, SignatureKey};
use hotshot_types::{light_client::StateKeyPair, network::PeerConfigKeys};
use toml::toml;
#[test]
fn test_permissioned_stake_table_from_toml() {
setup_test();

let mut keys = Vec::new();
for i in 0..3 {
let (pubkey, _) = BLSPubKey::generated_from_seed_indexed([0; 32], i);
let state_kp = StateKeyPair::generate_from_seed_indexed([0; 32], i).0;
let ver_key = state_kp.ver_key();
keys.push(PeerConfigKeys {
stake_table_key: pubkey,
state_ver_key: ver_key,
stake: 1,
da: i == 0,
});
}

let st_key_1 = keys[0].stake_table_key.to_string();
let verkey_1 = keys[0].state_ver_key.to_string();
let da_1 = keys[0].da;

let st_key_2 = keys[1].stake_table_key.to_string();
let verkey_2 = keys[1].state_ver_key.to_string();
let da_2 = keys[1].da;

let st_key_3 = keys[2].stake_table_key.to_string();
let verkey_3 = keys[2].state_ver_key.to_string();
let da_3 = keys[2].da;

let toml = toml! {
[[public_keys]]
stake_table_key = st_key_1
state_ver_key = verkey_1
stake = 1
da = da_1

[[public_keys]]
stake_table_key = st_key_2
state_ver_key = verkey_2
stake = 1
da = da_2

[[public_keys]]
stake_table_key = st_key_3
state_ver_key = verkey_3
stake = 2
da = da_3

}
.to_string();

let toml_st: PermissionedStakeTableConfig = toml::from_str(&toml).unwrap();

assert_eq!(toml_st.public_keys.len(), 3);

// TODO: add `PartialEq` to PeerConfigKeys
assert_eq!(toml_st.public_keys[0].state_ver_key, keys[0].state_ver_key);
assert_eq!(
toml_st.public_keys[0].stake_table_key,
keys[0].stake_table_key
);
assert_eq!(toml_st.public_keys[0].da, da_1);
assert_eq!(toml_st.public_keys[0].stake, 1);

assert_eq!(toml_st.public_keys[1].state_ver_key, keys[1].state_ver_key);
assert_eq!(
toml_st.public_keys[1].stake_table_key,
keys[1].stake_table_key
);
assert_eq!(toml_st.public_keys[1].da, da_2);
assert_eq!(toml_st.public_keys[1].stake, 1);

assert_eq!(toml_st.public_keys[2].state_ver_key, keys[2].state_ver_key);
assert_eq!(
toml_st.public_keys[2].stake_table_key,
keys[2].stake_table_key
);
assert_eq!(toml_st.public_keys[2].da, da_3);
assert_eq!(toml_st.public_keys[2].stake, 2);
}
}

0 comments on commit 77ff146

Please sign in to comment.