Skip to content

Commit

Permalink
[release-builder] Make release builder use a relative path for raw sc…
Browse files Browse the repository at this point in the history
…ript

Currently this absolute path only works from within a docker image

This change makes the path relative and possible to run from elsewhere

Test Plan:
```
RUST_BACKTRACE=1 cargo run --profile performance -p aptos-release-builder \
    generate-proposals \
    --release-config aptos-move/aptos-release-builder/data/release.yaml --output-dir banana
```

Pull Request: #9529
  • Loading branch information
perryjrandall committed Aug 8, 2023
1 parent 62668cd commit 13ef7f8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 33 deletions.
2 changes: 1 addition & 1 deletion aptos-move/aptos-release-builder/data/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ proposals:
discussion_url: "https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-28.md"
execution_mode: MultiStep
update_sequence:
- RawScript: /aptos/aptos-move/aptos-release-builder/data/proposals/aip_28_initialization.move
- RawScript: aptos-move/aptos-release-builder/data/proposals/aip_28_initialization.move
- FeatureFlag:
enabled:
- partial_governance_voting
Expand Down
22 changes: 18 additions & 4 deletions aptos-move/aptos-release-builder/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use self::framework::FrameworkReleaseConfig;
use crate::{aptos_framework_path, components::feature_flags::Features, release_builder_path};
use anyhow::{anyhow, bail, Result};
use crate::{aptos_core_path, aptos_framework_path, components::feature_flags::Features};
use anyhow::{anyhow, bail, Context, Result};
use aptos::governance::GenerateExecutionHash;
use aptos_rest_client::Client;
use aptos_temppath::TempPath;
Expand Down Expand Up @@ -205,15 +205,16 @@ impl ReleaseEntry {
}
},
ReleaseEntry::RawScript(script_path) => {
let base_path = release_builder_path().join(script_path.as_path());
let base_path = aptos_core_path().join(script_path.as_path());
let file_name = base_path
.file_name()
.and_then(|name| name.to_str())
.ok_or_else(|| {
anyhow!("Unable to obtain file name for proposal: {:?}", script_path)
})?
.to_string();
let file_content = std::fs::read_to_string(base_path)?;
let file_content = std::fs::read_to_string(base_path)
.with_context(|| format!("Unable to read file: {}", script_path.display()))?;

if let ExecutionMode::MultiStep = execution_mode {
// Render the hash for multi step proposal.
Expand Down Expand Up @@ -347,6 +348,19 @@ impl ReleaseConfig {

// Create directories for source and metadata.
let mut source_dir = base_path.to_path_buf();

// If source dir doesnt exist create it, if it does exist error
if !source_dir.exists() {
println!("Creating source directory: {:?}", source_dir);
std::fs::create_dir(source_dir.as_path()).map_err(|err| {
anyhow!(
"Fail to create folder for source: {} {:?}",
source_dir.display(),
err
)
})?;
}

source_dir.push("sources");

std::fs::create_dir(source_dir.as_path())
Expand Down
6 changes: 0 additions & 6 deletions aptos-move/aptos-release-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,3 @@ pub(crate) fn aptos_framework_path() -> PathBuf {
path.push("aptos-move/framework/aptos-framework");
path
}

pub(crate) fn release_builder_path() -> PathBuf {
let mut path = aptos_core_path();
path.push("aptos-move/aptos-release-builder");
path
}
57 changes: 35 additions & 22 deletions aptos-move/aptos-release-builder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use anyhow::Context;
use aptos_crypto::{ed25519::Ed25519PrivateKey, ValidCryptoMaterialStringExt};
use aptos_release_builder::{
components::fetch_config,
Expand Down Expand Up @@ -84,7 +84,7 @@ pub enum InputOptions {
}

#[tokio::main]
async fn main() -> Result<()> {
async fn main() {
let args = Argument::parse();
initialize_aptos_core_path(args.aptos_core_path.clone());

Expand All @@ -93,11 +93,15 @@ async fn main() -> Result<()> {
Commands::GenerateProposals {
release_config,
output_dir,
} => aptos_release_builder::ReleaseConfig::load_config(release_config.as_path())?
.generate_release_proposal_scripts(output_dir.as_path()),
Commands::WriteDefault { output_path } => {
aptos_release_builder::ReleaseConfig::default().save_config(output_path.as_path())
},
} => aptos_release_builder::ReleaseConfig::load_config(release_config.as_path())
.with_context(|| "Failed to load release config".to_string())
.unwrap()
.generate_release_proposal_scripts(output_dir.as_path())
.with_context(|| "Failed to generate release proposal scripts".to_string())
.unwrap(),
Commands::WriteDefault { output_path } => aptos_release_builder::ReleaseConfig::default()
.save_config(output_path.as_path())
.unwrap(),
Commands::ValidateProposals {
release_config,
input_option,
Expand All @@ -107,7 +111,8 @@ async fn main() -> Result<()> {
output_dir,
} => {
let config =
aptos_release_builder::ReleaseConfig::load_config(release_config.as_path())?;
aptos_release_builder::ReleaseConfig::load_config(release_config.as_path())
.unwrap();

let root_key_path = aptos_temppath::TempPath::new();
root_key_path.create_as_file().unwrap();
Expand All @@ -117,21 +122,25 @@ async fn main() -> Result<()> {
aptos_release_builder::validate::NetworkConfig::new_from_dir(
endpoint.clone(),
test_dir.as_path(),
)?
)
.unwrap()
},
InputOptions::FromArgs {
root_key,
validator_address,
validator_key,
} => {
let root_key = Ed25519PrivateKey::from_encoded_string(&root_key)?;
let validator_key = Ed25519PrivateKey::from_encoded_string(&validator_key)?;
let validator_account = AccountAddress::from_hex(validator_address.as_bytes())?;
let root_key = Ed25519PrivateKey::from_encoded_string(&root_key).unwrap();
let validator_key =
Ed25519PrivateKey::from_encoded_string(&validator_key).unwrap();
let validator_account =
AccountAddress::from_hex(validator_address.as_bytes()).unwrap();

let mut root_key_path = root_key_path.path().to_path_buf();
root_key_path.set_extension("key");

std::fs::write(root_key_path.as_path(), bcs::to_bytes(&root_key)?)?;
std::fs::write(root_key_path.as_path(), bcs::to_bytes(&root_key).unwrap())
.unwrap();

aptos_release_builder::validate::NetworkConfig {
root_key_path,
Expand All @@ -148,30 +157,34 @@ async fn main() -> Result<()> {
if mint_to_validator {
let chain_id = aptos_rest_client::Client::new(endpoint)
.get_ledger_information()
.await?
.await
.unwrap()
.inner()
.chain_id;

if chain_id == ChainId::mainnet().id() || chain_id == ChainId::testnet().id() {
anyhow::bail!("Mint to mainnet/testnet is not allowed");
panic!("Mint to mainnet/testnet is not allowed");
}

network_config.mint_to_validator().await?;
network_config.mint_to_validator().await.unwrap();
}

network_config
.set_fast_resolve(FAST_RESOLUTION_TIME)
.await?;
.await
.unwrap();
aptos_release_builder::validate::validate_config_and_generate_release(
config,
network_config.clone(),
output_dir,
)
.await?;
.await
.unwrap();
// Reset resolution time back to normal after resolution
network_config
.set_fast_resolve(DEFAULT_RESOLUTION_TIME)
.await
.unwrap()
},
Commands::PrintConfigs {
endpoint,
Expand All @@ -185,7 +198,7 @@ async fn main() -> Result<()> {
($($type:ty), *) => {
$(
println!("{}", std::any::type_name::<$type>());
println!("{}", serde_yaml::to_string(&fetch_config::<$type>(&client)?)?);
println!("{}", serde_yaml::to_string(&fetch_config::<$type>(&client).unwrap()).unwrap());
)*
}
}
Expand All @@ -197,14 +210,14 @@ async fn main() -> Result<()> {
}

// Print Activated Features
let features = fetch_config::<Features>(&client)?;
let features = fetch_config::<Features>(&client).unwrap();
println!(
"Features\n{}",
serde_yaml::to_string(
&aptos_release_builder::components::feature_flags::Features::from(&features)
)?
)
.unwrap()
);
Ok(())
},
}
}
Expand Down

0 comments on commit 13ef7f8

Please sign in to comment.