From c21d104a7a02a8ce743e8d06f4c61f1f391db3e7 Mon Sep 17 00:00:00 2001 From: Igor Date: Wed, 18 Oct 2023 09:25:07 -0700 Subject: [PATCH] fix lint --- .../aptos-framework/doc/aggregator_v2.md | 29 +++++++++++--- .../sources/aggregator_v2/aggregator_v2.move | 38 +++++++++--------- .../aggregator_v2/aggregator_v2.spec.move | 5 +++ .../aggregator_natives/aggregator_v2.rs | 40 ++++++++++--------- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/aggregator_v2.md b/aptos-move/framework/aptos-framework/doc/aggregator_v2.md index 9fd3230df6d94d..44971e4af48bcd 100644 --- a/aptos-move/framework/aptos-framework/doc/aggregator_v2.md +++ b/aptos-move/framework/aptos-framework/doc/aggregator_v2.md @@ -34,6 +34,7 @@ operation that also reduced parallelism, and should be avoided as much as possib - [Function `test_aggregator_valid_type`](#0x1_aggregator_v2_test_aggregator_valid_type) - [Specification](#@Specification_1) - [Function `create_aggregator`](#@Specification_1_create_aggregator) + - [Function `create_unbounded_aggregator`](#@Specification_1_create_unbounded_aggregator) - [Function `try_add`](#@Specification_1_try_add) - [Function `try_sub`](#@Specification_1_try_sub) - [Function `read`](#@Specification_1_read) @@ -56,7 +57,7 @@ operation that also reduced parallelism, and should be avoided as much as possib Represents an integer which supports parallel additions and subtractions across multiple transactions. See the module description for more details. -Currently supported types for Element are u64 and u128. +Currently supported types for IntElement are u64 and u128.
struct Aggregator<IntElement> has drop, store
@@ -164,7 +165,7 @@ and any calls will raise this error.
 
 
 
-Arguments passed to concat exceed max limit of 256 bytes (for prefix and suffix together)
+Arguments passed to concat exceed max limit of 256 bytes (for prefix and suffix together).
 
 
 
const ECONCAT_STRING_LENGTH_TOO_LARGE: u64 = 8;
@@ -223,7 +224,7 @@ Returns max_value exceeding which aggregator overflows.
 
 Creates new aggregator, with given 'max_value'.
 
-Currently supported types for Element are u64 and u128.
+Currently supported types for IntElement are u64 and u128.
 EAGGREGATOR_ELEMENT_TYPE_NOT_SUPPORTED raised if called with a different type.
 
 
@@ -250,7 +251,7 @@ EAGGREGATOR_ELEMENT_TYPE_NOT_SUPPORTED raised if called with a different type.
 Creates new aggregator, without any 'max_value' on top of the implicit bound restriction
 due to the width of the type (i.e. MAX_U64 for u64, MAX_U128 for u128).
 
-Currently supported types for Element are u64 and u128.
+Currently supported types for IntElement are u64 and u128.
 EAGGREGATOR_ELEMENT_TYPE_NOT_SUPPORTED raised if called with a different type.
 
 
@@ -521,7 +522,7 @@ If length of prefix and suffix together exceed 256 bytes, ECONCAT_STRING_LENGTH_
 
 
 
-
public fun test_aggregator_valid_type()
+
fun test_aggregator_valid_type()
 
@@ -530,7 +531,7 @@ If length of prefix and suffix together exceed 256 bytes, ECONCAT_STRING_LENGTH_ Implementation -
public fun test_aggregator_valid_type() {
+
fun test_aggregator_valid_type() {
     create_unbounded_aggregator<u64>();
     create_unbounded_aggregator<u128>();
     create_aggregator<u64>(5);
@@ -558,6 +559,22 @@ If length of prefix and suffix together exceed 256 bytes, ECONCAT_STRING_LENGTH_
 
 
 
+
pragma opaque;
+
+ + + + + +### Function `create_unbounded_aggregator` + + +
public fun create_unbounded_aggregator<IntElement: copy, drop>(): aggregator_v2::Aggregator<IntElement>
+
+ + + +
pragma opaque;
 
diff --git a/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.move b/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.move index df077b183be0ea..ceaca49991698a 100644 --- a/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.move +++ b/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.move @@ -27,7 +27,7 @@ module aptos_framework::aggregator_v2 { /// The generic type supplied to the aggregator is not supported. const EUNSUPPORTED_AGGREGATOR_TYPE: u64 = 7; - /// Arguments passed to concat exceed max limit of 256 bytes (for prefix and suffix together) + /// Arguments passed to concat exceed max limit of 256 bytes (for prefix and suffix together). const ECONCAT_STRING_LENGTH_TOO_LARGE: u64 = 8; /// The native aggregator function, that is in the move file, is not yet supported. @@ -37,7 +37,7 @@ module aptos_framework::aggregator_v2 { /// Represents an integer which supports parallel additions and subtractions /// across multiple transactions. See the module description for more details. /// - /// Currently supported types for Element are u64 and u128. + /// Currently supported types for IntElement are u64 and u128. struct Aggregator has store, drop { value: IntElement, max_value: IntElement, @@ -57,14 +57,14 @@ module aptos_framework::aggregator_v2 { /// Creates new aggregator, with given 'max_value'. /// - /// Currently supported types for Element are u64 and u128. + /// Currently supported types for IntElement are u64 and u128. /// EAGGREGATOR_ELEMENT_TYPE_NOT_SUPPORTED raised if called with a different type. public native fun create_aggregator(max_value: IntElement): Aggregator; /// Creates new aggregator, without any 'max_value' on top of the implicit bound restriction /// due to the width of the type (i.e. MAX_U64 for u64, MAX_U128 for u128). /// - /// Currently supported types for Element are u64 and u128. + /// Currently supported types for IntElement are u64 and u128. /// EAGGREGATOR_ELEMENT_TYPE_NOT_SUPPORTED raised if called with a different type. public native fun create_unbounded_aggregator(): Aggregator; @@ -73,7 +73,7 @@ module aptos_framework::aggregator_v2 { public native fun try_add(aggregator: &mut Aggregator, value: IntElement): bool; // Adds `value` to aggregator, uncoditionally. - // If addition would exceed the max_value, EAGGREGATOR_OVERFLOW exception will be thrown + // If addition would exceed the max_value, EAGGREGATOR_OVERFLOW exception will be thrown. public fun add(aggregator: &mut Aggregator, value: IntElement) { assert!(try_add(aggregator, value), error::out_of_range(EAGGREGATOR_OVERFLOW)); } @@ -82,8 +82,8 @@ module aptos_framework::aggregator_v2 { /// If subtraction would result in a negative value, `false` is returned, and aggregator value is left unchanged. public native fun try_sub(aggregator: &mut Aggregator, value: IntElement): bool; - // Adds `value` to aggregator, uncoditionally. - // If subtraction would result in a negative value, EAGGREGATOR_UNDERFLOW exception will be thrown + // Subtracts `value` to aggregator, uncoditionally. + // If subtraction would result in a negative value, EAGGREGATOR_UNDERFLOW exception will be thrown. public fun sub(aggregator: &mut Aggregator, value: IntElement) { assert!(try_sub(aggregator, value), error::out_of_range(EAGGREGATOR_UNDERFLOW)); } @@ -118,7 +118,7 @@ module aptos_framework::aggregator_v2 { public native fun string_concat(before: String, snapshot: &AggregatorSnapshot, after: String): AggregatorSnapshot; #[test] - public fun test_aggregator() { + fun test_aggregator() { let agg = create_aggregator(10); assert!(try_add(&mut agg, 5), 1); assert!(try_add(&mut agg, 5), 2); @@ -135,7 +135,7 @@ module aptos_framework::aggregator_v2 { } #[test] - public fun test_correct_read() { + fun test_correct_read() { let snapshot = create_snapshot(42); assert!(read_snapshot(&snapshot) == 42, 0); @@ -145,13 +145,13 @@ module aptos_framework::aggregator_v2 { #[test] #[expected_failure(abort_code = 0x030009, location = Self)] - public fun test_copy_not_yet_supported() { + fun test_copy_not_yet_supported() { let snapshot = create_snapshot(42); copy_snapshot(&snapshot); } #[test] - public fun test_string_concat1() { + fun test_string_concat1() { let snapshot = create_snapshot(42); let snapshot2 = string_concat(std::string::utf8(b"before"), &snapshot, std::string::utf8(b"after")); assert!(read_snapshot(&snapshot2) == std::string::utf8(b"before42after"), 0); @@ -159,14 +159,16 @@ module aptos_framework::aggregator_v2 { #[test] #[expected_failure(abort_code = 0x030005, location = Self)] - public fun test_string_concat_from_string_not_supported() { + fun test_string_concat_from_string_not_supported() { let snapshot = create_snapshot(std::string::utf8(b"42")); string_concat(std::string::utf8(b"before"), &snapshot, std::string::utf8(b"after")); } + // Tests commented out, as flag used in rust cannot be disabled. + // #[test(fx = @std)] // #[expected_failure(abort_code = 0x030006, location = Self)] - // public fun test_snapshot_feature_not_enabled(fx: &signer) { + // fun test_snapshot_feature_not_enabled(fx: &signer) { // use std::features; // use aptos_framework::reconfiguration; // let feature = features::get_aggregator_v2_api_feature(); @@ -177,7 +179,7 @@ module aptos_framework::aggregator_v2 { // #[test(fx = @std)] // #[expected_failure(abort_code = 0x030006, location = Self)] - // public fun test_aggregator_feature_not_enabled(fx: &signer) { + // fun test_aggregator_feature_not_enabled(fx: &signer) { // use std::features; // use aptos_framework::reconfiguration; // let feature = features::get_aggregator_v2_api_feature(); @@ -188,11 +190,11 @@ module aptos_framework::aggregator_v2 { #[test] #[expected_failure(abort_code = 0x030007, location = Self)] - public fun test_aggregator_invalid_type1() { + fun test_aggregator_invalid_type1() { create_unbounded_aggregator(); } - public fun test_aggregator_valid_type() { + fun test_aggregator_valid_type() { create_unbounded_aggregator(); create_unbounded_aggregator(); create_aggregator(5); @@ -201,14 +203,14 @@ module aptos_framework::aggregator_v2 { #[test] #[expected_failure(abort_code = 0x030005, location = Self)] - public fun test_snpashot_invalid_type1() { + fun test_snpashot_invalid_type1() { use std::option; create_snapshot(option::some(42)); } #[test] #[expected_failure(abort_code = 0x030005, location = Self)] - public fun test_snpashot_invalid_type2() { + fun test_snpashot_invalid_type2() { create_snapshot(vector[42]); } } diff --git a/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.spec.move b/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.spec.move index fa50ff228da632..459978eaa7186d 100644 --- a/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.spec.move +++ b/aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.spec.move @@ -4,6 +4,11 @@ spec aptos_framework::aggregator_v2 { pragma opaque; } + spec create_unbounded_aggregator { + // TODO: temporary mockup. + pragma opaque; + } + spec try_add { // TODO: temporary mockup. pragma opaque; diff --git a/aptos-move/framework/src/natives/aggregator_natives/aggregator_v2.rs b/aptos-move/framework/src/natives/aggregator_natives/aggregator_v2.rs index 5d1730026658b5..4a25c2a76ba590 100644 --- a/aptos-move/framework/src/natives/aggregator_natives/aggregator_v2.rs +++ b/aptos-move/framework/src/natives/aggregator_natives/aggregator_v2.rs @@ -36,7 +36,7 @@ pub const EAGGREGATOR_API_NOT_ENABLED: u64 = 0x03_0006; /// The generic type supplied to the aggregators is not supported. pub const EUNSUPPORTED_AGGREGATOR_TYPE: u64 = 0x03_0007; -/// Arguments passed to concat exceed max limit of 256 bytes (for prefix and suffix together) +/// Arguments passed to concat exceed max limit of 256 bytes (for prefix and suffix together). pub const ECONCAT_STRING_LENGTH_TOO_LARGE: u64 = 0x03_0008; /// The native aggregator function, that is in the move file, is not yet supported. @@ -57,21 +57,19 @@ fn is_string_type(context: &SafeNativeContext, type_arg: &Type) -> SafeNativeRes } /// Given the native function argument and a type, returns a tuple of its -/// fields: (`aggregator id`, `limit`). +/// fields: (`aggregator id`, `max_value`). pub fn get_aggregator_fields_by_type( ty_arg: &Type, agg: &StructRef, ) -> SafeNativeResult<(u128, u128)> { match ty_arg { Type::U128 => { - // Get aggregator information and a value to add. - let (id, limit) = get_aggregator_fields_u128(agg)?; - Ok((id, limit)) + let (id, max_value) = get_aggregator_fields_u128(agg)?; + Ok((id, max_value)) }, Type::U64 => { - // Get aggregator information and a value to add. - let (id, limit) = get_aggregator_fields_u64(agg)?; - Ok((id as u128, limit as u128)) + let (id, max_value) = get_aggregator_fields_u64(agg)?; + Ok((id as u128, max_value as u128)) }, _ => Err(SafeNativeError::Abort { abort_code: EUNSUPPORTED_AGGREGATOR_TYPE, @@ -166,7 +164,7 @@ impl SnapshotType { }, )]))) }, - // ty_arg cannot be Integer, if value is String + // Type cannot be Integer, if value is String _ => Err(SafeNativeError::Abort { abort_code: EUNSUPPORTED_AGGREGATOR_SNAPSHOT_TYPE, }), @@ -255,7 +253,7 @@ macro_rules! abort_if_not_enabled { } /*************************************************************************************************** - * native fun create_aggregator(max_value: Element): Aggregator; + * native fun create_aggregator(max_value: IntElement): Aggregator; **************************************************************************************************/ fn native_create_aggregator( @@ -266,6 +264,7 @@ fn native_create_aggregator( abort_if_not_enabled!(context); debug_assert_eq!(args.len(), 1); + debug_assert_eq!(ty_args.len(), 1); context.charge(AGGREGATOR_V2_CREATE_AGGREGATOR_BASE)?; let max_value = pop_value_by_type(&ty_args[0], &mut args)?; @@ -290,6 +289,7 @@ fn native_create_unbounded_aggregator( abort_if_not_enabled!(context); debug_assert_eq!(args.len(), 0); + debug_assert_eq!(ty_args.len(), 1); context.charge(AGGREGATOR_V2_CREATE_AGGREGATOR_BASE)?; let max_value = { @@ -313,7 +313,7 @@ fn native_create_unbounded_aggregator( } /*************************************************************************************************** - * native fun try_add(aggregator: &mut Aggregator, value: Element): bool; + * native fun try_add(aggregator: &mut Aggregator, value: IntElement): bool; **************************************************************************************************/ fn native_try_add( context: &mut SafeNativeContext, @@ -323,6 +323,7 @@ fn native_try_add( abort_if_not_enabled!(context); debug_assert_eq!(args.len(), 2); + debug_assert_eq!(ty_args.len(), 1); context.charge(AGGREGATOR_V2_TRY_ADD_BASE)?; let input = pop_value_by_type(&ty_args[0], &mut args)?; @@ -344,7 +345,7 @@ fn native_try_add( } /*************************************************************************************************** - * native fun try_sub(aggregator: &mut Aggregator, value: Element): bool; + * native fun try_sub(aggregator: &mut Aggregator, value: IntElement): bool; **************************************************************************************************/ fn native_try_sub( context: &mut SafeNativeContext, @@ -354,6 +355,7 @@ fn native_try_sub( abort_if_not_enabled!(context); debug_assert_eq!(args.len(), 2); + debug_assert_eq!(ty_args.len(), 1); context.charge(AGGREGATOR_V2_TRY_SUB_BASE)?; let input = pop_value_by_type(&ty_args[0], &mut args)?; @@ -374,7 +376,7 @@ fn native_try_sub( } /*************************************************************************************************** - * native fun read(aggregator: &Aggregator): Element; + * native fun read(aggregator: &Aggregator): IntElement; **************************************************************************************************/ fn native_read( @@ -385,6 +387,7 @@ fn native_read( abort_if_not_enabled!(context); debug_assert_eq!(args.len(), 1); + debug_assert_eq!(ty_args.len(), 1); context.charge(AGGREGATOR_V2_READ_BASE)?; let (agg_value, agg_max_value) = @@ -401,7 +404,7 @@ fn native_read( } /*************************************************************************************************** - * native fun snapshot(aggregator: &Aggregator): AggregatorSnapshot; + * native fun snapshot(aggregator: &Aggregator): AggregatorSnapshot; **************************************************************************************************/ fn native_snapshot( @@ -412,6 +415,7 @@ fn native_snapshot( abort_if_not_enabled!(context); debug_assert_eq!(args.len(), 1); + debug_assert_eq!(ty_args.len(), 1); context.charge(AGGREGATOR_V2_SNAPSHOT_BASE)?; let (agg_value, _agg_max_value) = @@ -425,7 +429,7 @@ fn native_snapshot( } /*************************************************************************************************** - * native fun create_snapshot(value: Element): AggregatorSnapshot; + * native fun create_snapshot(value: Element): AggregatorSnapshot **************************************************************************************************/ fn native_create_snapshot( @@ -450,7 +454,7 @@ fn native_create_snapshot( } /*************************************************************************************************** - * native fun copy_snapshot(snapshot: AggregatorSnapshot): AggregatorSnapshot; + * native fun copy_snapshot(snapshot: &AggregatorSnapshot): AggregatorSnapshot **************************************************************************************************/ fn native_copy_snapshot( @@ -478,7 +482,7 @@ fn native_copy_snapshot( } /*************************************************************************************************** - * native fun read_snapshot(snapshot: AggregatorSnapshot): Element; + * native fun read_snapshot(snapshot: &AggregatorSnapshot): Element; **************************************************************************************************/ fn native_read_snapshot( @@ -503,7 +507,7 @@ fn native_read_snapshot( } /*************************************************************************************************** - * native fun native fun string_concat(before: String, snapshot: &AggregatorSnapshot, after: String): AggregatorSnapshot; + * native fun string_concat(before: String, snapshot: &AggregatorSnapshot, after: String): AggregatorSnapshot; **************************************************************************************************/ fn native_string_concat(