Skip to content

Commit

Permalink
Add a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
junkil-park committed Aug 11, 2023
1 parent 026ff65 commit 58c688a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
20 changes: 14 additions & 6 deletions aptos-move/framework/aptos-stdlib/sources/debug.move
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ module aptos_std::debug {
}


#[test_only]
use std::features;
#[test(s = @0x123)]
fun test_print_primitive_types(s: signer) {
let u8 = 255u8;
Expand Down Expand Up @@ -131,8 +133,10 @@ module aptos_std::debug {
let a = @0x1234c0ffee;
assert_equal(&a, b"@0x1234c0ffee");

let signer = s;
assert_equal(&signer, b"signer(@0x123)");
if (features::aptos_stdlib_patch_enabled()) {
let signer = s;
assert_equal(&signer, b"signer(@0x123)");
}
}

const MSG_1 : vector<u8> = b"abcdef";
Expand Down Expand Up @@ -183,8 +187,10 @@ module aptos_std::debug {
let v_addr = vector[@0x1234, @0x5678, @0xabcdef];
assert_equal(&v_addr, b"[ @0x1234, @0x5678, @0xabcdef ]");

let v_signer = vector[s1, s2];
assert_equal(&v_signer, b"[ signer(@0x123), signer(@0x456) ]");
if(features::aptos_stdlib_patch_enabled()) {
let v_signer = vector[s1, s2];
assert_equal(&v_signer, b"[ signer(@0x123), signer(@0x456) ]");
};

let v = vector[
TestInner {
Expand Down Expand Up @@ -227,8 +233,10 @@ module aptos_std::debug {
let v_addr = vector[vector[@0x1234, @0x5678], vector[@0xabcdef, @0x9999]];
assert_equal(&v_addr, b"[\n [ @0x1234, @0x5678 ],\n [ @0xabcdef, @0x9999 ]\n]");

let v_signer = vector[vector[s1], vector[s2]];
assert_equal(&v_signer, b"[\n [ signer(@0x123) ],\n [ signer(@0x456) ]\n]");
if(features::aptos_stdlib_patch_enabled()) {
let v_signer = vector[vector[s1], vector[s2]];
assert_equal(&v_signer, b"[\n [ signer(@0x123) ],\n [ signer(@0x456) ]\n]");
};

let v = vector[
vector[
Expand Down
60 changes: 60 additions & 0 deletions aptos-move/framework/move-stdlib/doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ return true.
- [Function `auids_enabled`](#0x1_features_auids_enabled)
- [Function `get_bulletproofs_feature`](#0x1_features_get_bulletproofs_feature)
- [Function `bulletproofs_enabled`](#0x1_features_bulletproofs_enabled)
- [Function `get_aptos_stdlib_patch_feature`](#0x1_features_get_aptos_stdlib_patch_feature)
- [Function `aptos_stdlib_patch_enabled`](#0x1_features_aptos_stdlib_patch_enabled)
- [Function `change_feature_flags`](#0x1_features_change_feature_flags)
- [Function `is_enabled`](#0x1_features_is_enabled)
- [Function `set`](#0x1_features_set)
Expand Down Expand Up @@ -119,6 +121,18 @@ The enabled features, represented by a bitset stored on chain.
## Constants


<a name="0x1_features_APTOS_STDLIB_PATCH"></a>

Whether the aptos_stdlib patch is enabled. The patch is deprecating the private functions
that are supposed to be test-only, and fixing the signer formatter.
Lifetime: transient


<pre><code><b>const</b> <a href="features.md#0x1_features_APTOS_STDLIB_PATCH">APTOS_STDLIB_PATCH</a>: u64 = 25;
</code></pre>



<a name="0x1_features_APTOS_STD_CHAIN_ID_NATIVES"></a>

Whether the new <code>aptos_stdlib::type_info::chain_id()</code> native for fetching the chain ID is enabled.
Expand Down Expand Up @@ -1186,6 +1200,52 @@ Lifetime: transient



</details>

<a name="0x1_features_get_aptos_stdlib_patch_feature"></a>

## Function `get_aptos_stdlib_patch_feature`



<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_aptos_stdlib_patch_feature">get_aptos_stdlib_patch_feature</a>(): u64
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_aptos_stdlib_patch_feature">get_aptos_stdlib_patch_feature</a>(): u64 { <a href="features.md#0x1_features_APTOS_STDLIB_PATCH">APTOS_STDLIB_PATCH</a> }
</code></pre>



</details>

<a name="0x1_features_aptos_stdlib_patch_enabled"></a>

## Function `aptos_stdlib_patch_enabled`



<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_aptos_stdlib_patch_enabled">aptos_stdlib_patch_enabled</a>(): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_aptos_stdlib_patch_enabled">aptos_stdlib_patch_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_APTOS_STDLIB_PATCH">APTOS_STDLIB_PATCH</a>)
}
</code></pre>



</details>

<a name="0x1_features_change_feature_flags"></a>
Expand Down
12 changes: 12 additions & 0 deletions aptos-move/framework/move-stdlib/sources/configs/features.move
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ module std::features {
is_enabled(BULLETPROOFS_NATIVES)
}

/// Whether the aptos_stdlib patch is enabled. The patch is deprecating the private functions
/// that are supposed to be test-only, and fixing the signer formatter.
/// Lifetime: transient

const APTOS_STDLIB_PATCH: u64 = 25;

public fun get_aptos_stdlib_patch_feature(): u64 { APTOS_STDLIB_PATCH }

public fun aptos_stdlib_patch_enabled(): bool acquires Features {
is_enabled(APTOS_STDLIB_PATCH)
}

// ============================================================================================
// Feature Flag Implementation

Expand Down
27 changes: 20 additions & 7 deletions aptos-move/framework/src/natives/string_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use aptos_native_interface::{
safely_pop_arg, RawSafeNative, SafeNativeBuilder, SafeNativeContext, SafeNativeError,
SafeNativeResult,
};
use aptos_types::on_chain_config::FeatureFlag;
use ark_std::iterable::Iterable;
use move_core_types::{
account_address::AccountAddress,
Expand Down Expand Up @@ -175,18 +176,30 @@ fn native_format_impl(
write!(out, "@{}", str).unwrap();
},
MoveTypeLayout::Signer => {
let strct = val.value_as::<Struct>()?;
let addr = strct
.unpack()?
.next()
.unwrap()
.value_as::<move_core_types::account_address::AccountAddress>()?;
let feature_enabled = context
.context
.get_feature_flags()
.is_enabled(FeatureFlag::APTOS_STDLIB_PATCH);
let addr = if feature_enabled {
val.value_as::<Struct>()?
.unpack()?
.next()
.unwrap()
.value_as::<move_core_types::account_address::AccountAddress>()?
} else {
val.value_as::<move_core_types::account_address::AccountAddress>()?
};

let str = if context.canonicalize {
addr.to_canonical_string()
} else {
addr.to_hex_literal()
};
write!(out, "signer(@{})", str).unwrap();
if feature_enabled {
write!(out, "signer(@{})", str).unwrap();
} else {
write!(out, "signer({})", str).unwrap();
}
},
MoveTypeLayout::Vector(ty) => {
if let MoveTypeLayout::U8 = ty.as_ref() {
Expand Down
1 change: 1 addition & 0 deletions types/src/on_chain_config/aptos_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum FeatureFlag {
GAS_PAYER_ENABLED = 22,
APTOS_UNIQUE_IDENTIFIERS = 23,
BULLETPROOFS_NATIVES = 24,
APTOS_STDLIB_PATCH = 25,
}

/// Representation of features on chain as a bitset.
Expand Down

0 comments on commit 58c688a

Please sign in to comment.