Skip to content

Commit

Permalink
Merge branch 'aptos-labs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mpsc0x authored Aug 16, 2024
2 parents ca2c78a + 73fa99b commit 41fa87f
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ jobs:
with:
GIT_SHA: ${{ needs.determine-docker-build-metadata.outputs.gitSha }}
FORGE_TEST_SUITE: compat
IMAGE_TAG: 1c2ee7082d6eff8c811ee25d6f5a7d00860a75d5 #aptos-node-v1.16.0
IMAGE_TAG: d1bf834728a0cf166d993f4728dfca54f3086fb0 #aptos-node-v1.18.0
FORGE_RUNNER_DURATION_SECS: 300
COMMENT_HEADER: forge-compat
FORGE_NAMESPACE: forge-compat-${{ needs.determine-docker-build-metadata.outputs.targetCacheId }}
Expand Down Expand Up @@ -340,7 +340,7 @@ jobs:
with:
GIT_SHA: ${{ needs.determine-docker-build-metadata.outputs.gitSha }}
FORGE_TEST_SUITE: framework_upgrade
IMAGE_TAG: 1c2ee7082d6eff8c811ee25d6f5a7d00860a75d5 #aptos-node-v1.16.0
IMAGE_TAG: d1bf834728a0cf166d993f4728dfca54f3086fb0 #aptos-node-v1.18.0
FORGE_RUNNER_DURATION_SECS: 3600
COMMENT_HEADER: forge-framework-upgrade
FORGE_NAMESPACE: forge-framework-upgrade-${{ needs.determine-docker-build-metadata.outputs.targetCacheId }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/forge-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
uses: aptos-labs/aptos-core/.github/workflows/workflow-run-forge.yaml@main
secrets: inherit
with:
IMAGE_TAG: 1c2ee7082d6eff8c811ee25d6f5a7d00860a75d5 #aptos-node-v1.16.0
IMAGE_TAG: d1bf834728a0cf166d993f4728dfca54f3086fb0 #aptos-node-v1.18.0
FORGE_NAMESPACE: forge-framework-upgrade-${{ needs.determine-test-metadata.outputs.BRANCH_HASH }}
FORGE_RUNNER_DURATION_SECS: 7200 # Run for 2 hours
FORGE_TEST_SUITE: framework_upgrade
Expand Down Expand Up @@ -269,7 +269,7 @@ jobs:
FORGE_RUNNER_DURATION_SECS: 300 # Run for 5 minutes
# This will upgrade from testnet branch to the latest main
FORGE_TEST_SUITE: compat
IMAGE_TAG: 1c2ee7082d6eff8c811ee25d6f5a7d00860a75d5 #aptos-node-v1.16.0
IMAGE_TAG: d1bf834728a0cf166d993f4728dfca54f3086fb0 #aptos-node-v1.18.0
GIT_SHA: ${{ needs.determine-test-metadata.outputs.IMAGE_TAG }} # this is the git ref to checkout
POST_TO_SLACK: true

Expand Down
25 changes: 14 additions & 11 deletions crates/aptos-telemetry-service/src/prometheus_push_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub async fn handle_metrics_ingest(
) -> anyhow::Result<impl Reply, Rejection> {
debug!("handling prometheus metrics ingest");

let enable_location_labels = env::var("FEATURE_LOCATION_LABELS_ENABLED")
.map(|val| val.parse::<bool>().unwrap_or(false))
.unwrap_or(false);

let enable_random_label = env::var("FEATURE_RANDOM_LABEL_ENABLED")
.map(|val| val.parse::<bool>().unwrap_or(false))
.unwrap_or(false);
Expand All @@ -53,17 +57,16 @@ pub async fn handle_metrics_ingest(
.map(|val| val.parse::<i32>().unwrap_or(20))
.unwrap_or(20);

let extra_labels = [
claims_to_extra_labels(
&claims,
context
.peer_identities()
.get(&claims.chain_id)
.and_then(|peers| peers.get(&claims.peer_id)),
),
peer_location_labels(&context, &claims.peer_id),
]
.concat();
let mut extra_labels = claims_to_extra_labels(
&claims,
context
.peer_identities()
.get(&claims.chain_id)
.and_then(|peers| peers.get(&claims.peer_id)),
);
if enable_location_labels {
extra_labels.extend_from_slice(&peer_location_labels(&context, &claims.peer_id));
}

let extra_labels_with_random_label = if enable_random_label {
let random_num = rand::thread_rng().gen_range(0, max_random_value);
Expand Down
1 change: 1 addition & 0 deletions crates/aptos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
- Add safe methods to delete a profile, to rename a profile, and to output the private key of a profile.
- Add `aptos update movefmt`. This installs / updates the `movefmt` binary, which is needed for the new `aptos move fmt` subcommand.
- Integrate the Move formatter `movefmt` which is now available via `aptos move fmt`

Expand Down
140 changes: 140 additions & 0 deletions crates/aptos/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ use std::{collections::BTreeMap, fmt::Formatter, path::PathBuf, str::FromStr};
/// default configuration, and user specific settings.
#[derive(Parser)]
pub enum ConfigTool {
DeleteProfile(DeleteProfile),
GenerateShellCompletions(GenerateShellCompletions),
RenameProfile(RenameProfile),
SetGlobalConfig(SetGlobalConfig),
ShowGlobalConfig(ShowGlobalConfig),
ShowPrivateKey(ShowPrivateKey),
ShowProfiles(ShowProfiles),
}

impl ConfigTool {
pub async fn execute(self) -> CliResult {
match self {
ConfigTool::DeleteProfile(tool) => tool.execute_serialized().await,
ConfigTool::GenerateShellCompletions(tool) => tool.execute_serialized_success().await,
ConfigTool::RenameProfile(tool) => tool.execute_serialized().await,
ConfigTool::SetGlobalConfig(tool) => tool.execute_serialized().await,
ConfigTool::ShowGlobalConfig(tool) => tool.execute_serialized().await,
ConfigTool::ShowPrivateKey(tool) => tool.execute_serialized().await,
ConfigTool::ShowProfiles(tool) => tool.execute_serialized().await,
}
}
Expand Down Expand Up @@ -112,6 +118,47 @@ impl CliCommand<GlobalConfig> for SetGlobalConfig {
}
}

/// Show the private key for the given profile
#[derive(Parser, Debug)]
pub struct ShowPrivateKey {
/// Which profile's private key to show
#[clap(long)]
profile: String,
}

#[async_trait]
impl CliCommand<String> for ShowPrivateKey {
fn command_name(&self) -> &'static str {
"ShowPrivateKey"
}

async fn execute(self) -> CliTypedResult<String> {
let config = CliConfig::load(ConfigSearchMode::CurrentDir)?;

if let Some(profiles) = &config.profiles {
if let Some(profile) = profiles.get(&self.profile.clone()) {
if let Some(private_key) = &profile.private_key {
Ok(format!("0x{}", hex::encode(private_key.to_bytes())))
} else {
Err(CliError::CommandArgumentError(format!(
"Profile {} does not have a private key",
self.profile
)))
}
} else {
Err(CliError::CommandArgumentError(format!(
"Profile {} does not exist",
self.profile
)))
}
} else {
Err(CliError::CommandArgumentError(
"Config has no profiles".to_string(),
))
}
}
}

/// Shows the current profiles available
///
/// This will only show public information and will not show
Expand Down Expand Up @@ -150,6 +197,99 @@ impl CliCommand<BTreeMap<String, ProfileSummary>> for ShowProfiles {
}
}

/// Delete the specified profile.
#[derive(Parser, Debug)]
pub struct DeleteProfile {
/// Which profile to delete
#[clap(long)]
profile: String,
}

#[async_trait]
impl CliCommand<String> for DeleteProfile {
fn command_name(&self) -> &'static str {
"DeleteProfile"
}

async fn execute(self) -> CliTypedResult<String> {
let mut config = CliConfig::load(ConfigSearchMode::CurrentDir)?;

if let Some(profiles) = &mut config.profiles {
if profiles.remove(&self.profile).is_none() {
Err(CliError::CommandArgumentError(format!(
"Profile {} does not exist",
self.profile
)))
} else {
config.save().map_err(|err| {
CliError::UnexpectedError(format!(
"Unable to save config after deleting profile: {}",
err,
))
})?;
Ok(format!("Deleted profile {}", self.profile))
}
} else {
Err(CliError::CommandArgumentError(
"Config has no profiles".to_string(),
))
}
}
}

/// Rename the specified profile.
#[derive(Parser, Debug)]
pub struct RenameProfile {
/// Which profile to rename
#[clap(long)]
profile: String,

/// New profile name
#[clap(long)]
new_profile_name: String,
}

#[async_trait]
impl CliCommand<String> for RenameProfile {
fn command_name(&self) -> &'static str {
"RenameProfile"
}

async fn execute(self) -> CliTypedResult<String> {
let mut config = CliConfig::load(ConfigSearchMode::CurrentDir)?;

if let Some(profiles) = &mut config.profiles {
if profiles.contains_key(&self.new_profile_name.clone()) {
Err(CliError::CommandArgumentError(format!(
"Profile {} already exists",
self.new_profile_name
)))
} else if let Some(profile_config) = profiles.remove(&self.profile) {
profiles.insert(self.new_profile_name.clone(), profile_config);
config.save().map_err(|err| {
CliError::UnexpectedError(format!(
"Unable to save config after renaming profile: {}",
err,
))
})?;
Ok(format!(
"Renamed profile {} to {}",
self.profile, self.new_profile_name
))
} else {
Err(CliError::CommandArgumentError(format!(
"Profile {} does not exist",
self.profile
)))
}
} else {
Err(CliError::CommandArgumentError(
"Config has no profiles".to_string(),
))
}
}
}

/// Shows the properties in the global config
#[derive(Parser, Debug)]
pub struct ShowGlobalConfig {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

============ bytecode verification failed ========

Diagnostics:
bug: bytecode verification failed with unexpected status code `MOVELOC_UNAVAILABLE_ERROR`. This is a compiler bug, consider reporting it.
┌─ tests/ability-check/bug_14189.move:34:18
34 │ let x2 = S3 { x: x1, y: x0, z: x1 };
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module 0x42::test {
struct S0 has copy, drop {
x: u8,
}

struct S1 has drop {
x: u64,
y: bool,
}

struct S2 has drop {
x: S0,
y: u8,
}

struct S3 has drop {
x: S2,
y: S0,
z: S2,
}

fun assign_chained(x: S3): S3 {
x.x.x.x + x.y.x + x.z.x.x;
x.x.x.x = 0;
x.y.x = 1;
x.z.x.x = 2;
x
}

fun test_assign_chained(): S3 {
let x0 = S0 { x: 42 };
let x1 = S2 { x: x0, y: 42 };
// x1: S2 where S2 is not copy
let x2 = S3 { x: x1, y: x0, z: x1 };
x2 = assign_chained(x2);
x2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

============ bytecode verification failed ========

Diagnostics:
bug: bytecode verification failed with unexpected status code `MOVELOC_UNAVAILABLE_ERROR`. This is a compiler bug, consider reporting it.
┌─ tests/ability-check/bug_14227.move:19:32
19 │ let _common_vector_2 = CommonFieldsVector::Bar {
│ ╭────────────────────────────────^
20 │ │ x: vector[2],
21 │ │ y: vector[_common_fields]
22 │ │ };
│ ╰─────────^
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module 0x815::m {

enum CommonFields has drop {
Foo{x: u64, y: u8},
Bar{x: u64, y: u8, z: u32}
}

enum CommonFieldsVector has drop {
Foo{x: vector<u8>},
Bar{x: vector<u8>, y: vector<CommonFields>}
}

fun test_enum_vector() {
let _common_fields = CommonFields::Bar {
x: 30,
y: 40,
z: 50
};
let _common_vector_2 = CommonFieldsVector::Bar {
x: vector[2],
y: vector[_common_fields]
};
let _common_vector_3 = CommonFieldsVector::Bar {
x: vector[2],
y: vector[_common_fields]
};

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Diagnostics:
error: cannot immutably borrow since mutable references exist
┌─ tests/reference-safety/immu_borrow_bug.move:15:9
14 │ common.x = 15;
│ --------
│ │
│ used by field borrow
│ previous mutable local borrow
15 │ common.x
│ ^^^^^^--
│ │
│ requirement enforced here
│ immutable borrow attempted here
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module 0x815::m {

enum CommonFields has drop {
Foo{x: u64, y: u8},
Bar{x: u64, y: u8, z: u32}
}

fun t9_common_field(): u64 {
let common = CommonFields::Bar {
x: 30,
y: 40,
z: 50
};
common.x = 15;
common.x
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Diagnostics:
error: cannot immutably borrow since mutable references exist
┌─ tests/reference-safety/immu_borrow_bug.move:15:9
14 │ common.x = 15;
│ --------
│ │
│ used by field borrow
│ previous mutable local borrow
15 │ common.x
│ ^^^^^^--
│ │
│ requirement enforced here
│ immutable borrow attempted here

0 comments on commit 41fa87f

Please sign in to comment.