From 01d06ab6509056e0f1447af1f7a573fc6431d29f Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Wed, 6 Sep 2023 16:47:45 -0400 Subject: [PATCH 01/18] added set_finalizers host function --- libraries/eosiolib/capi/eosio/privileged.h | 10 ++ .../contracts/eosio/finalizer_set.hpp | 39 +++++ libraries/native/intrinsics.cpp | 154 +++++++++--------- .../native/native/eosio/intrinsics_def.hpp | 3 +- tests/integration/contracts.hpp.in | 3 + tests/integration/set_finalizers_tests.cpp | 79 +++++++++ .../compile-fail/host_functions_tests.cpp | 1 + tests/unit/test_contracts/CMakeLists.txt | 1 + tests/unit/test_contracts/capi/privileged.c | 1 + .../test_contracts/set_finalizers_tests.cpp | 12 ++ tools/include/eosio/gen.hpp | 3 +- 11 files changed, 224 insertions(+), 82 deletions(-) create mode 100644 libraries/eosiolib/contracts/eosio/finalizer_set.hpp create mode 100644 tests/integration/set_finalizers_tests.cpp create mode 100644 tests/unit/test_contracts/set_finalizers_tests.cpp diff --git a/libraries/eosiolib/capi/eosio/privileged.h b/libraries/eosiolib/capi/eosio/privileged.h index 8628c00769..7c909c6a12 100644 --- a/libraries/eosiolib/capi/eosio/privileged.h +++ b/libraries/eosiolib/capi/eosio/privileged.h @@ -123,6 +123,16 @@ void set_kv_parameters_packed( const char* data, uint32_t datalen ); __attribute__((eosio_wasm_import)) void preactivate_feature( const struct capi_checksum256* feature_digest ); +/** + * Submits a finalizer set change to Hotstuff + * + * @param data - pointer finalizer_set object packed as bytes + * @param len - size of packed finalazer_set object + * @pre `data` is a valid pointer to a range of memory at least `len` bytes long that contains packed abi_finalizer_set data + */ +__attribute__((eosio_wasm_import)) +void set_finalizers( const char* data, uint32_t len ); + #ifdef __cplusplus } #endif diff --git a/libraries/eosiolib/contracts/eosio/finalizer_set.hpp b/libraries/eosiolib/contracts/eosio/finalizer_set.hpp new file mode 100644 index 0000000000..a81b6c4aaf --- /dev/null +++ b/libraries/eosiolib/contracts/eosio/finalizer_set.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "../../capi/eosio/types.h" +#include "../../core/eosio/crypto_bls_ext.hpp" + +#include +#include +#include + +namespace eosio { + namespace internal_use_do_not_use { + extern "C" { + __attribute__((eosio_wasm_import)) + void set_finalizers( const char* data, uint32_t len ); + } // extern "C" + } //internal_use_do_not_use + + struct abi_finalizer_authority { + std::string description; + uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold + std::vector public_key_g1_jacobian; // Jacobian little endian + + EOSLIB_SERIALIZE(abi_finalizer_authority, (description)(fweight)(public_key_g1_jacobian)); + }; + struct abi_finalizer_set { + uint64_t fthreshold = 0; + std::vector finalizers; + + EOSLIB_SERIALIZE(abi_finalizer_set, (fthreshold)(finalizers)); + }; + + void set_finalizers( const abi_finalizer_set& fin_set ) { + for (const auto& finalizer : fin_set.finalizers) + eosio::check(finalizer.public_key_g1_jacobian.size() == sizeof(bls_g1), "public key has a wrong size" ); + auto packed = eosio::pack(fin_set); + internal_use_do_not_use::set_finalizers(packed.data(), packed.size()); + } + +} //eosio \ No newline at end of file diff --git a/libraries/native/intrinsics.cpp b/libraries/native/intrinsics.cpp index a1db008f82..9b758123de 100644 --- a/libraries/native/intrinsics.cpp +++ b/libraries/native/intrinsics.cpp @@ -906,83 +906,77 @@ extern "C" { return intrinsics::get().call(data, datalen); } -} - -int32_t blake2_f( uint32_t rounds, const char* state, uint32_t state_len, const char* msg, uint32_t msg_len, - const char* t0_offset, uint32_t t0_len, const char* t1_offset, uint32_t t1_len, int32_t final, char* result, uint32_t result_len) { - return intrinsics::get().call(rounds, state, state_len, msg, msg_len, t0_offset, t0_len, t1_offset, t1_len, final, result, result_len); -} - -int32_t k1_recover( const char* sig, uint32_t sig_len, const char* dig, uint32_t dig_len, char* pub, uint32_t pub_len) { - return intrinsics::get().call(sig, sig_len, dig, dig_len, pub, pub_len); -} - -int32_t alt_bn128_add( const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* result, uint32_t result_len) { - return intrinsics::get().call(op1, op1_len, op2, op2_len, result, result_len); -} - -int32_t alt_bn128_mul( const char* g1, uint32_t g1_len, const char* scalar, uint32_t scalar_len, char* result, uint32_t result_len) { - return intrinsics::get().call(g1, g1_len, scalar, scalar_len, result, result_len); -} - -int32_t alt_bn128_pair( const char* pairs, uint32_t pairs_len) { - return intrinsics::get().call(pairs, pairs_len); -} - -int32_t mod_exp( const char* base, uint32_t base_len, const char* exp, uint32_t exp_len, const char* mod, uint32_t mod_len, char* result, uint32_t result_len) { - return intrinsics::get().call(base, base_len, exp, exp_len, mod, mod_len, result, result_len); -} - -void sha3( const char* data, uint32_t data_len, char* hash, uint32_t hash_len, int32_t keccak ) { - intrinsics::get().call(data, data_len, hash, hash_len, keccak); -} - -int32_t bls_g1_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(op1, op1_len, op2, op2_len, res, res_len); -} - -int32_t bls_g2_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(op1, op1_len, op2, op2_len, res, res_len); -} - -int32_t bls_g1_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(point, point_len, scalar, scalar_len, res, res_len); -} - -int32_t bls_g2_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(point, point_len, scalar, scalar_len, res, res_len); -} - -int32_t bls_g1_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len) -{ - return intrinsics::get().call(points, points_len, scalars, scalars_len, n, res, res_len); -} - -int32_t bls_g2_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len) -{ - return intrinsics::get().call(points, points_len, scalars, scalars_len, n, res, res_len); -} - -int32_t bls_pairing(const char* g1_points, uint32_t g1_points_len, const char* g2_points, uint32_t g2_points_len, uint32_t n, char* res, uint32_t res_len) -{ - return intrinsics::get().call(g1_points, g1_points_len, g1_points, g1_points_len, n, res, res_len); -} - -int32_t bls_g1_map(const char* e, uint32_t e_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(e, e_len, res, res_len); -} - -int32_t bls_g2_map(const char* e, uint32_t e_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(e, e_len, res, res_len); -} - -int32_t bls_fp_mod(const char* s, uint32_t s_len, char* res, uint32_t res_len) -{ - return intrinsics::get().call(s, s_len, res, res_len); -} + int32_t blake2_f( uint32_t rounds, const char* state, uint32_t state_len, const char* msg, uint32_t msg_len, + const char* t0_offset, uint32_t t0_len, const char* t1_offset, uint32_t t1_len, int32_t final, char* result, uint32_t result_len) { + return intrinsics::get().call(rounds, state, state_len, msg, msg_len, t0_offset, t0_len, t1_offset, t1_len, final, result, result_len); + } + + int32_t k1_recover( const char* sig, uint32_t sig_len, const char* dig, uint32_t dig_len, char* pub, uint32_t pub_len) { + return intrinsics::get().call(sig, sig_len, dig, dig_len, pub, pub_len); + } + + int32_t alt_bn128_add( const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* result, uint32_t result_len) { + return intrinsics::get().call(op1, op1_len, op2, op2_len, result, result_len); + } + + int32_t alt_bn128_mul( const char* g1, uint32_t g1_len, const char* scalar, uint32_t scalar_len, char* result, uint32_t result_len) { + return intrinsics::get().call(g1, g1_len, scalar, scalar_len, result, result_len); + } + + int32_t alt_bn128_pair( const char* pairs, uint32_t pairs_len) { + return intrinsics::get().call(pairs, pairs_len); + } + + int32_t mod_exp( const char* base, uint32_t base_len, const char* exp, uint32_t exp_len, const char* mod, uint32_t mod_len, char* result, uint32_t result_len) { + return intrinsics::get().call(base, base_len, exp, exp_len, mod, mod_len, result, result_len); + } + + void sha3( const char* data, uint32_t data_len, char* hash, uint32_t hash_len, int32_t keccak ) { + intrinsics::get().call(data, data_len, hash, hash_len, keccak); + } + + int32_t bls_g1_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len) { + return intrinsics::get().call(op1, op1_len, op2, op2_len, res, res_len); + } + + int32_t bls_g2_add(const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* res, uint32_t res_len) { + return intrinsics::get().call(op1, op1_len, op2, op2_len, res, res_len); + } + + int32_t bls_g1_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len) { + return intrinsics::get().call(point, point_len, scalar, scalar_len, res, res_len); + } + + int32_t bls_g2_mul(const char* point, uint32_t point_len, const char* scalar, uint32_t scalar_len, char* res, uint32_t res_len) { + return intrinsics::get().call(point, point_len, scalar, scalar_len, res, res_len); + } + + int32_t bls_g1_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len) { + return intrinsics::get().call(points, points_len, scalars, scalars_len, n, res, res_len); + } + + int32_t bls_g2_exp(const char* points, uint32_t points_len, const char* scalars, uint32_t scalars_len, uint32_t n, char* res, uint32_t res_len) { + return intrinsics::get().call(points, points_len, scalars, scalars_len, n, res, res_len); + } + + int32_t bls_pairing(const char* g1_points, uint32_t g1_points_len, const char* g2_points, uint32_t g2_points_len, uint32_t n, char* res, uint32_t res_len) { + return intrinsics::get().call(g1_points, g1_points_len, g1_points, g1_points_len, n, res, res_len); + } + + int32_t bls_g1_map(const char* e, uint32_t e_len, char* res, uint32_t res_len) { + return intrinsics::get().call(e, e_len, res, res_len); + } + + int32_t bls_g2_map(const char* e, uint32_t e_len, char* res, uint32_t res_len) { + return intrinsics::get().call(e, e_len, res, res_len); + } + + int32_t bls_fp_mod(const char* s, uint32_t s_len, char* res, uint32_t res_len) { + return intrinsics::get().call(s, s_len, res, res_len); + } + + void set_finalizers(const char* data, uint32_t len) { + intrinsics::get().call(data, len); + } + +} // extern "C" diff --git a/libraries/native/native/eosio/intrinsics_def.hpp b/libraries/native/native/eosio/intrinsics_def.hpp index 7affd102e0..ca4d602c6a 100644 --- a/libraries/native/native/eosio/intrinsics_def.hpp +++ b/libraries/native/native/eosio/intrinsics_def.hpp @@ -183,7 +183,8 @@ intrinsic_macro(bls_g2_exp) \ intrinsic_macro(bls_pairing) \ intrinsic_macro(bls_g1_map) \ intrinsic_macro(bls_g2_map) \ -intrinsic_macro(bls_fp_mod) +intrinsic_macro(bls_fp_mod) \ +intrinsic_macro(set_finalizers) diff --git a/tests/integration/contracts.hpp.in b/tests/integration/contracts.hpp.in index 982b8b72f8..d8dc4cf017 100644 --- a/tests/integration/contracts.hpp.in +++ b/tests/integration/contracts.hpp.in @@ -25,6 +25,9 @@ namespace eosio::testing { static std::vector bls_primitives_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/bls_primitives_tests.wasm"); } static std::vector bls_primitives_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/bls_primitives_tests.abi"); } + + static std::vector set_finalizers_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/set_finalizers_tests.wasm"); } + static std::vector set_finalizers_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/set_finalizers_tests.abi"); } static std::vector get_code_hash_write_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/get_code_hash_write.wasm"); } static std::vector get_code_hash_write_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/get_code_hash_write.abi"); } diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp new file mode 100644 index 0000000000..48ca8a97e7 --- /dev/null +++ b/tests/integration/set_finalizers_tests.cpp @@ -0,0 +1,79 @@ +#include + +#include +#include +#include + +#include + +namespace eosio::chain { +struct finalizer_authority { + + std::string description; + uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold + std::array public_key; + +}; + +struct finalizer_set { + + uint32_t generation = 0; ///< sequentially incrementing version number + uint64_t fthreshold = 0; ///< vote fweight threshold to finalize blocks + std::vector finalizers; ///< Instant Finality voter set +}; + +} // eosio::chain + +using namespace eosio; +using namespace eosio::testing; +using namespace fc; + +using mvo = fc::mutable_variant_object; + +BOOST_AUTO_TEST_SUITE(set_finalizers_tests) + +BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { + create_accounts( { "test"_n } ); + produce_block(); + + set_code( config::system_account_name, contracts::set_finalizers_test_wasm() ); + set_abi( config::system_account_name, contracts::set_finalizers_test_abi().data() ); + + produce_blocks(); + + + BOOST_ASSERT( control->get_finalizers().finalizers.empty() ); + + const std::vector G1 = {0x16, 0x0c, 0x53, 0xfd, 0x90, 0x87, 0xb3, 0x5c, 0xf5, 0xff, 0x76, 0x99, 0x67, 0xfc, 0x17, 0x78, 0xc1, 0xa1, 0x3b, 0x14, 0xc7, 0x95, 0x4f, 0x15, 0x47, 0xe7, 0xd0, 0xf3, 0xcd, 0x6a, 0xae, 0xf0, 0x40, 0xf4, 0xdb, 0x21, 0xcc, 0x6e, 0xce, 0xed, 0x75, 0xfb, 0x0b, 0x9e, 0x41, 0x77, 0x01, 0x12, 0x3a, 0x88, 0x18, 0xf3, 0x2a, 0x6c, 0x52, 0xff, 0x70, 0x02, 0x3b, 0x38, 0xe4, 0x9c, 0x89, 0x92, 0x55, 0xd0, 0xa9, 0x9f, 0x8d, 0x73, 0xd7, 0x89, 0x2a, 0xc1, 0x44, 0xa3, 0x5b, 0xf3, 0xca, 0x12, 0x17, 0x53, 0x4b, 0x96, 0x76, 0x1b, 0xff, 0x3c, 0x30, 0x44, 0x77, 0xe9, 0xed, 0xd2, 0x44, 0x0e, 0xfd, 0xff, 0x02, 0x00, 0x00, 0x00, 0x09, 0x76, 0x02, 0x00, 0x0c, 0xc4, 0x0b, 0x00, 0xf4, 0xeb, 0xba, 0x58, 0xc7, 0x53, 0x57, 0x98, 0x48, 0x5f, 0x45, 0x57, 0x52, 0x70, 0x53, 0x58, 0xce, 0x77, 0x6d, 0xec, 0x56, 0xa2, 0x97, 0x1a, 0x07, 0x5c, 0x93, 0xe4, 0x80, 0xfa, 0xc3, 0x5e, 0xf6, 0x15}; + // fin_set should be the following struct: + // struct abi_finalizer_authority { + // std::string description; + // uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold + // std::vector public_key_g1_jacobian; // Jacobian little endian + // }; + // struct abi_finalizer_set { + // uint64_t fthreshold = 0; + // std::vector finalizers; + // }; + push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() + ("fin_set", mvo()("fthreshold", 1) + ("finalizers", std::vector{mvo() + ("description", "test_desc") + ("fweight", 1) + ("public_key_g1_jacobian", *reinterpret_cast*>(&G1))}))); + produce_blocks(); + + BOOST_ASSERT( control->get_finalizers().finalizers.size() == 1 ); + + // testing wrong public key size + BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() + ("fin_set", mvo()("fthreshold", 1) + ("finalizers", std::vector{mvo() + ("description", "test_desc") + ("fweight", 1) + ("public_key_g1_jacobian", std::vector{'a', 'b', 'c'})}))), fc::exception); + BOOST_ASSERT( control->get_finalizers().finalizers.size() == 1 ); + +} FC_LOG_AND_RETHROW() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/tests/toolchain/compile-fail/host_functions_tests.cpp b/tests/toolchain/compile-fail/host_functions_tests.cpp index 27068436e7..06fdcc98f7 100644 --- a/tests/toolchain/compile-fail/host_functions_tests.cpp +++ b/tests/toolchain/compile-fail/host_functions_tests.cpp @@ -8,6 +8,7 @@ set_blockchain_parameters_packed : yes set_parameters_packed : yes set_privileged : yes send_deferred : yes +set_finalizers : yes */ #include diff --git a/tests/unit/test_contracts/CMakeLists.txt b/tests/unit/test_contracts/CMakeLists.txt index 8fc0e6e8a8..3728039199 100644 --- a/tests/unit/test_contracts/CMakeLists.txt +++ b/tests/unit/test_contracts/CMakeLists.txt @@ -8,6 +8,7 @@ add_contract(transfer_contract transfer_contract transfer.cpp) add_contract(minimal_tests minimal_tests minimal_tests.cpp) add_contract(crypto_primitives_tests crypto_primitives_tests crypto_primitives_tests.cpp) add_contract(bls_primitives_tests bls_primitives_tests bls_primitives_tests.cpp) +add_contract(set_finalizers_tests set_finalizers_tests set_finalizers_tests.cpp) add_contract(get_code_hash_tests get_code_hash_write get_code_hash_write.cpp) add_contract(get_code_hash_tests get_code_hash_read get_code_hash_read.cpp) add_contract(name_pk_tests name_pk_tests name_pk_tests.cpp) diff --git a/tests/unit/test_contracts/capi/privileged.c b/tests/unit/test_contracts/capi/privileged.c index e4ea864c52..3bc040cf50 100644 --- a/tests/unit/test_contracts/capi/privileged.c +++ b/tests/unit/test_contracts/capi/privileged.c @@ -11,4 +11,5 @@ void test_privileged( void ) { set_blockchain_parameters_packed(NULL, 0); get_blockchain_parameters_packed(NULL, 0); preactivate_feature(NULL); + set_finalizers(NULL, 0); } diff --git a/tests/unit/test_contracts/set_finalizers_tests.cpp b/tests/unit/test_contracts/set_finalizers_tests.cpp new file mode 100644 index 0000000000..32c4982884 --- /dev/null +++ b/tests/unit/test_contracts/set_finalizers_tests.cpp @@ -0,0 +1,12 @@ +#include +#include + +class [[eosio::contract]] set_finalizers_tests : public eosio::contract{ +public: + using contract::contract; + + [[eosio::action]] + void setfinal(const eosio::abi_finalizer_set& fin_set) { + eosio::set_finalizers(fin_set); + } +}; \ No newline at end of file diff --git a/tools/include/eosio/gen.hpp b/tools/include/eosio/gen.hpp index 3637e74fea..6a6a7bd8c5 100644 --- a/tools/include/eosio/gen.hpp +++ b/tools/include/eosio/gen.hpp @@ -895,7 +895,8 @@ struct generation_utils { "db_idx_long_double_remove", "send_deferred", "send_inline", - "send_context_free_inline" + "send_context_free_inline", + "set_finalizers" }; return write_host_funcs.count(func_decl->getNameInfo().getAsString()) >= 1; From 6f61e695547e4646ef36b072339b973c62133578 Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Wed, 6 Sep 2023 16:53:26 -0400 Subject: [PATCH 02/18] leap main -> hotstuff_integration --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1ab9eedf7c..d22916152a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -74,7 +74,7 @@ jobs: owner: AntelopeIO repo: leap file: 'leap-dev.*(x86_64|amd64).deb' - target: main + target: hotstuff_integration artifact-name: leap-dev-ubuntu20-amd64 container-package: experimental-binaries token: ${{github.token}} From 5a0664705c47420b1ba1131bd62970295625aed3 Mon Sep 17 00:00:00 2001 From: Peter Oschwald Date: Tue, 5 Sep 2023 17:17:13 -0500 Subject: [PATCH 03/18] Make leap-dev download target configurable. Use defaults.json to specify default location/target to attempt to downlaod the leap-dev package from. Allow dynamic configuration through workflow_dispatch input in github. --- .cicd/defaults.json | 6 ++++++ .github/workflows/build.yaml | 40 ++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .cicd/defaults.json diff --git a/.cicd/defaults.json b/.cicd/defaults.json new file mode 100644 index 0000000000..5aadcc5e12 --- /dev/null +++ b/.cicd/defaults.json @@ -0,0 +1,6 @@ +{ + "leap-dev":{ + "target":"main", + "prerelease":false + } + } \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d22916152a..9df3a3ff40 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,6 +7,17 @@ on: - "release/*" pull_request: workflow_dispatch: + inputs: + override-leap-dev: + description: Override leap-dev target + type: string + override-leap-dev-prerelease: + type: choice + description: Override leap-dev prelease + options: + - default + - true + - false permissions: packages: write @@ -53,9 +64,33 @@ jobs: push: true tags: ${{fromJSON(needs.d.outputs.p)[matrix.platform].image}} file: ${{fromJSON(needs.d.outputs.p)[matrix.platform].dockerfile}} + + versions: + name: Determine Versions + runs-on: ubuntu-latest + outputs: + leap-dev-target: ${{steps.versions.outputs.leap-dev-target}} + leap-dev-prerelease: ${{steps.versions.outputs.leap-dev-prerelease}} + steps: + - name: Setup versions from input or defaults + id: versions + env: + GH_TOKEN: ${{github.token}} + run: | + DEFAULTS_JSON=$(curl -sSfL $(gh api https://api.github.com/repos/${{github.repository}}/contents/.cicd/defaults.json?ref=${{github.sha}} --jq .download_url)) + echo leap-dev-target=$(echo "$DEFAULTS_JSON" | jq -r '."leap-dev".target') >> $GITHUB_OUTPUT + echo leap-dev-prerelease=$(echo "$DEFAULTS_JSON" | jq -r '."leap-dev".prerelease') >> $GITHUB_OUTPUT + + if [[ "${{inputs.override-leap-dev}}" != "" ]]; then + echo leap-dev-target=${{inputs.override-leap-dev}} >> $GITHUB_OUTPUT + fi + if [[ "${{inputs.override-leap-dev-prerelease}}" == +(true|false) ]]; then + echo leap-dev-prerelease=${{inputs.override-leap-dev-prerelease}} >> $GITHUB_OUTPUT + fi + Build: name: Build & Test - needs: [d, build-platforms] + needs: [d, build-platforms, versions] if: always() && needs.d.result == 'success' && (needs.build-platforms.result == 'success' || needs.build-platforms.result == 'skipped') strategy: fail-fast: false @@ -69,12 +104,13 @@ jobs: submodules: recursive - name: Download leap-dev.deb (Ubuntu 20 only) if: matrix.platform == 'ubuntu20' - uses: AntelopeIO/asset-artifact-download-action@v2 + uses: AntelopeIO/asset-artifact-download-action@v3 with: owner: AntelopeIO repo: leap file: 'leap-dev.*(x86_64|amd64).deb' target: hotstuff_integration + prereleases: ${{fromJSON(needs.versions.outputs.leap-dev-prerelease)}} artifact-name: leap-dev-ubuntu20-amd64 container-package: experimental-binaries token: ${{github.token}} From 492d92373ec2c81a9e92058b337531afce217761 Mon Sep 17 00:00:00 2001 From: Peter Oschwald Date: Tue, 5 Sep 2023 18:49:39 -0500 Subject: [PATCH 04/18] Remove unneeded token with v3. --- .github/workflows/build.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9df3a3ff40..59e18c4090 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -113,7 +113,6 @@ jobs: prereleases: ${{fromJSON(needs.versions.outputs.leap-dev-prerelease)}} artifact-name: leap-dev-ubuntu20-amd64 container-package: experimental-binaries - token: ${{github.token}} - name: Install leap-dev.deb (Ubuntu 20 only) if: matrix.platform == 'ubuntu20' run: | From 409e5b2f31276b29f8c111fb218bd8a09bb07359 Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Thu, 7 Sep 2023 14:01:17 -0400 Subject: [PATCH 05/18] correct leap-dev branch --- .cicd/defaults.json | 2 +- .github/workflows/build.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.cicd/defaults.json b/.cicd/defaults.json index 5aadcc5e12..49400aa35c 100644 --- a/.cicd/defaults.json +++ b/.cicd/defaults.json @@ -1,6 +1,6 @@ { "leap-dev":{ - "target":"main", + "target":"hotstuff_integration", "prerelease":false } } \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 59e18c4090..7f70ff46a8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -109,7 +109,7 @@ jobs: owner: AntelopeIO repo: leap file: 'leap-dev.*(x86_64|amd64).deb' - target: hotstuff_integration + target: '${{needs.versions.outputs.leap-dev-target}}' prereleases: ${{fromJSON(needs.versions.outputs.leap-dev-prerelease)}} artifact-name: leap-dev-ubuntu20-amd64 container-package: experimental-binaries From 17b6b4dcc9786db43f0cf8b03a302766b4c08344 Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Thu, 7 Sep 2023 16:13:18 -0400 Subject: [PATCH 06/18] fix after leap branch update --- tests/integration/set_finalizers_tests.cpp | 44 +++++++--------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index 48ca8a97e7..ce30b48dcf 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -6,6 +6,12 @@ #include +using namespace eosio; +using namespace eosio::testing; +using namespace fc; + +using mvo = fc::mutable_variant_object; + namespace eosio::chain { struct finalizer_authority { @@ -15,21 +21,8 @@ struct finalizer_authority { }; -struct finalizer_set { - - uint32_t generation = 0; ///< sequentially incrementing version number - uint64_t fthreshold = 0; ///< vote fweight threshold to finalize blocks - std::vector finalizers; ///< Instant Finality voter set -}; - } // eosio::chain -using namespace eosio; -using namespace eosio::testing; -using namespace fc; - -using mvo = fc::mutable_variant_object; - BOOST_AUTO_TEST_SUITE(set_finalizers_tests) BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { @@ -39,31 +32,21 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { set_code( config::system_account_name, contracts::set_finalizers_test_wasm() ); set_abi( config::system_account_name, contracts::set_finalizers_test_abi().data() ); - produce_blocks(); - - - BOOST_ASSERT( control->get_finalizers().finalizers.empty() ); + signed_block_ptr cur_block = produce_block(); + std::optional ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); + BOOST_ASSERT(!ext); const std::vector G1 = {0x16, 0x0c, 0x53, 0xfd, 0x90, 0x87, 0xb3, 0x5c, 0xf5, 0xff, 0x76, 0x99, 0x67, 0xfc, 0x17, 0x78, 0xc1, 0xa1, 0x3b, 0x14, 0xc7, 0x95, 0x4f, 0x15, 0x47, 0xe7, 0xd0, 0xf3, 0xcd, 0x6a, 0xae, 0xf0, 0x40, 0xf4, 0xdb, 0x21, 0xcc, 0x6e, 0xce, 0xed, 0x75, 0xfb, 0x0b, 0x9e, 0x41, 0x77, 0x01, 0x12, 0x3a, 0x88, 0x18, 0xf3, 0x2a, 0x6c, 0x52, 0xff, 0x70, 0x02, 0x3b, 0x38, 0xe4, 0x9c, 0x89, 0x92, 0x55, 0xd0, 0xa9, 0x9f, 0x8d, 0x73, 0xd7, 0x89, 0x2a, 0xc1, 0x44, 0xa3, 0x5b, 0xf3, 0xca, 0x12, 0x17, 0x53, 0x4b, 0x96, 0x76, 0x1b, 0xff, 0x3c, 0x30, 0x44, 0x77, 0xe9, 0xed, 0xd2, 0x44, 0x0e, 0xfd, 0xff, 0x02, 0x00, 0x00, 0x00, 0x09, 0x76, 0x02, 0x00, 0x0c, 0xc4, 0x0b, 0x00, 0xf4, 0xeb, 0xba, 0x58, 0xc7, 0x53, 0x57, 0x98, 0x48, 0x5f, 0x45, 0x57, 0x52, 0x70, 0x53, 0x58, 0xce, 0x77, 0x6d, 0xec, 0x56, 0xa2, 0x97, 0x1a, 0x07, 0x5c, 0x93, 0xe4, 0x80, 0xfa, 0xc3, 0x5e, 0xf6, 0x15}; - // fin_set should be the following struct: - // struct abi_finalizer_authority { - // std::string description; - // uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold - // std::vector public_key_g1_jacobian; // Jacobian little endian - // }; - // struct abi_finalizer_set { - // uint64_t fthreshold = 0; - // std::vector finalizers; - // }; + push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() ("fin_set", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") ("fweight", 1) ("public_key_g1_jacobian", *reinterpret_cast*>(&G1))}))); - produce_blocks(); - - BOOST_ASSERT( control->get_finalizers().finalizers.size() == 1 ); + cur_block = produce_block(); + ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); + BOOST_ASSERT(ext && std::get(*ext).finalizers.size() == 1 ); // testing wrong public key size BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() @@ -72,7 +55,6 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { ("description", "test_desc") ("fweight", 1) ("public_key_g1_jacobian", std::vector{'a', 'b', 'c'})}))), fc::exception); - BOOST_ASSERT( control->get_finalizers().finalizers.size() == 1 ); } FC_LOG_AND_RETHROW() From 3e233826c037f841e5276285ed096dbec295fa0e Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Mon, 11 Sep 2023 17:30:39 -0400 Subject: [PATCH 07/18] partialy #218 review concerns addressed --- libraries/eosiolib/capi/eosio/privileged.h | 1 + .../contracts/eosio/finalizer_set.hpp | 6 ++-- .../eosiolib/core/eosio/crypto_bls_ext.hpp | 15 +++++---- tests/integration/set_finalizers_tests.cpp | 32 +++++++++++++++---- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libraries/eosiolib/capi/eosio/privileged.h b/libraries/eosiolib/capi/eosio/privileged.h index 7c909c6a12..edd3dd9047 100644 --- a/libraries/eosiolib/capi/eosio/privileged.h +++ b/libraries/eosiolib/capi/eosio/privileged.h @@ -129,6 +129,7 @@ void preactivate_feature( const struct capi_checksum256* feature_digest ); * @param data - pointer finalizer_set object packed as bytes * @param len - size of packed finalazer_set object * @pre `data` is a valid pointer to a range of memory at least `len` bytes long that contains packed abi_finalizer_set data + * abi_finalizer_set structure is defined in finalizer_set.hpp */ __attribute__((eosio_wasm_import)) void set_finalizers( const char* data, uint32_t len ); diff --git a/libraries/eosiolib/contracts/eosio/finalizer_set.hpp b/libraries/eosiolib/contracts/eosio/finalizer_set.hpp index a81b6c4aaf..450d85e3cc 100644 --- a/libraries/eosiolib/contracts/eosio/finalizer_set.hpp +++ b/libraries/eosiolib/contracts/eosio/finalizer_set.hpp @@ -18,9 +18,9 @@ namespace eosio { struct abi_finalizer_authority { std::string description; uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold - std::vector public_key_g1_jacobian; // Jacobian little endian + std::vector public_key_g1_affine_le; // Affine little endian - EOSLIB_SERIALIZE(abi_finalizer_authority, (description)(fweight)(public_key_g1_jacobian)); + EOSLIB_SERIALIZE(abi_finalizer_authority, (description)(fweight)(public_key_g1_affine_le)); }; struct abi_finalizer_set { uint64_t fthreshold = 0; @@ -31,7 +31,7 @@ namespace eosio { void set_finalizers( const abi_finalizer_set& fin_set ) { for (const auto& finalizer : fin_set.finalizers) - eosio::check(finalizer.public_key_g1_jacobian.size() == sizeof(bls_g1), "public key has a wrong size" ); + eosio::check(finalizer.public_key_g1_affine_le.size() == sizeof(bls_g1_affine), "public key has a wrong size" ); auto packed = eosio::pack(fin_set); internal_use_do_not_use::set_finalizers(packed.data(), packed.size()); } diff --git a/libraries/eosiolib/core/eosio/crypto_bls_ext.hpp b/libraries/eosiolib/core/eosio/crypto_bls_ext.hpp index 7a62b57b1c..613858c397 100644 --- a/libraries/eosiolib/core/eosio/crypto_bls_ext.hpp +++ b/libraries/eosiolib/core/eosio/crypto_bls_ext.hpp @@ -43,13 +43,14 @@ namespace eosio { } } - using bls_scalar = std::array; - using bls_fp = std::array; - using bls_s = std::array; - using bls_fp2 = std::array; - using bls_g1 = std::array; - using bls_g2 = std::array; - using bls_gt = std::array; + using bls_scalar = std::array; + using bls_fp = std::array; + using bls_s = std::array; + using bls_fp2 = std::array; + using bls_g1 = std::array; + using bls_g1_affine = std::array; + using bls_g2 = std::array; + using bls_gt = std::array; int32_t bls_g1_add(const bls_g1& op1, const bls_g1& op2, bls_g1& res) { return internal_use_do_not_use::bls_g1_add( diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index ce30b48dcf..69c8a659fa 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -34,19 +34,39 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { signed_block_ptr cur_block = produce_block(); std::optional ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); - BOOST_ASSERT(!ext); - - const std::vector G1 = {0x16, 0x0c, 0x53, 0xfd, 0x90, 0x87, 0xb3, 0x5c, 0xf5, 0xff, 0x76, 0x99, 0x67, 0xfc, 0x17, 0x78, 0xc1, 0xa1, 0x3b, 0x14, 0xc7, 0x95, 0x4f, 0x15, 0x47, 0xe7, 0xd0, 0xf3, 0xcd, 0x6a, 0xae, 0xf0, 0x40, 0xf4, 0xdb, 0x21, 0xcc, 0x6e, 0xce, 0xed, 0x75, 0xfb, 0x0b, 0x9e, 0x41, 0x77, 0x01, 0x12, 0x3a, 0x88, 0x18, 0xf3, 0x2a, 0x6c, 0x52, 0xff, 0x70, 0x02, 0x3b, 0x38, 0xe4, 0x9c, 0x89, 0x92, 0x55, 0xd0, 0xa9, 0x9f, 0x8d, 0x73, 0xd7, 0x89, 0x2a, 0xc1, 0x44, 0xa3, 0x5b, 0xf3, 0xca, 0x12, 0x17, 0x53, 0x4b, 0x96, 0x76, 0x1b, 0xff, 0x3c, 0x30, 0x44, 0x77, 0xe9, 0xed, 0xd2, 0x44, 0x0e, 0xfd, 0xff, 0x02, 0x00, 0x00, 0x00, 0x09, 0x76, 0x02, 0x00, 0x0c, 0xc4, 0x0b, 0x00, 0xf4, 0xeb, 0xba, 0x58, 0xc7, 0x53, 0x57, 0x98, 0x48, 0x5f, 0x45, 0x57, 0x52, 0x70, 0x53, 0x58, 0xce, 0x77, 0x6d, 0xec, 0x56, 0xa2, 0x97, 0x1a, 0x07, 0x5c, 0x93, 0xe4, 0x80, 0xfa, 0xc3, 0x5e, 0xf6, 0x15}; + BOOST_CHECK(!ext); + + const std::vector G1 = {0x16, 0x0c, 0x53, 0xfd, 0x90, 0x87, 0xb3, 0x5c, + 0xf5, 0xff, 0x76, 0x99, 0x67, 0xfc, 0x17, 0x78, + 0xc1, 0xa1, 0x3b, 0x14, 0xc7, 0x95, 0x4f, 0x15, + 0x47, 0xe7, 0xd0, 0xf3, 0xcd, 0x6a, 0xae, 0xf0, + 0x40, 0xf4, 0xdb, 0x21, 0xcc, 0x6e, 0xce, 0xed, + 0x75, 0xfb, 0x0b, 0x9e, 0x41, 0x77, 0x01, 0x12, + 0x3a, 0x88, 0x18, 0xf3, 0x2a, 0x6c, 0x52, 0xff, + 0x70, 0x02, 0x3b, 0x38, 0xe4, 0x9c, 0x89, 0x92, + 0x55, 0xd0, 0xa9, 0x9f, 0x8d, 0x73, 0xd7, 0x89, + 0x2a, 0xc1, 0x44, 0xa3, 0x5b, 0xf3, 0xca, 0x12, + 0x17, 0x53, 0x4b, 0x96, 0x76, 0x1b, 0xff, 0x3c, + 0x30, 0x44, 0x77, 0xe9, 0xed, 0xd2, 0x44, 0x0e, + 0xfd, 0xff, 0x02, 0x00, 0x00, 0x00, 0x09, 0x76, + 0x02, 0x00, 0x0c, 0xc4, 0x0b, 0x00, 0xf4, 0xeb, + 0xba, 0x58, 0xc7, 0x53, 0x57, 0x98, 0x48, 0x5f, + 0x45, 0x57, 0x52, 0x70, 0x53, 0x58, 0xce, 0x77, + 0x6d, 0xec, 0x56, 0xa2, 0x97, 0x1a, 0x07, 0x5c, + 0x93, 0xe4, 0x80, 0xfa, 0xc3, 0x5e, 0xf6, 0x15}; // 18x8 = 144 bytes push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() ("fin_set", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") ("fweight", 1) - ("public_key_g1_jacobian", *reinterpret_cast*>(&G1))}))); + ("public_key_g1_affine_le", *reinterpret_cast*>(&G1))}))); cur_block = produce_block(); ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); - BOOST_ASSERT(ext && std::get(*ext).finalizers.size() == 1 ); + BOOST_CHECK(ext); + auto finalizers = std::get(*ext).finalizers; + BOOST_CHECK(finalizers.size() == 1 ); + BOOST_CHECK(finalizers[0].public_key == *reinterpret_cast*>(G1.data()) ); // testing wrong public key size BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() @@ -54,7 +74,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { ("finalizers", std::vector{mvo() ("description", "test_desc") ("fweight", 1) - ("public_key_g1_jacobian", std::vector{'a', 'b', 'c'})}))), fc::exception); + ("public_key_g1_affine_le", std::vector{'a', 'b', 'c'})}))), fc::exception); } FC_LOG_AND_RETHROW() From 1dc5b7d8d6aa510a0e2849c4e72e3ba88b704914 Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Thu, 14 Sep 2023 16:43:51 -0400 Subject: [PATCH 08/18] key type switched to affine --- tests/integration/set_finalizers_tests.cpp | 36 +++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index 69c8a659fa..6d42e5118e 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -17,7 +17,7 @@ struct finalizer_authority { std::string description; uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold - std::array public_key; + std::array public_key; }; @@ -36,25 +36,19 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { std::optional ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); BOOST_CHECK(!ext); - const std::vector G1 = {0x16, 0x0c, 0x53, 0xfd, 0x90, 0x87, 0xb3, 0x5c, - 0xf5, 0xff, 0x76, 0x99, 0x67, 0xfc, 0x17, 0x78, - 0xc1, 0xa1, 0x3b, 0x14, 0xc7, 0x95, 0x4f, 0x15, - 0x47, 0xe7, 0xd0, 0xf3, 0xcd, 0x6a, 0xae, 0xf0, - 0x40, 0xf4, 0xdb, 0x21, 0xcc, 0x6e, 0xce, 0xed, - 0x75, 0xfb, 0x0b, 0x9e, 0x41, 0x77, 0x01, 0x12, - 0x3a, 0x88, 0x18, 0xf3, 0x2a, 0x6c, 0x52, 0xff, - 0x70, 0x02, 0x3b, 0x38, 0xe4, 0x9c, 0x89, 0x92, - 0x55, 0xd0, 0xa9, 0x9f, 0x8d, 0x73, 0xd7, 0x89, - 0x2a, 0xc1, 0x44, 0xa3, 0x5b, 0xf3, 0xca, 0x12, - 0x17, 0x53, 0x4b, 0x96, 0x76, 0x1b, 0xff, 0x3c, - 0x30, 0x44, 0x77, 0xe9, 0xed, 0xd2, 0x44, 0x0e, - 0xfd, 0xff, 0x02, 0x00, 0x00, 0x00, 0x09, 0x76, - 0x02, 0x00, 0x0c, 0xc4, 0x0b, 0x00, 0xf4, 0xeb, - 0xba, 0x58, 0xc7, 0x53, 0x57, 0x98, 0x48, 0x5f, - 0x45, 0x57, 0x52, 0x70, 0x53, 0x58, 0xce, 0x77, - 0x6d, 0xec, 0x56, 0xa2, 0x97, 0x1a, 0x07, 0x5c, - 0x93, 0xe4, 0x80, 0xfa, 0xc3, 0x5e, 0xf6, 0x15}; // 18x8 = 144 bytes - + const std::vector G1 = {0x22, 0x0e, 0xf5, 0xc4, 0x9c, 0x18, 0x68, 0xe8, + 0x5b, 0x82, 0x65, 0x8d, 0xf9, 0x76, 0x6f, 0xc2, + 0xce, 0xe4, 0xbd, 0x0b, 0x5d, 0x98, 0x80, 0xd4, + 0xcd, 0xee, 0x91, 0x39, 0xed, 0xd3, 0xc4, 0xeb, + 0xda, 0xe4, 0x07, 0x4f, 0x1d, 0x3d, 0xb3, 0xf3, + 0xc9, 0x21, 0x39, 0x62, 0x94, 0x2e, 0xef, 0x09, + 0x1b, 0x00, 0xd9, 0xf2, 0xa9, 0xb8, 0x37, 0x01, + 0x5c, 0x8d, 0xbe, 0x50, 0x7f, 0x24, 0x2a, 0xee, + 0x45, 0x92, 0x72, 0x58, 0x9b, 0x6b, 0x29, 0x73, + 0xbc, 0xf3, 0x3e, 0xb4, 0x60, 0x87, 0x22, 0xc7, + 0x0c, 0x1a, 0xc3, 0xd1, 0xad, 0xe4, 0x0c, 0x84, + 0x5b, 0x9e, 0x15, 0xea, 0x63, 0x80, 0x08, 0x0a}; // 12x8 = 96 bytes + push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() ("fin_set", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() @@ -66,7 +60,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { BOOST_CHECK(ext); auto finalizers = std::get(*ext).finalizers; BOOST_CHECK(finalizers.size() == 1 ); - BOOST_CHECK(finalizers[0].public_key == *reinterpret_cast*>(G1.data()) ); + BOOST_CHECK(finalizers[0].description == "test_desc" ); // testing wrong public key size BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() From 8d6265dd983b7303fc7e0136a501ffc69769d3b5 Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Fri, 15 Sep 2023 19:44:46 -0400 Subject: [PATCH 09/18] use abi_serializer instead of structure definition --- tests/integration/set_finalizers_tests.cpp | 31 ++++++++-------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index 6d42e5118e..81fdebf421 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -12,17 +12,6 @@ using namespace fc; using mvo = fc::mutable_variant_object; -namespace eosio::chain { -struct finalizer_authority { - - std::string description; - uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold - std::array public_key; - -}; - -} // eosio::chain - BOOST_AUTO_TEST_SUITE(set_finalizers_tests) BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { @@ -32,9 +21,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { set_code( config::system_account_name, contracts::set_finalizers_test_wasm() ); set_abi( config::system_account_name, contracts::set_finalizers_test_abi().data() ); - signed_block_ptr cur_block = produce_block(); - std::optional ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); - BOOST_CHECK(!ext); + produce_block(); const std::vector G1 = {0x22, 0x0e, 0xf5, 0xc4, 0x9c, 0x18, 0x68, 0xe8, 0x5b, 0x82, 0x65, 0x8d, 0xf9, 0x76, 0x6f, 0xc2, @@ -55,12 +42,16 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { ("description", "test_desc") ("fweight", 1) ("public_key_g1_affine_le", *reinterpret_cast*>(&G1))}))); - cur_block = produce_block(); - ext = cur_block->extract_header_extension(hs_finalizer_set_extension::extension_id()); - BOOST_CHECK(ext); - auto finalizers = std::get(*ext).finalizers; - BOOST_CHECK(finalizers.size() == 1 ); - BOOST_CHECK(finalizers[0].description == "test_desc" ); + signed_block_ptr cur_block = produce_block(); + fc::variant pretty_output; + abi_serializer::to_variant( *cur_block, pretty_output, get_resolver(), fc::microseconds::maximum() ); + BOOST_ASSERT(pretty_output.get_object().contains("proposed_finalizer_set")); + BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["generation"] == 1); + BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["fthreshold"] == 1); + BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["finalizers"].size() == 1); + BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["finalizers"][size_t(0)]["description"] == "test_desc"); + BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["finalizers"][size_t(0)]["fweight"] == 1); + //TODO: add key check here after base64 support will be added // testing wrong public key size BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() From 290e80681a6a64ac1e8501ae4b2e1ee4e32ad3a7 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 7 Dec 2023 11:01:42 -0500 Subject: [PATCH 10/18] fix a compile error due to type alias bls_g1_affine changed to bls_g1 --- libraries/eosiolib/contracts/eosio/finalizer_set.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/eosiolib/contracts/eosio/finalizer_set.hpp b/libraries/eosiolib/contracts/eosio/finalizer_set.hpp index 450d85e3cc..e60f5450ec 100644 --- a/libraries/eosiolib/contracts/eosio/finalizer_set.hpp +++ b/libraries/eosiolib/contracts/eosio/finalizer_set.hpp @@ -31,9 +31,9 @@ namespace eosio { void set_finalizers( const abi_finalizer_set& fin_set ) { for (const auto& finalizer : fin_set.finalizers) - eosio::check(finalizer.public_key_g1_affine_le.size() == sizeof(bls_g1_affine), "public key has a wrong size" ); + eosio::check(finalizer.public_key_g1_affine_le.size() == sizeof(bls_g1), "public key has a wrong size" ); auto packed = eosio::pack(fin_set); internal_use_do_not_use::set_finalizers(packed.data(), packed.size()); } -} //eosio \ No newline at end of file +} //eosio From 5e504d3e620c86424d3ccc8ee7e5770ebc053381 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 7 Dec 2023 16:04:19 -0500 Subject: [PATCH 11/18] Fix set_finalizers_tests * Use BOOST_REQUIRE_EQUAL and BOOST_REQUIRE; existing BOOST_ASSERT does not run during tests * Update to Leap changes of proposed_finalizer_set to proposed_finalizer_policy --- tests/integration/set_finalizers_tests.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index 81fdebf421..bb8ab4e229 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -45,12 +45,12 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { signed_block_ptr cur_block = produce_block(); fc::variant pretty_output; abi_serializer::to_variant( *cur_block, pretty_output, get_resolver(), fc::microseconds::maximum() ); - BOOST_ASSERT(pretty_output.get_object().contains("proposed_finalizer_set")); - BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["generation"] == 1); - BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["fthreshold"] == 1); - BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["finalizers"].size() == 1); - BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["finalizers"][size_t(0)]["description"] == "test_desc"); - BOOST_ASSERT(pretty_output["proposed_finalizer_set"]["finalizers"][size_t(0)]["fweight"] == 1); + BOOST_REQUIRE(pretty_output.get_object().contains("proposed_finalizer_policy")); + BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["generation"], 1); + BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["fthreshold"], 1); + BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"].size(), 1u); + BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["description"], "test_desc"); + BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["fweight"], 1); //TODO: add key check here after base64 support will be added // testing wrong public key size @@ -63,4 +63,4 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { } FC_LOG_AND_RETHROW() -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() From cb73eae8450b6c4cceed2aee1db6cd6740f1f2c9 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 7 Dec 2023 16:33:09 -0500 Subject: [PATCH 12/18] Update set_finalizers_tests * Fixed breaking strict-aliasing rules * Added public key check --- tests/integration/set_finalizers_tests.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index bb8ab4e229..871e352809 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -23,25 +23,12 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { produce_block(); - const std::vector G1 = {0x22, 0x0e, 0xf5, 0xc4, 0x9c, 0x18, 0x68, 0xe8, - 0x5b, 0x82, 0x65, 0x8d, 0xf9, 0x76, 0x6f, 0xc2, - 0xce, 0xe4, 0xbd, 0x0b, 0x5d, 0x98, 0x80, 0xd4, - 0xcd, 0xee, 0x91, 0x39, 0xed, 0xd3, 0xc4, 0xeb, - 0xda, 0xe4, 0x07, 0x4f, 0x1d, 0x3d, 0xb3, 0xf3, - 0xc9, 0x21, 0x39, 0x62, 0x94, 0x2e, 0xef, 0x09, - 0x1b, 0x00, 0xd9, 0xf2, 0xa9, 0xb8, 0x37, 0x01, - 0x5c, 0x8d, 0xbe, 0x50, 0x7f, 0x24, 0x2a, 0xee, - 0x45, 0x92, 0x72, 0x58, 0x9b, 0x6b, 0x29, 0x73, - 0xbc, 0xf3, 0x3e, 0xb4, 0x60, 0x87, 0x22, 0xc7, - 0x0c, 0x1a, 0xc3, 0xd1, 0xad, 0xe4, 0x0c, 0x84, - 0x5b, 0x9e, 0x15, 0xea, 0x63, 0x80, 0x08, 0x0a}; // 12x8 = 96 bytes - push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() ("fin_set", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") ("fweight", 1) - ("public_key_g1_affine_le", *reinterpret_cast*>(&G1))}))); + ("public_key_g1_affine_le", "220ef5c49c1868e85b82658df9766fc2cee4bd0b5d9880d4cdee9139edd3c4ebdae4074f1d3db3f3c9213962942eef091b00d9f2a9b837015c8dbe507f242aee459272589b6b2973bcf33eb4608722c70c1ac3d1ade40c845b9e15ea6380080a")}))); signed_block_ptr cur_block = produce_block(); fc::variant pretty_output; abi_serializer::to_variant( *cur_block, pretty_output, get_resolver(), fc::microseconds::maximum() ); @@ -51,7 +38,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"].size(), 1u); BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["description"], "test_desc"); BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["fweight"], 1); - //TODO: add key check here after base64 support will be added + BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["public_key"], "PUB_BLS_Ig71xJwYaOhbgmWN+XZvws7kvQtdmIDUze6ROe3TxOva5AdPHT2z88khOWKULu8JGwDZ8qm4NwFcjb5QfyQq7kWSclibaylzvPM+tGCHIscMGsPRreQMhFueFepjgAgKXjOb8g=="); // testing wrong public key size BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() From 30786faac59a5a64b3405ce7c762d12acd2cc121 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 7 Dec 2023 16:54:17 -0500 Subject: [PATCH 13/18] rename finalizer_set.hpp -> finalizer_policy.hpp --- .../contracts/eosio/{finalizer_set.hpp => finalizer_policy.hpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libraries/eosiolib/contracts/eosio/{finalizer_set.hpp => finalizer_policy.hpp} (100%) diff --git a/libraries/eosiolib/contracts/eosio/finalizer_set.hpp b/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp similarity index 100% rename from libraries/eosiolib/contracts/eosio/finalizer_set.hpp rename to libraries/eosiolib/contracts/eosio/finalizer_policy.hpp From 8ab3b6b5b3788ad12d944f16fc45b759a13ce855 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 7 Dec 2023 20:21:39 -0500 Subject: [PATCH 14/18] update set_finalizers_tests.cpp to include finalizer_policy.hpp --- tests/unit/test_contracts/set_finalizers_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_contracts/set_finalizers_tests.cpp b/tests/unit/test_contracts/set_finalizers_tests.cpp index 32c4982884..ad0895b8a1 100644 --- a/tests/unit/test_contracts/set_finalizers_tests.cpp +++ b/tests/unit/test_contracts/set_finalizers_tests.cpp @@ -1,5 +1,5 @@ #include -#include +#include class [[eosio::contract]] set_finalizers_tests : public eosio::contract{ public: @@ -9,4 +9,4 @@ class [[eosio::contract]] set_finalizers_tests : public eosio::contract{ void setfinal(const eosio::abi_finalizer_set& fin_set) { eosio::set_finalizers(fin_set); } -}; \ No newline at end of file +}; From f43d6efc7984ca7253eeecd2499fb4e6428a4add Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 7 Dec 2023 21:11:09 -0500 Subject: [PATCH 15/18] change abi_finalizer_set to abi_finalizer_policy --- .../eosiolib/contracts/eosio/finalizer_policy.hpp | 10 +++++----- tests/unit/test_contracts/set_finalizers_tests.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp b/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp index e60f5450ec..69f9e5f717 100644 --- a/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp +++ b/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp @@ -22,17 +22,17 @@ namespace eosio { EOSLIB_SERIALIZE(abi_finalizer_authority, (description)(fweight)(public_key_g1_affine_le)); }; - struct abi_finalizer_set { + struct abi_finalizer_policy { uint64_t fthreshold = 0; std::vector finalizers; - EOSLIB_SERIALIZE(abi_finalizer_set, (fthreshold)(finalizers)); + EOSLIB_SERIALIZE(abi_finalizer_policy, (fthreshold)(finalizers)); }; - void set_finalizers( const abi_finalizer_set& fin_set ) { - for (const auto& finalizer : fin_set.finalizers) + void set_finalizers( const abi_finalizer_policy& finalizer_policy ) { + for (const auto& finalizer : finalizer_policy.finalizers) eosio::check(finalizer.public_key_g1_affine_le.size() == sizeof(bls_g1), "public key has a wrong size" ); - auto packed = eosio::pack(fin_set); + auto packed = eosio::pack(finalizer_policy); internal_use_do_not_use::set_finalizers(packed.data(), packed.size()); } diff --git a/tests/unit/test_contracts/set_finalizers_tests.cpp b/tests/unit/test_contracts/set_finalizers_tests.cpp index ad0895b8a1..1b4fb7d8ca 100644 --- a/tests/unit/test_contracts/set_finalizers_tests.cpp +++ b/tests/unit/test_contracts/set_finalizers_tests.cpp @@ -6,7 +6,7 @@ class [[eosio::contract]] set_finalizers_tests : public eosio::contract{ using contract::contract; [[eosio::action]] - void setfinal(const eosio::abi_finalizer_set& fin_set) { - eosio::set_finalizers(fin_set); + void setfinal(const eosio::abi_finalizer_policy& finalizer_policy) { + eosio::set_finalizers(finalizer_policy); } }; From c82af4eb22d5499f0225dad7f3c06d0a68a1847b Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 8 Dec 2023 08:30:44 -0500 Subject: [PATCH 16/18] update tests to use finalizer_policy --- tests/integration/set_finalizers_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/set_finalizers_tests.cpp index 871e352809..82e041f2ce 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/set_finalizers_tests.cpp @@ -24,7 +24,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { produce_block(); push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() - ("fin_set", mvo()("fthreshold", 1) + ("finalizer_policy", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") ("fweight", 1) @@ -42,7 +42,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { // testing wrong public key size BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() - ("fin_set", mvo()("fthreshold", 1) + ("finalizer_policy", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") ("fweight", 1) From a532a6dec4d54624b2a7c31705930e295c3385bb Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 8 Dec 2023 21:29:56 -0500 Subject: [PATCH 17/18] rename files and tests from set_finalizers to instant_finality --- .../eosiolib/capi/eosio/instant_finality.h | 26 +++++++++++++++++++ libraries/eosiolib/capi/eosio/privileged.h | 11 -------- ...alizer_policy.hpp => instant_finality.hpp} | 15 +++++++++-- .../native/native/eosio/intrinsics_def.hpp | 1 + tests/integration/contracts.hpp.in | 4 +-- ...s_tests.cpp => instant_finality_tests.cpp} | 12 ++++----- tests/unit/test_contracts/CMakeLists.txt | 2 +- tests/unit/test_contracts/capi/privileged.c | 1 + .../test_contracts/instant_finality_tests.cpp | 12 +++++++++ .../test_contracts/set_finalizers_tests.cpp | 12 --------- 10 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 libraries/eosiolib/capi/eosio/instant_finality.h rename libraries/eosiolib/contracts/eosio/{finalizer_policy.hpp => instant_finality.hpp} (78%) rename tests/integration/{set_finalizers_tests.cpp => instant_finality_tests.cpp} (85%) create mode 100644 tests/unit/test_contracts/instant_finality_tests.cpp delete mode 100644 tests/unit/test_contracts/set_finalizers_tests.cpp diff --git a/libraries/eosiolib/capi/eosio/instant_finality.h b/libraries/eosiolib/capi/eosio/instant_finality.h new file mode 100644 index 0000000000..9c6494514c --- /dev/null +++ b/libraries/eosiolib/capi/eosio/instant_finality.h @@ -0,0 +1,26 @@ +#pragma once +#include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup instant_finality_c Instant_finality C API + * @ingroup c_api + * @brief Defines %C Instant_finality API + */ + +/** + * Submits a finalizer policy change to Instant Finality + * + * @param data - pointer finalizer_set object packed as bytes + * @param len - size of packed finalazer_set object + * @pre `data` is a valid pointer to a range of memory at least `len` bytes long that contains packed abi_finalizer_policy data + * abi_finalizer_policy structure is defined in instant_finality.hpp + */ +__attribute__((eosio_wasm_import)) +void set_finalizers( const char* data, uint32_t len ); + +#ifdef __cplusplus +} +#endif diff --git a/libraries/eosiolib/capi/eosio/privileged.h b/libraries/eosiolib/capi/eosio/privileged.h index edd3dd9047..8628c00769 100644 --- a/libraries/eosiolib/capi/eosio/privileged.h +++ b/libraries/eosiolib/capi/eosio/privileged.h @@ -123,17 +123,6 @@ void set_kv_parameters_packed( const char* data, uint32_t datalen ); __attribute__((eosio_wasm_import)) void preactivate_feature( const struct capi_checksum256* feature_digest ); -/** - * Submits a finalizer set change to Hotstuff - * - * @param data - pointer finalizer_set object packed as bytes - * @param len - size of packed finalazer_set object - * @pre `data` is a valid pointer to a range of memory at least `len` bytes long that contains packed abi_finalizer_set data - * abi_finalizer_set structure is defined in finalizer_set.hpp - */ -__attribute__((eosio_wasm_import)) -void set_finalizers( const char* data, uint32_t len ); - #ifdef __cplusplus } #endif diff --git a/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp b/libraries/eosiolib/contracts/eosio/instant_finality.hpp similarity index 78% rename from libraries/eosiolib/contracts/eosio/finalizer_policy.hpp rename to libraries/eosiolib/contracts/eosio/instant_finality.hpp index 69f9e5f717..0976a0ceda 100644 --- a/libraries/eosiolib/contracts/eosio/finalizer_policy.hpp +++ b/libraries/eosiolib/contracts/eosio/instant_finality.hpp @@ -5,7 +5,13 @@ #include #include -#include + +/** + * @defgroup instant_finality Instant_finality + * @ingroup instant_finality + * @ingroup contracts + * @brief Defines C++ Instant Finality API + */ namespace eosio { namespace internal_use_do_not_use { @@ -29,7 +35,12 @@ namespace eosio { EOSLIB_SERIALIZE(abi_finalizer_policy, (fthreshold)(finalizers)); }; - void set_finalizers( const abi_finalizer_policy& finalizer_policy ) { +/** + * Submits a finalizer policy change to Instant Finality + * + * @param finalizer_policy - finalizer policy to be set + */ + inline void set_finalizers( const abi_finalizer_policy& finalizer_policy ) { for (const auto& finalizer : finalizer_policy.finalizers) eosio::check(finalizer.public_key_g1_affine_le.size() == sizeof(bls_g1), "public key has a wrong size" ); auto packed = eosio::pack(finalizer_policy); diff --git a/libraries/native/native/eosio/intrinsics_def.hpp b/libraries/native/native/eosio/intrinsics_def.hpp index e6740fdc87..5121017dda 100644 --- a/libraries/native/native/eosio/intrinsics_def.hpp +++ b/libraries/native/native/eosio/intrinsics_def.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/integration/contracts.hpp.in b/tests/integration/contracts.hpp.in index d8dc4cf017..b4be50e834 100644 --- a/tests/integration/contracts.hpp.in +++ b/tests/integration/contracts.hpp.in @@ -26,8 +26,8 @@ namespace eosio::testing { static std::vector bls_primitives_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/bls_primitives_tests.wasm"); } static std::vector bls_primitives_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/bls_primitives_tests.abi"); } - static std::vector set_finalizers_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/set_finalizers_tests.wasm"); } - static std::vector set_finalizers_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/set_finalizers_tests.abi"); } + static std::vector instant_finality_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/instant_finality_tests.wasm"); } + static std::vector instant_finality_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/instant_finality_tests.abi"); } static std::vector get_code_hash_write_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/get_code_hash_write.wasm"); } static std::vector get_code_hash_write_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/get_code_hash_write.abi"); } diff --git a/tests/integration/set_finalizers_tests.cpp b/tests/integration/instant_finality_tests.cpp similarity index 85% rename from tests/integration/set_finalizers_tests.cpp rename to tests/integration/instant_finality_tests.cpp index 82e041f2ce..009a1c9464 100644 --- a/tests/integration/set_finalizers_tests.cpp +++ b/tests/integration/instant_finality_tests.cpp @@ -12,18 +12,18 @@ using namespace fc; using mvo = fc::mutable_variant_object; -BOOST_AUTO_TEST_SUITE(set_finalizers_tests) +BOOST_AUTO_TEST_SUITE(instant_finality_tests) -BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { +BOOST_FIXTURE_TEST_CASE(instant_finality_test, tester) try { create_accounts( { "test"_n } ); produce_block(); - set_code( config::system_account_name, contracts::set_finalizers_test_wasm() ); - set_abi( config::system_account_name, contracts::set_finalizers_test_abi().data() ); + set_code( config::system_account_name, contracts::instant_finality_test_wasm() ); + set_abi( config::system_account_name, contracts::instant_finality_test_abi().data() ); produce_block(); - push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() + push_action(config::system_account_name, "setfinalizer"_n, "test"_n, mvo() ("finalizer_policy", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") @@ -41,7 +41,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try { BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["public_key"], "PUB_BLS_Ig71xJwYaOhbgmWN+XZvws7kvQtdmIDUze6ROe3TxOva5AdPHT2z88khOWKULu8JGwDZ8qm4NwFcjb5QfyQq7kWSclibaylzvPM+tGCHIscMGsPRreQMhFueFepjgAgKXjOb8g=="); // testing wrong public key size - BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo() + BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinalizer"_n, "test"_n, mvo() ("finalizer_policy", mvo()("fthreshold", 1) ("finalizers", std::vector{mvo() ("description", "test_desc") diff --git a/tests/unit/test_contracts/CMakeLists.txt b/tests/unit/test_contracts/CMakeLists.txt index 3728039199..1cc1107231 100644 --- a/tests/unit/test_contracts/CMakeLists.txt +++ b/tests/unit/test_contracts/CMakeLists.txt @@ -8,7 +8,7 @@ add_contract(transfer_contract transfer_contract transfer.cpp) add_contract(minimal_tests minimal_tests minimal_tests.cpp) add_contract(crypto_primitives_tests crypto_primitives_tests crypto_primitives_tests.cpp) add_contract(bls_primitives_tests bls_primitives_tests bls_primitives_tests.cpp) -add_contract(set_finalizers_tests set_finalizers_tests set_finalizers_tests.cpp) +add_contract(instant_finality_tests instant_finality_tests instant_finality_tests.cpp) add_contract(get_code_hash_tests get_code_hash_write get_code_hash_write.cpp) add_contract(get_code_hash_tests get_code_hash_read get_code_hash_read.cpp) add_contract(name_pk_tests name_pk_tests name_pk_tests.cpp) diff --git a/tests/unit/test_contracts/capi/privileged.c b/tests/unit/test_contracts/capi/privileged.c index 3bc040cf50..e1131c918a 100644 --- a/tests/unit/test_contracts/capi/privileged.c +++ b/tests/unit/test_contracts/capi/privileged.c @@ -1,4 +1,5 @@ #include +#include #include void test_privileged( void ) { diff --git a/tests/unit/test_contracts/instant_finality_tests.cpp b/tests/unit/test_contracts/instant_finality_tests.cpp new file mode 100644 index 0000000000..ca5f1851f4 --- /dev/null +++ b/tests/unit/test_contracts/instant_finality_tests.cpp @@ -0,0 +1,12 @@ +#include +#include + +class [[eosio::contract]] instant_finality_tests : public eosio::contract{ +public: + using contract::contract; + + [[eosio::action]] + void setfinalizer(const eosio::abi_finalizer_policy& finalizer_policy) { + eosio::set_finalizers(finalizer_policy); + } +}; diff --git a/tests/unit/test_contracts/set_finalizers_tests.cpp b/tests/unit/test_contracts/set_finalizers_tests.cpp deleted file mode 100644 index 1b4fb7d8ca..0000000000 --- a/tests/unit/test_contracts/set_finalizers_tests.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -class [[eosio::contract]] set_finalizers_tests : public eosio::contract{ -public: - using contract::contract; - - [[eosio::action]] - void setfinal(const eosio::abi_finalizer_policy& finalizer_policy) { - eosio::set_finalizers(finalizer_policy); - } -}; From 7eeaba0761a36b963517b66a9c521d3790c17e73 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Sun, 10 Dec 2023 09:34:34 -0500 Subject: [PATCH 18/18] change finalazer_set to finalazer_policy in ia couple of comments --- libraries/eosiolib/capi/eosio/instant_finality.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/eosiolib/capi/eosio/instant_finality.h b/libraries/eosiolib/capi/eosio/instant_finality.h index 9c6494514c..1ed3d2c05a 100644 --- a/libraries/eosiolib/capi/eosio/instant_finality.h +++ b/libraries/eosiolib/capi/eosio/instant_finality.h @@ -13,8 +13,8 @@ extern "C" { /** * Submits a finalizer policy change to Instant Finality * - * @param data - pointer finalizer_set object packed as bytes - * @param len - size of packed finalazer_set object + * @param data - pointer finalizer_policy object packed as bytes + * @param len - size of packed finalazer_policy object * @pre `data` is a valid pointer to a range of memory at least `len` bytes long that contains packed abi_finalizer_policy data * abi_finalizer_policy structure is defined in instant_finality.hpp */