From 58c688a8803ecbb6df967eab1cecc2018eece0bb Mon Sep 17 00:00:00 2001 From: Junkil Park Date: Thu, 10 Aug 2023 18:16:36 -0700 Subject: [PATCH] Add a feature flag --- .../framework/aptos-stdlib/sources/debug.move | 20 +++++-- .../framework/move-stdlib/doc/features.md | 60 +++++++++++++++++++ .../move-stdlib/sources/configs/features.move | 12 ++++ .../framework/src/natives/string_utils.rs | 27 ++++++--- types/src/on_chain_config/aptos_features.rs | 1 + 5 files changed, 107 insertions(+), 13 deletions(-) diff --git a/aptos-move/framework/aptos-stdlib/sources/debug.move b/aptos-move/framework/aptos-stdlib/sources/debug.move index d9574bf29ce2e..d4b7130506d41 100644 --- a/aptos-move/framework/aptos-stdlib/sources/debug.move +++ b/aptos-move/framework/aptos-stdlib/sources/debug.move @@ -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; @@ -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 = b"abcdef"; @@ -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 { @@ -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[ diff --git a/aptos-move/framework/move-stdlib/doc/features.md b/aptos-move/framework/move-stdlib/doc/features.md index 299e233ab084f..2184b9e1ab39f 100644 --- a/aptos-move/framework/move-stdlib/doc/features.md +++ b/aptos-move/framework/move-stdlib/doc/features.md @@ -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) @@ -119,6 +121,18 @@ The enabled features, represented by a bitset stored on chain. ## Constants + + +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;
+
+ + + Whether the new aptos_stdlib::type_info::chain_id() native for fetching the chain ID is enabled. @@ -1186,6 +1200,52 @@ Lifetime: transient + + + + +## Function `get_aptos_stdlib_patch_feature` + + + +
public fun get_aptos_stdlib_patch_feature(): u64
+
+ + + +
+Implementation + + +
public fun get_aptos_stdlib_patch_feature(): u64 { APTOS_STDLIB_PATCH }
+
+ + + +
+ + + +## Function `aptos_stdlib_patch_enabled` + + + +
public fun aptos_stdlib_patch_enabled(): bool
+
+ + + +
+Implementation + + +
public fun aptos_stdlib_patch_enabled(): bool acquires Features {
+    is_enabled(APTOS_STDLIB_PATCH)
+}
+
+ + +
diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index a20a1c3efb57c..caa55a24a5938 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -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 diff --git a/aptos-move/framework/src/natives/string_utils.rs b/aptos-move/framework/src/natives/string_utils.rs index 4fdf4c8d32a00..b889c202a78b5 100644 --- a/aptos-move/framework/src/natives/string_utils.rs +++ b/aptos-move/framework/src/natives/string_utils.rs @@ -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, @@ -175,18 +176,30 @@ fn native_format_impl( write!(out, "@{}", str).unwrap(); }, MoveTypeLayout::Signer => { - let strct = val.value_as::()?; - let addr = strct - .unpack()? - .next() - .unwrap() - .value_as::()?; + let feature_enabled = context + .context + .get_feature_flags() + .is_enabled(FeatureFlag::APTOS_STDLIB_PATCH); + let addr = if feature_enabled { + val.value_as::()? + .unpack()? + .next() + .unwrap() + .value_as::()? + } else { + val.value_as::()? + }; + 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() { diff --git a/types/src/on_chain_config/aptos_features.rs b/types/src/on_chain_config/aptos_features.rs index 05a3c51f23d2c..52431f591d44d 100644 --- a/types/src/on_chain_config/aptos_features.rs +++ b/types/src/on_chain_config/aptos_features.rs @@ -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.