Skip to content

Commit d6ada0f

Browse files
authored
[move/rust] libra-framework patch 7.0.3 & AppCfg private key for testsuite (#313)
Co-authored-by: xyz <xyz>
1 parent b7aaed3 commit d6ada0f

File tree

26 files changed

+280
-99
lines changed

26 files changed

+280
-99
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework/cached-packages/src/libra_framework_sdk_builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![allow(dead_code)]
1414
#![allow(unused_imports)]
1515
#![allow(clippy::too_many_arguments)]
16-
1716
use diem_types::{
1817
account_address::AccountAddress,
1918
transaction::{EntryFunction, TransactionPayload},

framework/libra-framework/sources/diem_governance.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ module diem_framework::diem_governance {
423423
}
424424

425425
#[view]
426-
// is the proposal complete and executed?
426+
// how many votes on the proposal
427427
public fun get_votes(proposal_id: u64): (u128, u128) {
428428
voting::get_votes<GovernanceProposal>(@diem_framework, proposal_id)
429429
}

framework/libra-framework/sources/ol_sources/address_utils.move

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ module ol_framework::address_utils {
3333

3434
// Shuffle addresses with the same values to ensure randomness position
3535
public fun shuffle_duplicates(addresses: &mut vector<address>, values: &vector<u64>) {
36+
// belt and suspenders, if migration didn't happen.
37+
// assert!(randomness::is_init(), error::invalid_state(ERANDOM_INIT_ERROR));
38+
3639
assert!(vector::length(addresses) == vector::length(values), error::invalid_argument(EDIFFERENT_LENGTH));
3740
let len = vector::length(values);
3841
let i = 0;

framework/libra-framework/sources/ol_sources/epoch_boundary.move

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module diem_framework::epoch_boundary {
4343
const ETRIGGER_EPOCH_UNAUTHORIZED: u64 = 1;
4444
/// Epoch is not ready for reconfiguration
4545
const ETRIGGER_NOT_READY: u64 = 2;
46-
/// Epoch number mismat
46+
/// Epoch number mismatch
4747
const ENOT_SAME_EPOCH: u64 = 3;
4848

4949
/////// Constants ////////
@@ -254,20 +254,22 @@ module diem_framework::epoch_boundary {
254254
}
255255

256256
#[view]
257-
/// check to see if the epoch Boundary Bit is true
257+
/// check to see if the epoch BoundaryBit is true
258258
public fun can_trigger(): bool acquires BoundaryBit {
259259
let state = borrow_global_mut<BoundaryBit>(@ol_framework);
260260
assert!(state.ready, ETRIGGER_NOT_READY);
261-
assert!(state.closing_epoch == reconfiguration::get_current_epoch(),
261+
// greater than, in case there is an epoch change due to an epoch bump in
262+
// testnet Twin tools, or a rescue operation.
263+
assert!(state.closing_epoch <= reconfiguration::get_current_epoch(),
262264
ENOT_SAME_EPOCH);
263265
true
264266
}
265267

266268
// This function handles the necessary migrations that occur at the epoch boundary
267269
// when new modules or structures are added by chain upgrades.
268-
fun migrate_data(root: &signer) {
269-
randomness::initialize(root);
270-
migrations::execute(root);
270+
fun migrate_data(framework: &signer) {
271+
randomness::initialize(framework);
272+
migrations::execute(framework);
271273
}
272274

273275
// Contains all of 0L's business logic for end of epoch.

framework/libra-framework/sources/ol_sources/vouch.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module ol_framework::vouch {
1111
use diem_framework::system_addresses;
1212
use diem_framework::transaction_fee;
1313

14-
use diem_std::debug::print;
14+
use diem_std::debug::print;
1515

1616
friend diem_framework::genesis;
1717
friend ol_framework::proof_of_fee;

framework/libra-framework/sources/randomness.move

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module diem_framework::randomness {
3737
friend diem_framework::block;
3838
friend ol_framework::musical_chairs;
3939

40-
const DST: vector<u8> = b"ALL_YOUR_BASE";
40+
const INIT_SEED: vector<u8> = b"all your base are belong to us";
4141

4242

4343
const MAX_U256: u256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
@@ -68,12 +68,17 @@ module diem_framework::randomness {
6868
move_to(framework, PerBlockRandomness {
6969
epoch: 0,
7070
round: 0,
71-
seed: option::none(),
71+
seed: option::some(INIT_SEED),
7272
seq: 0,
7373
});
7474
}
7575
}
7676

77+
#[view]
78+
public fun is_init(): bool {
79+
exists<PerBlockRandomness>(@diem_framework)
80+
}
81+
7782
#[test_only]
7883
public fun initialize_for_testing(framework: &signer) acquires PerBlockRandomness {
7984
initialize(framework);
@@ -98,18 +103,24 @@ module diem_framework::randomness {
98103
// public facing API.
99104
// assert!(is_unbiasable(), E_API_USE_IS_BIASIBLE);
100105

101-
let input = DST;
102106
let randomness = borrow_global_mut<PerBlockRandomness>(@diem_framework);
103-
let seed = *option::borrow(&randomness.seed);
104107

105-
vector::append(&mut input, seed);
108+
// belt and suspenders if something didn't initialize
109+
let input = if (option::is_some(&randomness.seed)) {
110+
*option::borrow(&randomness.seed)
111+
} else {
112+
INIT_SEED
113+
};
114+
115+
106116
// 0L NOTE: these native APIs dont exist in 0L V7.
107117
// get_transaction_hash() doesnt exist. So different than vendor,
108118
// we will always increment a seed based on the block hash.
109119
// Note: will then be the previousl block's hash for the next
110120
// transaction.
111121
// we will add the script hash of the entry function as a placeholder
112122
// though this will likely not be adding much entropy.
123+
113124
vector::append(&mut input,
114125
transaction_context::get_script_hash());
115126

framework/releases/head.mrb

346 Bytes
Binary file not shown.
Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
1-
use diem_forge::{LocalSwarm, Swarm};
1+
use diem_forge::{LocalSwarm, Node};
22
use diem_sdk::crypto::PrivateKey;
33
use diem_sdk::types::LocalAccount;
4+
use diem_types::chain_id::NamedChain;
45
use libra_types::core_types::network_playlist::NetworkPlaylist;
56
use libra_types::{core_types::app_cfg::AppCfg, exports::AuthenticationKey};
67
use std::path::PathBuf;
7-
use url::Url;
88

99
/// 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.
10-
pub async fn init_val_config_files(
10+
pub fn init_val_config_files(
1111
swarm: &mut LocalSwarm,
1212
nth: usize,
13-
dir: PathBuf,
13+
dir_opt: Option<PathBuf>,
1414
) -> anyhow::Result<(LocalAccount, AppCfg)> {
15-
let info = swarm.diem_public_info_for_node(nth);
16-
let url: Url = info.url().parse().unwrap();
15+
// TODO: unclear why public info needs to be a mutable borrow
16+
let node = swarm
17+
.validators()
18+
.nth(nth)
19+
.expect("could not get nth validator");
20+
let url = node.rest_api_endpoint();
1721

18-
let node = swarm.validators().next().unwrap();
19-
let np = NetworkPlaylist::new(Some(url), Some(diem_types::chain_id::NamedChain::TESTING));
22+
let dir = dir_opt.unwrap_or(node.config_path().parent().unwrap().to_owned());
23+
24+
let chain_name = NamedChain::from_chain_id(&swarm.chain_id()).ok();
25+
let np = NetworkPlaylist::new(Some(url), chain_name);
26+
let cfg_key = node.account_private_key().as_ref().unwrap();
27+
let prikey = cfg_key.private_key();
28+
let pubkey = prikey.public_key();
2029
let mut app_cfg = AppCfg::init_app_configs(
21-
AuthenticationKey::ed25519(&node.account_private_key().as_ref().unwrap().public_key()),
30+
AuthenticationKey::ed25519(&pubkey),
2231
node.peer_id(),
2332
Some(dir),
2433
Some(np.chain_name),
2534
Some(np),
26-
)
27-
.unwrap();
28-
29-
let pri_key = node
30-
.account_private_key()
31-
.as_ref()
32-
.expect("could not get pri_key")
33-
.private_key();
34-
let auth = AuthenticationKey::ed25519(&pri_key.public_key());
35+
)?;
36+
3537
let profile = app_cfg
3638
.get_profile_mut(None)
3739
.expect("could not get profile");
38-
profile.set_private_key(&pri_key);
3940

40-
let local_account = LocalAccount::new(auth.derived_address(), pri_key, 0);
41+
profile.set_private_key(&prikey);
42+
43+
let local_account = LocalAccount::new(profile.account, prikey, 0);
4144

4245
Ok((local_account, app_cfg))
4346
}
47+
48+
/// helper to save libra-cli config files for each of the validators in
49+
/// their local temp folder (alongside validator.yaml)
50+
pub fn save_cli_config_all(swarm: &mut LocalSwarm) -> anyhow::Result<()> {
51+
let len = swarm.validators().count();
52+
for i in 0..len {
53+
// a libra-cli-config file will be created at the temp swarm
54+
// directory of the node
55+
let (_, app_cfg) = init_val_config_files(swarm, i, None)?;
56+
let _file = app_cfg.save_file()?;
57+
}
58+
Ok(())
59+
}

testsuites/twin/Makefile

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# NOTE: you'll need to have a db of a fullnode already synced
2+
# twin tool will make a copy of this
3+
# THE DB WILL NOT BE WRITTEN TO
4+
5+
# TMP_DIR = /tmp/.tmpCu3Rxh/
6+
7+
ifndef DB_DIR
8+
DB_DIR=$$HOME/.libra/data/db
9+
endif
10+
11+
ifndef UPGRADE_SCRIPT_PATH
12+
UPGRADE_SCRIPT_PATH = $$HOME/upgrade-six/
13+
endif
14+
15+
ifndef FRAMEWORK_SOURCE_PATH
16+
FRAMEWORK_SOURCE_PATH = $$HOME/libra-framework/framework
17+
endif
18+
19+
ifndef DIEM_FORGE_NODE_BIN_PATH
20+
DIEM_FORGE_NODE_BIN_PATH = $$HOME/.cargo/bin/libra
21+
endif
22+
23+
PROPOSAL_ID = 6
24+
25+
##### INSTRUCTIONS
26+
27+
# Grab the essentials:
28+
# sudo apt update
29+
# sudo apt install -y git build-essential cmake clang llvm libgmp-dev pkg-config libssl-dev lld libpq-dev
30+
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
31+
32+
# 1. use an up to date libra-cli binary
33+
# > cargo build --release -p libra --locked
34+
# > cp target/release/libra ~/.cargo/bin/
35+
36+
# 2. Make sure you have a fullnode that is already syced, you'll need the DB_DIR of it
37+
# if you are starting fresh use:
38+
# > libra config fullnode-init
39+
# > libra node
40+
# check height while syncing
41+
# > watch -n 5 'curl -s 127.0.0.1:9101/metrics | grep diem_state_sync_version'
42+
43+
# 2. compile the new libra-framework MOVE code with:
44+
# > make upgrade-script
45+
# note the defaults for input: FRAMEWORK_SOURCE_PATH and and output: UPGRADE_SCRIPT_PATH
46+
47+
# 3. start a Twin swarm locally
48+
# > make start-twin
49+
# NOTE: the output `temp files found at: /tmp/<......> `
50+
# A local Twin of mainnet is now running on your machine.
51+
52+
# 4. export that temp dir to your path
53+
# > export TMP_DIR=/tmp/<......>
54+
55+
# Now your can do transactions as the new random validators
56+
# 5. check validator set
57+
# > make view-vals
58+
59+
# 6. try to tigger epoch
60+
# > make tx-epoch
61+
# NOTE: this usually should fail unless enough time has passed.
62+
63+
# 7. Send the full upgrade e2e
64+
# > make upgrade-ceremony
65+
66+
# 8. check the state of the proposal
67+
# > make view-state
68+
69+
# start twin with three validators
70+
start-twin:
71+
cargo run -p libra-twin-tests -- -d ${DB_DIR} -c 3
72+
73+
74+
######### UPGRADE SCRIPT GENERATION
75+
upgrade-script: move-build-framework move-build-script
76+
77+
move-build-framework:
78+
cd ${FRAMEWORK_SOURCE_PATH} && libra move framework release
79+
80+
move-build-script:
81+
libra move framework upgrade --core-modules libra-framework --output-dir ${UPGRADE_SCRIPT_PATH} --framework-local-dir ${FRAMEWORK_SOURCE_PATH}
82+
83+
######## EPOCH TRIGGER
84+
tx-epoch:
85+
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml governance epoch-boundary
86+
87+
88+
######## UPGRADE TRANSACTIONS
89+
upgrade-ceremony: tx-propose tx-vote tx-resolve
90+
91+
tx-propose:
92+
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml governance propose -d ${UPGRADE_SCRIPT_PATH}/1-libra-framework -m https://tbd.com
93+
94+
tx-vote:
95+
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml governance vote -i ${PROPOSAL_ID}
96+
libra txs -c ${TMP_DIR}/1/libra-cli-config.yaml governance vote -i ${PROPOSAL_ID}
97+
libra txs -c ${TMP_DIR}/2/libra-cli-config.yaml governance vote -i ${PROPOSAL_ID}
98+
99+
tx-resolve:
100+
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
101+
102+
#### VIEW STATE OF UPGRADE PROPOSALS
103+
view-state:
104+
libra query -c ${TMP_DIR}/0/libra-cli-config.yaml view -f 0x1::diem_governance::get_proposal_state -a ${PROPOSAL_ID}
105+
106+
view-resolve:
107+
libra query -c ${TMP_DIR}/0/libra-cli-config.yaml view -f 0x1::diem_governance::get_can_resolve -a ${PROPOSAL_ID}
108+
109+
view-vals:
110+
libra query -c ${TMP_DIR}/0/libra-cli-config.yaml view -f 0x1::stake::get_current_validators
111+
112+
113+
######## OTHER
114+
debug-keys:
115+
cat ${TMP_DIR}/0/private-identity.yaml
116+
cat ${TMP_DIR}/1/private-identity.yaml
117+
cat ${TMP_DIR}/2/private-identity.yaml
118+
119+
help-tx-bid-shuffle:
120+
libra txs -c ${TMP_DIR}/0/libra-cli-config.yaml validator pof -b 0.3 -e 1000
121+
libra txs -c ${TMP_DIR}/1/libra-cli-config.yaml validator pof -b 0.4 -e 1000
122+
libra txs -c ${TMP_DIR}/2/libra-cli-config.yaml validator pof -b 0.5 -e 1000

0 commit comments

Comments
 (0)