Skip to content

Commit

Permalink
[AptosFramework] remove DPN dependency from a few crates
Browse files Browse the repository at this point in the history
  • Loading branch information
zekun000 authored and aptos-bot committed Mar 25, 2022
1 parent 0233b9a commit b731520
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 406 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions aptos-move/framework/aptos-framework/releases/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use anyhow::Result;
use framework_releases::{Release, ReleaseFetcher};
use move_binary_format::file_format::CompiledModule;
use move_command_line_common::files::{extension_equals, find_filenames, MOVE_COMPILED_EXTENSION};
use once_cell::sync::Lazy;
use std::path::PathBuf;

/// Load the serialized modules from the specified release.
pub fn load_modules_from_release(release_name: &str) -> Result<Vec<Vec<u8>>> {
Expand All @@ -28,3 +30,14 @@ pub fn current_modules() -> &'static [CompiledModule] {
pub fn current_module_blobs() -> &'static [Vec<u8>] {
&CURRENT_MODULE_BLOBS
}

/// Load the serialized modules from the specified paths.
pub fn load_modules_from_paths(paths: &[PathBuf]) -> Vec<Vec<u8>> {
find_filenames(paths, |path| {
extension_equals(path, MOVE_COMPILED_EXTENSION)
})
.expect("module loading failed")
.iter()
.map(|file_name| std::fs::read(file_name).unwrap())
.collect::<Vec<_>>()
}
1 change: 0 additions & 1 deletion aptos-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ consensus = { path = "../consensus" }
consensus-notifications = { path = "../state-sync/inter-component/consensus-notifications" }
crash-handler = { path = "../crates/crash-handler" }
data-streaming-service = { path = "../state-sync/state-sync-v2/data-streaming-service" }
diem-framework-releases = { path = "../aptos-move/framework/DPN/releases" }
debug-interface = { path = "../crates/debug-interface" }
event-notifications = { path = "../state-sync/inter-component/event-notifications" }
executor = { path = "../execution/executor" }
Expand Down
2 changes: 1 addition & 1 deletion aptos-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() {
None
};
let genesis_modules = if let Some(module_paths) = args.genesis_modules {
diem_framework_releases::load_modules_from_paths(&module_paths)
aptos_framework_releases::load_modules_from_paths(&module_paths)
} else {
aptos_framework_releases::current_module_blobs().to_vec()
};
Expand Down
2 changes: 1 addition & 1 deletion config/management/genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ executor = { path = "../../../execution/executor" }
bcs = "0.1.2"
aptos-config = { path = "../.."}
aptos-crypto = { path = "../../../crates/aptos-crypto" }
diem-framework-releases = { path = "../../../aptos-move/framework/DPN/releases" }
aptos-framework-releases = { path = "../../../aptos-move/framework/aptos-framework/releases" }
aptos-global-constants = { path = "../../global-constants" }
aptos-management = { path = ".." }
aptos-secure-storage = { path = "../../../secure/storage" }
Expand Down
2 changes: 1 addition & 1 deletion config/management/genesis/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub mod tests {
// Step 2) Upload the Move modules
let tempdir = aptos_temppath::TempPath::new();
tempdir.create_as_dir().unwrap();
for b in diem_framework_releases::current_module_blobs() {
for b in aptos_framework_releases::current_module_blobs() {
let mut temppath =
aptos_temppath::TempPath::new_with_temp_dir(tempdir.path().to_path_buf());
temppath.create_as_file().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion config/management/genesis/src/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn test_config() -> (NodeConfig, Ed25519PrivateKey) {
path.create_as_dir().unwrap();
let (root_keys, _genesis, _genesis_waypoint, validators) = ValidatorBuilder::new(
path.path(),
diem_framework_releases::current_module_blobs().to_vec(),
aptos_framework_releases::current_module_blobs().to_vec(),
)
.template(NodeConfig::default_for_validator())
.build(StdRng::from_seed([0; 32]))
Expand Down
1 change: 1 addition & 0 deletions execution/executor-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ schemadb = { path = "../../storage/schemadb" }
storage-client = { path = "../../storage/storage-client" }
storage-interface = { path = "../../storage/storage-interface" }
aptos-transaction-builder = { path = "../../sdk/transaction-builder" }
aptos-sdk = { path = "../../sdk" }

[dev-dependencies]
aptos-temppath = { path = "../../crates/aptos-temppath" }
Expand Down
6 changes: 3 additions & 3 deletions execution/executor-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ mod tests {
checkpoint_dir.create_as_dir().unwrap();

crate::db_generator::run(
25, /* num_accounts */
10, /* init_account_balance */
5, /* block_size */
25, /* num_accounts */
10000, /* init_account_balance */
5, /* block_size */
storage_dir.as_ref(),
NO_OP_STORAGE_PRUNER_CONFIG, /* prune_window */
);
Expand Down
6 changes: 3 additions & 3 deletions execution/executor-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ fn main() {
opt.block_size,
data_dir,
StoragePrunerConfig::new(
state_store_prune_window,
default_store_prune_window,
max_version_to_prune_per_batch,
Some(state_store_prune_window.unwrap_or(1_000_000)),
Some(default_store_prune_window.unwrap_or(10_000_000)),
Some(max_version_to_prune_per_batch.unwrap_or(100)),
),
);
}
Expand Down
104 changes: 32 additions & 72 deletions execution/executor-benchmark/src/transaction_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ use aptos_crypto::{
PrivateKey, SigningKey, Uniform,
};
use aptos_logger::info;
use aptos_transaction_builder::stdlib::{
encode_create_parent_vasp_account_script, encode_peer_to_peer_with_metadata_script,
};
use aptos_sdk::transaction_builder::TransactionFactory;
use aptos_types::{
account_address::AccountAddress,
account_config::{
testnet_dd_account_address, treasury_compliance_account_address, xus_tag, AccountResource,
XUS_NAME,
},
account_config::{aptos_root_address, AccountResource},
chain_id::ChainId,
transaction::{
authenticator::AuthenticationKey, RawTransaction, Script, SignedTransaction, Transaction,
Version,
},
transaction::{RawTransaction, SignedTransaction, Transaction, Version},
};
use chrono::Local;
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -64,6 +56,7 @@ struct P2pTestCase {
num_accounts: usize,
}

// TODO: use LocalAccount instead
#[derive(Deserialize, Serialize)]
struct AccountData {
private_key: Ed25519PrivateKey,
Expand All @@ -72,14 +65,6 @@ struct AccountData {
sequence_number: u64,
}

impl AccountData {
pub fn auth_key_prefix(&self) -> Vec<u8> {
AuthenticationKey::ed25519(&self.public_key)
.prefix()
.to_vec()
}
}

pub struct TransactionGenerator {
/// The current state of the accounts. The main purpose is to keep track of the sequence number
/// so generated transactions are guaranteed to be successfully executed.
Expand Down Expand Up @@ -219,8 +204,15 @@ impl TransactionGenerator {
self.gen_transfer_transactions(block_size, num_transfer_blocks);
}

pub fn transaction_factory() -> TransactionFactory {
TransactionFactory::new(ChainId::test())
.with_transaction_expiration_time(300)
.with_gas_unit_price(1)
.with_max_gas_amount(1000)
}

pub fn gen_account_creations(&mut self, block_size: usize) -> Vec<Vec<Transaction>> {
let tc_account = treasury_compliance_account_address();
let root_address = aptos_root_address();
let mut txn_block = vec![];

println!(
Expand All @@ -233,18 +225,13 @@ impl TransactionGenerator {
let mut transactions = Vec::with_capacity(block_size);
for (j, account) in block.iter().enumerate() {
let txn = create_transaction(
tc_account,
(i * block_size + j) as u64,
&self.genesis_key,
self.genesis_key.public_key(),
encode_create_parent_vasp_account_script(
xus_tag(),
0,
account.address,
account.auth_key_prefix(),
vec![],
false, /* add all currencies */
),
Self::transaction_factory()
.create_user_account(&account.public_key)
.sender(root_address)
.sequence_number((i * block_size + j) as u64)
.build(),
);
transactions.push(txn);
}
Expand All @@ -267,30 +254,23 @@ impl TransactionGenerator {
init_account_balance: u64,
block_size: usize,
) -> Vec<Vec<Transaction>> {
let testnet_dd_account = testnet_dd_account_address();
let root_address = aptos_root_address();
let mut txn_block = vec![];

println!(
"[{}] Generating {} mint txns.",
now_fmt!(),
self.accounts_cache.len(),
);
let bar = get_progress_bar(self.accounts_cache.len());
let total_accounts = self.accounts_cache.len();
println!("[{}] Generating {} mint txns.", now_fmt!(), total_accounts,);
let bar = get_progress_bar(total_accounts);
for (i, block) in self.accounts_cache.chunks(block_size).enumerate() {
let mut transactions = Vec::with_capacity(block_size);
for (j, account) in block.iter().enumerate() {
let txn = create_transaction(
testnet_dd_account,
(i * block_size + j) as u64,
&self.genesis_key,
self.genesis_key.public_key(),
encode_peer_to_peer_with_metadata_script(
xus_tag(),
account.address,
init_account_balance,
vec![],
vec![],
),
Self::transaction_factory()
.mint(account.address, init_account_balance)
.sender(root_address)
.sequence_number((total_accounts + i * block_size + j) as u64)
.build(),
);
transactions.push(txn);
}
Expand Down Expand Up @@ -326,17 +306,13 @@ impl TransactionGenerator {
let sender = &self.accounts_cache[sender_idx];
let receiver = &self.accounts_cache[receiver_idx];
let txn = create_transaction(
sender.address,
sender.sequence_number,
&sender.private_key,
sender.public_key.clone(),
encode_peer_to_peer_with_metadata_script(
xus_tag(),
receiver.address,
1, /* amount */
vec![],
vec![],
),
Self::transaction_factory()
.transfer(receiver.address, 1)
.sender(sender.address)
.sequence_number(sender.sequence_number)
.build(),
);
transactions.push(txn);
self.accounts_cache[sender_idx].sequence_number += 1;
Expand Down Expand Up @@ -381,26 +357,10 @@ impl TransactionGenerator {
}

fn create_transaction(
sender: AccountAddress,
sequence_number: u64,
private_key: &Ed25519PrivateKey,
public_key: Ed25519PublicKey,
program: Script,
raw_txn: RawTransaction,
) -> Transaction {
let now = aptos_infallible::duration_since_epoch();
let expiration_time = now.as_secs() + 3600;

let raw_txn = RawTransaction::new_script(
sender,
sequence_number,
program,
1_000_000, /* max_gas_amount */
0, /* gas_unit_price */
XUS_NAME.to_owned(), /* gas_currency_code */
expiration_time,
ChainId::test(),
);

let signature = private_key.sign(&raw_txn);
let signed_txn = SignedTransaction::new(raw_txn, public_key, signature);
Transaction::UserTransaction(signed_txn)
Expand Down
2 changes: 1 addition & 1 deletion storage/inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ anyhow = "1.0.52"
structopt = "0.3.21"
tempfile = "3.2.0"

diem-framework-releases = { path = "../../aptos-move/framework/DPN/releases" }
aptos-framework-releases = { path = "../../aptos-move/framework/aptos-framework/releases" }
aptosdb = { path = "../aptosdb" }
aptos-config = { path = "../../config" }
aptos-crypto = { path = "../../crates/aptos-crypto" }
Expand Down
5 changes: 2 additions & 3 deletions storage/inspector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use anyhow::Result;
use aptos_config::config::{RocksdbConfig, NO_OP_STORAGE_PRUNER_CONFIG};
use aptos_logger::info;
use aptosdb::AptosDB;
use diem_framework_releases::name_for_script;
use std::path::PathBuf;
use storage_interface::DbReader;

Expand Down Expand Up @@ -78,7 +77,7 @@ fn print_txn(db: &AptosDB, version: u64) {
println!(
"Transaction {}: {}",
version,
tx.format_for_client(|bytes| name_for_script(bytes).unwrap())
tx.format_for_client(|_| "Unexpected script in aptos-framework".to_string())
);
}

Expand Down Expand Up @@ -117,7 +116,7 @@ fn list_txns(db: &AptosDB) {
v,
tx.expect("Unable to read TX")
.0
.format_for_client(|bytes| name_for_script(bytes).unwrap())
.format_for_client(|_| "Unexpected script in aptos-framework".to_string())
);
}
}
Expand Down
1 change: 0 additions & 1 deletion testsuite/smoke-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ aptos-config = { path = "../../config" }
aptos-crypto = { path = "../../crates/aptos-crypto" }
diem-experimental-framework-releases = { path = "../../aptos-move/framework/experimental/releases" }
framework = { path = "../../aptos-move/framework" }
diem-framework-releases = { path = "../../aptos-move/framework/DPN/releases" }
aptos-rest-client = { path = "../../crates/aptos-rest-client" }
aptos-sdk = { path = "../../sdk" }
aptos-temppath = { path = "../../crates/aptos-temppath" }
Expand Down
Loading

0 comments on commit b731520

Please sign in to comment.