-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move/rust] libra-framework patch 7.0.3 & AppCfg private key for test…
…suite (#313) Co-authored-by: xyz <xyz>
- Loading branch information
Showing
26 changed files
with
280 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,59 @@ | ||
use diem_forge::{LocalSwarm, Swarm}; | ||
use diem_forge::{LocalSwarm, Node}; | ||
use diem_sdk::crypto::PrivateKey; | ||
use diem_sdk::types::LocalAccount; | ||
use diem_types::chain_id::NamedChain; | ||
use libra_types::core_types::network_playlist::NetworkPlaylist; | ||
use libra_types::{core_types::app_cfg::AppCfg, exports::AuthenticationKey}; | ||
use std::path::PathBuf; | ||
use url::Url; | ||
|
||
/// Set up the 0L local files, and get an AppCfg back after initializing in a temp dir, that will drop at the end of the test. | ||
pub async fn init_val_config_files( | ||
pub fn init_val_config_files( | ||
swarm: &mut LocalSwarm, | ||
nth: usize, | ||
dir: PathBuf, | ||
dir_opt: Option<PathBuf>, | ||
) -> anyhow::Result<(LocalAccount, AppCfg)> { | ||
let info = swarm.diem_public_info_for_node(nth); | ||
let url: Url = info.url().parse().unwrap(); | ||
// TODO: unclear why public info needs to be a mutable borrow | ||
let node = swarm | ||
.validators() | ||
.nth(nth) | ||
.expect("could not get nth validator"); | ||
let url = node.rest_api_endpoint(); | ||
|
||
let node = swarm.validators().next().unwrap(); | ||
let np = NetworkPlaylist::new(Some(url), Some(diem_types::chain_id::NamedChain::TESTING)); | ||
let dir = dir_opt.unwrap_or(node.config_path().parent().unwrap().to_owned()); | ||
|
||
let chain_name = NamedChain::from_chain_id(&swarm.chain_id()).ok(); | ||
let np = NetworkPlaylist::new(Some(url), chain_name); | ||
let cfg_key = node.account_private_key().as_ref().unwrap(); | ||
let prikey = cfg_key.private_key(); | ||
let pubkey = prikey.public_key(); | ||
let mut app_cfg = AppCfg::init_app_configs( | ||
AuthenticationKey::ed25519(&node.account_private_key().as_ref().unwrap().public_key()), | ||
AuthenticationKey::ed25519(&pubkey), | ||
node.peer_id(), | ||
Some(dir), | ||
Some(np.chain_name), | ||
Some(np), | ||
) | ||
.unwrap(); | ||
|
||
let pri_key = node | ||
.account_private_key() | ||
.as_ref() | ||
.expect("could not get pri_key") | ||
.private_key(); | ||
let auth = AuthenticationKey::ed25519(&pri_key.public_key()); | ||
)?; | ||
|
||
let profile = app_cfg | ||
.get_profile_mut(None) | ||
.expect("could not get profile"); | ||
profile.set_private_key(&pri_key); | ||
|
||
let local_account = LocalAccount::new(auth.derived_address(), pri_key, 0); | ||
profile.set_private_key(&prikey); | ||
|
||
let local_account = LocalAccount::new(profile.account, prikey, 0); | ||
|
||
Ok((local_account, app_cfg)) | ||
} | ||
|
||
/// helper to save libra-cli config files for each of the validators in | ||
/// their local temp folder (alongside validator.yaml) | ||
pub fn save_cli_config_all(swarm: &mut LocalSwarm) -> anyhow::Result<()> { | ||
let len = swarm.validators().count(); | ||
for i in 0..len { | ||
// a libra-cli-config file will be created at the temp swarm | ||
// directory of the node | ||
let (_, app_cfg) = init_val_config_files(swarm, i, None)?; | ||
let _file = app_cfg.save_file()?; | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# NOTE: you'll need to have a db of a fullnode already synced | ||
# twin tool will make a copy of this | ||
# THE DB WILL NOT BE WRITTEN TO | ||
|
||
# TMP_DIR = /tmp/.tmpCu3Rxh/ | ||
|
||
ifndef DB_DIR | ||
DB_DIR=$$HOME/.libra/data/db | ||
endif | ||
|
||
ifndef UPGRADE_SCRIPT_PATH | ||
UPGRADE_SCRIPT_PATH = $$HOME/upgrade-six/ | ||
endif | ||
|
||
ifndef FRAMEWORK_SOURCE_PATH | ||
FRAMEWORK_SOURCE_PATH = $$HOME/libra-framework/framework | ||
endif | ||
|
||
ifndef DIEM_FORGE_NODE_BIN_PATH | ||
DIEM_FORGE_NODE_BIN_PATH = $$HOME/.cargo/bin/libra | ||
endif | ||
|
||
PROPOSAL_ID = 6 | ||
|
||
##### INSTRUCTIONS | ||
|
||
# Grab the essentials: | ||
# sudo apt update | ||
# sudo apt install -y git build-essential cmake clang llvm libgmp-dev pkg-config libssl-dev lld libpq-dev | ||
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh | ||
|
||
# 1. use an up to date libra-cli binary | ||
# > cargo build --release -p libra --locked | ||
# > cp target/release/libra ~/.cargo/bin/ | ||
|
||
# 2. Make sure you have a fullnode that is already syced, you'll need the DB_DIR of it | ||
# if you are starting fresh use: | ||
# > libra config fullnode-init | ||
# > libra node | ||
# check height while syncing | ||
# > watch -n 5 'curl -s 127.0.0.1:9101/metrics | grep diem_state_sync_version' | ||
|
||
# 2. compile the new libra-framework MOVE code with: | ||
# > make upgrade-script | ||
# note the defaults for input: FRAMEWORK_SOURCE_PATH and and output: UPGRADE_SCRIPT_PATH | ||
|
||
# 3. start a Twin swarm locally | ||
# > make start-twin | ||
# NOTE: the output `temp files found at: /tmp/<......> ` | ||
# A local Twin of mainnet is now running on your machine. | ||
|
||
# 4. export that temp dir to your path | ||
# > export TMP_DIR=/tmp/<......> | ||
|
||
# Now your can do transactions as the new random validators | ||
# 5. check validator set | ||
# > make view-vals | ||
|
||
# 6. try to tigger epoch | ||
# > make tx-epoch | ||
# NOTE: this usually should fail unless enough time has passed. | ||
|
||
# 7. Send the full upgrade e2e | ||
# > make upgrade-ceremony | ||
|
||
# 8. check the state of the proposal | ||
# > make view-state | ||
|
||
# start twin with three validators | ||
start-twin: | ||
cargo run -p libra-twin-tests -- -d ${DB_DIR} -c 3 | ||
|
||
|
||
######### UPGRADE SCRIPT GENERATION | ||
upgrade-script: move-build-framework move-build-script | ||
|
||
move-build-framework: | ||
cd ${FRAMEWORK_SOURCE_PATH} && libra move framework release | ||
|
||
move-build-script: | ||
libra move framework upgrade --core-modules libra-framework --output-dir ${UPGRADE_SCRIPT_PATH} --framework-local-dir ${FRAMEWORK_SOURCE_PATH} | ||
|
||
######## EPOCH TRIGGER | ||
tx-epoch: | ||
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml governance epoch-boundary | ||
|
||
|
||
######## UPGRADE TRANSACTIONS | ||
upgrade-ceremony: tx-propose tx-vote tx-resolve | ||
|
||
tx-propose: | ||
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml governance propose -d ${UPGRADE_SCRIPT_PATH}/1-libra-framework -m https://tbd.com | ||
|
||
tx-vote: | ||
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml governance vote -i ${PROPOSAL_ID} | ||
libra txs -c ${TMP_DIR}/1/libra-cli-config.yaml governance vote -i ${PROPOSAL_ID} | ||
libra txs -c ${TMP_DIR}/2/libra-cli-config.yaml governance vote -i ${PROPOSAL_ID} | ||
|
||
tx-resolve: | ||
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml --tx-profile critical governance resolve -i ${PROPOSAL_ID} -d ${UPGRADE_SCRIPT_PATH}/1-libra-framework | ||
|
||
#### VIEW STATE OF UPGRADE PROPOSALS | ||
view-state: | ||
libra query -c ${TMP_DIR}/0/libra-cli-config.yaml view -f 0x1::diem_governance::get_proposal_state -a ${PROPOSAL_ID} | ||
|
||
view-resolve: | ||
libra query -c ${TMP_DIR}/0/libra-cli-config.yaml view -f 0x1::diem_governance::get_can_resolve -a ${PROPOSAL_ID} | ||
|
||
view-vals: | ||
libra query -c ${TMP_DIR}/0/libra-cli-config.yaml view -f 0x1::stake::get_current_validators | ||
|
||
|
||
######## OTHER | ||
debug-keys: | ||
cat ${TMP_DIR}/0/private-identity.yaml | ||
cat ${TMP_DIR}/1/private-identity.yaml | ||
cat ${TMP_DIR}/2/private-identity.yaml | ||
|
||
help-tx-bid-shuffle: | ||
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml validator pof -b 0.3 -e 1000 | ||
libra txs -c ${TMP_DIR}/1/libra-cli-config.yaml validator pof -b 0.4 -e 1000 | ||
libra txs -c ${TMP_DIR}/2/libra-cli-config.yaml validator pof -b 0.5 -e 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.