Skip to content

Commit

Permalink
[migration] add consensus reward to migration (#226)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
Co-authored-by: coin1111 <celticsnow123@gmail.com>
Co-authored-by: sirouk <8901571+sirouk@users.noreply.github.com>
Co-authored-by: 0xzoz <zeroexzoz@gmail.com>
Co-authored-by: zoz <97761083+0xzoz@users.noreply.github.com>
  • Loading branch information
6 people committed Aug 8, 2024
1 parent 10f0b2d commit 7cd6496
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 225,489 deletions.
10 changes: 7 additions & 3 deletions framework/libra-framework/sources/ol_sources/proof_of_fee.move
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ module ol_framework::proof_of_fee {

// on a migration genesis for mainnet the genesis reward needs to be calculated
// from supply data.
fun genesis_migrate_reward(vm: &signer, nominal_reward: u64) acquires
public fun genesis_migrate_reward(framework: &signer, nominal_reward: u64) acquires
ConsensusReward {
system_addresses::assert_ol(vm); // either 0x1 or 0x0
system_addresses::assert_diem_framework(framework); // either 0x1 or 0x0

// Nominal reward at end of V6 was 178204815
if (nominal_reward > 178204815) return;


let state = borrow_global_mut<ConsensusReward>(@ol_framework);
state.nominal_reward = nominal_reward;
state.net_reward = nominal_reward; // just for info purposes. It gets calculated
// on first epoch change.
// on next epoch change.
}

fun init(account_sig: &signer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ module ol_framework::multi_action {
// Governance, will only say if it passed or not.
// Note: The underlying Ballot deals with the GUID generation
struct Proposal<ProposalData> has store, drop {
// id: u64,
// The transaction to be executed
proposal_data: ProposalData,
// The votes received
Expand All @@ -129,7 +128,6 @@ module ol_framework::multi_action {
};

Proposal<ProposalData> {
// id: 0,
proposal_data,
votes: vector::empty<address>(),
approved: false,
Expand All @@ -151,21 +149,16 @@ module ol_framework::multi_action {
// Governance contains the constraints for each Action that are checked on each vote (n_sigs, expiration, signers, etc)
// Also, an initial Action of type PropGovSigners is created, which is used to govern the signers and threshold for this account.
public(friend) fun init_gov(sig: &signer) {

// heals un-initialized state, and does nothing if state already exists.

// assert!(cfg_default_n_sigs > 0, error::invalid_argument(ENO_SIGNERS));

let multisig_address = signer::address_of(sig);
// User footgun. The signer of this account is bricked, and as such the signer can no longer be an authority.
// assert!(!vector::contains(m_seed_authorities, &multisig_address),
// error::invalid_argument(ESIGNER_CANT_BE_AUTHORITY));

if (!exists<Governance>(multisig_address)) {
move_to(sig, Governance {
cfg_duration_epochs: DEFAULT_EPOCHS_EXPIRE,
cfg_default_n_sigs: 0, // deprecate
signers: vector::empty(), // *m_seed_authorities, // deprecate
signers: vector::empty(),
withdraw_capability: option::none(),
guid_capability: account::create_guid_capability(sig),
});
Expand Down Expand Up @@ -222,7 +215,7 @@ module ol_framework::multi_action {
}

/// An initial "sponsor" who is the signer of the initialization account calls this function.
// This function creates the data structures, but also IMPORTANTLY it rotates the AuthKey of the account to a system-wide unusuable key (b"brick_all_your_base_are_belong_to_us").
// This function creates the data structures.
public(friend) fun init_type<ProposalData: store + drop >(
sig: &signer,
can_withdraw: bool,
Expand Down Expand Up @@ -312,9 +305,6 @@ module ol_framework::multi_action {
assert_authorized(sig, multisig_address);

let action = borrow_global_mut<Action<ProposalData>>(multisig_address);
// let ms = borrow_global_mut<Governance>(multisig_address);
// go through all proposals and clean up expired ones.
// lazy_cleanup_expired(action);

// does this proposal already exist in the pending list?
let (found, uid, _idx, _status_enum, _is_complete) = search_proposals_by_data<ProposalData>(&action.vote, proposal);
Expand Down Expand Up @@ -408,7 +398,6 @@ module ol_framework::multi_action {
let b = vector::borrow(b_vec, i);
let t = ballot::get_type_struct<Proposal<ProposalData>>(b);


if (epoch > t.expiration_epoch) {
let id = ballot::get_ballot_id(b);
vector::push_back(&mut id_vec, id);
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/genesis/src/genesis_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn fetch_genesis_info(
let layout: LibraSimpleLayout = from_yaml(&String::from_utf8(base64::decode(l_file)?)?)?;
OLProgress::complete("fetched layout file");

let pb = OLProgress::spin_steady(100, "fetching validator registrations".to_string());
let pb = OLProgress::spin_steady(500, "fetching validator registrations".to_string());

let validators = get_validator_configs(&client, &layout, false)?;
OLProgress::complete("fetched validator configs");
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis/src/genesis_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ pub fn set_final_supply(session: &mut SessionExt) {

pub fn set_validator_baseline_reward(session: &mut SessionExt, nominal_reward: u64) {
let serialized_values = serialize_values(&vec![
MoveValue::Signer(AccountAddress::ZERO), // must be called by 0x0
MoveValue::Signer(CORE_CODE_ADDRESS), // must be called by 0x1
MoveValue::U64(nominal_reward),
]);

Expand Down
48 changes: 26 additions & 22 deletions tools/genesis/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use diem_gas::{
};
use diem_logger::prelude::*;
use diem_types::{
account_config::CORE_CODE_ADDRESS,
chain_id::{ChainId, NamedChain},
on_chain_config::{
Features, GasScheduleV2, OnChainConsensusConfig, OnChainExecutionConfig, TimedFeatures,
Expand Down Expand Up @@ -124,29 +125,39 @@ pub fn encode_genesis_change_set(

initialize_features(&mut session);

// TODO: consolidate with set_final_supply below
initialize_diem_coin(&mut session);
warn!("initialize_diem_coin");
println!("initialize_diem_coin");

// final supply must be set after coin is initialized, but before any
// accounts are created
// NOTE: this is a hard coded figure, since it would not change between
// upgrades.
set_final_supply(&mut session);

initialize_on_chain_governance(&mut session, genesis_config);

//////// MIGRATION ////////
if !recovery.is_empty() {
// let supply = populate_supply_stats_from_legacy(recovery)
// .expect("could not parse supply from legacy file");

//////// FRAMEWORK STATE ////////
// Migrate standalone framework account 0x1 state
let framework_state = recovery.iter().find(|e| {
if let Some(a) = e.account {
return a == CORE_CODE_ADDRESS;
}
false
});

if let Some(f) = framework_state {
// need to set the baseline reward based on supply settings
if let Some(cr) = f.consensus_reward.as_ref() {
set_validator_baseline_reward(&mut session, cr.nominal_reward);
}
}

//////// MIGRATE ALL USERS ////////
genesis_functions::genesis_migrate_all_users(&mut session, recovery)
.expect("could not migrate users");

// need to set the baseline reward based on supply settings
// TODO
let todo_pof_baseline = 10000;
set_validator_baseline_reward(&mut session, todo_pof_baseline);

// cumulative deposits (for match index) also need separate
// migration for CW
genesis_migrate_cumu_deposits(&mut session, recovery)
Expand All @@ -156,22 +167,15 @@ pub fn encode_genesis_change_set(
OLProgress::complete("user migration complete");

//////// 0L ////////
// moved this to happen after legacy account migration, since the validators need to have their accounts migrated as well, including the mapping of legacy address to the authkey (which no longer derives to the previous same address).
// Note: the operator accounts at genesis will be different.
// moved this to happen after legacy account migration, since the validators
// may need to have their accounts migrated as well, including the mapping
// of legacy address to the authkey (which no longer derives to the previous
// same address).
create_and_initialize_validators(&mut session, validators);

// //////// 0L ////////
// // need to ajust for rounding issues from target supply
// rounding_mint(&mut session, supply_settings);

// // add some coins in each validator account.
// if chain_id != ChainId::new(1) || option_env!("LIBRA_CI").is_some() {
// mint_genesis_bootstrap_coin(&mut session, validators);
// }

OLProgress::complete("initialized genesis validators");

let spin = OLProgress::spin_steady(100, "publishing framework".to_string());
let spin = OLProgress::spin_steady(500, "publishing framework".to_string());

set_genesis_end(&mut session);

Expand Down
1 change: 0 additions & 1 deletion tools/genesis/tests/fixtures/migration_sanitized.json

This file was deleted.

2 changes: 1 addition & 1 deletion tools/genesis/tests/fixtures/sample_export_recovery.json

Large diffs are not rendered by default.

Loading

0 comments on commit 7cd6496

Please sign in to comment.