Skip to content

Commit

Permalink
[cli] Fix address parsing for large package publishing override address
Browse files Browse the repository at this point in the history
The CLI was parsing the address deep in the code instead of the top level
argument parsing.  This now also allows you to use address aliasing
  • Loading branch information
gregnazario committed Oct 30, 2024
1 parent c44f1a3 commit 0d1fea9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use move_core_types::{
account_address::AccountAddress, parser::parse_struct_tag, vm_status::StatusCode,
};
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, option::Option, path::Path};
use std::{collections::BTreeMap, option::Option, path::Path, str::FromStr};

/// Number of transactions needed for staging code chunks before publishing to accounts or objects
/// This is used to derive object address for testing object code deployment feature
Expand Down Expand Up @@ -143,7 +143,7 @@ impl LargePackageTestContext {
package_code,
publish_type,
Some(self.object_address),
LARGE_PACKAGES_MODULE_ADDRESS,
AccountAddress::from_str(LARGE_PACKAGES_MODULE_ADDRESS).unwrap(),
)
}
}
Expand Down
22 changes: 11 additions & 11 deletions aptos-move/framework/src/chunked_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn chunk_package_and_create_payloads(
package_code: Vec<Vec<u8>>,
publish_type: PublishType,
object_address: Option<AccountAddress>,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> Vec<TransactionPayload> {
// Chunk the metadata
let mut metadata_chunks = create_chunks(metadata);
Expand Down Expand Up @@ -105,11 +105,11 @@ fn large_packages_stage_code_chunk(
metadata_chunk: Vec<u8>,
code_indices: Vec<u16>,
code_chunks: Vec<Vec<u8>>,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal(large_packages_module_address).unwrap(),
large_packages_module_address,
ident_str!("large_packages").to_owned(),
),
ident_str!("stage_code_chunk").to_owned(),
Expand All @@ -127,11 +127,11 @@ fn large_packages_stage_code_chunk_and_publish_to_account(
metadata_chunk: Vec<u8>,
code_indices: Vec<u16>,
code_chunks: Vec<Vec<u8>>,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal(large_packages_module_address).unwrap(),
large_packages_module_address,
ident_str!("large_packages").to_owned(),
),
ident_str!("stage_code_chunk_and_publish_to_account").to_owned(),
Expand All @@ -149,11 +149,11 @@ fn large_packages_stage_code_chunk_and_publish_to_object(
metadata_chunk: Vec<u8>,
code_indices: Vec<u16>,
code_chunks: Vec<Vec<u8>>,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal(large_packages_module_address).unwrap(),
large_packages_module_address,
ident_str!("large_packages").to_owned(),
),
ident_str!("stage_code_chunk_and_publish_to_object").to_owned(),
Expand All @@ -172,11 +172,11 @@ fn large_packages_stage_code_chunk_and_upgrade_object_code(
code_indices: Vec<u16>,
code_chunks: Vec<Vec<u8>>,
code_object: AccountAddress,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal(large_packages_module_address).unwrap(),
large_packages_module_address,
ident_str!("large_packages").to_owned(),
),
ident_str!("stage_code_chunk_and_upgrade_object_code").to_owned(),
Expand All @@ -192,11 +192,11 @@ fn large_packages_stage_code_chunk_and_upgrade_object_code(

// Cleanup account's `StagingArea` resource.
pub fn large_packages_cleanup_staging_area(
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal(large_packages_module_address).unwrap(),
large_packages_module_address,
ident_str!("large_packages").to_owned(),
),
ident_str!("cleanup_staging_area").to_owned(),
Expand Down
2 changes: 2 additions & 0 deletions crates/aptos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
All notable changes to the Aptos CLI will be captured in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format set out by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Allow for setting large-packages module for chunking publish mode with `--large-packages-module-address`
- [`Fix`] Remove unwraps to make outputs go through regular error handling

## [4.2.6] - 2024/10/23
Expand Down
8 changes: 6 additions & 2 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,10 @@ pub struct ChunkedPublishOption {
pub(crate) chunked_publish: bool,

/// Address of the `large_packages` move module for chunked publishing
#[clap(long, default_value = LARGE_PACKAGES_MODULE_ADDRESS)]
pub(crate) large_packages_module_address: String,
///
/// By default, on the module is published at `0x0e1ca3011bdd07246d4d16d909dbb2d6953a86c4735d5acf5865d962c630cce7`
/// on Testnet and Mainnet. On any other network, you will need to first publish it from the framework
/// under move-examples/large_packages.
#[clap(long, default_value = LARGE_PACKAGES_MODULE_ADDRESS, value_parser = crate::common::types::load_account_arg)]
pub(crate) large_packages_module_address: AccountAddress,
}
36 changes: 18 additions & 18 deletions crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ impl AsyncTryInto<ChunkedPublishPayloads> for &PublishPackage {
package,
PublishType::AccountDeploy,
None,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?;

let size = &chunked_publish_payloads
Expand Down Expand Up @@ -1012,7 +1012,7 @@ fn create_chunked_publish_payloads(
package: BuiltPackage,
publish_type: PublishType,
object_address: Option<AccountAddress>,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> CliTypedResult<ChunkedPublishPayloads> {
let compiled_units = package.extract_code();
let metadata = package.extract_metadata()?;
Expand Down Expand Up @@ -1050,7 +1050,7 @@ impl CliCommand<TransactionSummary> for PublishPackage {
submit_chunked_publish_transactions(
chunked_package_payloads.payloads,
&self.txn_options,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)
.await
} else {
Expand Down Expand Up @@ -1156,7 +1156,7 @@ impl CliCommand<TransactionSummary> for CreateObjectAndPublishPackage {
package,
PublishType::AccountDeploy,
None,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?
.payloads;
let staging_tx_count = (mock_payloads.len() - 1) as u64;
Expand All @@ -1182,7 +1182,7 @@ impl CliCommand<TransactionSummary> for CreateObjectAndPublishPackage {
package,
PublishType::ObjectDeploy,
None,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?
.payloads;

Expand All @@ -1197,7 +1197,7 @@ impl CliCommand<TransactionSummary> for CreateObjectAndPublishPackage {
submit_chunked_publish_transactions(
payloads,
&self.txn_options,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)
.await
} else {
Expand Down Expand Up @@ -1294,7 +1294,7 @@ impl CliCommand<TransactionSummary> for UpgradeObjectPackage {
built_package,
PublishType::ObjectUpgrade,
Some(self.object_address),
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?
.payloads;

Expand All @@ -1308,7 +1308,7 @@ impl CliCommand<TransactionSummary> for UpgradeObjectPackage {
submit_chunked_publish_transactions(
payloads,
&self.txn_options,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)
.await
} else {
Expand Down Expand Up @@ -1385,7 +1385,7 @@ impl CliCommand<TransactionSummary> for DeployObjectCode {
package,
PublishType::AccountDeploy,
None,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?
.payloads;
let staging_tx_count = (mock_payloads.len() - 1) as u64;
Expand All @@ -1411,7 +1411,7 @@ impl CliCommand<TransactionSummary> for DeployObjectCode {
package,
PublishType::ObjectDeploy,
None,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?
.payloads;

Expand All @@ -1426,7 +1426,7 @@ impl CliCommand<TransactionSummary> for DeployObjectCode {
submit_chunked_publish_transactions(
payloads,
&self.txn_options,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)
.await
} else {
Expand Down Expand Up @@ -1529,7 +1529,7 @@ impl CliCommand<TransactionSummary> for UpgradeCodeObject {
package,
PublishType::ObjectUpgrade,
Some(self.object_address),
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)?
.payloads;

Expand All @@ -1543,7 +1543,7 @@ impl CliCommand<TransactionSummary> for UpgradeCodeObject {
submit_chunked_publish_transactions(
payloads,
&self.txn_options,
&self.chunked_publish_option.large_packages_module_address,
self.chunked_publish_option.large_packages_module_address,
)
.await
} else {
Expand Down Expand Up @@ -1594,7 +1594,7 @@ fn build_package_options(
async fn submit_chunked_publish_transactions(
payloads: Vec<TransactionPayload>,
txn_options: &TransactionOptions,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> CliTypedResult<TransactionSummary> {
let mut publishing_result = Err(CliError::UnexpectedError(
"No payload provided for batch transaction run".to_string(),
Expand Down Expand Up @@ -1666,7 +1666,7 @@ async fn submit_chunked_publish_transactions(

async fn is_staging_area_empty(
txn_options: &TransactionOptions,
large_packages_module_address: &str,
large_packages_module_address: AccountAddress,
) -> CliTypedResult<bool> {
let url = txn_options.rest_options.url(&txn_options.profile_options)?;
let client = Client::new(url);
Expand Down Expand Up @@ -1702,8 +1702,8 @@ pub struct ClearStagingArea {
pub(crate) txn_options: TransactionOptions,

/// Address of the `large_packages` move module for chunked publishing
#[clap(long, default_value = LARGE_PACKAGES_MODULE_ADDRESS)]
pub(crate) large_packages_module_address: String,
#[clap(long, default_value = LARGE_PACKAGES_MODULE_ADDRESS, value_parser = crate::common::types::load_account_arg)]
pub(crate) large_packages_module_address: AccountAddress,
}

#[async_trait]
Expand All @@ -1718,7 +1718,7 @@ impl CliCommand<TransactionSummary> for ClearStagingArea {
&self.large_packages_module_address,
self.txn_options.profile_options.account_address()?
);
let payload = large_packages_cleanup_staging_area(&self.large_packages_module_address);
let payload = large_packages_cleanup_staging_area(self.large_packages_module_address);
self.txn_options
.submit_transaction(payload)
.await
Expand Down
5 changes: 4 additions & 1 deletion crates/aptos/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,10 @@ impl CliTestFramework {
},
chunked_publish_option: ChunkedPublishOption {
chunked_publish: false,
large_packages_module_address: LARGE_PACKAGES_MODULE_ADDRESS.to_string(),
large_packages_module_address: AccountAddress::from_str(
LARGE_PACKAGES_MODULE_ADDRESS,
)
.unwrap(),
},
}
.execute()
Expand Down

0 comments on commit 0d1fea9

Please sign in to comment.