Skip to content
New issue

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

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

Already on GitHub? # to your account

[testnet] mint default balances for blank genesis #349

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions framework/libra-framework/sources/ol_sources/libra_coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ module ol_framework::libra_coin {
exists<MintCapStore>(signer::address_of(account))
}

/// Only called during genesis to destroy the diem framework account's mint capability once all initial validators
/// and accounts have been initialized during genesis.
public(friend) fun destroy_mint_cap(diem_framework: &signer) acquires MintCapStore {
system_addresses::assert_diem_framework(diem_framework);
let MintCapStore { mint_cap } = move_from<MintCapStore>(@diem_framework);
coin::destroy_mint_cap(mint_cap);
}
// /// Only called during genesis to destroy the diem framework account's mint capability once all initial validators
// /// and accounts have been initialized during genesis.
// public(friend) fun destroy_mint_cap(diem_framework: &signer) acquires MintCapStore {
// system_addresses::assert_diem_framework(diem_framework);
// let MintCapStore { mint_cap } = move_from<MintCapStore>(@diem_framework);
// coin::destroy_mint_cap(mint_cap);
// }

// at genesis we need to init the final supply
// done at genesis_migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ spec ol_framework::libra_coin {
ensures exists<coin::CoinInfo<LibraCoin>>(addr);
}

spec destroy_mint_cap {
let addr = signer::address_of(diem_framework);
aborts_if addr != @diem_framework;
aborts_if !exists<MintCapStore>(@diem_framework);
}
// spec destroy_mint_cap {
// let addr = signer::address_of(diem_framework);
// aborts_if addr != @diem_framework;
// aborts_if !exists<MintCapStore>(@diem_framework);
// }

// Test function,not needed verify.
spec configure_accounts_for_test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
friend ol_framework::genesis_migration;
friend ol_framework::genesis;

// #[test_only]
// friend ol_framework::mock;

/// no policy at this address
const ENO_BENEFICIARY_POLICY: u64 = 1;
/// there is a non zero balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
module ol_framework::test_migration {
use ol_framework::genesis_migration;
use ol_framework::mock;
// use ol_framework::infra_escrow;
// use ol_framework::slow_wallet;
// use ol_framework::ol_account;
// use diem_framework::coin;
// use ol_framework::libra_coin;
use std::signer;
use std::bcs;

Expand Down
1 change: 0 additions & 1 deletion tools/genesis/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn make_recovery_genesis_from_vec_legacy_recovery(
genesis_vals: &[Validator],
framework_release: &ReleaseBundle,
chain_id: ChainId,
// supply_settings: Option<SupplySettings>,
genesis_config: &GenesisConfiguration,
) -> Result<Transaction, Error> {
// let supply_settings = supply_settings.unwrap_or_default();
Expand Down
5 changes: 0 additions & 5 deletions tools/genesis/src/genesis_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ pub fn build(
&silly_config(&genesis_config),
)?
} else {
dbg!(&"hi4");

fetch_genesis_info(
github_owner,
github_repository,
Expand All @@ -130,7 +128,6 @@ pub fn build(
&gen_info.validators,
&gen_info.framework,
gen_info.chain_id,
// supply_settings.clone(),
&genesis_config,
)?;

Expand Down Expand Up @@ -211,15 +208,13 @@ pub fn fetch_genesis_info(
genesis_config: &VmGenesisGenesisConfiguration,
chain_id: &NamedChain,
) -> Result<GenesisInfo> {
// let client = git_options.get_client()?;
let client = Client::new(
github_owner, // doesn't matter
github_repository,
DEFAULT_GIT_BRANCH.to_string(),
github_token,
);

// let layout: Layout = client.get(Path::new(LAYOUT_FILE))?;
let l_file = client.get_file(&Path::new(LAYOUT_FILE).display().to_string())?;
let layout: LibraSimpleLayout = from_yaml(&String::from_utf8(base64::decode(l_file)?)?)?;
OLProgress::complete("fetched layout file");
Expand Down
43 changes: 40 additions & 3 deletions tools/genesis/src/testnet_setup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use crate::{genesis_builder, parse_json};
use anyhow::bail;
use diem_genesis::config::{HostAndPort, ValidatorConfiguration};
use libra_backwards_compatibility::legacy_recovery_v6::LegacyRecoveryV6;
use libra_config::validator_config;
use libra_types::{core_types::fixtures::TestPersona, exports::NamedChain};
use libra_types::{
core_types::fixtures::TestPersona,
exports::{AccountAddress, AuthenticationKey, NamedChain},
move_resource::{
cumulative_deposits::LegacyBalanceResourceV6,
pledge_account::{MyPledgesResource, PledgeAccountResource},
},
ONCHAIN_DECIMAL_PRECISION,
};
use std::{fs, path::PathBuf, thread, time};

// Sets up the environment for the given test persona.
Expand Down Expand Up @@ -39,7 +48,6 @@ pub async fn setup(
);

// create the local files for my_persona
// let db_path = data_path;
if data_path.exists() {
println!("WARN: deleting {}, in 5 secs", &data_path.display());
let delay = time::Duration::from_secs(5);
Expand Down Expand Up @@ -74,7 +82,9 @@ pub async fn setup(
let mut recovery = if let Some(p) = legacy_data_path {
parse_json::recovery_file_parse(p)?
} else {
vec![]
// this is probably a testnet, we need to minimally start the infra escrow
// and balance on validators
generate_testnet_state_for_vals(&val_cfg)
};

// Builds the genesis block with the specified configurations.
Expand All @@ -90,3 +100,30 @@ pub async fn setup(
)?;
Ok(())
}

fn generate_testnet_state_for_vals(vals: &[ValidatorConfiguration]) -> Vec<LegacyRecoveryV6> {
let mut recovery: Vec<LegacyRecoveryV6> = vec![];
for v in vals {
let mut l = LegacyRecoveryV6 {
account: Some(v.owner_account_address.into()),
auth_key: Some(AuthenticationKey::ed25519(&v.owner_account_public_key)),
balance: Some(LegacyBalanceResourceV6 {
coin: 10_000_000 * 10u64.pow(ONCHAIN_DECIMAL_PRECISION as u32),
}),
..Default::default()
};

let p = PledgeAccountResource {
address_of_beneficiary: AccountAddress::ONE,
amount: 100_000_000 * 10u64.pow(ONCHAIN_DECIMAL_PRECISION as u32),
pledge: 100_000_000 * 10u64.pow(ONCHAIN_DECIMAL_PRECISION as u32),
epoch_of_last_deposit: 0,
lifetime_pledged: 100_000_000 * 10u64.pow(ONCHAIN_DECIMAL_PRECISION as u32),
lifetime_withdrawn: 0,
};
l.my_pledge = Some(MyPledgesResource { list: vec![p] });
recovery.push(l);
}

recovery
}
Loading