Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[tools] vfn configs #109

Merged
merged 15 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
303 changes: 152 additions & 151 deletions Cargo.lock

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,37 @@ libra-txs = { path = "tools/txs" }
libra-wallet = { path = "tools/wallet" }
vdf = { git = "https://github.com/0o-de-lally/verifiable_delay.git" }

diem-api-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-debugger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-db = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-forge = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-transactional-test-harness = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
smoke-test = { package = "smoke-test", git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-api-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-debugger = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-db = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-forge = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-transactional-test-harness = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
smoke-test = { package = "smoke-test", git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }

diem = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-build-info = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-node = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-rest-client = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-sdk = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-config = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-crypto = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-global-constants = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-keygen = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-logger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-gas = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-vm = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-vm-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-executor = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-framework = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-cached-packages = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-github-client = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-release-builder = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-language-e2e-tests = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-state-view = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-storage-interface = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-temppath = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-build-info = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-node = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-rest-client = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-sdk = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-config = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-crypto = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-global-constants = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-keygen = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-logger = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-gas = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-vm = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-vm-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-executor = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-framework = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-cached-packages = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-github-client = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-release-builder = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-language-e2e-tests = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-state-view = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-storage-interface = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
diem-temppath = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }

### External crate dependencies.
# 0L NOTE: most of these are not used. But we leave the entire block here
Expand Down Expand Up @@ -314,12 +314,12 @@ serde_with = "^3"
# move-abigen = { path = "third_party/move/move-prover/move-abigen" }
# move-binary-format = { path = "third_party/move/move-binary-format" }
# ... see full list in Aptos repo
move-binary-format = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-core-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-command-line-common = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-compiler = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-model = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-vm-test-utils = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-binary-format = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
move-core-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
move-command-line-common = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
move-compiler = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
move-model = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
move-vm-test-utils = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }

# uses a profile similar to `cli` in Diem/Cargo.toml
# optimized for performance and size
Expand Down
2 changes: 1 addition & 1 deletion framework/cached-packages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = { workspace = true }
[dependencies]
bcs = { workspace = true }
# Note the generated SDK code uses hard coded `diemtypes`
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "839afb1" }
move-core-types = { workspace = true }
once_cell = { workspace = true }

Expand Down
48 changes: 24 additions & 24 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ pub enum EntryFunctionCall {

/// Only callable in tests and testnets where the core resources account exists.
/// Claim the delegated mint capability and destroy the delegated token.
GasCoinClaimMintCapability {},
LibraCoinClaimMintCapability {},

/// Only callable in tests and testnets where the core resources account exists.
/// Create delegated token for the address so the account could claim MintCapability later.
GasCoinDelegateMintCapability {
LibraCoinDelegateMintCapability {
to: AccountAddress,
},

/// Root account can mint to an address. Only used for genesis and tests.
/// The "root" account in smoke tests has some privileges.
GasCoinMintToImpl {
LibraCoinMintToImpl {
dst_addr: AccountAddress,
amount: u64,
},
Expand Down Expand Up @@ -705,9 +705,9 @@ impl EntryFunctionCall {
id,
} => donor_voice_vote_veto_tx(multisig_address, id),
JailUnjailByVoucher { addr } => jail_unjail_by_voucher(addr),
GasCoinClaimMintCapability {} => gas_coin_claim_mint_capability(),
GasCoinDelegateMintCapability { to } => gas_coin_delegate_mint_capability(to),
GasCoinMintToImpl { dst_addr, amount } => gas_coin_mint_to_impl(dst_addr, amount),
LibraCoinClaimMintCapability {} => libra_coin_claim_mint_capability(),
LibraCoinDelegateMintCapability { to } => libra_coin_delegate_mint_capability(to),
LibraCoinMintToImpl { dst_addr, amount } => libra_coin_mint_to_impl(dst_addr, amount),
MultisigAccountAddOwner { new_owner } => multisig_account_add_owner(new_owner),
MultisigAccountAddOwners { new_owners } => multisig_account_add_owners(new_owners),
MultisigAccountApproveTransaction {
Expand Down Expand Up @@ -1515,14 +1515,14 @@ pub fn jail_unjail_by_voucher(addr: AccountAddress) -> TransactionPayload {

/// Only callable in tests and testnets where the core resources account exists.
/// Claim the delegated mint capability and destroy the delegated token.
pub fn gas_coin_claim_mint_capability() -> TransactionPayload {
pub fn libra_coin_claim_mint_capability() -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("gas_coin").to_owned(),
ident_str!("libra_coin").to_owned(),
),
ident_str!("claim_mint_capability").to_owned(),
vec![],
Expand All @@ -1532,14 +1532,14 @@ pub fn gas_coin_claim_mint_capability() -> TransactionPayload {

/// Only callable in tests and testnets where the core resources account exists.
/// Create delegated token for the address so the account could claim MintCapability later.
pub fn gas_coin_delegate_mint_capability(to: AccountAddress) -> TransactionPayload {
pub fn libra_coin_delegate_mint_capability(to: AccountAddress) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("gas_coin").to_owned(),
ident_str!("libra_coin").to_owned(),
),
ident_str!("delegate_mint_capability").to_owned(),
vec![],
Expand All @@ -1549,14 +1549,14 @@ pub fn gas_coin_delegate_mint_capability(to: AccountAddress) -> TransactionPaylo

/// Root account can mint to an address. Only used for genesis and tests.
/// The "root" account in smoke tests has some privileges.
pub fn gas_coin_mint_to_impl(dst_addr: AccountAddress, amount: u64) -> TransactionPayload {
pub fn libra_coin_mint_to_impl(dst_addr: AccountAddress, amount: u64) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("gas_coin").to_owned(),
ident_str!("libra_coin").to_owned(),
),
ident_str!("mint_to_impl").to_owned(),
vec![],
Expand Down Expand Up @@ -2723,31 +2723,31 @@ mod decoder {
}
}

pub fn gas_coin_claim_mint_capability(
pub fn libra_coin_claim_mint_capability(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(_script) = payload {
Some(EntryFunctionCall::GasCoinClaimMintCapability {})
Some(EntryFunctionCall::LibraCoinClaimMintCapability {})
} else {
None
}
}

pub fn gas_coin_delegate_mint_capability(
pub fn libra_coin_delegate_mint_capability(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::GasCoinDelegateMintCapability {
Some(EntryFunctionCall::LibraCoinDelegateMintCapability {
to: bcs::from_bytes(script.args().get(0)?).ok()?,
})
} else {
None
}
}

pub fn gas_coin_mint_to_impl(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
pub fn libra_coin_mint_to_impl(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::GasCoinMintToImpl {
Some(EntryFunctionCall::LibraCoinMintToImpl {
dst_addr: bcs::from_bytes(script.args().get(0)?).ok()?,
amount: bcs::from_bytes(script.args().get(1)?).ok()?,
})
Expand Down Expand Up @@ -3335,16 +3335,16 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
Box::new(decoder::jail_unjail_by_voucher),
);
map.insert(
"gas_coin_claim_mint_capability".to_string(),
Box::new(decoder::gas_coin_claim_mint_capability),
"libra_coin_claim_mint_capability".to_string(),
Box::new(decoder::libra_coin_claim_mint_capability),
);
map.insert(
"gas_coin_delegate_mint_capability".to_string(),
Box::new(decoder::gas_coin_delegate_mint_capability),
"libra_coin_delegate_mint_capability".to_string(),
Box::new(decoder::libra_coin_delegate_mint_capability),
);
map.insert(
"gas_coin_mint_to_impl".to_string(),
Box::new(decoder::gas_coin_mint_to_impl),
"libra_coin_mint_to_impl".to_string(),
Box::new(decoder::libra_coin_mint_to_impl),
);
map.insert(
"multisig_account_add_owner".to_string(),
Expand Down
18 changes: 8 additions & 10 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// This module defines a struct storing the metadata of the block and new block events.
module diem_framework::block {
use std::error;
use std::features;
use std::vector;
use std::option;

Expand All @@ -12,7 +11,6 @@ module diem_framework::block {
use diem_framework::state_storage;
use diem_framework::system_addresses;
use diem_framework::timestamp;
use diem_framework::transaction_fee;
// use diem_std::debug::print;

//////// 0L ////////
Expand Down Expand Up @@ -141,14 +139,14 @@ module diem_framework::block {
};
emit_new_block_event(&vm, &mut block_metadata_ref.new_block_events, new_block_event);

if (features::collect_and_distribute_gas_fees()) {
// Assign the fees collected from the previous block to the previous block proposer.
// If for any reason the fees cannot be assigned, this function burns the collected coins.
transaction_fee::process_collected_fees();
// Set the proposer of this block as the receiver of the fees, so that the fees for this
// block are assigned to the right account.
transaction_fee::register_proposer_for_fee_collection(proposer);
};
// if (features::collect_and_distribute_gas_fees()) {
// // Assign the fees collected from the previous block to the previous block proposer.
// // If for any reason the fees cannot be assigned, this function burns the collected coins.
// transaction_fee::process_collected_fees();
// // Set the proposer of this block as the receiver of the fees, so that the fees for this
// // block are assigned to the right account.
// transaction_fee::register_proposer_for_fee_collection(proposer);
// };

// Performance scores have to be updated before the epoch transition as the transaction that triggers the
// transition is the last block in the previous epoch.
Expand Down
50 changes: 2 additions & 48 deletions framework/libra-framework/sources/modified_source/coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module diem_framework::coin {
use std::error;
use std::option::{Self, Option};
use std::signer;
use std::fixed_point32;

use diem_framework::account::{Self, WithdrawCapability};
use diem_framework::aggregator_factory;
Expand All @@ -14,15 +13,13 @@ module diem_framework::coin {
use diem_framework::system_addresses;

use diem_std::type_info;
use diem_std::math64;
// use diem_std::debug::print;

friend ol_framework::gas_coin;
friend ol_framework::libra_coin;
friend ol_framework::burn;
friend ol_framework::ol_account;
friend diem_framework::genesis;
friend diem_framework::genesis_migration;
friend ol_framework::rewards;
friend diem_framework::transaction_fee;


Expand Down Expand Up @@ -241,58 +238,15 @@ module diem_framework::coin {
type_info::account_address(&type_info)
}

#[view]
// #[view]
/// Returns the balance of `owner` for provided `CoinType`.
public fun balance<CoinType>(owner: address): u64 acquires CoinStore {
// should not abort if the VM might call this
if (!is_account_registered<CoinType>(owner)) return 0;
borrow_global<CoinStore<CoinType>>(owner).coin.value
}

#[view]
/// Returns a human readable version of the balance with (integer, decimal_part)
public fun balance_human<CoinType>(owner: address): (u64, u64) acquires CoinStore, CoinInfo {
assert!(
is_account_registered<CoinType>(owner),
error::not_found(ECOIN_STORE_NOT_PUBLISHED),
);

let unscaled_value = borrow_global<CoinStore<CoinType>>(owner).coin.value;
assert!(unscaled_value > 0, error::out_of_range(EZERO_COIN_AMOUNT));

let decimal_places = decimals<CoinType>();
let scaling = math64::pow(10, (decimal_places as u64));
let value = fixed_point32::create_from_rational(unscaled_value, scaling);
// multply will TRUNCATE.
let integer_part = fixed_point32::multiply_u64(1, value);

let decimal_part = unscaled_value - (integer_part * scaling);

(integer_part, decimal_part)
}

#[test(source = @0x1)]
public entry fun test_human_read(
source: signer,
) acquires CoinInfo, CoinStore {
let source_addr = signer::address_of(&source);
account::create_account_for_test(source_addr);
let (burn_cap, freeze_cap, mint_cap) = initialize_and_register_fake_money(&source, 8, true);

let coins_minted = mint<FakeMoney>(1234567890, &mint_cap);
deposit(source_addr, coins_minted);
// assert!(balance<FakeMoney>(source_addr) == 100, 0);

let (integer, decimal) = balance_human<FakeMoney>(source_addr);
assert!(integer == 12, 7357001);
assert!(decimal == 34567890, 7357002);

move_to(&source, FakeMoneyCapabilities {
burn_cap,
freeze_cap,
mint_cap,
});
}

#[view]
/// Returns `true` if the type `CoinType` is an initialized coin.
Expand Down
Loading
Loading